This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6
Sam 97eba92a2e BUGFIX: user screen.width cause it will be more correct
BUGFIX: fix deprecation and regression in cloaking
PERF: cache progressWidth super aggresively to avoid reflows
2014-06-02 10:30:16 +10:00

29 lines
874 B
JavaScript

/*global Modernizr:true*/
/**
Initializes the `Discourse.Capabilities` singleton by sniffing out the browser
capabilities.
**/
export default {
name: "sniff-capabilities",
initialize: function() {
var $html = $('html'),
touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1),
caps = Discourse.Capabilities.current();
// Store the touch ability in our capabilities object
caps.set('touch', touch);
$html.addClass(touch ? 'discourse-touch' : 'discourse-no-touch');
// Detect Android
if (navigator) {
var ua = navigator.userAgent;
caps.set('android', ua && ua.indexOf('Android') !== -1);
}
// We consider high res a device with 1280 horizontal pixels. High DPI tablets like
// iPads should report as 1024.
caps.set('highRes', window.screen.width >= 1280);
}
};