Debian Codegraph @

dojox/app/README.txt

raw
1 -------------------------------------------------------------------------------
2 dojox/app
3 -------------------------------------------------------------------------------
4 Project state: stable
5
6 This project is licensed under the Dojo Tookit licensing scheme and contributions
7 provided under the Dojo CLA.
8 -------------------------------------------------------------------------------
9 Project authors
10 Dustin Machi
11 Stephen Zhang
12 Eric Wang
13 Ed Chatelain
14 Christophe Jolif
15 -------------------------------------------------------------------------------
16 Project description
17
18 dojox/app is a small application framework providing a set of classes to manage the the lifecycle and behavior of a single page application delivered to a mobile or desktop platform.
19 The main class, Application, is responsible for providing the lifecycle of the application and is designed to be easily modified with additional custom behaviors.
20 An application instance contains views which provide the visible user interface.
21 The available views, module dependencies, and other information about the application are all passed into the Application class through a JSON configuration file.
22 -------------------------------------------------------------------------------
23 Dependencies:
24
25 Dojo Core (dijit, dojox/mobile).
26 -------------------------------------------------------------------------------
27 Documentation
28
29 config.json
30
31 The config file defines all of the dependencies, application behaviors, top level views, and any other information required for the application to function.
32
33 Example Config:
34 ```javascript
35 {
36 /* any object that complies with Dojo AMD loader configuration. */
37 "loaderConfig" : {
38 "paths": {
39 "mypackage" : "can/be/found/here"
40 }
41 },
42
43 /* global application dependencies */
44 "dependencies": [
45 "dojox/mobile/Heading",
46 "dojo/mobile/RoundRect",
47 "my/custom/module"
48 ],
49
50 /* Application Modules. These are implicitly added to the above set of dependencies */
51 modules: [
52 "dojox/app/module/history",
53 "my/custom/appModule"
54 ],
55
56 /* Application Controllers. */
57 "controllers": [
58 "dojox/app/controllers/History",
59 "my/custom/appController"
60 ],
61
62 /* The Application level HTML template. */
63 template: "./views/example.html",
64
65 /* Application level view controller. Application will have a root view even if it has no template.
66 "./views/myView.js" -- load controller from "./views/myView.js",
67 no controller -- no controller for this view */
68 "controller": "./views/myView.js",
69
70 /* the view to start on by default */
71 "defaultView": "home",
72
73 /* transition to use if none has been provided */
74 "defaultTransition": "slide",
75
76 /* Views */
77 "views": {
78
79 /* home is a top level dojox.app.view */
80 "home": {
81
82 /* dependencies specific to this view */
83 "dependencies: [
84 "dojox/mobile/ListItem",
85 "dojox/mobile/EdgeToEdgeCategory"
86 ],
87
88 /* template to use for this view */
89 template: "./views/home.html"
90
91 /* view controller. "none" -- ,
92 "./views/myHome.js" -- load controller from "./views/myHome.js",
93 no controller -- no controller for this view */
94 },
95
96 /* tabs view contains three child views */
97 "tabs": {
98 /* the tabs view template */
99 "template": "./views/tabScene.html",
100
101 /* the default view within tabs view */
102 "defaultView": "tab1",
103
104 /* when transitioning between tabs, use a flip animation by default */
105 "defaultTransition": "flip",
106
107 //the views available to tabs view
108 "views": {
109 "tab1":{
110 "template": "./views/tabs/tab1.html"
111 /* no controller define for tab1 view, load tab1 view controller from the same location as the template. */
112 },
113 "tab2":{
114 "template": "./views/tabs/tab2.html"
115 },
116 "tab3":{
117 "template": "./views/tabs/tab3.html"
118 }
119 },
120
121 /* dependencies specific to tabs view */
122 "dependencies":["dojox/mobile/RoundRectList","dojox/mobile/ListItem", "dojox/mobile/EdgeToEdgeCategory"]
123 }
124
125 }
126 }
127 ```
128
129 Property descriptions
130
131 - loaderConfig - This is the configuration that will be passed to the Dojo AMD loader. This allows to specify for example where the loader needs to find modules.
132 See: http://livedocs.dojotoolkit.org/loader/amd#module-identifiers
133
134 - dependencies - These are the modules that are required for the application to run when defined at the root of the configuration.
135 When defined inside of a view, the dependency property defines modules which must be loaded before that view can be instantiated.
136
137 - modules - The modules property defines application modules that will mixed into the Application class to control the lifecycle and behavior of the application. This property will become the array of mixins provided to a dojo/declare extending the base Application class. In other words, the Application class that is instantiated dynamically is created at run time using the base class and this list of modules.
138
139 - controllers - The controllers property defines application controllers that will be loaded during application startup to respond to events of the application. The controllers bind events on application's root domNode and the events can be triggered by application's emit() method and documented actions.
140
141 - template - This is the template/HTML that is used for the application when defined at the root of the configuration.
142 Within the context of a view, it is the template/HTML for defining the view.
143
144 - controller - This is the view controller that is used for the application template view when defined at the root of the configuration. It implements the view's life cycle interface like init(), beforeActivate(), destroy(), etc. and allows one to control the view.
145
146 - defaultView - The defaultView defines the startup view for the application.
147
148 - defaultTransition - This is the default transition method for top level views when defined at the root of the configuration.
149 When defined within a view, it is the default transition method for the associated views only.
150
151 - views - The views property is a nested set of objects defining the views available to the application. Details of views classes is discussed below.
152
153 - stores - The dojo/store implementations that will be used by the application
154
155 - models - The models (potentially dojox/mvc models) connecting to the stores and exposing data to the application.
156
157 - id - The identifier of the application, a global variable with the id name is created by the application.
158
159 Some additional properties, such as name and description are reserved for future use, but their exact use is still under development.
160
161 The Application module:
162
163 The Application class itself doesn't currently exist as an exported class.
164 This module exports a generation function, which when provided a configuration file will declare & instantiate the application class that will actually be used on a page. Finally it then starts it up at a specific node:
165
166 ```javascript
167 require(["dojox/json/ref", "dojox/app/main", "dojo/text!app/config.json"],function(json, Application, config){
168 app = Application(json.parse(config));
169 });
170 ```
171
172 The View module:
173
174 The View module provides a View class to construct View instances, a template rendering engine to render view template and view lifecycle APIs. Each View can have one parent view and several children views. It provides a templated container to host the domNodes for the children views. Its purpose is to allow the layout of the view to be provided through an html template and to have a set of children views which the view transitions between. For example, to display a set of tabs, you would use a View with a child view for each tab. The view's template would define where within the view the children views are displayed and where any tab buttons and such are displayed.
175 In this case the "template", for the base View is pretty simple. It is a simple HTML content. However, nodes within the template can be tagged with data-app-constraint="top" (bottom, left, right) to define where that node and its children should be displayed.
176 For example:
177
178 ```html
179 <div style="background:#c5ccd3;" class="view mblView">
180 <div data-app-constraint="top" data-dojo-type="dojox/mobile/Heading">Tab View</div>
181 <ul data-app-constraint="top" data-dojo-type="dojox/mobile/TabBar" barType="segmentedControl">
182 <li data-dojo-type="dojox/mobile/TabBarButton" icon1="images/tab-icon-16.png" icon2="images/tab-icon-16h.png"
183 transitionOptions='{title:"TabScene-Tab1",target:"tabscene,tab1",url: "#tabscene,tab1"}' selected="true">Tab 1</li>
184 <li data-dojo-type="dojox/mobile/TabBarButton" icon1="images/tab-icon-15.png" icon2="images/tab-icon-15h.png"
185 transitionOptions='{title:"TabScene-Tab2",target:"tabscene,tab2",url: "#tabscene,tab2"}'>Tab 2</li>
186 <li data-dojo-type="dojox/mobile/TabBarButton" icon1="images/tab-icon-10.png" icon2="images/tab-icon-10h.png"
187 transitionOptions='{title:"TabScene-Tab3",target:"tabscene,tab3",url: "#tabscene,tab3"}'>Tab 3</li>
188 </ul>
189 </div>
190 ```
191
192 This template for the tabs view defines two areas with region top, a header and the tab buttons. The will be placed at the top of this main view when rendered.
193
194 Normally, when using a BorderContainer, one would also have a data-app-constraint="center" section. In the case of a View however, the "center" region will be applied to the currently active view (the current tab for example).
195
196 The application can also provide view controller modules to implement the View lifecyle APIs (like init(), destory(),...) for each view. The Transition controller controls the transition from one child view to another. This includes propagating transition events on to children if the active child is itself another view.
197
198 The Controller module:
199
200 The Controller module provides a base Class to control the application by binding events on application's root domNode. Several controllers required by the framework are implemented in dojox/app/controllers package:
201
202 * Load controller: load view templates and view controllers
203 * Transition controller: respond to "startTransition" event and do transition between views
204 * Layout controller: perform views layout
205 * History controller: maintain application's history. This is based on HTML5 history APIs and will not work on platforms that do not support it like IE, Android 3 & 4, iOS4, etc.
206 * HistoryHash controller: maintain application's history. This is based on URL hash and has limitation if refresh the browser and back to an URL which out of current application's history stack.
207
208 A developer using the dojox/app framwork can define additional custom controller by extending the base class (dojox/app/Controller) and specifying them in the application configuration file. The events binding to application's root domNode is done by default.
209 A developer can use Controller's bind() method to bind event to document, window or dojo/Evented object if needed.
210
211 ```javascript
212 define(["dojo/_base/lang", "dojo/_base/declare"], function(lang, declare){
213
214 return declare("myApp.myController", Controller, {
215
216 constructor: function(app, events){
217 // summary:
218 // bind "myEvent1" and "myEvent2" events on application's root domNode.
219 // bind "resize" event on window
220 // app:
221 // dojox.app application instance.
222 // events:
223 // {event : handler}
224 this.events = {
225 "myEvent1": this.myEvent1,
226 "myEvent2": this.myEvent2
227 };
228 this.inherited(arguments);
229
230 // bind "resize" event on window
231 this.bind(window, "resize", this.onResize);
232 },
233
234 myEvent1: function(){
235 // add your code here
236 },
237
238 myEvent2: function(){
239 // add your code here
240 },
241
242 onResize: function(){
243 // add your code here
244 }
245 });
246 });
247 ```