123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- if(!dojo._hasResource["dojo.back"]){
- dojo._hasResource["dojo.back"] = true;
- dojo.provide("dojo.back");
- dojo.getObject("back", true, dojo);
- (function(){
- var back = dojo.back,
-
- getHash= back.getHash= function(){
- var h = window.location.hash;
- if(h.charAt(0) == "#"){ h = h.substring(1); }
- return dojo.isMozilla ? h : decodeURIComponent(h);
- },
-
- setHash= back.setHash= function(h){
- if(!h){ h = ""; }
- window.location.hash = encodeURIComponent(h);
- historyCounter = history.length;
- };
- var initialHref = (typeof(window) !== "undefined") ? window.location.href : "";
- var initialHash = (typeof(window) !== "undefined") ? getHash() : "";
- var initialState = null;
- var locationTimer = null;
- var bookmarkAnchor = null;
- var historyIframe = null;
- var forwardStack = [];
- var historyStack = [];
- var moveForward = false;
- var changingUrl = false;
- var historyCounter;
- function handleBackButton(){
-
-
- var current = historyStack.pop();
- if(!current){ return; }
- var last = historyStack[historyStack.length-1];
- if(!last && historyStack.length == 0){
- last = initialState;
- }
- if(last){
- if(last.kwArgs["back"]){
- last.kwArgs["back"]();
- }else if(last.kwArgs["backButton"]){
- last.kwArgs["backButton"]();
- }else if(last.kwArgs["handle"]){
- last.kwArgs.handle("back");
- }
- }
- forwardStack.push(current);
- }
- back.goBack = handleBackButton;
- function handleForwardButton(){
-
- var last = forwardStack.pop();
- if(!last){ return; }
- if(last.kwArgs["forward"]){
- last.kwArgs.forward();
- }else if(last.kwArgs["forwardButton"]){
- last.kwArgs.forwardButton();
- }else if(last.kwArgs["handle"]){
- last.kwArgs.handle("forward");
- }
- historyStack.push(last);
- }
- back.goForward = handleForwardButton;
- function createState(url, args, hash){
-
- return {"url": url, "kwArgs": args, "urlHash": hash};
- }
- function getUrlQuery(url){
-
- var segments = url.split("?");
- if(segments.length < 2){
- return null;
- }
- else{
- return segments[1];
- }
- }
-
- function loadIframeHistory(){
-
- var url = (dojo.config["dojoIframeHistoryUrl"] || dojo.moduleUrl("dojo", "resources/iframe_history.html")) + "?" + (new Date()).getTime();
- moveForward = true;
- if(historyIframe){
- dojo.isWebKit ? historyIframe.location = url : window.frames[historyIframe.name].location = url;
- }else{
-
- }
- return url;
- }
- function checkLocation(){
- if(!changingUrl){
- var hsl = historyStack.length;
-
- var hash = getHash();
- if((hash === initialHash||window.location.href == initialHref)&&(hsl == 1)){
-
-
-
- handleBackButton();
- return;
- }
-
-
-
- if(forwardStack.length > 0){
- if(forwardStack[forwardStack.length-1].urlHash === hash){
- handleForwardButton();
- return;
- }
- }
-
-
- if((hsl >= 2)&&(historyStack[hsl-2])){
- if(historyStack[hsl-2].urlHash === hash){
- handleBackButton();
- return;
- }
- }
- }
- };
-
- back.init = function(){
-
-
-
-
-
-
- if(dojo.byId("dj_history")){ return; }
- var src = dojo.config["dojoIframeHistoryUrl"] || dojo.moduleUrl("dojo", "resources/iframe_history.html");
- if (dojo._postLoad) {
- console.error("dojo.back.init() must be called before the DOM has loaded. "
- + "If using xdomain loading or djConfig.debugAtAllCosts, include dojo.back "
- + "in a build layer.");
- } else {
- document.write('<iframe style="border:0;width:1px;height:1px;position:absolute;visibility:hidden;bottom:0;right:0;" name="dj_history" id="dj_history" src="' + src + '"></iframe>');
- }
- };
- back.setInitialState = function(/*Object*/args){
-
-
-
-
-
-
-
-
- initialState = createState(initialHref, args, initialHash);
- };
-
-
-
-
-
-
- back.addToHistory = function(/*dojo.__backArgs*/ args){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- forwardStack = [];
- var hash = null;
- var url = null;
- if(!historyIframe){
- if(dojo.config["useXDomain"] && !dojo.config["dojoIframeHistoryUrl"]){
- console.warn("dojo.back: When using cross-domain Dojo builds,"
- + " please save iframe_history.html to your domain and set djConfig.dojoIframeHistoryUrl"
- + " to the path on your domain to iframe_history.html");
- }
- historyIframe = window.frames["dj_history"];
- }
- if(!bookmarkAnchor){
- bookmarkAnchor = dojo.create("a", {style: {display: "none"}}, dojo.body());
- }
- if(args["changeUrl"]){
- hash = ""+ ((args["changeUrl"]!==true) ? args["changeUrl"] : (new Date()).getTime());
-
-
-
-
-
-
-
-
- if(historyStack.length == 0 && initialState.urlHash == hash){
- initialState = createState(url, args, hash);
- return;
- }else if(historyStack.length > 0 && historyStack[historyStack.length - 1].urlHash == hash){
- historyStack[historyStack.length - 1] = createState(url, args, hash);
- return;
- }
- changingUrl = true;
- setTimeout(function() {
- setHash(hash);
- changingUrl = false;
- }, 1);
- bookmarkAnchor.href = hash;
-
- if(dojo.isIE){
- url = loadIframeHistory();
- var oldCB = args["back"]||args["backButton"]||args["handle"];
-
-
-
- var tcb = function(handleName){
- if(getHash() != ""){
- setTimeout(function() { setHash(hash); }, 1);
- }
-
- oldCB.apply(this, [handleName]);
- };
-
-
- if(args["back"]){
- args.back = tcb;
- }else if(args["backButton"]){
- args.backButton = tcb;
- }else if(args["handle"]){
- args.handle = tcb;
- }
-
- var oldFW = args["forward"]||args["forwardButton"]||args["handle"];
-
-
-
-
- var tfw = function(handleName){
- if(getHash() != ""){
- setHash(hash);
- }
- if(oldFW){
-
- oldFW.apply(this, [handleName]);
- }
- };
-
- if(args["forward"]){
- args.forward = tfw;
- }else if(args["forwardButton"]){
- args.forwardButton = tfw;
- }else if(args["handle"]){
- args.handle = tfw;
- }
- }else if(!dojo.isIE){
-
- if(!locationTimer){
- locationTimer = setInterval(checkLocation, 200);
- }
-
- }
- }else{
- url = loadIframeHistory();
- }
- historyStack.push(createState(url, args, hash));
- };
- back._iframeLoaded = function(evt, ifrLoc){
-
-
- var query = getUrlQuery(ifrLoc.href);
- if(query == null){
-
-
- if(historyStack.length == 1){
- handleBackButton();
- }
- return;
- }
- if(moveForward){
-
- moveForward = false;
- return;
- }
-
-
-
- if(historyStack.length >= 2 && query == getUrlQuery(historyStack[historyStack.length-2].url)){
- handleBackButton();
- }else if(forwardStack.length > 0 && query == getUrlQuery(forwardStack[forwardStack.length-1].url)){
- handleForwardButton();
- }
- };
- })();
- }
|