/* YUI 3.17.2 (build 9c3c78e) Copyright 2014 Yahoo! Inc. All rights reserved. Licensed under the BSD License. http://yuilibrary.com/license/ */ YUI.add('history-html5', function (Y, NAME) { /** * Provides browser history management using the HTML5 history API. * * @module history * @submodule history-html5 * @since 3.2.0 */ /** *

* Provides browser history management using the HTML5 history API. *

* *

* When calling the add(), addValue(), * replace(), or replaceValue() methods on * HistoryHTML5, the following additional options are supported: *

* *
*
title (String)
*
* Title to use for the new history entry. Browsers will typically display * this title to the user in the detailed history window or in a dropdown * menu attached to the back/forward buttons. If not specified, the title * of the current document will be used. *
* *
url (String)
*
* URL to display to the user for the new history entry. This URL will be * visible in the browser's address bar and will be the bookmarked URL if * the user bookmarks the page. It may be a relative path ("foo/bar"), an * absolute path ("/foo/bar"), or a full URL ("http://example.com/foo/bar"). * If you specify a full URL, the origin must be the same as the * origin of the current page, or an error will occur. If no URL is * specified, the current URL will not be changed. *
*
* * @class HistoryHTML5 * @extends HistoryBase * @constructor * @param {Object} config (optional) Configuration object. */ var HistoryBase = Y.HistoryBase, Lang = Y.Lang, win = Y.config.win, useHistoryHTML5 = Y.config.useHistoryHTML5, SRC_POPSTATE = 'popstate', SRC_REPLACE = HistoryBase.SRC_REPLACE; function HistoryHTML5() { HistoryHTML5.superclass.constructor.apply(this, arguments); } Y.extend(HistoryHTML5, HistoryBase, { // -- Initialization ------------------------------------------------------- _init: function (config) { var bookmarkedState; try { bookmarkedState = win.history.state; } catch(e) { bookmarkedState = null; } // Treat empty state objects as `null` so they're not processed further. if (Y.Object.isEmpty(bookmarkedState)) { bookmarkedState = null; } config || (config = {}); // If both the initial state and the bookmarked state are objects, merge // them (bookmarked state wins). if (config.initialState && Lang.type(config.initialState) === 'object' && Lang.type(bookmarkedState) === 'object') { this._initialState = Y.merge(config.initialState, bookmarkedState); } else { // Otherwise, the bookmarked state always wins if there is one. If // there isn't a bookmarked state, history-base will take care of // falling back to config.initialState or null. this._initialState = bookmarkedState; } Y.on('popstate', this._onPopState, win, this); HistoryHTML5.superclass._init.apply(this, arguments); }, // -- Protected Methods ---------------------------------------------------- /** * Overrides HistoryBase's _storeState() and pushes or replaces * a history entry using the HTML5 history API when necessary. * * @method _storeState * @param {String} src Source of the changes. * @param {Object} newState New state to store. * @param {Object} options Zero or more options. * @protected */ _storeState: function (src, newState, options) { if (src !== SRC_POPSTATE) { win.history[src === SRC_REPLACE ? 'replaceState' : 'pushState']( newState, options.title || Y.config.doc.title || '', options.url || Y.config.doc.URL ); } HistoryHTML5.superclass._storeState.apply(this, arguments); }, // -- Protected Event Handlers --------------------------------------------- /** * Handler for popstate events. * * @method _onPopState * @param {Event} e * @protected */ _onPopState: function (e) { this._resolveChanges(SRC_POPSTATE, e._event.state || null); } }, { // -- Public Static Properties --------------------------------------------- NAME: 'historyhtml5', /** * Constant used to identify state changes originating from * popstate events. * * @property SRC_POPSTATE * @type String * @static * @final */ SRC_POPSTATE: SRC_POPSTATE }); if (!Y.Node.DOM_EVENTS.popstate) { Y.Node.DOM_EVENTS.popstate = 1; } Y.HistoryHTML5 = HistoryHTML5; /** *

* If true, the Y.History alias will always point to * Y.HistoryHTML5 when the history-html5 module is loaded, even if * the current browser doesn't support HTML5 history. *

* *

* If false, the Y.History alias will always point to * Y.HistoryHash when the history-hash module is loaded, even if * the current browser supports HTML5 history. *

* *

* If neither true nor false, the * Y.History alias will point to the best available history adapter * that the browser supports. This is the default behavior. *

* * @property useHistoryHTML5 * @type boolean * @for config * @since 3.2.0 */ // HistoryHTML5 will always win over HistoryHash unless useHistoryHTML5 is false // or HTML5 history is not supported. if (useHistoryHTML5 === true || (useHistoryHTML5 !== false && HistoryBase.html5)) { Y.History = HistoryHTML5; } }, '3.17.2', {"optional": ["json"], "requires": ["event-base", "history-base", "node-base"]});