diff options
Diffstat (limited to 'js/dojo/dojox/app/module')
| -rw-r--r-- | js/dojo/dojox/app/module/env.js | 22 | ||||
| -rw-r--r-- | js/dojo/dojox/app/module/history.js | 91 | ||||
| -rw-r--r-- | js/dojo/dojox/app/module/lifecycle.js | 27 |
3 files changed, 140 insertions, 0 deletions
diff --git a/js/dojo/dojox/app/module/env.js b/js/dojo/dojox/app/module/env.js new file mode 100644 index 0000000..f4e8601 --- /dev/null +++ b/js/dojo/dojox/app/module/env.js @@ -0,0 +1,22 @@ +//>>built +define("dojox/app/module/env", ["dojo/_base/declare"], function(declare){ + return declare(null, { + mode: "", + init: function(){ + + //TODO BROADLY categorize the mode of the app...mobile,desktop + // This should be done with UA sniffing, but remember + // very broadly, this is for purposes of deciding + // which ui to render, NOT feature detection + /* + this.mode="mobile"; + var def = this.inherited(arguments); + + //just an example + return def.then(function(){ + console.log("env init after inherited inits"); + }); + */ + } + }); +}); diff --git a/js/dojo/dojox/app/module/history.js b/js/dojo/dojox/app/module/history.js new file mode 100644 index 0000000..56e6851 --- /dev/null +++ b/js/dojo/dojox/app/module/history.js @@ -0,0 +1,91 @@ +//>>built +define("dojox/app/module/history", ["dojo/_base/kernel","dojo/_base/lang", "dojo/_base/declare", "dojo/on"],function(dojo,dlang,declare,listen){ + return declare(null, { + postCreate: function(params,node){ + this.inherited(arguments); + var hash=window.location.hash; + this._startView= ((hash && hash.charAt(0)=="#")?hash.substr(1):hash)||this.defaultView; + + listen(this.domNode, "startTransition", dojo.hitch(this, "onStartTransition")); + listen(window,"popstate", dojo.hitch(this, "onPopState")); + }, + startup: function(){ + this.inherited(arguments); + }, + + onStartTransition: function(evt){ + console.log("onStartTransition", evt.detail.href, history.state); + if (evt.preventDefault){ + evt.preventDefault(); + } + + var target = evt.detail.target; + var regex = /#(.+)/; + if(!target && regex.test(evt.detail.href)){ + target = evt.detail.href.match(regex)[1]; + } + + //prevent event from bubbling to window and being + //processed by dojox/mobile/ViewController + evt.cancelBubble = true; + if(evt.stopPropagation){ + evt.stopPropagation(); + } + + dojo.when(this.transition(target, dojo.mixin({reverse: false},evt.detail)), dojo.hitch(this, function(){ + history.pushState(evt.detail,evt.detail.href, evt.detail.url); + })) + + }, + + /* + onHashChange: function(evt){ + var target = window.location.hash.substr(1);; + var evt = {target: window.location.hash, url: "#" + target,title:null}; + //this.onStartTransition(evt); + }, + */ + + onPopState: function(evt){ + // Check application status, if application status not STARTED, do nothing. + // when clean browser's cache then refresh the current page, it will trigger popState event. + // but the application not start, it will throw an error. + if(this.getStatus() !== this.lifecycle.STARTED ){ + return; + } + var state = evt.state; + if (!state){ + + if(!this._startView && window.location.hash){ + state={ + target: (location.hash && location.hash.charAt(0)=="#")?location.hash.substr(1):location.hash, + url: location.hash + } + }else{ + state={}; + } + } + + var target = state.target || this._startView || this.defaultView; + + if (this._startView){ + this._startView=null; + } + var title = state.title||null; + var href = state.url || null; + + if (evt._sim) { + history.replaceState(state, title, href ); + } + + /* + dojo.when(this.transition(window.history.state, {rev: true}), dojo.hitch(this, function(){ + + console.log('done transition from onPopState'); + })) + */ + var currentState = history.state; + this.transition(target, dojo.mixin({reverse: true},state)); + } + }); +}); diff --git a/js/dojo/dojox/app/module/lifecycle.js b/js/dojo/dojox/app/module/lifecycle.js new file mode 100644 index 0000000..d444463 --- /dev/null +++ b/js/dojo/dojox/app/module/lifecycle.js @@ -0,0 +1,27 @@ +//>>built +define("dojox/app/module/lifecycle", ["dojo/_base/declare", "dojo/_base/connect"], function(declare, connect){ + return declare(null, { + + lifecycle: { + UNKNOWN: 0, //unknown + STARTING: 1, //starting + STARTED: 2, //started + STOPPING: 3, //stopping + STOPPED: 4 //stopped + }, + + _status: 0, //unknown + + getStatus: function(){ + return this._status; + }, + + setStatus: function(newStatus){ + this._status = newStatus; + + // publish /app/stauts event. + // application can subscribe this event to do some status change operation. + connect.publish("/app/status", [newStatus]); + } + }); +}); |
