Skip to content

Commit

Permalink
Merge pull request #20 from thoov/patch-1
Browse files Browse the repository at this point in the history
Do not blow away existing attributeBindings
  • Loading branch information
runspired committed Sep 14, 2016
2 parents 2d9b4e7 + cded5af commit ef6418f
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions addon/mixins/touch-action.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
import Ember from 'ember';

const {
computed,
Mixin,
String: { htmlSafe }
} = Ember;
const { computed, get, set, String: { htmlSafe } } = Ember;

export default Mixin.create({
const SafeTouchAction = htmlSafe('touch-action: manipulation; -ms-touch-action: manipulation; cursor: pointer;');
const SafeEmptyString = htmlSafe('');

export default Ember.Mixin.create({
init() {
this._super(...arguments);
if (this.tagName) {
this.attributeBindings = ['touchActionStyle:style'];
this.applyStyle = true;
} else {
this.applyStyle = false;

if (this.tagName || this.elementId) {
let newAttributeBindings = [];
const bindings = get(this, 'attributeBindings');

if (Array.isArray(bindings)) {
newAttributeBindings = newAttributeBindings.concat(bindings);
}

newAttributeBindings.push('touchActionStyle:style');
set(this, 'attributeBindings', newAttributeBindings);
}
},

touchActionStyle: computed(function() {
const type = get(this, 'type');
const click = get(this, 'click');
const tagName = get(this, 'tagName');

// we apply if click is present and tagName is present
let applyStyle = this.applyStyle && this.click;

if (!applyStyle) {
// we apply if tagName
const tagName = this.get('tagName');
const type = this.get('type');
let applyStyle = tagName && click;

if (tagName && click) {
let isFocusable = ['button', 'input', 'a', 'textarea'].indexOf(tagName) !== -1;

if (isFocusable) {
if (tagName === 'input') {
isFocusable = ['button', 'submit', 'text', 'file'].indexOf(type) !== -1;
}
if (isFocusable && tagName === 'input') {
isFocusable = ['button', 'submit', 'text', 'file'].indexOf(type) !== -1;
}

applyStyle = isFocusable;
}

return htmlSafe(applyStyle ? 'touch-action: manipulation; -ms-touch-action: manipulation; cursor: pointer;' : '');
return applyStyle ? SafeTouchAction : SafeEmptyString;
})
});

0 comments on commit ef6418f

Please sign in to comment.