76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Provides browser history management using the HTML5 history API.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module history
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @submodule history-html5
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @since 3.2.0
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Provides browser history management using the HTML5 history API.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * When calling the <code>add()</code>, <code>addValue()</code>,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <code>replace()</code>, or <code>replaceValue()</code> methods on
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <code>HistoryHTML5</code>, the following additional options are supported:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt><strong>title (String)</strong></dt>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Title to use for the new history entry. Browsers will typically display
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * this title to the user in the detailed history window or in a dropdown
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * menu attached to the back/forward buttons. If not specified, the title
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * of the current document will be used.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt><strong>url (String)</strong></dt>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * URL to display to the user for the new history entry. This URL will be
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * visible in the browser's address bar and will be the bookmarked URL if
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the user bookmarks the page. It may be a relative path ("foo/bar"), an
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * absolute path ("/foo/bar"), or a full URL ("http://example.com/foo/bar").
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If you specify a full URL, the origin <i>must</i> be the same as the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * origin of the current page, or an error will occur. If no URL is
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * specified, the current URL will not be changed.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @class HistoryHTML5
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @extends HistoryBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @constructor
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} config (optional) Configuration object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass HistoryHTML5.superclass.constructor.apply(this, arguments);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // -- Initialization -------------------------------------------------------
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // If both the initial state and the bookmarked state are objects, merge
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // them (bookmarked state wins).
c0d83403b13f02bc6fdcf62a712de150a7f974e2Dav Glass this._initialState = Y.merge(config.initialState, bookmarkedState);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Otherwise, the bookmarked state always wins if there is one. If
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // there isn't a bookmarked state, history-base will take care of
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // falling back to config.initialState or null.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass HistoryHTML5.superclass._init.apply(this, arguments);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // -- Protected Methods ----------------------------------------------------
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Overrides HistoryBase's <code>_storeState()</code> and pushes or replaces
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * a history entry using the HTML5 history API when necessary.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _storeState
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {String} src Source of the changes.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} newState New state to store.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Object} options Zero or more options.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass win.history[src === SRC_REPLACE ? 'replaceState' : 'pushState'](
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass HistoryHTML5.superclass._storeState.apply(this, arguments);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // -- Protected Event Handlers ---------------------------------------------
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Handler for popstate events.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _onPopState
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {Event} e
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _onPopState: function (e) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._resolveChanges(SRC_POPSTATE, e._event.state || null);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // -- Public Static Properties ---------------------------------------------
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Constant used to identify state changes originating from
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <code>popstate</code> events.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property SRC_POPSTATE
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If <code>true</code>, the <code>Y.History</code> alias will always point to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <code>Y.HistoryHTML5</code> when the history-html5 module is loaded, even if
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the current browser doesn't support HTML5 history.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If <code>false</code>, the <code>Y.History</code> alias will always point to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <code>Y.HistoryHash</code> when the history-hash module is loaded, even if
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the current browser supports HTML5 history.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If neither <code>true</code> nor <code>false</code>, the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <code>Y.History</code> alias will point to the best available history adapter
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * that the browser supports. This is the default behavior.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property useHistoryHTML5
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type boolean
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @for config
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @since 3.2.0
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// HistoryHTML5 will always win over HistoryHash unless useHistoryHTML5 is false
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// or HTML5 history is not supported.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassif (useHistoryHTML5 === true || (useHistoryHTML5 !== false &&
2aec82ac14ef1ebde4d5cc4ad35848834dacec6eRyan Grove}, '@VERSION@' ,{optional:['json'], requires:['event-base', 'history-base', 'node-base']});