mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Use capabilities
object for browser sniffing
This commit is contained in:
parent
a7f2741674
commit
f734a0731e
2 changed files with 15 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue