From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojo/back.js | 394 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 394 insertions(+) create mode 100644 includes/js/dojo/back.js (limited to 'includes/js/dojo/back.js') diff --git a/includes/js/dojo/back.js b/includes/js/dojo/back.js new file mode 100644 index 0000000..3c62b82 --- /dev/null +++ b/includes/js/dojo/back.js @@ -0,0 +1,394 @@ +if(!dojo._hasResource["dojo.back"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.back"] = true; +dojo.provide("dojo.back"); + +/*===== +dojo.back = { + // summary: Browser history management resources +} +=====*/ + + +(function(){ + var back = dojo.back; + + // everyone deals with encoding the hash slightly differently + + function getHash(){ + var h = window.location.hash; + if(h.charAt(0) == "#"){ h = h.substring(1); } + return dojo.isMozilla ? h : decodeURIComponent(h); + } + + function setHash(h){ + if(!h){ h = ""; } + window.location.hash = encodeURIComponent(h); + historyCounter = history.length; + } + + // if we're in the test for these methods, expose them on dojo.back. ok'd with alex. + if(dojo.exists("tests.back-hash")){ + back.getHash = getHash; + back.setHash = setHash; + } + + 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(){ + //summary: private method. Do not call this directly. + + //The "current" page is always at the top of the history stack. + //console.debug("handlingBackButton"); + 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); + //console.debug("done handling back"); + } + + back.goBack = handleBackButton; + + function handleForwardButton(){ + //summary: private method. Do not call this directly. + //console.debug("handling forward"); + 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); + //console.debug("done handling forward"); + } + + back.goForward = handleForwardButton; + + function createState(url, args, hash){ + //summary: private method. Do not call this directly. + return {"url": url, "kwArgs": args, "urlHash": hash}; //Object + } + + function getUrlQuery(url){ + //summary: private method. Do not call this directly. + var segments = url.split("?"); + if(segments.length < 2){ + return null; //null + } + else{ + return segments[1]; //String + } + } + + function loadIframeHistory(){ + //summary: private method. Do not call this directly. + var url = (dojo.config["dojoIframeHistoryUrl"] || dojo.moduleUrl("dojo", "resources/iframe_history.html")) + "?" + (new Date()).getTime(); + moveForward = true; + if(historyIframe){ + dojo.isSafari ? historyIframe.location = url : window.frames[historyIframe.name].location = url; + }else{ + //console.warn("dojo.back: Not initialised. You need to call dojo.back.init() from a