Fixing lint errors and mousedown on mobile browsers

1) Fixed a handful of errors caught by the linter.
2) Mobile browsers register a press and hold as a touch event rather
than a regular mouse down event. The code has been updated so that
these touch events will be registered and sent to the mouse down
handler.
This commit is contained in:
Ryan Kraus 2016-01-11 00:33:14 -05:00
parent 073c8cdcd0
commit 0a0f827e3a

View File

@ -73,16 +73,18 @@ export default new Polymer({
supportsVolumeButtons: { supportsVolumeButtons: {
type: Boolean, type: Boolean,
value: false, value: false,
} },
}, },
attached() { attached() {
// This is required to bind a mousedown event in all browsers // This is required to bind a mousedown event in all browsers
// Specifically, Safari does not allow the on-down flag let _this = this;
var _this = this; window.test = this.$.volumeUp;
this.$.volumeUp.onmousedown = function() {_this.handleVolumeUp()}; this.$.volumeUp.onmousedown = function onVolumeUpDown() {_this.handleVolumeUp();};
this.$.volumeDown.onmousedown = function() {_this.handleVolumeDown()}; this.$.volumeUp.ontouchstart = function onVolumeUpDown() {_this.handleVolumeUp();};
this.$.volumeDown.onmousedown = function onVolumeDownDown() {_this.handleVolumeDown();};
this.$.volumeDown.ontouchstart = function onVolumeDownDown() {_this.handleVolumeDown();};
}, },
stateObjChanged(newVal) { stateObjChanged(newVal) {
@ -154,21 +156,21 @@ export default new Polymer({
this.callService('volume_mute', { is_volume_muted: !this.isMuted }); this.callService('volume_mute', { is_volume_muted: !this.isMuted });
}, },
handleVolumeUp(ev) { handleVolumeUp() {
var obj = this.$.volumeUp; let obj = this.$.volumeUp;
this.handleVolumeWorker('volume_up', obj, true); this.handleVolumeWorker('volume_up', obj, true);
}, },
handleVolumeDown(ev) { handleVolumeDown() {
var obj = this.$.volumeDown; let obj = this.$.volumeDown;
this.handleVolumeWorker('volume_down', obj, true); this.handleVolumeWorker('volume_down', obj, true);
}, },
handleVolumeWorker(service, obj, force) { handleVolumeWorker(service, obj, force) {
if (force || (obj != undefined && obj.pointerDown)) { if (force || (obj !== undefined && obj.pointerDown)) {
this.callService(service); this.callService(service);
var _this = this; let _this = this;
setTimeout(function(){ _this.handleVolumeWorker(service, obj, false); }, 500); setTimeout(function callback() {_this.handleVolumeWorker(service, obj, false);}, 500);
} }
}, },