history-hash-debug.js revision 2aec82ac14ef1ebde4d5cc4ad35848834dacec6e
/**
* Provides browser history management backed by
* <code>window.location.hash</code>, as well as convenience methods for working
* with the location hash and a synthetic <code>hashchange</code> event that
* normalizes differences across browsers.
*
* @module history
* @submodule history-hash
* @since 3.2.0
* @class HistoryHash
* @extends HistoryBase
* @constructor
* @param {Object} config (optional) Configuration object. See the HistoryBase
* documentation for details.
*/
var HistoryBase = Y.HistoryBase,
YArray = Y.Array,
YObject = Y.Object,
SRC_HASH = 'hash',
// In order to work around a nasty bug in WebKit that affects iOS 5, we need to
// listen for the pageshow event (which occurs when the page is restored from
// the page cache) and recreate our `window` and `location` references, since
// old references get detached even though they shouldn't be.
//
// Older versions of iOS bypass the page cache when an `unload` event listener
// is attached, but not iOS 5 for some reason.
//
// More details at https://bugs.webkit.org/show_bug.cgi?id=34679
if (e.persisted) {
}
}, false);
}
function HistoryHash() {
}
// -- Initialization -------------------------------------------------------
// If an initialState was provided, merge the bookmarked state into it
// (the bookmarked state wins).
// Subscribe to the synthetic hashchange event (defined below) to handle
// changes.
},
// -- Protected Methods ----------------------------------------------------
// Stringify all values to ensure that comparisons don't fail after
// they're coerced to strings in the location hash.
}
});
},
// Update the location hash with the changes, but only if the new hash
// actually differs from the current hash (this avoids creating multiple
// history entries for a single state).
//
// We always compare decoded hashes, since it's possible that the hash
// could be set incorrectly to a non-encoded value outside of
// HistoryHash.
}
},
// -- Protected Event Handlers ---------------------------------------------
/**
* Handler for hashchange events.
*
* @method _afterHashChange
* @param {Event} e
* @protected
*/
_afterHashChange: function (e) {
}
}, {
// -- Public Static Properties ---------------------------------------------
NAME: 'historyHash',
/**
* Constant used to identify state changes originating from
* <code>hashchange</code> events.
*
* @property SRC_HASH
* @type String
* @static
* @final
*/
/**
* <p>
* Prefix to prepend when setting the hash fragment. For example, if the
* prefix is <code>!</code> and the hash fragment is set to
* <code>#foo=bar&baz=quux</code>, the final hash fragment in the URL will
* become <code>#!foo=bar&baz=quux</code>. This can be used to help make an
* Ajax application crawlable in accordance with Google's guidelines at
* </p>
*
* <p>
* Note that this prefix applies to all HistoryHash instances. It's not
* possible for individual instances to use their own prefixes since they
* all operate on the same URL.
* </p>
*
* @property hashPrefix
* @type String
* @default ''
* @static
*/
hashPrefix: '',
// -- Protected Static Properties ------------------------------------------
/**
*
* @property _REGEX_HASH
* @type RegExp
* @protected
* @static
* @final
*/
_REGEX_HASH: /([^\?#&]+)=([^&]+)/g,
// -- Public Static Methods ------------------------------------------------
/**
* pairs.
*
* @method createHash
* @return {String} location hash string
* @static
*/
createHash: function (params) {
hash = [];
}
});
},
/**
* Wrapper around <code>decodeURIComponent()</code> that also converts +
* chars into spaces.
*
* @method decode
* @param {String} string string to decode
* @return {String} decoded string
* @static
*/
},
/**
* Wrapper around <code>encodeURIComponent()</code> that converts spaces to
* + chars.
*
* @method encode
* @param {String} string string to encode
* @return {String} encoded string
* @static
*/
},
/**
* Gets the raw (not decoded) current location hash, minus the preceding '#'
* character and the hashPrefix (if one is set).
*
* @method getHash
* @return {String} current location hash
* @static
*/
// Gecko's window.location.hash returns a decoded string and we want all
// encoding untouched, so we need to get the hash value from
// window.location.href instead. We have to use UA sniffing rather than
// feature detection, since the only way to detect this would be to
// actually change the hash.
} : function () {
// Slight code duplication here, but execution speed is of the essence
// since getHash() is called every 50ms to poll for changes in browsers
// that don't support native onhashchange. An additional function call
// would add unnecessary overhead.
}),
/**
* Gets the current bookmarkable URL.
*
* @method getUrl
* @return {String} current bookmarkable URL
* @static
*/
getUrl: function () {
},
/**
* pairs. If <i>hash</i> is not specified, the current location hash will
* be used.
*
* @method parseHash
* @param {String} hash (optional) location hash string
* @static
*/
i,
len,
params = {},
if (prefix) {
}
}
}
return params;
},
/**
* Replaces the browser's current location hash with the specified hash
* and removes all forward navigation states, without creating a new browser
* history entry. Automatically prepends the <code>hashPrefix</code> if one
* is set.
*
* @method replaceHash
* @param {String} hash new location hash
* @static
*/
replaceHash: function (hash) {
}
},
/**
* Sets the browser's location hash to the specified string. Automatically
* prepends the <code>hashPrefix</code> if one is set.
*
* @method setHash
* @param {String} hash new location hash
* @static
*/
}
}
});
// -- Synthetic hashchange Event -----------------------------------------------
// TODO: YUIDoc currently doesn't provide a good way to document synthetic DOM
// events. For now, we're just documenting the hashchange event on the YUI
// object, which is about the best we can do until enhancements are made to
// YUIDoc.
/**
Synthetic <code>window.onhashchange</code> event that normalizes differences
across browsers and provides support for browsers that don't natively support
<code>onhashchange</code>.
This event is provided by the <code>history-hash</code> module.
@example
YUI().use('history-hash', function (Y) {
Y.on('hashchange', function (e) {
// Handle hashchange events on the current window.
}, Y.config.win);
});
@event hashchange
@param {EventFacade} e Event facade with the following additional
properties:
<dl>
<dt>oldHash</dt>
<dd>
Previous hash fragment value before the change.
</dd>
<dt>oldUrl</dt>
<dd>
Previous URL (including the hash fragment) before the change.
</dd>
<dt>newHash</dt>
<dd>
New hash fragment value after the change.
</dd>
<dt>newUrl</dt>
<dd>
New URL (including the hash fragment) after the change.
</dd>
</dl>
@for YUI
@since 3.2.0
**/
if (!hashNotifiers) {
}
// Ignore this subscription if the node is anything other than the
// window or document body, since those are the only elements that
// should support the hashchange event. Note that the body could also be
// a frameset, but that's okay since framesets support hashchange too.
}
},
if (index !== -1) {
}
}
});
if (HistoryBase.nativeHashChange) {
// Wrap the browser's native hashchange event.
// Iterate over a copy of the hashNotifiers array since a subscriber
// could detach during iteration and cause the array to be re-indexed.
_event : e,
});
});
}, win);
} else {
// Begin polling for location hash changes if there's not already a global
// poll running.
facade = {
};
});
}
}, null, true);
}
}
// works around a nasty Safari bug when the back button is used to return
// from a page on another domain, but results in slightly worse performance.
// This bug is not present in Chrome.
//
// Unfortunately a UA sniff is unavoidable here, but the consequences of a
// false positive are minor.
//
// Current as of Safari 5.0 (6533.16).
//
// Note that this workaround has no effect in iOS 5, so a separate
// workaround using the 'pageshow' event is used there (see the top of this
// file).
}
Y.HistoryHash = HistoryHash;
// HistoryHash will never win over HistoryHTML5 unless useHistoryHTML5 is false.
Y.History = HistoryHash;
}