Use capabilities object for browser sniffing

This commit is contained in:
Robin Ward 2015-09-28 11:44:37 -04:00
parent a7f2741674
commit f734a0731e
2 changed files with 15 additions and 12 deletions

View file

@ -1,23 +1,24 @@
/*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 {
name: "sniff-capabilities",
initialize: function(container, application) {
var $html = $('html'),
touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1),
caps = Ember.Object.create();
initialize(container, application) {
const $html = $('html'),
touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1),
caps = Ember.Object.create();
// Store the touch ability in our capabilities object
caps.set('touch', touch);
$html.addClass(touch ? 'discourse-touch' : 'discourse-no-touch');
// Detect Android
// Detect Devices
if (navigator) {
var ua = navigator.userAgent;
caps.set('android', ua && ua.indexOf('Android') !== -1);
const ua = navigator.userAgent;
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

View file

@ -36,7 +36,9 @@ export default Ember.View.extend({
// the quote reply widget
//
// 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);
}
@ -70,7 +72,7 @@ export default Ember.View.extend({
// Android is dodgy, touchend often will not fire
// https://code.google.com/p/android/issues/detail?id=19827
if (!navigator.userAgent.match(/Android/)) {
if (!android) {
$(document)
.on('touchstart.quote-button', function(){
view.set('isTouchInProgress', true);