templates/jquery/history.html4.js in compass-jquery-plugin-0.3.2.7 vs templates/jquery/history.html4.js in compass-jquery-plugin-0.3.2.8

- old
+ new

@@ -4,594 +4,603 @@ * @author Benjamin Arthur Lupton <contact@balupton.com> * @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com> * @license New BSD License <http://creativecommons.org/licenses/BSD/> */ -(function(window,undefined){ - "use strict"; +(function(window, undefined) { + "use strict"; - // -------------------------------------------------------------------------- - // Initialise + // -------------------------------------------------------------------------- + // Initialise - // Localise Globals - var - document = window.document, // Make sure we are using the correct document - History = window.History = window.History||{}; // Public History Object + // Localise Globals + var + document = window.document, // Make sure we are using the correct document + setTimeout = window.setTimeout || setTimeout, + clearTimeout = window.clearTimeout || clearTimeout, + setInterval = window.setInterval || setInterval, + History = window.History = window.History || {}; // Public History Object - // Check Existence - if ( typeof History.initHtml4 !== 'undefined' ) { - throw new Error('History.js HTML4 Support has already been loaded...'); - } + // Check Existence + if (typeof History.initHtml4 !== 'undefined') { + throw new Error('History.js HTML4 Support has already been loaded...'); + } - // -------------------------------------------------------------------------- - // Initialise HTML4 Support + // -------------------------------------------------------------------------- + // Initialise HTML4 Support - // Initialise HTML4 Support - History.initHtml4 = function(){ - // Initialise - if ( typeof History.initHtml4.initialized !== 'undefined' ) { - // Already Loaded - return false; - } - else { - History.initHtml4.initialized = true; - } + // Initialise HTML4 Support + History.initHtml4 = function() { + // Initialise + if (typeof History.initHtml4.initialized !== 'undefined') { + // Already Loaded + return false; + } + else { + History.initHtml4.initialized = true; + } - // ---------------------------------------------------------------------- - // Hash Storage + // ---------------------------------------------------------------------- + // Properties - /** - * History.savedHashes - * Store the hashes in an array - */ - History.savedHashes = []; + /** + * History.enabled + * Is History enabled? + */ + History.enabled = true; - /** - * History.isLastHash(newHash) - * Checks if the hash is the last hash - * @param {string} newHash - * @return {boolean} true - */ - History.isLastHash = function(newHash){ - // Prepare - var oldHash = History.getHashByIndex(); - // Check - var isLast = newHash === oldHash; + // ---------------------------------------------------------------------- + // Hash Storage - // Return isLast - return isLast; - }; + /** + * History.savedHashes + * Store the hashes in an array + */ + History.savedHashes = []; - /** - * History.saveHash(newHash) - * Push a Hash - * @param {string} newHash - * @return {boolean} true - */ - History.saveHash = function(newHash){ - // Check Hash - if ( History.isLastHash(newHash) ) { - return false; - } + /** + * History.isLastHash(newHash) + * Checks if the hash is the last hash + * @param {string} newHash + * @return {boolean} true + */ + History.isLastHash = function(newHash) { + // Prepare + var oldHash = History.getHashByIndex(); - // Push the Hash - History.savedHashes.push(newHash); + // Check + var isLast = newHash === oldHash; - // Return true - return true; - }; + // Return isLast + return isLast; + }; - /** - * History.getHashByIndex() - * Gets a hash by the index - * @param {integer} index - * @return {string} - */ - History.getHashByIndex = function(index){ - // Prepare - var hash = null; + /** + * History.saveHash(newHash) + * Push a Hash + * @param {string} newHash + * @return {boolean} true + */ + History.saveHash = function(newHash) { + // Check Hash + if (History.isLastHash(newHash)) { + return false; + } - // Handle - if ( typeof index === 'undefined' ) { - // Get the last inserted - hash = History.savedHashes[History.savedHashes.length-1]; - } - else if ( index < 0 ) { - // Get from the end - hash = History.savedHashes[History.savedHashes.length+index]; - } - else { - // Get from the beginning - hash = History.savedHashes[index]; - } + // Push the Hash + History.savedHashes.push(newHash); - // Return hash - return hash; - }; + // Return true + return true; + }; - // ---------------------------------------------------------------------- - // Discarded States + /** + * History.getHashByIndex() + * Gets a hash by the index + * @param {integer} index + * @return {string} + */ + History.getHashByIndex = function(index) { + // Prepare + var hash = null; - /** - * History.discardedHashes - * A hashed array of discarded hashes - */ - History.discardedHashes = {}; + // Handle + if (typeof index === 'undefined') { + // Get the last inserted + hash = History.savedHashes[History.savedHashes.length - 1]; + } + else if (index < 0) { + // Get from the end + hash = History.savedHashes[History.savedHashes.length + index]; + } + else { + // Get from the beginning + hash = History.savedHashes[index]; + } - /** - * History.discardedStates - * A hashed array of discarded states - */ - History.discardedStates = {}; + // Return hash + return hash; + }; - /** - * History.discardState(State) - * Discards the state by ignoring it through History - * @param {object} State - * @return {true} - */ - History.discardState = function(discardedState,forwardState,backState){ - //History.debug('History.discardState', arguments); - // Prepare - var discardedStateHash = History.getHashByState(discardedState); + // ---------------------------------------------------------------------- + // Discarded States - // Create Discard Object - var discardObject = { - 'discardedState': discardedState, - 'backState': backState, - 'forwardState': forwardState - }; + /** + * History.discardedHashes + * A hashed array of discarded hashes + */ + History.discardedHashes = {}; - // Add to DiscardedStates - History.discardedStates[discardedStateHash] = discardObject; + /** + * History.discardedStates + * A hashed array of discarded states + */ + History.discardedStates = {}; - // Return true - return true; - }; + /** + * History.discardState(State) + * Discards the state by ignoring it through History + * @param {object} State + * @return {true} + */ + History.discardState = function(discardedState, forwardState, backState) { + //History.debug('History.discardState', arguments); + // Prepare + var discardedStateHash = History.getHashByState(discardedState); - /** - * History.discardHash(hash) - * Discards the hash by ignoring it through History - * @param {string} hash - * @return {true} - */ - History.discardHash = function(discardedHash,forwardState,backState){ - //History.debug('History.discardState', arguments); - // Create Discard Object - var discardObject = { - 'discardedHash': discardedHash, - 'backState': backState, - 'forwardState': forwardState - }; + // Create Discard Object + var discardObject = { + 'discardedState': discardedState, + 'backState': backState, + 'forwardState': forwardState + }; - // Add to discardedHash - History.discardedHashes[discardedHash] = discardObject; + // Add to DiscardedStates + History.discardedStates[discardedStateHash] = discardObject; - // Return true - return true; - }; + // Return true + return true; + }; - /** - * History.discardState(State) - * Checks to see if the state is discarded - * @param {object} State - * @return {bool} - */ - History.discardedState = function(State){ - // Prepare - var StateHash = History.getHashByState(State); + /** + * History.discardHash(hash) + * Discards the hash by ignoring it through History + * @param {string} hash + * @return {true} + */ + History.discardHash = function(discardedHash, forwardState, backState) { + //History.debug('History.discardState', arguments); + // Create Discard Object + var discardObject = { + 'discardedHash': discardedHash, + 'backState': backState, + 'forwardState': forwardState + }; - // Check - var discarded = History.discardedStates[StateHash]||false; + // Add to discardedHash + History.discardedHashes[discardedHash] = discardObject; - // Return true - return discarded; - }; + // Return true + return true; + }; - /** - * History.discardedHash(hash) - * Checks to see if the state is discarded - * @param {string} State - * @return {bool} - */ - History.discardedHash = function(hash){ - // Check - var discarded = History.discardedHashes[hash]||false; + /** + * History.discardState(State) + * Checks to see if the state is discarded + * @param {object} State + * @return {bool} + */ + History.discardedState = function(State) { + // Prepare + var StateHash = History.getHashByState(State); - // Return true - return discarded; - }; + // Check + var discarded = History.discardedStates[StateHash] || false; - /** - * History.recycleState(State) - * Allows a discarded state to be used again - * @param {object} data - * @param {string} title - * @param {string} url - * @return {true} - */ - History.recycleState = function(State){ - //History.debug('History.recycleState', arguments); - // Prepare - var StateHash = History.getHashByState(State); + // Return true + return discarded; + }; - // Remove from DiscardedStates - if ( History.discardedState(State) ) { - delete History.discardedStates[StateHash]; - } + /** + * History.discardedHash(hash) + * Checks to see if the state is discarded + * @param {string} State + * @return {bool} + */ + History.discardedHash = function(hash) { + // Check + var discarded = History.discardedHashes[hash] || false; - // Return true - return true; - }; + // Return true + return discarded; + }; - // ---------------------------------------------------------------------- - // HTML4 HashChange Support + /** + * History.recycleState(State) + * Allows a discarded state to be used again + * @param {object} data + * @param {string} title + * @param {string} url + * @return {true} + */ + History.recycleState = function(State) { + //History.debug('History.recycleState', arguments); + // Prepare + var StateHash = History.getHashByState(State); - if ( History.emulated.hashChange ) { - /* - * We must emulate the HTML4 HashChange Support by manually checking for hash changes - */ + // Remove from DiscardedStates + if (History.discardedState(State)) { + delete History.discardedStates[StateHash]; + } - /** - * History.hashChangeInit() - * Init the HashChange Emulation - */ - History.hashChangeInit = function(){ - // Define our Checker Function - History.checkerFunction = null; + // Return true + return true; + }; - // Define some variables that will help in our checker function - var - lastDocumentHash = ''; + // ---------------------------------------------------------------------- + // HTML4 HashChange Support - // Handle depending on the browser - if ( History.isInternetExplorer() ) { - // IE6 and IE7 - // We need to use an iframe to emulate the back and forward buttons + if (History.emulated.hashChange) { + /* + * We must emulate the HTML4 HashChange Support by manually checking for hash changes + */ - // Create iFrame - var - iframeId = 'historyjs-iframe', - iframe = document.createElement('iframe'); + /** + * History.hashChangeInit() + * Init the HashChange Emulation + */ + History.hashChangeInit = function() { + // Define our Checker Function + History.checkerFunction = null; - // Adjust iFarme - iframe.setAttribute('id', iframeId); - iframe.style.display = 'none'; + // Define some variables that will help in our checker function + var + lastDocumentHash = ''; - // Append iFrame - document.body.appendChild(iframe); + // Handle depending on the browser + if (History.isInternetExplorer()) { + // IE6 and IE7 + // We need to use an iframe to emulate the back and forward buttons - // Create initial history entry - iframe.contentWindow.document.open(); - iframe.contentWindow.document.close(); + // Create iFrame + var + iframeId = 'historyjs-iframe', + iframe = document.createElement('iframe'); - // Define some variables that will help in our checker function - var - lastIframeHash = '', - checkerRunning = false; + // Adjust iFarme + iframe.setAttribute('id', iframeId); + iframe.style.display = 'none'; - // Define the checker function - History.checkerFunction = function(){ - // Check Running - if ( checkerRunning ) { - return false; - } + // Append iFrame + document.body.appendChild(iframe); - // Update Running - checkerRunning = true; + // Create initial history entry + iframe.contentWindow.document.open(); + iframe.contentWindow.document.close(); - // Fetch - var - documentHash = History.getHash()||'', - iframeHash = History.unescapeHash(iframe.contentWindow.document.location.hash)||''; + // Define some variables that will help in our checker function + var + lastIframeHash = '', + checkerRunning = false; - // The Document Hash has changed (application caused) - if ( documentHash !== lastDocumentHash ) { - // Equalise - lastDocumentHash = documentHash; + // Define the checker function + History.checkerFunction = function() { + // Check Running + if (checkerRunning) { + return false; + } - // Create a history entry in the iframe - if ( iframeHash !== documentHash ) { - //History.debug('hashchange.checker: iframe hash change', 'documentHash (new):', documentHash, 'iframeHash (old):', iframeHash); + // Update Running + checkerRunning = true; - // Equalise - lastIframeHash = iframeHash = documentHash; + // Fetch + var + documentHash = History.getHash() || '', + iframeHash = History.unescapeHash(iframe.contentWindow.document.location.hash) || ''; - // Create History Entry - iframe.contentWindow.document.open(); - iframe.contentWindow.document.close(); + // The Document Hash has changed (application caused) + if (documentHash !== lastDocumentHash) { + // Equalise + lastDocumentHash = documentHash; - // Update the iframe's hash - iframe.contentWindow.document.location.hash = History.escapeHash(documentHash); - } + // Create a history entry in the iframe + if (iframeHash !== documentHash) { + //History.debug('hashchange.checker: iframe hash change', 'documentHash (new):', documentHash, 'iframeHash (old):', iframeHash); - // Trigger Hashchange Event - History.Adapter.trigger(window,'hashchange'); - } + // Equalise + lastIframeHash = iframeHash = documentHash; - // The iFrame Hash has changed (back button caused) - else if ( iframeHash !== lastIframeHash ) { - //History.debug('hashchange.checker: iframe hash out of sync', 'iframeHash (new):', iframeHash, 'documentHash (old):', documentHash); + // Create History Entry + iframe.contentWindow.document.open(); + iframe.contentWindow.document.close(); - // Equalise - lastIframeHash = iframeHash; + // Update the iframe's hash + iframe.contentWindow.document.location.hash = History.escapeHash(documentHash); + } - // Update the Hash - History.setHash(iframeHash,false); - } + // Trigger Hashchange Event + History.Adapter.trigger(window, 'hashchange'); + } - // Reset Running - checkerRunning = false; + // The iFrame Hash has changed (back button caused) + else if (iframeHash !== lastIframeHash) { + //History.debug('hashchange.checker: iframe hash out of sync', 'iframeHash (new):', iframeHash, 'documentHash (old):', documentHash); - // Return true - return true; - }; - } - else { - // We are not IE - // Firefox 1 or 2, Opera + // Equalise + lastIframeHash = iframeHash; - // Define the checker function - History.checkerFunction = function(){ - // Prepare - var documentHash = History.getHash(); + // Update the Hash + History.setHash(iframeHash, false); + } - // The Document Hash has changed (application caused) - if ( documentHash !== lastDocumentHash ) { - // Equalise - lastDocumentHash = documentHash; + // Reset Running + checkerRunning = false; - // Trigger Hashchange Event - History.Adapter.trigger(window,'hashchange'); - } + // Return true + return true; + }; + } + else { + // We are not IE + // Firefox 1 or 2, Opera - // Return true - return true; - }; - } + // Define the checker function + History.checkerFunction = function() { + // Prepare + var documentHash = History.getHash(); - // Apply the checker function - setInterval(History.checkerFunction, History.options.hashChangeInterval); + // The Document Hash has changed (application caused) + if (documentHash !== lastDocumentHash) { + // Equalise + lastDocumentHash = documentHash; - // Done - return true; - }; // History.hashChangeInit + // Trigger Hashchange Event + History.Adapter.trigger(window, 'hashchange'); + } - // Bind hashChangeInit - History.Adapter.onDomLoad(History.hashChangeInit); + // Return true + return true; + }; + } - } // History.emulated.hashChange + // Apply the checker function + setInterval(History.checkerFunction, History.options.hashChangeInterval); + // Done + return true; + }; // History.hashChangeInit - // ---------------------------------------------------------------------- - // HTML5 State Support + // Bind hashChangeInit + History.Adapter.onDomLoad(History.hashChangeInit); - if ( History.emulated.pushState ) { - /* - * We must emulate the HTML5 State Management by using HTML4 HashChange - */ + } // History.emulated.hashChange - /** - * History.onHashChange(event) - * Trigger HTML5's window.onpopstate via HTML4 HashChange Support - */ - History.onHashChange = function(event){ - //History.debug('History.onHashChange', arguments); - // Prepare - var - currentUrl = ((event && event.newURL) || document.location.href), - currentHash = History.getHashByUrl(currentUrl), - currentState = null, - currentStateHash = null, - currentStateHashExits = null; + // ---------------------------------------------------------------------- + // HTML5 State Support - // Check if we are the same state - if ( History.isLastHash(currentHash) ) { - // There has been no change (just the page's hash has finally propagated) - //History.debug('History.onHashChange: no change'); - History.busy(false); - return false; - } + if (History.emulated.pushState) { + /* + * We must emulate the HTML5 State Management by using HTML4 HashChange + */ - // Reset the double check - History.doubleCheckComplete(); + /** + * History.onHashChange(event) + * Trigger HTML5's window.onpopstate via HTML4 HashChange Support + */ + History.onHashChange = function(event) { + //History.debug('History.onHashChange', arguments); - // Store our location for use in detecting back/forward direction - History.saveHash(currentHash); + // Prepare + var + currentUrl = ((event && event.newURL) || document.location.href), + currentHash = History.getHashByUrl(currentUrl), + currentState = null, + currentStateHash = null, + currentStateHashExits = null; - // Expand Hash - currentState = History.extractState(currentHash||document.location.href); - if ( !currentState ) { - //History.debug('History.onHashChange: traditional anchor', currentHash); - // Traditional Anchor Hash - History.Adapter.trigger(window,'anchorchange'); - History.busy(false); - return false; - } + // Check if we are the same state + if (History.isLastHash(currentHash)) { + // There has been no change (just the page's hash has finally propagated) + //History.debug('History.onHashChange: no change'); + History.busy(false); + return false; + } - // Check if we are the same state - if ( History.isLastSavedState(currentState) ) { - //History.debug('History.onHashChange: no change'); - // There has been no change (just the page's hash has finally propagated) - History.busy(false); - return false; - } + // Reset the double check + History.doubleCheckComplete(); - // Create the state Hash - currentStateHash = History.getHashByState(currentState); + // Store our location for use in detecting back/forward direction + History.saveHash(currentHash); - // Check if we are DiscardedState - var discardObject = History.discardedState(currentState); - if ( discardObject ) { - // Ignore this state as it has been discarded and go back to the state before it - if ( History.getHashByIndex(-2) === History.getHashByState(discardObject.forwardState) ) { - // We are going backwards - //History.debug('History.onHashChange: go backwards'); - History.back(false); - } else { - // We are going forwards - //History.debug('History.onHashChange: go forwards'); - History.forward(false); - } - History.busy(false); - return false; - } + // Expand Hash + if (currentHash && History.isTraditionalAnchor(currentHash)) { + //History.debug('History.onHashChange: traditional anchor', currentHash); + // Traditional Anchor Hash + History.Adapter.trigger(window, 'anchorchange'); + History.busy(false); + return false; + } - // Push the new HTML5 State - //History.debug('History.onHashChange: success hashchange'); - History.pushState(currentState.data,currentState.title,currentState.url,false); + // Create State + currentState = History.extractState(History.getFullUrl(currentHash || document.location.href, false), true); - // End onHashChange closure - return true; - }; - History.Adapter.bind(window,'hashchange',History.onHashChange); + // Check if we are the same state + if (History.isLastSavedState(currentState)) { + //History.debug('History.onHashChange: no change'); + // There has been no change (just the page's hash has finally propagated) + History.busy(false); + return false; + } - /** - * History.pushState(data,title,url) - * Add a new State to the history object, become it, and trigger onpopstate - * We have to trigger for HTML4 compatibility - * @param {object} data - * @param {string} title - * @param {string} url - * @return {true} - */ - History.pushState = function(data,title,url,queue){ - //History.debug('History.pushState: called', arguments); + // Create the state Hash + currentStateHash = History.getHashByState(currentState); - // Check the State - if ( History.getHashByUrl(url) ) { - throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).'); - } + // Check if we are DiscardedState + var discardObject = History.discardedState(currentState); + if (discardObject) { + // Ignore this state as it has been discarded and go back to the state before it + if (History.getHashByIndex(-2) === History.getHashByState(discardObject.forwardState)) { + // We are going backwards + //History.debug('History.onHashChange: go backwards'); + History.back(false); + } else { + // We are going forwards + //History.debug('History.onHashChange: go forwards'); + History.forward(false); + } + return false; + } - // Handle Queueing - if ( queue !== false && History.busy() ) { - // Wait + Push to Queue - //History.debug('History.pushState: we must wait', arguments); - History.pushQueue({ - scope: History, - callback: History.pushState, - args: arguments, - queue: queue - }); - return false; - } + // Push the new HTML5 State + //History.debug('History.onHashChange: success hashchange'); + History.pushState(currentState.data, currentState.title, currentState.url, false); - // Make Busy - History.busy(true); + // End onHashChange closure + return true; + }; + History.Adapter.bind(window, 'hashchange', History.onHashChange); - // Fetch the State Object - var - newState = History.createStateObject(data,title,url), - newStateHash = History.getHashByState(newState), - oldState = History.getState(false), - oldStateHash = History.getHashByState(oldState), - html4Hash = History.getHash(); + /** + * History.pushState(data,title,url) + * Add a new State to the history object, become it, and trigger onpopstate + * We have to trigger for HTML4 compatibility + * @param {object} data + * @param {string} title + * @param {string} url + * @return {true} + */ + History.pushState = function(data, title, url, queue) { + //History.debug('History.pushState: called', arguments); - // Store the newState - History.storeState(newState); - History.expectedStateId = newState.id; + // Check the State + if (History.getHashByUrl(url)) { + throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).'); + } - // Recycle the State - History.recycleState(newState); + // Handle Queueing + if (queue !== false && History.busy()) { + // Wait + Push to Queue + //History.debug('History.pushState: we must wait', arguments); + History.pushQueue({ + scope: History, + callback: History.pushState, + args: arguments, + queue: queue + }); + return false; + } - // Force update of the title - History.setTitle(newState); + // Make Busy + History.busy(true); - // Check if we are the same State - if ( newStateHash === oldStateHash ) { - //History.debug('History.pushState: no change', newStateHash); - History.busy(false); - return false; - } + // Fetch the State Object + var + newState = History.createStateObject(data, title, url), + newStateHash = History.getHashByState(newState), + oldState = History.getState(false), + oldStateHash = History.getHashByState(oldState), + html4Hash = History.getHash(); - // Update HTML4 Hash - if ( newStateHash !== html4Hash && newStateHash !== History.getShortUrl(document.location.href) ) { - //History.debug('History.pushState: update hash', newStateHash, html4Hash); - History.setHash(newStateHash,false); - return false; - } + // Store the newState + History.storeState(newState); + History.expectedStateId = newState.id; - // Update HTML5 State - History.saveState(newState); + // Recycle the State + History.recycleState(newState); - // Fire HTML5 Event - //History.debug('History.pushState: trigger popstate'); - History.Adapter.trigger(window,'statechange'); - History.busy(false); + // Force update of the title + History.setTitle(newState); - // End pushState closure - return true; - }; + // Check if we are the same State + if (newStateHash === oldStateHash) { + //History.debug('History.pushState: no change', newStateHash); + History.busy(false); + return false; + } - /** - * History.replaceState(data,title,url) - * Replace the State and trigger onpopstate - * We have to trigger for HTML4 compatibility - * @param {object} data - * @param {string} title - * @param {string} url - * @return {true} - */ - History.replaceState = function(data,title,url,queue){ - //History.debug('History.replaceState: called', arguments); + // Update HTML4 Hash + if (newStateHash !== html4Hash && newStateHash !== History.getShortUrl(document.location.href)) { + //History.debug('History.pushState: update hash', newStateHash, html4Hash); + History.setHash(newStateHash, false); + return false; + } - // Check the State - if ( History.getHashByUrl(url) ) { - throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).'); - } + // Update HTML5 State + History.saveState(newState); - // Handle Queueing - if ( queue !== false && History.busy() ) { - // Wait + Push to Queue - //History.debug('History.replaceState: we must wait', arguments); - History.pushQueue({ - scope: History, - callback: History.replaceState, - args: arguments, - queue: queue - }); - return false; - } + // Fire HTML5 Event + //History.debug('History.pushState: trigger popstate'); + History.Adapter.trigger(window, 'statechange'); + History.busy(false); - // Make Busy - History.busy(true); + // End pushState closure + return true; + }; - // Fetch the State Objects - var - newState = History.createStateObject(data,title,url), - oldState = History.getState(false), - previousState = History.getStateByIndex(-2); + /** + * History.replaceState(data,title,url) + * Replace the State and trigger onpopstate + * We have to trigger for HTML4 compatibility + * @param {object} data + * @param {string} title + * @param {string} url + * @return {true} + */ + History.replaceState = function(data, title, url, queue) { + //History.debug('History.replaceState: called', arguments); - // Discard Old State - History.discardState(oldState,newState,previousState); + // Check the State + if (History.getHashByUrl(url)) { + throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).'); + } - // Alias to PushState - History.pushState(newState.data,newState.title,newState.url,false); + // Handle Queueing + if (queue !== false && History.busy()) { + // Wait + Push to Queue + //History.debug('History.replaceState: we must wait', arguments); + History.pushQueue({ + scope: History, + callback: History.replaceState, + args: arguments, + queue: queue + }); + return false; + } - // End replaceState closure - return true; - }; + // Make Busy + History.busy(true); - /** - * Create the initial State - */ - History.saveState(History.storeState(History.createStateObject({},'',document.location.href))); + // Fetch the State Objects + var + newState = History.createStateObject(data, title, url), + oldState = History.getState(false), + previousState = History.getStateByIndex(-2); - /** - * Ensure initial state is handled correctly - */ - if ( History.getHash() && !History.emulated.hashChange ) { - History.Adapter.onDomLoad(function(){ - History.Adapter.trigger(window,'hashchange'); - }); - } + // Discard Old State + History.discardState(oldState, newState, previousState); - } // History.emulated.pushState + // Alias to PushState + History.pushState(newState.data, newState.title, newState.url, false); - }; // History.initHtml4 + // End replaceState closure + return true; + }; - // Try and Initialise History - History.init(); + /** + * Ensure initial state is handled correctly + */ + if (History.getHash() && !History.emulated.hashChange) { + History.Adapter.onDomLoad(function() { + History.Adapter.trigger(window, 'hashchange'); + }); + } + + } // History.emulated.pushState + + }; // History.initHtml4 + + // Try and Initialise History + History.init(); })(window);