Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/html/lib/layout/list/source/AlphaJumper.js
blob: 2f85d00ae5b97936871b272de55db76b8e2c4a51 (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
61
62
63
64
65
66
67
68
69
70
enyo.kind({
	name: "enyo.AlphaJumper",
	classes: "enyo-alpha-jumper enyo-border-box",
	published: {
		marker: null
	},
	events: {
		onAlphaJump: ""
	},
	handlers: {
		ondown: "down",
		onmove: "move",
		onup: "up"
	},
	initComponents: function() {
		for (var s="A".charCodeAt(0), i=s; i<s+26; i++) {
			this.createComponent({content: String.fromCharCode(i)});
		}
		this.inherited(arguments);
	},
	down: function(inSender, inEvent) {
		if (this.tracking) {
			enyo.dispatcher.release();
		}
		this.tracking = true;
		if (this.hasNode()) {
			var b = this.node.getBoundingClientRect();
			// IE8 does not return width
			var w = (b.width === undefined) ? (b.right - b.left) : b.width;
			this.x = b.left + w/2;
		}
		enyo.dispatcher.capture(this);
		this.track(inEvent);
	},
	move: function(inSender, inEvent) {
		if (this.tracking) {
			this.track(inEvent);
		}
	},
	up: function() {
		if (this.tracking) {
			enyo.dispatcher.release();
			this.setMarker(null);
			this.tracking = false;
		}
	},
	track: function(inEvent) {
		var n = document.elementFromPoint(this.x, inEvent.pageY);
		var c = this.nodeToControl(n);
		if (c) {
			this.setMarker(c);
		}
	},
	nodeToControl: function(inNode) {
		for (var i=0, c$=this.controls, c; c=c$[i]; i++) {
			if (inNode == c.hasNode()) {
				return c;
			}
		}
	},
	markerChanged: function(inLast) {
		if (inLast) {
			inLast.removeClass("active");
		}
		if (this.marker) {
			this.marker.addClass("active");
			this.doAlphaJump({letter: this.marker.getContent(), index: this.marker.indexInContainer()});
		}
	}
});