Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/html/lib/layout/list/source/PulldownList.js
blob: 8d0dab1241c0a5bebd3491443c02578c7b5df597 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
A list that provides a pull-to-refresh feature, which allows new data to be
retrieved and updated in the list.

PulldownList provides the onPullRelease event to allow an application to start
retrieving new data.  The onPullComplete event indicates that the pull is
complete and it's time to update the list with the new data.

	{name: "list", kind: "PulldownList", onSetupItem: "setupItem",
		onPullRelease: "pullRelease", onPullComplete: "pullComplete",
		components: [
			{name: "item"}
		]}

	pullRelease: function() {
		this.search();
	},
	processSearchResults: function(inRequest, inResponse) {
		this.results = inResponse.results;
		this.$.list.setCount(this.results.length);
		this.$.list.completePull();
	},
	pullComplete: function() {
		this.$.list.reset();
	}
*/
enyo.kind({
	name: "enyo.PulldownList",
	kind: "List",
	touch: true,
	pully: null,
	pulldownTools: [
		{name: "pulldown", classes: "enyo-list-pulldown", components: [
			{name: "puller", kind: "Puller"}
		]}
	],
	events: {
		onPullStart: "",
		onPullCancel: "",
		onPull: "",
		onPullRelease: "",
		onPullComplete: ""
	},
	handlers: {
		onScrollStart: "scrollStartHandler",
		onScroll: "scrollHandler",
		onScrollStop: "scrollStopHandler",
		ondragfinish: "dragfinish"
	},
	//
	pullingMessage: "Pull down to refresh...",
	pulledMessage: "Release to refresh...",
	loadingMessage: "Loading...",
	//
	pullingIconClass: "enyo-puller-arrow enyo-puller-arrow-down",
	pulledIconClass: "enyo-puller-arrow enyo-puller-arrow-up",
	loadingIconClass: "",
	//* @protected
	create: function() {
		var p = {kind: "Puller", showing: false, text: this.loadingMessage, iconClass: this.loadingIconClass, onCreate: "setPully"};
		this.listTools.splice(0, 0, p);
		this.inherited(arguments);
		this.setPulling();
	},
	initComponents: function() {
		this.createChrome(this.pulldownTools);
		this.accel = enyo.dom.canAccelerate();
		this.translation = this.accel ? "translate3d" : "translate";
		this.inherited(arguments);
	},
	setPully: function(inSender, inEvent) {
		this.pully = inEvent.originator;
	},
	scrollStartHandler: function() {
		this.firedPullStart = false;
		this.firedPull = false;
		this.firedPullCancel = false;
	},
	scrollHandler: function(inSender) {
		if (this.completingPull) {
			this.pully.setShowing(false);
		}
		var s = this.getStrategy().$.scrollMath;
		var over = s.y;
		if (s.isInOverScroll() && over > 0) {
			enyo.dom.transformValue(this.$.pulldown, this.translation, "0," + over + "px" + (this.accel ? ",0" : ""));
			if (!this.firedPullStart) {
				this.firedPullStart = true;
				this.pullStart();
				this.pullHeight = this.$.pulldown.getBounds().height;
			}
			if (over > this.pullHeight && !this.firedPull) {
				this.firedPull = true;
				this.firedPullCancel = false;
				this.pull();
			}
			if (this.firedPull && !this.firedPullCancel && over < this.pullHeight) {
				this.firedPullCancel = true;
				this.firedPull = false;
				this.pullCancel();
			}
		}
	},
	scrollStopHandler: function() {
		if (this.completingPull) {
			this.completingPull = false;
			this.doPullComplete();
		}
	},
	dragfinish: function() {
		if (this.firedPull) {
			var s = this.getStrategy().$.scrollMath;
			s.setScrollY(s.y - this.pullHeight);
			this.pullRelease();
		}
	},
	//* @public
	//* To signal that the list should execute pull completion.  This usually be called after the application has received the new data.
	completePull: function() {
		this.completingPull = true;
		this.$.strategy.$.scrollMath.setScrollY(this.pullHeight);
		this.$.strategy.$.scrollMath.start();
	},
	//* @protected
	pullStart: function() {
		this.setPulling();
		this.pully.setShowing(false);
		this.$.puller.setShowing(true);
		this.doPullStart();
	},
	pull: function() {
		this.setPulled();
		this.doPull();
	},
	pullCancel: function() {
		this.setPulling();
		this.doPullCancel();
	},
	pullRelease: function() {
		this.$.puller.setShowing(false);
		this.pully.setShowing(true);
		this.doPullRelease();
	},
	setPulling: function() {
		this.$.puller.setText(this.pullingMessage);
		this.$.puller.setIconClass(this.pullingIconClass);
	},
	setPulled: function() {
		this.$.puller.setText(this.pulledMessage);
		this.$.puller.setIconClass(this.pulledIconClass);
	}
});

enyo.kind({
	name: "enyo.Puller",
	classes: "enyo-puller",
	published: {
		text: "",
		iconClass: ""
	},
	events: {
		onCreate: ""
	},
	components: [
		{name: "icon"},
		{name: "text", tag: "span", classes: "enyo-puller-text"}
	],
	create: function() {
		this.inherited(arguments);
		this.doCreate();
		this.textChanged();
		this.iconClassChanged();
	},
	textChanged: function() {
		this.$.text.setContent(this.text);
	},
	iconClassChanged: function() {
		this.$.icon.setClasses(this.iconClass);
	}
});