- /**
- * History.escape()
- * normalize and Escape a Hash
- * @return {string}
- */
- History.escapeHash = function(hash){
- // Prepare
- var result = History.normalizeHash(hash);
-
- // Escape hash
- result = window.encodeURIComponent(result);
-
- // IE6 Escape Bug
- if ( !History.bugs.hashEscape ) {
- // Restore common parts
- result = result
- .replace(/\%21/g,'!')
- .replace(/\%26/g,'&')
- .replace(/\%3D/g,'=')
- .replace(/\%3F/g,'?');
- }
-
- // Return result
- return result;
- };
-
- /**
- * History.getHashByUrl(url)
- * Extracts the Hash from a URL
- * @param {string} url
- * @return {string} url
- */
- History.getHashByUrl = function(url){
- // Extract the hash
- var hash = String(url)
- .replace(/([^#]*)#?([^#]*)#?(.*)/, '$2')
- ;
-
- // Unescape hash
- hash = History.unescapeHash(hash);
-
- // Return hash
- return hash;
- };
-
- /**
- * History.setTitle(title)
- * Applies the title to the document
- * @param {State} newState
- * @return {Boolean}
- */
- History.setTitle = function(newState){
- // Prepare
- var title = newState.title,
- firstState;
-
- // Initial
- if ( !title ) {
- firstState = History.getStateByIndex(0);
- if ( firstState && firstState.url === newState.url ) {
- title = firstState.title||History.options.initialTitle;
- }
- }
-
- // Apply
- try {
- window.document.getElementsByTagName('title')[0].innerHTML = title.replace('<','<').replace('>','>').replace(' & ',' & ');
- }
- catch ( Exception ) { }
- window.document.title = title;
-
- // Chain
- return History;
- };
-
-
- // ====================================================================
- // Queueing
-
- /**
- * History.queues
- * The list of queues to use
- * First In, First Out
- */
- History.queues = [];
-
- /**
- * History.busy(value)
- * @param {boolean} value [optional]
- * @return {boolean} busy
- */
- History.busy = function(value){
- // Apply
- if ( typeof value !== 'undefined' ) {
- //History.debug('History.busy: changing ['+(History.busy.flag||false)+'] to ['+(value||false)+']', History.queues.length);
- History.busy.flag = value;
- }
- // Default
- else if ( typeof History.busy.flag === 'undefined' ) {
- History.busy.flag = false;
- }
-
- // Queue
- if ( !History.busy.flag ) {
- // Execute the next item in the queue
- window.clearTimeout(History.busy.timeout);
- var fireNext = function(){
- var i, queue, item;
- if ( History.busy.flag ) return;
- for ( i=History.queues.length-1; i >= 0; --i ) {
- queue = History.queues[i];
- if ( queue.length === 0 ) continue;
- item = queue.shift();
- History.fireQueueItem(item);
- History.busy.timeout = window.setTimeout(fireNext,History.options.busyDelay);
- }
- };
- History.busy.timeout = window.setTimeout(fireNext,History.options.busyDelay);
- }
-
- // Return
- return History.busy.flag;
- };
-
- /**
- * History.busy.flag
- */
- History.busy.flag = false;
-
- /**
- * History.fireQueueItem(item)
- * Fire a Queue Item
- * @param {Object} item
- * @return {Mixed} result
- */
- History.fireQueueItem = function(item){
- return item.callback.apply(item.scope||History,item.args||[]);
- };
-
- /**
- * History.pushQueue(callback,args)
- * Add an item to the queue
- * @param {Object} item [scope,callback,args,queue]
- */
- History.pushQueue = function(item){
- // Prepare the queue
- History.queues[item.queue||0] = History.queues[item.queue||0]||[];
-
- // Add to the queue
- History.queues[item.queue||0].push(item);
-
- // Chain
- return History;
- };
-
- /**
- * History.queue (item,queue), (func,queue), (func), (item)
- * Either firs the item now if not busy, or adds it to the queue
- */
- History.queue = function(item,queue){
- // Prepare
- if ( typeof item === 'function' ) {
- item = {
- callback: item
- };
- }
- if ( typeof queue !== 'undefined' ) {
- item.queue = queue;
- }
-
- // Handle
- if ( History.busy() ) {
- History.pushQueue(item);
- } else {
- History.fireQueueItem(item);
- }
-
- // Chain
- return History;
- };
-
- /**
- * History.clearQueue()
- * Clears the Queue
- */
- History.clearQueue = function(){
- History.busy.flag = false;
- History.queues = [];
- return History;
- };
-
-
- // ====================================================================
- // IE Bug Fix
-
- /**
- * History.stateChanged
- * States whether or not the state has changed since the last double check was initialised
- */
- History.stateChanged = false;
-
- /**
- * History.doubleChecker
- * Contains the timeout used for the double checks
- */
- History.doubleChecker = false;