diff options
Diffstat (limited to 'html/lib/onyx/source/Item.js')
-rw-r--r-- | html/lib/onyx/source/Item.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/html/lib/onyx/source/Item.js b/html/lib/onyx/source/Item.js new file mode 100644 index 0000000..377fb5b --- /dev/null +++ b/html/lib/onyx/source/Item.js @@ -0,0 +1,60 @@ +/** + A control designed to display a group of stacked items, typically used in + lists. Items are displayed with small guide lines between them; by default, + they are highlighted when tapped. Set *tapHighlight* to false to prevent the + highlighting. + + {kind: "onyx.Item", tapHighlight: false} +*/ +enyo.kind({ + name: "onyx.Item", + classes: "onyx-item", + tapHighlight: true, + handlers: { + onhold: "hold", + onrelease: "release" + }, + //* @public + hold: function(inSender, inEvent) { + if (this.tapHighlight) { + onyx.Item.addFlyweightClass(this.controlParent || this, "onyx-highlight", inEvent); + } + }, + //* @public + release: function(inSender, inEvent) { + if (this.tapHighlight) { + onyx.Item.removeFlyweightClass(this.controlParent || this, "onyx-highlight", inEvent); + } + }, + //* @protected + statics: { + addFlyweightClass: function(inControl, inClass, inEvent, inIndex) { + var flyweight = inEvent.flyweight; + if (flyweight) { + var index = inIndex != undefined ? inIndex : inEvent.index; + flyweight.performOnRow(index, function() { + if (!inControl.hasClass(inClass)) { + inControl.addClass(inClass); + } else { + inControl.setClassAttribute(inControl.getClassAttribute()); + } + }); + inControl.removeClass(inClass); + } + }, + // FIXME: dry + removeFlyweightClass: function(inControl, inClass, inEvent, inIndex) { + var flyweight = inEvent.flyweight; + if (flyweight) { + var index = inIndex != undefined ? inIndex : inEvent.index; + flyweight.performOnRow(index, function() { + if (!inControl.hasClass(inClass)) { + inControl.setClassAttribute(inControl.getClassAttribute()); + } else { + inControl.removeClass(inClass); + } + }); + } + } + } +});
\ No newline at end of file |