Use `capabilities` object for browser sniffing
This commit is contained in:
parent
a7f2741674
commit
f734a0731e
|
@ -1,23 +1,24 @@
|
||||||
/*global Modernizr:true*/
|
/*global Modernizr:true*/
|
||||||
|
|
||||||
/**
|
// Initializes an object that lets us know about our capabilities.
|
||||||
Initializes an object that lets us know about our capabilities.
|
|
||||||
**/
|
|
||||||
export default {
|
export default {
|
||||||
name: "sniff-capabilities",
|
name: "sniff-capabilities",
|
||||||
initialize: function(container, application) {
|
initialize(container, application) {
|
||||||
var $html = $('html'),
|
const $html = $('html'),
|
||||||
touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1),
|
touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1),
|
||||||
caps = Ember.Object.create();
|
caps = Ember.Object.create();
|
||||||
|
|
||||||
// Store the touch ability in our capabilities object
|
// Store the touch ability in our capabilities object
|
||||||
caps.set('touch', touch);
|
caps.set('touch', touch);
|
||||||
$html.addClass(touch ? 'discourse-touch' : 'discourse-no-touch');
|
$html.addClass(touch ? 'discourse-touch' : 'discourse-no-touch');
|
||||||
|
|
||||||
// Detect Android
|
// Detect Devices
|
||||||
if (navigator) {
|
if (navigator) {
|
||||||
var ua = navigator.userAgent;
|
const ua = navigator.userAgent;
|
||||||
caps.set('android', ua && ua.indexOf('Android') !== -1);
|
if (ua) {
|
||||||
|
caps.set('android', ua.indexOf('Android') !== -1);
|
||||||
|
caps.set('winphone', ua.indexOf('Windows Phone') !== -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We consider high res a device with 1280 horizontal pixels. High DPI tablets like
|
// We consider high res a device with 1280 horizontal pixels. High DPI tablets like
|
||||||
|
|
|
@ -36,7 +36,9 @@ export default Ember.View.extend({
|
||||||
// the quote reply widget
|
// the quote reply widget
|
||||||
//
|
//
|
||||||
// Same hack applied to Android cause it has unreliable touchend
|
// Same hack applied to Android cause it has unreliable touchend
|
||||||
if (navigator.userAgent.match(/Windows Phone/) || navigator.userAgent.match(/Android/)) {
|
const caps = this.capabilities;
|
||||||
|
const android = caps.get('android');
|
||||||
|
if (caps.get('winphone') || android) {
|
||||||
onSelectionChanged = _.debounce(onSelectionChanged, 500);
|
onSelectionChanged = _.debounce(onSelectionChanged, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +72,7 @@ export default Ember.View.extend({
|
||||||
|
|
||||||
// Android is dodgy, touchend often will not fire
|
// Android is dodgy, touchend often will not fire
|
||||||
// https://code.google.com/p/android/issues/detail?id=19827
|
// https://code.google.com/p/android/issues/detail?id=19827
|
||||||
if (!navigator.userAgent.match(/Android/)) {
|
if (!android) {
|
||||||
$(document)
|
$(document)
|
||||||
.on('touchstart.quote-button', function(){
|
.on('touchstart.quote-button', function(){
|
||||||
view.set('isTouchInProgress', true);
|
view.set('isTouchInProgress', true);
|
||||||
|
|
Loading…
Reference in New Issue