1 | define([ |
---|
2 | "dojo/_base/kernel", |
---|
3 | "dojo/_base/config", |
---|
4 | "dojo/_base/declare", |
---|
5 | "dijit/registry", // registry.getEnclosingWidget |
---|
6 | "dijit/_Contained", |
---|
7 | "dijit/_Container", |
---|
8 | "dijit/_WidgetBase", |
---|
9 | "./TransitionEvent", |
---|
10 | "./View" |
---|
11 | ], function(kernel, config, declare, registry, Contained, Container, WidgetBase, TransitionEvent, View){ |
---|
12 | |
---|
13 | /*===== |
---|
14 | var Contained = dijit._Contained; |
---|
15 | var Container = dijit._Container; |
---|
16 | var WidgetBase = dijit._WidgetBase; |
---|
17 | var TransitionEvent = dojox.mobile.TransitionEvent; |
---|
18 | var View = dojox.mobile.View; |
---|
19 | =====*/ |
---|
20 | |
---|
21 | // module: |
---|
22 | // dojox/mobile/_ItemBase |
---|
23 | // summary: |
---|
24 | // A base class for item classes (e.g. ListItem, IconItem, etc.) |
---|
25 | |
---|
26 | return declare("dojox.mobile._ItemBase", [WidgetBase, Container, Contained],{ |
---|
27 | // summary: |
---|
28 | // A base class for item classes (e.g. ListItem, IconItem, etc.) |
---|
29 | // description: |
---|
30 | // _ItemBase is a base class for widgets that have capability to |
---|
31 | // make a view transition when clicked. |
---|
32 | |
---|
33 | // icon: String |
---|
34 | // An icon image to display. The value can be either a path for an |
---|
35 | // image file or a class name of a DOM button. If icon is not |
---|
36 | // specified, the iconBase parameter of the parent widget is used. |
---|
37 | icon: "", |
---|
38 | |
---|
39 | // iconPos: String |
---|
40 | // The position of an aggregated icon. IconPos is comma separated |
---|
41 | // values like top,left,width,height (ex. "0,0,29,29"). If iconPos |
---|
42 | // is not specified, the iconPos parameter of the parent widget is |
---|
43 | // used. |
---|
44 | iconPos: "", // top,left,width,height (ex. "0,0,29,29") |
---|
45 | |
---|
46 | // alt: String |
---|
47 | // An alt text for the icon image. |
---|
48 | alt: "", |
---|
49 | |
---|
50 | // href: String |
---|
51 | // A URL of another web page to go to. |
---|
52 | href: "", |
---|
53 | |
---|
54 | // hrefTarget: String |
---|
55 | // A target that specifies where to open a page specified by |
---|
56 | // href. The value will be passed to the 2nd argument of |
---|
57 | // window.open(). |
---|
58 | hrefTarget: "", |
---|
59 | |
---|
60 | // moveTo: String |
---|
61 | // The id of the transition destination view which resides in the |
---|
62 | // current page. |
---|
63 | // |
---|
64 | // If the value has a hash sign ('#') before the id (e.g. #view1) |
---|
65 | // and the dojo.hash module is loaded by the user application, the |
---|
66 | // view transition updates the hash in the browser URL so that the |
---|
67 | // user can bookmark the destination view. In this case, the user |
---|
68 | // can also use the browser's back/forward button to navigate |
---|
69 | // through the views in the browser history. |
---|
70 | // |
---|
71 | // If null, transitions to a blank view. |
---|
72 | // If '#', returns immediately without transition. |
---|
73 | moveTo: "", |
---|
74 | |
---|
75 | // scene: String |
---|
76 | // The name of a scene. Used from dojox.mobile.app. |
---|
77 | scene: "", |
---|
78 | |
---|
79 | // clickable: Boolean |
---|
80 | // If true, this item becomes clickable even if a transition |
---|
81 | // destination (moveTo, etc.) is not specified. |
---|
82 | clickable: false, |
---|
83 | |
---|
84 | // url: String |
---|
85 | // A URL of an html fragment page or JSON data that represents a |
---|
86 | // new view content. The view content is loaded with XHR and |
---|
87 | // inserted in the current page. Then a view transition occurs to |
---|
88 | // the newly created view. The view is cached so that subsequent |
---|
89 | // requests would not load the content again. |
---|
90 | url: "", |
---|
91 | |
---|
92 | // urlTarget: String |
---|
93 | // Node id under which a new view will be created according to the |
---|
94 | // url parameter. If not specified, The new view will be created as |
---|
95 | // a sibling of the current view. |
---|
96 | urlTarget: "", |
---|
97 | |
---|
98 | // transition: String |
---|
99 | // A type of animated transition effect. You can choose from the |
---|
100 | // standard transition types, "slide", "fade", "flip", or from the |
---|
101 | // extended transition types, "cover", "coverv", "dissolve", |
---|
102 | // "reveal", "revealv", "scaleIn", "scaleOut", "slidev", |
---|
103 | // "swirl", "zoomIn", "zoomOut". If "none" is specified, transition |
---|
104 | // occurs immediately without animation. |
---|
105 | transition: "", |
---|
106 | |
---|
107 | // transitionDir: Number |
---|
108 | // The transition direction. If 1, transition forward. If -1, |
---|
109 | // transition backward. For example, the slide transition slides |
---|
110 | // the view from right to left when dir == 1, and from left to |
---|
111 | // right when dir == -1. |
---|
112 | transitionDir: 1, |
---|
113 | |
---|
114 | // transitionOptions: Object |
---|
115 | // A hash object that holds transition options. |
---|
116 | transitionOptions: null, |
---|
117 | |
---|
118 | // callback: Function|String |
---|
119 | // A callback function that is called when the transition has been |
---|
120 | // finished. A function reference, or name of a function in |
---|
121 | // context. |
---|
122 | callback: null, |
---|
123 | |
---|
124 | // sync: Boolean |
---|
125 | // If true, XHR for the view content specified with the url |
---|
126 | // parameter is performed synchronously. If false, it is done |
---|
127 | // asynchronously and the progress indicator is displayed while |
---|
128 | // loading the content. This parameter is effective only when the |
---|
129 | // url parameter is used. |
---|
130 | sync: true, |
---|
131 | |
---|
132 | // label: String |
---|
133 | // A label of the item. If the label is not specified, innerHTML is |
---|
134 | // used as a label. |
---|
135 | label: "", |
---|
136 | |
---|
137 | // toggle: Boolean |
---|
138 | // If true, the item acts like a toggle button. |
---|
139 | toggle: false, |
---|
140 | |
---|
141 | // _duration: Number |
---|
142 | // Duration of selection, milliseconds. |
---|
143 | _duration: 800, |
---|
144 | |
---|
145 | |
---|
146 | inheritParams: function(){ |
---|
147 | var parent = this.getParent(); |
---|
148 | if(parent){ |
---|
149 | if(!this.transition){ this.transition = parent.transition; } |
---|
150 | if(this.icon && parent.iconBase && |
---|
151 | parent.iconBase.charAt(parent.iconBase.length - 1) === '/'){ |
---|
152 | this.icon = parent.iconBase + this.icon; |
---|
153 | } |
---|
154 | if(!this.icon){ this.icon = parent.iconBase; } |
---|
155 | if(!this.iconPos){ this.iconPos = parent.iconPos; } |
---|
156 | } |
---|
157 | }, |
---|
158 | |
---|
159 | select: function(){ |
---|
160 | // summary: |
---|
161 | // Makes this widget in the selected state. |
---|
162 | // description: |
---|
163 | // Subclass must implement. |
---|
164 | }, |
---|
165 | |
---|
166 | deselect: function(){ |
---|
167 | // summary: |
---|
168 | // Makes this widget in the deselected state. |
---|
169 | // description: |
---|
170 | // Subclass must implement. |
---|
171 | }, |
---|
172 | |
---|
173 | defaultClickAction: function(e){ |
---|
174 | if(this.toggle){ |
---|
175 | if(this.selected){ |
---|
176 | this.deselect(); |
---|
177 | }else{ |
---|
178 | this.select(); |
---|
179 | } |
---|
180 | }else if(!this.selected){ |
---|
181 | this.select(); |
---|
182 | if(!this.selectOne){ |
---|
183 | var _this = this; |
---|
184 | setTimeout(function(){ |
---|
185 | _this.deselect(); |
---|
186 | }, this._duration); |
---|
187 | } |
---|
188 | var transOpts; |
---|
189 | if(this.moveTo || this.href || this.url || this.scene){ |
---|
190 | transOpts = {moveTo: this.moveTo, href: this.href, url: this.url, scene: this.scene, transition: this.transition, transitionDir: this.transitionDir}; |
---|
191 | }else if(this.transitionOptions){ |
---|
192 | transOpts = this.transitionOptions; |
---|
193 | } |
---|
194 | if(transOpts){ |
---|
195 | return new TransitionEvent(this.domNode,transOpts,e).dispatch(); |
---|
196 | } |
---|
197 | } |
---|
198 | }, |
---|
199 | |
---|
200 | getParent: function(){ |
---|
201 | // summary: |
---|
202 | // Gets the parent widget. |
---|
203 | // description: |
---|
204 | // Almost equivalent to _Contained#getParent, but this method |
---|
205 | // does not cause a script error even if this widget has no |
---|
206 | // parent yet. |
---|
207 | var ref = this.srcNodeRef || this.domNode; |
---|
208 | return ref && ref.parentNode ? registry.getEnclosingWidget(ref.parentNode) : null; |
---|
209 | }, |
---|
210 | |
---|
211 | setTransitionPos: function(e){ |
---|
212 | // summary: |
---|
213 | // Stores the clicked position for later use. |
---|
214 | // description: |
---|
215 | // Some of the transition animations (e.g. ScaleIn) needs the |
---|
216 | // clicked position. |
---|
217 | var w = this; |
---|
218 | while(true){ |
---|
219 | w = w.getParent(); |
---|
220 | if(!w || w instanceof View){ break; } |
---|
221 | } |
---|
222 | if(w){ |
---|
223 | w.clickedPosX = e.clientX; |
---|
224 | w.clickedPosY = e.clientY; |
---|
225 | } |
---|
226 | }, |
---|
227 | |
---|
228 | transitionTo: function(moveTo, href, url, scene){ |
---|
229 | // summary: |
---|
230 | // Performs a view transition. |
---|
231 | // description: |
---|
232 | // Given a transition destination, this method performs a view |
---|
233 | // transition. This method is typically called when this item |
---|
234 | // is clicked. |
---|
235 | if(config.isDebug){ |
---|
236 | var alreadyCalledHash = arguments.callee._ach || (arguments.callee._ach = {}), |
---|
237 | caller = (arguments.callee.caller || "unknown caller").toString(); |
---|
238 | if(!alreadyCalledHash[caller]){ |
---|
239 | kernel.deprecated(this.declaredClass + "::transitionTo() is deprecated." + |
---|
240 | caller, "", "2.0"); |
---|
241 | alreadyCalledHash[caller] = true; |
---|
242 | } |
---|
243 | } |
---|
244 | new TransitionEvent(this.domNode, {moveTo: moveTo, href: href, url: url, scene: scene, |
---|
245 | transition: this.transition, transitionDir: this.transitionDir}).dispatch(); |
---|
246 | } |
---|
247 | }); |
---|
248 | }); |
---|