Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/html/lib/onyx/source/Item.js
blob: 377fb5bac64a685d7efb311472cdafa1e1f32dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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);
					}
				});
			}
		}
	}
});