From ca3ad6305ec0655ad8475a12ac2228b61cdd9ba0 Mon Sep 17 00:00:00 2001 From: Lionel LASKE Date: Sat, 25 Aug 2012 20:23:36 +0000 Subject: Init commit --- (limited to 'html/lib/onyx/source/Item.js') 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 -- cgit v0.9.1