-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from thoov/patch-1
Do not blow away existing attributeBindings
- Loading branch information
Showing
1 changed file
with
25 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}) | ||
}); |