Skip to content
Browse files

Build Pjax.

  • Loading branch information...
1 parent 2047e6f commit 04aa96d3b5669aaf3bff1aae07d7b5083a24a37c @ericf ericf committed Nov 9, 2012
View
157 build/pjax-base/pjax-base-coverage.js
@@ -26,10 +26,10 @@ _yuitest_coverage["build/pjax-base/pjax-base.js"] = {
path: "build/pjax-base/pjax-base.js",
code: []
};
-_yuitest_coverage["build/pjax-base/pjax-base.js"].code=["YUI.add('pjax-base', function (Y, NAME) {","","/**","`Y.Router` extension that provides the core plumbing for enhanced navigation","implemented using the pjax technique (HTML5 pushState + Ajax).","","@module pjax","@submodule pjax-base","@since 3.5.0","**/","","var win = Y.config.win,",""," // The CSS class name used to filter link clicks from only the links which"," // the pjax enhanced navigation should be used."," CLASS_PJAX = Y.ClassNameManager.getClassName('pjax'),",""," /**"," Fired when navigating to a URL via Pjax.",""," When the `navigate()` method is called or a pjax link is clicked, this event"," will be fired if the browser supports HTML5 history _and_ the router has a"," route handler for the specified URL.",""," This is a useful event to listen to for adding a visual loading indicator"," while the route handlers are busy handling the URL change.",""," @event navigate"," @param {String} url The URL that the router will dispatch to its route"," handlers in order to fulfill the enhanced navigation \"request\"."," @param {Boolean} [force=false] Whether the enhanced navigation should occur"," even in browsers without HTML5 history."," @param {String} [hash] The hash-fragment (including \"#\") of the `url`. This"," will be present when the `url` differs from the current URL only by its"," hash and `navigateOnHash` has been set to `true`."," @param {Event} [originEvent] The event that caused the navigation. Usually"," this would be a click event from a \"pjax\" anchor element."," @param {Boolean} [replace] Whether or not the current history entry will be"," replaced, or a new entry will be created. Will default to `true` if the"," specified `url` is the same as the current URL."," @since 3.5.0"," **/"," EVT_NAVIGATE = 'navigate';","","/**","`Y.Router` extension that provides the core plumbing for enhanced navigation","implemented using the pjax technique (HTML5 `pushState` + Ajax).","","This makes it easy to enhance the navigation between the URLs of an application","in HTML5 history capable browsers by delegating to the router to fulfill the","\"request\" and seamlessly falling-back to using standard full-page reloads in","older, less-capable browsers.","","The `PjaxBase` class isn't useful on its own, but can be mixed into a","`Router`-based class to add Pjax functionality to that Router. For a pre-made","standalone Pjax router, see the `Pjax` class.",""," var MyRouter = Y.Base.create('myRouter', Y.Router, [Y.PjaxBase], {"," // ..."," });","","@class PjaxBase","@extensionfor Router","@since 3.5.0","**/","function PjaxBase() {}","","PjaxBase.prototype = {"," // -- Protected Properties -------------------------------------------------",""," /**"," Holds the delegated pjax-link click handler.",""," @property _pjaxEvents"," @type EventHandle"," @protected"," @since 3.5.0"," **/",""," /**"," Regex used to break up a URL string around the URL's path.",""," Subpattern captures:",""," 1. Origin, everything before the URL's path-part."," 2. The URL's path-part."," 3. Suffix, everything after the URL's path-part.",""," @property _regexURL"," @type RegExp"," @protected"," @since 3.5.0"," **/"," _regexURL: /^((?:[^\\/#?:]+:\\/\\/|\\/\\/)[^\\/]*)?([^?#]*)(\\?[^#]*)?(#.*)?$/,",""," // -- Lifecycle Methods ----------------------------------------------------"," initializer: function () {"," this.publish(EVT_NAVIGATE, {defaultFn: this._defNavigateFn});",""," // Pjax is all about progressively enhancing the navigation between"," // \"pages\", so by default we only want to handle and route link clicks"," // in HTML5 `pushState`-compatible browsers."," if (this.get('html5')) {"," this._pjaxBindUI();"," }"," },",""," destructor: function () {"," this._pjaxEvents && this._pjaxEvents.detach();"," },",""," // -- Public Methods -------------------------------------------------------",""," /**"," Navigates to the specified URL if there is a route handler that matches. In"," browsers capable of using HTML5 history, the navigation will be enhanced by"," firing the `navigate` event and having the router handle the \"request\"."," Non-HTML5 browsers will navigate to the new URL via manipulation of"," `window.location`.",""," When there is a route handler for the specified URL and it is being"," navigated to, this method will return `true`, otherwise it will return"," `false`.",""," **Note:** The specified URL _must_ be of the same origin as the current URL,"," otherwise an error will be logged and navigation will not occur. This is"," intended as both a security constraint and a purposely imposed limitation as"," it does not make sense to tell the router to navigate to a URL on a"," different scheme, host, or port.",""," @method navigate"," @param {String} url The URL to navigate to. This must be of the same origin"," as the current URL."," @param {Object} [options] Additional options to configure the navigation."," These are mixed into the `navigate` event facade."," @param {Boolean} [options.replace] Whether or not the current history"," entry will be replaced, or a new entry will be created. Will default"," to `true` if the specified `url` is the same as the current URL."," @param {Boolean} [options.force=false] Whether the enhanced navigation"," should occur even in browsers without HTML5 history."," @return {Boolean} `true` if the URL was navigated to, `false` otherwise."," @since 3.5.0"," **/"," navigate: function (url, options) {"," // The `_navigate()` method expects fully-resolved URLs."," url = this._resolveURL(url);",""," if (this._navigate(url, options)) {"," return true;"," }",""," if (!this._hasSameOrigin(url)) {"," Y.error('Security error: The new URL must be of the same origin as the current URL.');"," }",""," return false;"," },",""," // -- Protected Methods ----------------------------------------------------",""," /**"," Utility method to test whether a specified link/anchor node's `href` is of"," the same origin as the page's current location.",""," This normalize browser inconsistencies with how the `port` is reported for"," anchor elements (IE reports a value for the default port, e.g. \"80\").",""," @method _isLinkSameOrigin"," @param {Node} link The anchor element to test whether its `href` is of the"," same origin as the page's current location."," @return {Boolean} Whether or not the link's `href` is of the same origin as"," the page's current location."," @protected"," @since 3.6.0"," **/"," _isLinkSameOrigin: function (link) {"," var location = Y.getLocation(),"," protocol = location.protocol,"," hostname = location.hostname,"," port = parseInt(location.port, 10) || null,"," linkPort;",""," // Link must have the same `protocol` and `hostname` as the page's"," // currrent location."," if (link.get('protocol') !== protocol ||"," link.get('hostname') !== hostname) {",""," return false;"," }",""," linkPort = parseInt(link.get('port'), 10) || null;",""," // Normalize ports. In most cases browsers use an empty string when the"," // port is the default port, but IE does weird things with anchor"," // elements, so to be sure, this will re-assign the default ports before"," // they are compared."," if (protocol === 'http:') {"," port || (port = 80);"," linkPort || (linkPort = 80);"," } else if (protocol === 'https:') {"," port || (port = 443);"," linkPort || (linkPort = 443);"," }",""," // Finally, to be from the same origin, the link's `port` must match the"," // page's current `port`."," return linkPort === port;"," },",""," /**"," Underlying implementation for `navigate()`.",""," @method _navigate"," @param {String} url The fully-resolved URL that the router should dispatch"," to its route handlers to fulfill the enhanced navigation \"request\", or use"," to update `window.location` in non-HTML5 history capable browsers."," @param {Object} [options] Additional options to configure the navigation."," These are mixed into the `navigate` event facade."," @param {Boolean} [options.replace] Whether or not the current history"," entry will be replaced, or a new entry will be created. Will default"," to `true` if the specified `url` is the same as the current URL."," @param {Boolean} [options.force=false] Whether the enhanced navigation"," should occur even in browsers without HTML5 history."," @return {Boolean} `true` if the URL was navigated to, `false` otherwise."," @protected"," @since 3.5.0"," **/"," _navigate: function (url, options) {"," url = this._upgradeURL(url);",""," // Navigation can only be enhanced if there is a route-handler."," if (!this.hasRoute(url)) {"," return false;"," }",""," // Make a copy of `options` before modifying it."," options = Y.merge(options, {url: url});",""," var currentURL = this._getURL(),"," hash, hashlessURL;",""," // Captures the `url`'s hash and returns a URL without that hash."," hashlessURL = url.replace(/(#.*)$/, function (u, h, i) {"," hash = h;"," return u.substring(i);"," });",""," if (hash && hashlessURL === currentURL.replace(/#.*$/, '')) {"," // When the specified `url` and current URL only differ by the hash,"," // the browser should handle this in-page navigation normally."," if (!this.get('navigateOnHash')) {"," return false;"," }",""," options.hash = hash;"," }",""," // When navigating to the same URL as the current URL, behave like a"," // browser and replace the history entry instead of creating a new one."," 'replace' in options || (options.replace = url === currentURL);",""," // The `navigate` event will only fire and therefore enhance the"," // navigation to the new URL in HTML5 history enabled browsers or when"," // forced. Otherwise it will fallback to assigning or replacing the URL"," // on `window.location`."," if (this.get('html5') || options.force) {"," this.fire(EVT_NAVIGATE, options);"," } else {"," if (options.replace) {"," win && win.location.replace(url);"," } else {"," win && (win.location = url);"," }"," }",""," return true;"," },",""," /**"," Binds the delegation of link-click events that match the `linkSelector` to"," the `_onLinkClick()` handler.",""," By default this method will only be called if the browser is capable of"," using HTML5 history.",""," @method _pjaxBindUI"," @protected"," @since 3.5.0"," **/"," _pjaxBindUI: function () {"," // Only bind link if we haven't already."," if (!this._pjaxEvents) {"," this._pjaxEvents = Y.one('body').delegate('click',"," this._onLinkClick, this.get('linkSelector'), this);"," }"," },",""," // -- Protected Event Handlers ---------------------------------------------",""," /**"," Default handler for the `navigate` event.",""," Adds a new history entry or replaces the current entry for the specified URL"," and will scroll the page to the top if configured to do so.",""," @method _defNavigateFn"," @param {EventFacade} e"," @protected"," @since 3.5.0"," **/"," _defNavigateFn: function (e) {"," this[e.replace ? 'replace' : 'save'](e.url);",""," if (win && this.get('scrollToTop')) {"," // Scroll to the top of the page. The timeout ensures that the"," // scroll happens after navigation begins, so that the current"," // scroll position will be restored if the user clicks the back"," // button."," setTimeout(function () {"," win.scroll(0, 0);"," }, 1);"," }"," },",""," /**"," Handler for delegated link-click events which match the `linkSelector`.",""," This will attempt to enhance the navigation to the link element's `href` by"," passing the URL to the `_navigate()` method. When the navigation is being"," enhanced, the default action is prevented.",""," If the user clicks a link with the middle/right mouse buttons, or is holding"," down the Ctrl or Command keys, this method's behavior is not applied and"," allows the native behavior to occur. Similarly, if the router is not capable"," or handling the URL because no route-handlers match, the link click will"," behave natively.",""," @method _onLinkClick"," @param {EventFacade} e"," @protected"," @since 3.5.0"," **/"," _onLinkClick: function (e) {"," var link, url;",""," // Allow the native behavior on middle/right-click, or when Ctrl or"," // Command are pressed."," if (e.button !== 1 || e.ctrlKey || e.metaKey) { return; }",""," link = e.currentTarget;",""," // Only allow anchor elements because we need access to its `protocol`,"," // `host`, and `href` attributes."," if (link.get('tagName').toUpperCase() !== 'A') {"," return;"," }",""," // Same origin check to prevent trying to navigate to URLs from other"," // sites or things like mailto links."," if (!this._isLinkSameOrigin(link)) {"," return;"," }",""," // All browsers fully resolve an anchor's `href` property."," url = link.get('href');",""," // Try and navigate to the URL via the router, and prevent the default"," // link-click action if we do."," url && this._navigate(url, {originEvent: e}) && e.preventDefault();"," }","};","","PjaxBase.ATTRS = {"," /**"," CSS selector string used to filter link click events so that only the links"," which match it will have the enhanced navigation behavior of Pjax applied.",""," When a link is clicked and that link matches this selector, Pjax will"," attempt to dispatch to any route handlers matching the link's `href` URL. If"," HTML5 history is not supported or if no route handlers match, the link click"," will be handled by the browser just like any old link.",""," @attribute linkSelector"," @type String|Function"," @default \"a.yui3-pjax\""," @initOnly"," @since 3.5.0"," **/"," linkSelector: {"," value : 'a.' + CLASS_PJAX,"," writeOnce: 'initOnly'"," },",""," /**"," Whether navigating to a hash-fragment identifier on the current page should"," be enhanced and cause the `navigate` event to fire.",""," By default Pjax allows the browser to perform its default action when a user"," is navigating within a page by clicking in-page links"," (e.g. `<a href=\"#top\">Top of page</a>`) and does not attempt to interfere or"," enhance in-page navigation.",""," @attribute navigateOnHash"," @type Boolean"," @default false"," @since 3.5.0"," **/"," navigateOnHash: {"," value: false"," },",""," /**"," Whether the page should be scrolled to the top after navigating to a URL.",""," When the user clicks the browser's back button, the previous scroll position"," will be maintained.",""," @attribute scrollToTop"," @type Boolean"," @default true"," @since 3.5.0"," **/"," scrollToTop: {"," value: true"," }","};","","Y.PjaxBase = PjaxBase;","","","}, '@VERSION@', {\"requires\": [\"classnamemanager\", \"node-event-delegate\", \"router\"]});"];
-_yuitest_coverage["build/pjax-base/pjax-base.js"].lines = {"1":0,"12":0,"66":0,"68":0,"98":0,"103":0,"104":0,"109":0,"146":0,"148":0,"149":0,"152":0,"153":0,"156":0,"177":0,"185":0,"188":0,"191":0,"197":0,"198":0,"199":0,"200":0,"201":0,"202":0,"207":0,"229":0,"232":0,"233":0,"237":0,"239":0,"243":0,"244":0,"245":0,"248":0,"251":0,"252":0,"255":0,"260":0,"266":0,"267":0,"269":0,"270":0,"272":0,"276":0,"292":0,"293":0,"312":0,"314":0,"319":0,"320":0,"344":0,"348":0,"350":0,"354":0,"355":0,"360":0,"361":0,"365":0,"369":0,"373":0,"428":0};
-_yuitest_coverage["build/pjax-base/pjax-base.js"].functions = {"PjaxBase:66":0,"initializer:97":0,"destructor:108":0,"navigate:144":0,"_isLinkSameOrigin:176":0,"(anonymous 2):243":0,"_navigate:228":0,"_pjaxBindUI:290":0,"(anonymous 3):319":0,"_defNavigateFn:311":0,"_onLinkClick:343":0,"(anonymous 1):1":0};
-_yuitest_coverage["build/pjax-base/pjax-base.js"].coveredLines = 61;
+_yuitest_coverage["build/pjax-base/pjax-base.js"].code=["YUI.add('pjax-base', function (Y, NAME) {","","/**","`Y.Router` extension that provides the core plumbing for enhanced navigation","implemented using the pjax technique (HTML5 pushState + Ajax).","","@module pjax","@submodule pjax-base","@since 3.5.0","**/","","var win = Y.config.win,",""," // The CSS class name used to filter link clicks from only the links which"," // the pjax enhanced navigation should be used."," CLASS_PJAX = Y.ClassNameManager.getClassName('pjax'),",""," /**"," Fired when navigating to a URL via Pjax.",""," When the `navigate()` method is called or a pjax link is clicked, this event"," will be fired if the browser supports HTML5 history _and_ the router has a"," route handler for the specified URL.",""," This is a useful event to listen to for adding a visual loading indicator"," while the route handlers are busy handling the URL change.",""," @event navigate"," @param {String} url The URL that the router will dispatch to its route"," handlers in order to fulfill the enhanced navigation \"request\"."," @param {Boolean} [force=false] Whether the enhanced navigation should occur"," even in browsers without HTML5 history."," @param {String} [hash] The hash-fragment (including \"#\") of the `url`. This"," will be present when the `url` differs from the current URL only by its"," hash and `navigateOnHash` has been set to `true`."," @param {Event} [originEvent] The event that caused the navigation. Usually"," this would be a click event from a \"pjax\" anchor element."," @param {Boolean} [replace] Whether or not the current history entry will be"," replaced, or a new entry will be created. Will default to `true` if the"," specified `url` is the same as the current URL."," @since 3.5.0"," **/"," EVT_NAVIGATE = 'navigate';","","/**","`Y.Router` extension that provides the core plumbing for enhanced navigation","implemented using the pjax technique (HTML5 `pushState` + Ajax).","","This makes it easy to enhance the navigation between the URLs of an application","in HTML5 history capable browsers by delegating to the router to fulfill the","\"request\" and seamlessly falling-back to using standard full-page reloads in","older, less-capable browsers.","","The `PjaxBase` class isn't useful on its own, but can be mixed into a","`Router`-based class to add Pjax functionality to that Router. For a pre-made","standalone Pjax router, see the `Pjax` class.",""," var MyRouter = Y.Base.create('myRouter', Y.Router, [Y.PjaxBase], {"," // ..."," });","","@class PjaxBase","@extensionfor Router","@since 3.5.0","**/","function PjaxBase() {}","","PjaxBase.prototype = {"," // -- Protected Properties -------------------------------------------------",""," /**"," Holds the delegated pjax-link click handler.",""," @property _pjaxEvents"," @type EventHandle"," @protected"," @since 3.5.0"," **/",""," /**"," Regex used to break up a URL string around the URL's path.",""," Subpattern captures:",""," 1. Origin, everything before the URL's path-part."," 2. The URL's path-part."," 3. Suffix, everything after the URL's path-part.",""," @property _regexURL"," @type RegExp"," @protected"," @since 3.5.0"," **/"," _regexURL: /^((?:[^\\/#?:]+:\\/\\/|\\/\\/)[^\\/]*)?([^?#]*)(\\?[^#]*)?(#.*)?$/,",""," // -- Lifecycle Methods ----------------------------------------------------"," initializer: function () {"," this.publish(EVT_NAVIGATE, {defaultFn: this._defNavigateFn});",""," // Pjax is all about progressively enhancing the navigation between"," // \"pages\", so by default we only want to handle and route link clicks"," // in HTML5 `pushState`-compatible browsers."," if (this.get('html5')) {"," this._pjaxBindUI();"," }"," },",""," destructor: function () {"," if (this._pjaxEvents) {"," this._pjaxEvents.detach();"," }"," },",""," // -- Public Methods -------------------------------------------------------",""," /**"," Navigates to the specified URL if there is a route handler that matches. In"," browsers capable of using HTML5 history, the navigation will be enhanced by"," firing the `navigate` event and having the router handle the \"request\"."," Non-HTML5 browsers will navigate to the new URL via manipulation of"," `window.location`.",""," When there is a route handler for the specified URL and it is being"," navigated to, this method will return `true`, otherwise it will return"," `false`.",""," **Note:** The specified URL _must_ be of the same origin as the current URL,"," otherwise an error will be logged and navigation will not occur. This is"," intended as both a security constraint and a purposely imposed limitation as"," it does not make sense to tell the router to navigate to a URL on a"," different scheme, host, or port.",""," @method navigate"," @param {String} url The URL to navigate to. This must be of the same origin"," as the current URL."," @param {Object} [options] Additional options to configure the navigation."," These are mixed into the `navigate` event facade."," @param {Boolean} [options.replace] Whether or not the current history"," entry will be replaced, or a new entry will be created. Will default"," to `true` if the specified `url` is the same as the current URL."," @param {Boolean} [options.force=false] Whether the enhanced navigation"," should occur even in browsers without HTML5 history."," @return {Boolean} `true` if the URL was navigated to, `false` otherwise."," @since 3.5.0"," **/"," navigate: function (url, options) {"," // The `_navigate()` method expects fully-resolved URLs."," url = this._resolveURL(url);",""," if (this._navigate(url, options)) {"," return true;"," }",""," if (!this._hasSameOrigin(url)) {"," Y.error('Security error: The new URL must be of the same origin as the current URL.');"," }",""," return false;"," },",""," // -- Protected Methods ----------------------------------------------------",""," /**"," Utility method to test whether a specified link/anchor node's `href` is of"," the same origin as the page's current location.",""," This normalize browser inconsistencies with how the `port` is reported for"," anchor elements (IE reports a value for the default port, e.g. \"80\").",""," @method _isLinkSameOrigin"," @param {Node} link The anchor element to test whether its `href` is of the"," same origin as the page's current location."," @return {Boolean} Whether or not the link's `href` is of the same origin as"," the page's current location."," @protected"," @since 3.6.0"," **/"," _isLinkSameOrigin: function (link) {"," var location = Y.getLocation(),"," protocol = location.protocol,"," hostname = location.hostname,"," port = parseInt(location.port, 10) || null,"," linkPort;",""," // Link must have the same `protocol` and `hostname` as the page's"," // currrent location."," if (link.get('protocol') !== protocol ||"," link.get('hostname') !== hostname) {",""," return false;"," }",""," linkPort = parseInt(link.get('port'), 10) || null;",""," // Normalize ports. In most cases browsers use an empty string when the"," // port is the default port, but IE does weird things with anchor"," // elements, so to be sure, this will re-assign the default ports before"," // they are compared."," if (protocol === 'http:') {"," port || (port = 80);"," linkPort || (linkPort = 80);"," } else if (protocol === 'https:') {"," port || (port = 443);"," linkPort || (linkPort = 443);"," }",""," // Finally, to be from the same origin, the link's `port` must match the"," // page's current `port`."," return linkPort === port;"," },",""," /**"," Underlying implementation for `navigate()`.",""," @method _navigate"," @param {String} url The fully-resolved URL that the router should dispatch"," to its route handlers to fulfill the enhanced navigation \"request\", or use"," to update `window.location` in non-HTML5 history capable browsers."," @param {Object} [options] Additional options to configure the navigation."," These are mixed into the `navigate` event facade."," @param {Boolean} [options.replace] Whether or not the current history"," entry will be replaced, or a new entry will be created. Will default"," to `true` if the specified `url` is the same as the current URL."," @param {Boolean} [options.force=false] Whether the enhanced navigation"," should occur even in browsers without HTML5 history."," @return {Boolean} `true` if the URL was navigated to, `false` otherwise."," @protected"," @since 3.5.0"," **/"," _navigate: function (url, options) {"," url = this._upgradeURL(url);",""," // Navigation can only be enhanced if there is a route-handler."," if (!this.hasRoute(url)) {"," return false;"," }",""," // Make a copy of `options` before modifying it."," options = Y.merge(options, {url: url});",""," var currentURL = this._getURL(),"," hash, hashlessURL;",""," // Captures the `url`'s hash and returns a URL without that hash."," hashlessURL = url.replace(/(#.*)$/, function (u, h, i) {"," hash = h;"," return u.substring(i);"," });",""," if (hash && hashlessURL === currentURL.replace(/#.*$/, '')) {"," // When the specified `url` and current URL only differ by the hash,"," // the browser should handle this in-page navigation normally."," if (!this.get('navigateOnHash')) {"," return false;"," }",""," options.hash = hash;"," }",""," // When navigating to the same URL as the current URL, behave like a"," // browser and replace the history entry instead of creating a new one."," 'replace' in options || (options.replace = url === currentURL);",""," // The `navigate` event will only fire and therefore enhance the"," // navigation to the new URL in HTML5 history enabled browsers or when"," // forced. Otherwise it will fallback to assigning or replacing the URL"," // on `window.location`."," if (this.get('html5') || options.force) {"," this.fire(EVT_NAVIGATE, options);"," } else if (win) {"," if (options.replace) {"," win.location.replace(url);"," } else {"," win.location = url;"," }"," }",""," return true;"," },",""," /**"," Binds the delegation of link-click events that match the `linkSelector` to"," the `_onLinkClick()` handler.",""," By default this method will only be called if the browser is capable of"," using HTML5 history.",""," @method _pjaxBindUI"," @protected"," @since 3.5.0"," **/"," _pjaxBindUI: function () {"," // Only bind link if we haven't already."," if (!this._pjaxEvents) {"," this._pjaxEvents = Y.one('body').delegate('click',"," this._onLinkClick, this.get('linkSelector'), this);"," }"," },",""," // -- Protected Event Handlers ---------------------------------------------",""," /**"," Default handler for the `navigate` event.",""," Adds a new history entry or replaces the current entry for the specified URL"," and will scroll the page to the top if configured to do so.",""," @method _defNavigateFn"," @param {EventFacade} e"," @protected"," @since 3.5.0"," **/"," _defNavigateFn: function (e) {"," this[e.replace ? 'replace' : 'save'](e.url);",""," if (win && this.get('scrollToTop')) {"," // Scroll to the top of the page. The timeout ensures that the"," // scroll happens after navigation begins, so that the current"," // scroll position will be restored if the user clicks the back"," // button."," setTimeout(function () {"," win.scroll(0, 0);"," }, 1);"," }"," },",""," /**"," Handler for delegated link-click events which match the `linkSelector`.",""," This will attempt to enhance the navigation to the link element's `href` by"," passing the URL to the `_navigate()` method. When the navigation is being"," enhanced, the default action is prevented.",""," If the user clicks a link with the middle/right mouse buttons, or is holding"," down the Ctrl or Command keys, this method's behavior is not applied and"," allows the native behavior to occur. Similarly, if the router is not capable"," or handling the URL because no route-handlers match, the link click will"," behave natively.",""," @method _onLinkClick"," @param {EventFacade} e"," @protected"," @since 3.5.0"," **/"," _onLinkClick: function (e) {"," var link, url, navigated;",""," // Allow the native behavior on middle/right-click, or when Ctrl or"," // Command are pressed."," if (e.button !== 1 || e.ctrlKey || e.metaKey) { return; }",""," link = e.currentTarget;",""," // Only allow anchor elements because we need access to its `protocol`,"," // `host`, and `href` attributes."," if (link.get('tagName').toUpperCase() !== 'A') {"," return;"," }",""," // Same origin check to prevent trying to navigate to URLs from other"," // sites or things like mailto links."," if (!this._isLinkSameOrigin(link)) {"," return;"," }",""," // All browsers fully resolve an anchor's `href` property."," url = link.get('href');",""," // Try and navigate to the URL via the router, and prevent the default"," // link-click action if we do."," if (url) {"," navigated = this._navigate(url, {originEvent: e});",""," if (navigated) {"," e.preventDefault();"," }"," }"," }","};","","PjaxBase.ATTRS = {"," /**"," CSS selector string used to filter link click events so that only the links"," which match it will have the enhanced navigation behavior of Pjax applied.",""," When a link is clicked and that link matches this selector, Pjax will"," attempt to dispatch to any route handlers matching the link's `href` URL. If"," HTML5 history is not supported or if no route handlers match, the link click"," will be handled by the browser just like any old link.",""," @attribute linkSelector"," @type String|Function"," @default \"a.yui3-pjax\""," @initOnly"," @since 3.5.0"," **/"," linkSelector: {"," value : 'a.' + CLASS_PJAX,"," writeOnce: 'initOnly'"," },",""," /**"," Whether navigating to a hash-fragment identifier on the current page should"," be enhanced and cause the `navigate` event to fire.",""," By default Pjax allows the browser to perform its default action when a user"," is navigating within a page by clicking in-page links"," (e.g. `<a href=\"#top\">Top of page</a>`) and does not attempt to interfere or"," enhance in-page navigation.",""," @attribute navigateOnHash"," @type Boolean"," @default false"," @since 3.5.0"," **/"," navigateOnHash: {"," value: false"," },",""," /**"," Whether the page should be scrolled to the top after navigating to a URL.",""," When the user clicks the browser's back button, the previous scroll position"," will be maintained.",""," @attribute scrollToTop"," @type Boolean"," @default true"," @since 3.5.0"," **/"," scrollToTop: {"," value: true"," }","};","","Y.PjaxBase = PjaxBase;","","","}, '@VERSION@', {\"requires\": [\"classnamemanager\", \"node-event-delegate\", \"router\"]});"];
+_yuitest_coverage["build/pjax-base/pjax-base.js"].lines = {"1":0,"12":0,"66":0,"68":0,"98":0,"103":0,"104":0,"109":0,"110":0,"148":0,"150":0,"151":0,"154":0,"155":0,"158":0,"179":0,"187":0,"190":0,"193":0,"199":0,"200":0,"201":0,"202":0,"203":0,"204":0,"209":0,"231":0,"234":0,"235":0,"239":0,"241":0,"245":0,"246":0,"247":0,"250":0,"253":0,"254":0,"257":0,"262":0,"268":0,"269":0,"270":0,"271":0,"272":0,"274":0,"278":0,"294":0,"295":0,"314":0,"316":0,"321":0,"322":0,"346":0,"350":0,"352":0,"356":0,"357":0,"362":0,"363":0,"367":0,"371":0,"372":0,"374":0,"375":0,"381":0,"436":0};
+_yuitest_coverage["build/pjax-base/pjax-base.js"].functions = {"PjaxBase:66":0,"initializer:97":0,"destructor:108":0,"navigate:146":0,"_isLinkSameOrigin:178":0,"(anonymous 2):245":0,"_navigate:230":0,"_pjaxBindUI:292":0,"(anonymous 3):321":0,"_defNavigateFn:313":0,"_onLinkClick:345":0,"(anonymous 1):1":0};
+_yuitest_coverage["build/pjax-base/pjax-base.js"].coveredLines = 66;
_yuitest_coverage["build/pjax-base/pjax-base.js"].coveredFunctions = 12;
_yuitest_coverline("build/pjax-base/pjax-base.js", 1);
YUI.add('pjax-base', function (Y, NAME) {
@@ -150,7 +150,10 @@ this._pjaxBindUI();
destructor: function () {
_yuitest_coverfunc("build/pjax-base/pjax-base.js", "destructor", 108);
_yuitest_coverline("build/pjax-base/pjax-base.js", 109);
-this._pjaxEvents && this._pjaxEvents.detach();
+if (this._pjaxEvents) {
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 110);
+this._pjaxEvents.detach();
+ }
},
// -- Public Methods -------------------------------------------------------
@@ -187,23 +190,23 @@ this._pjaxEvents && this._pjaxEvents.detach();
**/
navigate: function (url, options) {
// The `_navigate()` method expects fully-resolved URLs.
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "navigate", 144);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 146);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "navigate", 146);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 148);
url = this._resolveURL(url);
- _yuitest_coverline("build/pjax-base/pjax-base.js", 148);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 150);
if (this._navigate(url, options)) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 149);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 151);
return true;
}
- _yuitest_coverline("build/pjax-base/pjax-base.js", 152);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 154);
if (!this._hasSameOrigin(url)) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 153);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 155);
Y.error('Security error: The new URL must be of the same origin as the current URL.');
}
- _yuitest_coverline("build/pjax-base/pjax-base.js", 156);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 158);
return false;
},
@@ -225,8 +228,8 @@ return false;
@since 3.6.0
**/
_isLinkSameOrigin: function (link) {
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_isLinkSameOrigin", 176);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 177);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_isLinkSameOrigin", 178);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 179);
var location = Y.getLocation(),
protocol = location.protocol,
hostname = location.hostname,
@@ -235,38 +238,38 @@ var location = Y.getLocation(),
// Link must have the same `protocol` and `hostname` as the page's
// currrent location.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 185);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 187);
if (link.get('protocol') !== protocol ||
link.get('hostname') !== hostname) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 188);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 190);
return false;
}
- _yuitest_coverline("build/pjax-base/pjax-base.js", 191);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 193);
linkPort = parseInt(link.get('port'), 10) || null;
// Normalize ports. In most cases browsers use an empty string when the
// port is the default port, but IE does weird things with anchor
// elements, so to be sure, this will re-assign the default ports before
// they are compared.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 197);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 199);
if (protocol === 'http:') {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 198);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 200);
port || (port = 80);
- _yuitest_coverline("build/pjax-base/pjax-base.js", 199);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 201);
linkPort || (linkPort = 80);
- } else {_yuitest_coverline("build/pjax-base/pjax-base.js", 200);
+ } else {_yuitest_coverline("build/pjax-base/pjax-base.js", 202);
if (protocol === 'https:') {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 201);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 203);
port || (port = 443);
- _yuitest_coverline("build/pjax-base/pjax-base.js", 202);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 204);
linkPort || (linkPort = 443);
}}
// Finally, to be from the same origin, the link's `port` must match the
// page's current `port`.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 207);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 209);
return linkPort === port;
},
@@ -289,74 +292,75 @@ return linkPort === port;
@since 3.5.0
**/
_navigate: function (url, options) {
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_navigate", 228);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 229);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_navigate", 230);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 231);
url = this._upgradeURL(url);
// Navigation can only be enhanced if there is a route-handler.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 232);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 234);
if (!this.hasRoute(url)) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 233);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 235);
return false;
}
// Make a copy of `options` before modifying it.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 237);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 239);
options = Y.merge(options, {url: url});
- _yuitest_coverline("build/pjax-base/pjax-base.js", 239);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 241);
var currentURL = this._getURL(),
hash, hashlessURL;
// Captures the `url`'s hash and returns a URL without that hash.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 243);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 245);
hashlessURL = url.replace(/(#.*)$/, function (u, h, i) {
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "(anonymous 2)", 243);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 244);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "(anonymous 2)", 245);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 246);
hash = h;
- _yuitest_coverline("build/pjax-base/pjax-base.js", 245);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 247);
return u.substring(i);
});
- _yuitest_coverline("build/pjax-base/pjax-base.js", 248);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 250);
if (hash && hashlessURL === currentURL.replace(/#.*$/, '')) {
// When the specified `url` and current URL only differ by the hash,
// the browser should handle this in-page navigation normally.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 251);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 253);
if (!this.get('navigateOnHash')) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 252);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 254);
return false;
}
- _yuitest_coverline("build/pjax-base/pjax-base.js", 255);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 257);
options.hash = hash;
}
// When navigating to the same URL as the current URL, behave like a
// browser and replace the history entry instead of creating a new one.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 260);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 262);
'replace' in options || (options.replace = url === currentURL);
// The `navigate` event will only fire and therefore enhance the
// navigation to the new URL in HTML5 history enabled browsers or when
// forced. Otherwise it will fallback to assigning or replacing the URL
// on `window.location`.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 266);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 268);
if (this.get('html5') || options.force) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 267);
-this.fire(EVT_NAVIGATE, options);
- } else {
_yuitest_coverline("build/pjax-base/pjax-base.js", 269);
+this.fire(EVT_NAVIGATE, options);
+ } else {_yuitest_coverline("build/pjax-base/pjax-base.js", 270);
+if (win) {
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 271);
if (options.replace) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 270);
-win && win.location.replace(url);
- } else {
_yuitest_coverline("build/pjax-base/pjax-base.js", 272);
-win && (win.location = url);
+win.location.replace(url);
+ } else {
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 274);
+win.location = url;
}
- }
+ }}
- _yuitest_coverline("build/pjax-base/pjax-base.js", 276);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 278);
return true;
},
@@ -373,10 +377,10 @@ return true;
**/
_pjaxBindUI: function () {
// Only bind link if we haven't already.
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_pjaxBindUI", 290);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 292);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_pjaxBindUI", 292);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 294);
if (!this._pjaxEvents) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 293);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 295);
this._pjaxEvents = Y.one('body').delegate('click',
this._onLinkClick, this.get('linkSelector'), this);
}
@@ -396,20 +400,20 @@ this._pjaxEvents = Y.one('body').delegate('click',
@since 3.5.0
**/
_defNavigateFn: function (e) {
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_defNavigateFn", 311);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 312);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_defNavigateFn", 313);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 314);
this[e.replace ? 'replace' : 'save'](e.url);
- _yuitest_coverline("build/pjax-base/pjax-base.js", 314);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 316);
if (win && this.get('scrollToTop')) {
// Scroll to the top of the page. The timeout ensures that the
// scroll happens after navigation begins, so that the current
// scroll position will be restored if the user clicks the back
// button.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 319);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 321);
setTimeout(function () {
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "(anonymous 3)", 319);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 320);
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "(anonymous 3)", 321);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 322);
win.scroll(0, 0);
}, 1);
}
@@ -434,46 +438,55 @@ win.scroll(0, 0);
@since 3.5.0
**/
_onLinkClick: function (e) {
- _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_onLinkClick", 343);
-_yuitest_coverline("build/pjax-base/pjax-base.js", 344);
-var link, url;
+ _yuitest_coverfunc("build/pjax-base/pjax-base.js", "_onLinkClick", 345);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 346);
+var link, url, navigated;
// Allow the native behavior on middle/right-click, or when Ctrl or
// Command are pressed.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 348);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 350);
if (e.button !== 1 || e.ctrlKey || e.metaKey) { return; }
- _yuitest_coverline("build/pjax-base/pjax-base.js", 350);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 352);
link = e.currentTarget;
// Only allow anchor elements because we need access to its `protocol`,
// `host`, and `href` attributes.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 354);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 356);
if (link.get('tagName').toUpperCase() !== 'A') {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 355);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 357);
return;
}
// Same origin check to prevent trying to navigate to URLs from other
// sites or things like mailto links.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 360);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 362);
if (!this._isLinkSameOrigin(link)) {
- _yuitest_coverline("build/pjax-base/pjax-base.js", 361);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 363);
return;
}
// All browsers fully resolve an anchor's `href` property.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 365);
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 367);
url = link.get('href');
// Try and navigate to the URL via the router, and prevent the default
// link-click action if we do.
- _yuitest_coverline("build/pjax-base/pjax-base.js", 369);
-url && this._navigate(url, {originEvent: e}) && e.preventDefault();
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 371);
+if (url) {
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 372);
+navigated = this._navigate(url, {originEvent: e});
+
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 374);
+if (navigated) {
+ _yuitest_coverline("build/pjax-base/pjax-base.js", 375);
+e.preventDefault();
+ }
+ }
}
};
-_yuitest_coverline("build/pjax-base/pjax-base.js", 373);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 381);
PjaxBase.ATTRS = {
/**
CSS selector string used to filter link click events so that only the links
@@ -529,7 +542,7 @@ PjaxBase.ATTRS = {
}
};
-_yuitest_coverline("build/pjax-base/pjax-base.js", 428);
+_yuitest_coverline("build/pjax-base/pjax-base.js", 436);
Y.PjaxBase = PjaxBase;
View
20 build/pjax-base/pjax-base-debug.js
@@ -106,7 +106,9 @@ PjaxBase.prototype = {
},
destructor: function () {
- this._pjaxEvents && this._pjaxEvents.detach();
+ if (this._pjaxEvents) {
+ this._pjaxEvents.detach();
+ }
},
// -- Public Methods -------------------------------------------------------
@@ -265,11 +267,11 @@ PjaxBase.prototype = {
// on `window.location`.
if (this.get('html5') || options.force) {
this.fire(EVT_NAVIGATE, options);
- } else {
+ } else if (win) {
if (options.replace) {
- win && win.location.replace(url);
+ win.location.replace(url);
} else {
- win && (win.location = url);
+ win.location = url;
}
}
@@ -341,7 +343,7 @@ PjaxBase.prototype = {
@since 3.5.0
**/
_onLinkClick: function (e) {
- var link, url;
+ var link, url, navigated;
// Allow the native behavior on middle/right-click, or when Ctrl or
// Command are pressed.
@@ -367,7 +369,13 @@ PjaxBase.prototype = {
// Try and navigate to the URL via the router, and prevent the default
// link-click action if we do.
- url && this._navigate(url, {originEvent: e}) && e.preventDefault();
+ if (url) {
+ navigated = this._navigate(url, {originEvent: e});
+
+ if (navigated) {
+ e.preventDefault();
+ }
+ }
}
};
View
2 build/pjax-base/pjax-base-min.js
@@ -1 +1 @@
-YUI.add("pjax-base",function(e,t){function s(){}var n=e.config.win,r=e.ClassNameManager.getClassName("pjax"),i="navigate";s.prototype={_regexURL:/^((?:[^\/#?:]+:\/\/|\/\/)[^\/]*)?([^?#]*)(\?[^#]*)?(#.*)?$/,initializer:function(){this.publish(i,{defaultFn:this._defNavigateFn}),this.get("html5")&&this._pjaxBindUI()},destructor:function(){this._pjaxEvents&&this._pjaxEvents.detach()},navigate:function(t,n){return t=this._resolveURL(t),this._navigate(t,n)?!0:(this._hasSameOrigin(t)||e.error("Security error: The new URL must be of the same origin as the current URL."),!1)},_isLinkSameOrigin:function(t){var n=e.getLocation(),r=n.protocol,i=n.hostname,s=parseInt(n.port,10)||null,o;return t.get("protocol")!==r||t.get("hostname")!==i?!1:(o=parseInt(t.get("port"),10)||null,r==="http:"?(s||(s=80),o||(o=80)):r==="https:"&&(s||(s=443),o||(o=443)),o===s)},_navigate:function(t,r){t=this._upgradeURL(t);if(!this.hasRoute(t))return!1;r=e.merge(r,{url:t});var s=this._getURL(),o,u;u=t.replace(/(#.*)$/,function(e,t,n){return o=t,e.substring(n)});if(o&&u===s.replace(/#.*$/,"")){if(!this.get("navigateOnHash"))return!1;r.hash=o}return"replace"in r||(r.replace=t===s),this.get("html5")||r.force?this.fire(i,r):r.replace?n&&n.location.replace(t):n&&(n.location=t),!0},_pjaxBindUI:function(){this._pjaxEvents||(this._pjaxEvents=e.one("body").delegate("click",this._onLinkClick,this.get("linkSelector"),this))},_defNavigateFn:function(e){this[e.replace?"replace":"save"](e.url),n&&this.get("scrollToTop")&&setTimeout(function(){n.scroll(0,0)},1)},_onLinkClick:function(e){var t,n;if(e.button!==1||e.ctrlKey||e.metaKey)return;t=e.currentTarget;if(t.get("tagName").toUpperCase()!=="A")return;if(!this._isLinkSameOrigin(t))return;n=t.get("href"),n&&this._navigate(n,{originEvent:e})&&e.preventDefault()}},s.ATTRS={linkSelector:{value:"a."+r,writeOnce:"initOnly"},navigateOnHash:{value:!1},scrollToTop:{value:!0}},e.PjaxBase=s},"@VERSION@",{requires:["classnamemanager","node-event-delegate","router"]});
+YUI.add("pjax-base",function(e,t){function s(){}var n=e.config.win,r=e.ClassNameManager.getClassName("pjax"),i="navigate";s.prototype={_regexURL:/^((?:[^\/#?:]+:\/\/|\/\/)[^\/]*)?([^?#]*)(\?[^#]*)?(#.*)?$/,initializer:function(){this.publish(i,{defaultFn:this._defNavigateFn}),this.get("html5")&&this._pjaxBindUI()},destructor:function(){this._pjaxEvents&&this._pjaxEvents.detach()},navigate:function(t,n){return t=this._resolveURL(t),this._navigate(t,n)?!0:(this._hasSameOrigin(t)||e.error("Security error: The new URL must be of the same origin as the current URL."),!1)},_isLinkSameOrigin:function(t){var n=e.getLocation(),r=n.protocol,i=n.hostname,s=parseInt(n.port,10)||null,o;return t.get("protocol")!==r||t.get("hostname")!==i?!1:(o=parseInt(t.get("port"),10)||null,r==="http:"?(s||(s=80),o||(o=80)):r==="https:"&&(s||(s=443),o||(o=443)),o===s)},_navigate:function(t,r){t=this._upgradeURL(t);if(!this.hasRoute(t))return!1;r=e.merge(r,{url:t});var s=this._getURL(),o,u;u=t.replace(/(#.*)$/,function(e,t,n){return o=t,e.substring(n)});if(o&&u===s.replace(/#.*$/,"")){if(!this.get("navigateOnHash"))return!1;r.hash=o}return"replace"in r||(r.replace=t===s),this.get("html5")||r.force?this.fire(i,r):n&&(r.replace?n.location.replace(t):n.location=t),!0},_pjaxBindUI:function(){this._pjaxEvents||(this._pjaxEvents=e.one("body").delegate("click",this._onLinkClick,this.get("linkSelector"),this))},_defNavigateFn:function(e){this[e.replace?"replace":"save"](e.url),n&&this.get("scrollToTop")&&setTimeout(function(){n.scroll(0,0)},1)},_onLinkClick:function(e){var t,n,r;if(e.button!==1||e.ctrlKey||e.metaKey)return;t=e.currentTarget;if(t.get("tagName").toUpperCase()!=="A")return;if(!this._isLinkSameOrigin(t))return;n=t.get("href"),n&&(r=this._navigate(n,{originEvent:e}),r&&e.preventDefault())}},s.ATTRS={linkSelector:{value:"a."+r,writeOnce:"initOnly"},navigateOnHash:{value:!1},scrollToTop:{value:!0}},e.PjaxBase=s},"@VERSION@",{requires:["classnamemanager","node-event-delegate","router"]});
View
20 build/pjax-base/pjax-base.js
@@ -106,7 +106,9 @@ PjaxBase.prototype = {
},
destructor: function () {
- this._pjaxEvents && this._pjaxEvents.detach();
+ if (this._pjaxEvents) {
+ this._pjaxEvents.detach();
+ }
},
// -- Public Methods -------------------------------------------------------
@@ -265,11 +267,11 @@ PjaxBase.prototype = {
// on `window.location`.
if (this.get('html5') || options.force) {
this.fire(EVT_NAVIGATE, options);
- } else {
+ } else if (win) {
if (options.replace) {
- win && win.location.replace(url);
+ win.location.replace(url);
} else {
- win && (win.location = url);
+ win.location = url;
}
}
@@ -341,7 +343,7 @@ PjaxBase.prototype = {
@since 3.5.0
**/
_onLinkClick: function (e) {
- var link, url;
+ var link, url, navigated;
// Allow the native behavior on middle/right-click, or when Ctrl or
// Command are pressed.
@@ -366,7 +368,13 @@ PjaxBase.prototype = {
// Try and navigate to the URL via the router, and prevent the default
// link-click action if we do.
- url && this._navigate(url, {originEvent: e}) && e.preventDefault();
+ if (url) {
+ navigated = this._navigate(url, {originEvent: e});
+
+ if (navigated) {
+ e.preventDefault();
+ }
+ }
}
};
View
6 build/pjax-content/pjax-content-coverage.js
@@ -26,7 +26,7 @@ _yuitest_coverage["build/pjax-content/pjax-content.js"] = {
path: "build/pjax-content/pjax-content.js",
code: []
};
-_yuitest_coverage["build/pjax-content/pjax-content.js"].code=["YUI.add('pjax-content', function (Y, NAME) {","","/**","`Y.Router` extension that provides the content fetching and handling needed to","implement the standard pjax (HTMP5 pushState + Ajax) functionality.","","@module pjax","@submodule pjax-content","@since 3.7.0","**/","","/**","`Y.Router` extension that provides the content fetching and handling needed to","implement the standard pjax (HTMP5 pushState + Ajax) functionality.","","This makes it easy to fetch server rendered content for URLs using Ajax. By","helping the router to fulfill the \"request\" for the content you can avoid full","page loads.","","The `PjaxContent` class isn't useful on its own, but can be mixed into a","`Router`-based class along with the `PjaxBase` class to add Pjax functionality","to that Router. For a pre-made standalone Pjax router, see the `Pjax` class.",""," var MyRouter = Y.Base.create('myRouter', Y.Router, ["," Y.PjaxBase,"," Y.PjaxContent"," ], {"," // ..."," });","","@class PjaxContent","@extensionfor Router","@since 3.7.0","**/","function PjaxContent() {}","","PjaxContent.prototype = {"," // -- Public Methods -------------------------------------------------------",""," /**"," Extracts and returns the relevant HTML content from an Ajax response. The"," content is extracted using the `contentSelector` attribute as a CSS"," selector. If `contentSelector` is `null`, the entire response will be"," returned.",""," The return value is an object containing two properties:",""," * `node`: A `Y.Node` instance for a document fragment containing the"," extracted HTML content.",""," * `title`: The title of the HTML page, if any, extracted using the"," `titleSelector` attribute (which defaults to looking for a `<title>`"," element). If `titleSelector` is not set or if a title could not be"," found, this property will be `undefined`.",""," @method getContent"," @param {String} responseText Raw Ajax response text."," @return {Object} Content object with the properties described above."," @since 3.5.0"," **/"," getContent: function (responseText) {"," var content = {},"," contentSelector = this.get('contentSelector'),"," frag = Y.Node.create(responseText || ''),"," titleSelector = this.get('titleSelector'),"," titleNode;",""," if (contentSelector) {"," content.node = frag.all(contentSelector).toFrag();"," } else {"," content.node = frag;"," }",""," if (titleSelector) {"," titleNode = frag.one(titleSelector);",""," if (titleNode) {"," content.title = titleNode.get('text');"," }"," }",""," return content;"," },",""," /**"," Pjax route middleware to load content from a server. This makes an Ajax"," request for the requested URL, parses the returned content and puts it on"," the route's response object.",""," This is route middleware and not intended to be the final callback for a"," route. This will add the following information to the route's request and"," response objects:",""," - `req.ioURL`: The full URL that was used to make the `Y.io()` XHR. This"," may contain `\"pjax=1\"` if the `addPjaxParam` option is set.",""," - `res.content`: An object containing `node` and `title` properties for"," the content extracted from the server's response. See `getContent()` for"," more details.",""," - `res.ioResponse`: The full `Y.io()` response object. This is useful if"," you need access to the XHR's response `status` or HTTP headers.",""," @example"," router.route('/foo/', 'loadContent', function (req, res, next) {"," Y.one('container').setHTML(res.content.node);"," Y.config.doc.title = res.content.title;"," });",""," @method loadContent"," @param {Object} req Request object."," @param {Object} res Response Object."," @param {Function} next Function to pass control to the next route callback."," @since 3.7.0"," @see Router.route()"," **/"," loadContent: function (req, res, next) {"," var url = req.url;",""," // If there's an outstanding request, abort it."," if (this._request) {"," this._request.abort();"," }",""," // Add a 'pjax=1' query parameter if enabled."," if (this.get('addPjaxParam')) {"," // Captures the path with query, and hash parts of the URL. Then"," // properly injects the \"pjax=1\" query param in the right place,"," // before any hash fragment, and returns the updated URL."," url = url.replace(/([^#]*)(#.*)?$/, function (match, path, hash) {"," path += (path.indexOf('?') > -1 ? '&' : '?') + 'pjax=1';"," return path + (hash || '');"," });"," }",""," // Send a request."," this._request = Y.io(url, {"," 'arguments': {"," route: {"," req : req,"," res : res,"," next: next"," },",""," url: url"," },",""," context: this,"," headers: {'X-PJAX': 'true'},"," timeout: this.get('timeout'),",""," on: {"," complete: this._onPjaxIOComplete,"," end : this._onPjaxIOEnd"," }"," });"," },",""," // -- Event Handlers -------------------------------------------------------",""," /**"," Handles IO complete events.",""," This parses the content from the `Y.io()` response and puts it on the"," route's response object.",""," @method _onPjaxIOComplete"," @param {String} id The `Y.io` transaction id."," @param {Object} ioResponse The `Y.io` response object."," @param {Object} details Extra details carried through from `loadContent()`."," @protected"," @since 3.7.0"," **/"," _onPjaxIOComplete: function (id, ioResponse, details) {"," var content = this.getContent(ioResponse.responseText),"," route = details.route,"," req = route.req,"," res = route.res;",""," // Put the URL requested through `Y.io` on the route's `req` object."," req.ioURL = details.url;",""," // Put the parsed content and `Y.io` response object on the route's"," // `res` object."," res.content = content;"," res.ioResponse = ioResponse;",""," route.next();"," },",""," /**"," Handles IO end events.",""," @method _onPjaxIOEnd"," @param {String} id The `Y.io` transaction id."," @param {Object} details Extra details carried through from `loadContent()`."," @protected"," @since 3.5.0"," **/"," _onPjaxIOEnd: function () {"," this._request = null;"," }","};","","PjaxContent.ATTRS = {"," /**"," If `true`, a \"pjax=1\" query parameter will be appended to all URLs"," requested via Pjax.",""," Browsers ignore HTTP request headers when caching content, so if the"," same URL is used to request a partial Pjax page and a full page, the"," browser will cache them under the same key and may later load the"," cached partial page when the user actually requests a full page (or vice"," versa).",""," To prevent this, we can add a bogus query parameter to the URL so that"," Pjax URLs will always be cached separately from non-Pjax URLs.",""," @attribute addPjaxParam"," @type Boolean"," @default true"," @since 3.5.0"," **/"," addPjaxParam: {"," value: true"," },",""," /**"," CSS selector used to extract a specific portion of the content of a page"," loaded via Pjax.",""," For example, if you wanted to load the page `example.html` but only use"," the content within an element with the id \"pjax-content\", you'd set"," `contentSelector` to \"#pjax-content\".",""," If not set, the entire page will be used.",""," @attribute contentSelector"," @type String"," @default null"," @since 3.5.0"," **/"," contentSelector: {"," value: null"," },",""," /**"," CSS selector used to extract a page title from the content of a page"," loaded via Pjax.",""," By default this is set to extract the title from the `<title>` element,"," but you could customize it to extract the title from an `<h1>`, or from"," any other element, if that's more appropriate for the content you're"," loading.",""," @attribute titleSelector"," @type String"," @default \"title\""," @since 3.5.0"," **/"," titleSelector: {"," value: 'title'"," },",""," /**"," Time in milliseconds after which an Ajax request should time out.",""," @attribute timeout"," @type Number"," @default 30000"," @since 3.5.0"," **/"," timeout: {"," value: 30000"," }","};","","Y.PjaxContent = PjaxContent;","","","}, '@VERSION@', {\"requires\": [\"io-base\", \"node-base\", \"router\"]});"];
+_yuitest_coverage["build/pjax-content/pjax-content.js"].code=["YUI.add('pjax-content', function (Y, NAME) {","","/**","`Y.Router` extension that provides the content fetching and handling needed to","implement the standard pjax (HTMP5 pushState + Ajax) functionality.","","@module pjax","@submodule pjax-content","@since 3.7.0","**/","","/**","`Y.Router` extension that provides the content fetching and handling needed to","implement the standard pjax (HTMP5 pushState + Ajax) functionality.","","This makes it easy to fetch server rendered content for URLs using Ajax. By","helping the router to fulfill the \"request\" for the content you can avoid full","page loads.","","The `PjaxContent` class isn't useful on its own, but can be mixed into a","`Router`-based class along with the `PjaxBase` class to add Pjax functionality","to that Router. For a pre-made standalone Pjax router, see the `Pjax` class.",""," var MyRouter = Y.Base.create('myRouter', Y.Router, ["," Y.PjaxBase,"," Y.PjaxContent"," ], {"," // ..."," });","","@class PjaxContent","@extensionfor Router","@since 3.7.0","**/","function PjaxContent() {}","","PjaxContent.prototype = {"," // -- Public Methods -------------------------------------------------------",""," /**"," Extracts and returns the relevant HTML content from an Ajax response. The"," content is extracted using the `contentSelector` attribute as a CSS"," selector. If `contentSelector` is `null`, the entire response will be"," returned.",""," The return value is an object containing two properties:",""," * `node`: A `Y.Node` instance for a document fragment containing the"," extracted HTML content.",""," * `title`: The title of the HTML page, if any, extracted using the"," `titleSelector` attribute (which defaults to looking for a `<title>`"," element). If `titleSelector` is not set or if a title could not be"," found, this property will be `undefined`.",""," @method getContent"," @param {String} responseText Raw Ajax response text."," @return {Object} Content object with the properties described above."," @since 3.5.0"," **/"," getContent: function (responseText) {"," var content = {},"," contentSelector = this.get('contentSelector'),"," frag = Y.Node.create(responseText || ''),"," titleSelector = this.get('titleSelector'),"," titleNode;",""," if (contentSelector && frag) {"," content.node = frag.all(contentSelector).toFrag();"," } else {"," content.node = frag;"," }",""," if (titleSelector && frag) {"," titleNode = frag.one(titleSelector);",""," if (titleNode) {"," content.title = titleNode.get('text');"," }"," }",""," return content;"," },",""," /**"," Pjax route middleware to load content from a server. This makes an Ajax"," request for the requested URL, parses the returned content and puts it on"," the route's response object.",""," This is route middleware and not intended to be the final callback for a"," route. This will add the following information to the route's request and"," response objects:",""," - `req.ioURL`: The full URL that was used to make the `Y.io()` XHR. This"," may contain `\"pjax=1\"` if the `addPjaxParam` option is set.",""," - `res.content`: An object containing `node` and `title` properties for"," the content extracted from the server's response. See `getContent()` for"," more details.",""," - `res.ioResponse`: The full `Y.io()` response object. This is useful if"," you need access to the XHR's response `status` or HTTP headers.",""," @example"," router.route('/foo/', 'loadContent', function (req, res, next) {"," Y.one('container').setHTML(res.content.node);"," Y.config.doc.title = res.content.title;"," });",""," @method loadContent"," @param {Object} req Request object."," @param {Object} res Response Object."," @param {Function} next Function to pass control to the next route callback."," @since 3.7.0"," @see Router.route()"," **/"," loadContent: function (req, res, next) {"," var url = req.url;",""," // If there's an outstanding request, abort it."," if (this._request) {"," this._request.abort();"," }",""," // Add a 'pjax=1' query parameter if enabled."," if (this.get('addPjaxParam')) {"," // Captures the path with query, and hash parts of the URL. Then"," // properly injects the \"pjax=1\" query param in the right place,"," // before any hash fragment, and returns the updated URL."," url = url.replace(/([^#]*)(#.*)?$/, function (match, path, hash) {"," path += (path.indexOf('?') > -1 ? '&' : '?') + 'pjax=1';"," return path + (hash || '');"," });"," }",""," // Send a request."," this._request = Y.io(url, {"," 'arguments': {"," route: {"," req : req,"," res : res,"," next: next"," },",""," url: url"," },",""," context: this,"," headers: {'X-PJAX': 'true'},"," timeout: this.get('timeout'),",""," on: {"," complete: this._onPjaxIOComplete,"," end : this._onPjaxIOEnd"," }"," });"," },",""," // -- Event Handlers -------------------------------------------------------",""," /**"," Handles IO complete events.",""," This parses the content from the `Y.io()` response and puts it on the"," route's response object.",""," @method _onPjaxIOComplete"," @param {String} id The `Y.io` transaction id."," @param {Object} ioResponse The `Y.io` response object."," @param {Object} details Extra details carried through from `loadContent()`."," @protected"," @since 3.7.0"," **/"," _onPjaxIOComplete: function (id, ioResponse, details) {"," var content = this.getContent(ioResponse.responseText),"," route = details.route,"," req = route.req,"," res = route.res;",""," // Put the URL requested through `Y.io` on the route's `req` object."," req.ioURL = details.url;",""," // Put the parsed content and `Y.io` response object on the route's"," // `res` object."," res.content = content;"," res.ioResponse = ioResponse;",""," route.next();"," },",""," /**"," Handles IO end events.",""," @method _onPjaxIOEnd"," @param {String} id The `Y.io` transaction id."," @param {Object} details Extra details carried through from `loadContent()`."," @protected"," @since 3.5.0"," **/"," _onPjaxIOEnd: function () {"," this._request = null;"," }","};","","PjaxContent.ATTRS = {"," /**"," If `true`, a \"pjax=1\" query parameter will be appended to all URLs"," requested via Pjax.",""," Browsers ignore HTTP request headers when caching content, so if the"," same URL is used to request a partial Pjax page and a full page, the"," browser will cache them under the same key and may later load the"," cached partial page when the user actually requests a full page (or vice"," versa).",""," To prevent this, we can add a bogus query parameter to the URL so that"," Pjax URLs will always be cached separately from non-Pjax URLs.",""," @attribute addPjaxParam"," @type Boolean"," @default true"," @since 3.5.0"," **/"," addPjaxParam: {"," value: true"," },",""," /**"," CSS selector used to extract a specific portion of the content of a page"," loaded via Pjax.",""," For example, if you wanted to load the page `example.html` but only use"," the content within an element with the id \"pjax-content\", you'd set"," `contentSelector` to \"#pjax-content\".",""," If not set, the entire page will be used.",""," @attribute contentSelector"," @type String"," @default null"," @since 3.5.0"," **/"," contentSelector: {"," value: null"," },",""," /**"," CSS selector used to extract a page title from the content of a page"," loaded via Pjax.",""," By default this is set to extract the title from the `<title>` element,"," but you could customize it to extract the title from an `<h1>`, or from"," any other element, if that's more appropriate for the content you're"," loading.",""," @attribute titleSelector"," @type String"," @default \"title\""," @since 3.5.0"," **/"," titleSelector: {"," value: 'title'"," },",""," /**"," Time in milliseconds after which an Ajax request should time out.",""," @attribute timeout"," @type Number"," @default 30000"," @since 3.5.0"," **/"," timeout: {"," value: 30000"," }","};","","Y.PjaxContent = PjaxContent;","","","}, '@VERSION@', {\"requires\": [\"io-base\", \"node-base\", \"router\"]});"];
_yuitest_coverage["build/pjax-content/pjax-content.js"].lines = {"1":0,"35":0,"37":0,"62":0,"68":0,"69":0,"71":0,"74":0,"75":0,"77":0,"78":0,"82":0,"118":0,"121":0,"122":0,"126":0,"130":0,"131":0,"132":0,"137":0,"175":0,"181":0,"185":0,"186":0,"188":0,"201":0,"205":0,"278":0};
_yuitest_coverage["build/pjax-content/pjax-content.js"].functions = {"PjaxContent:35":0,"getContent:61":0,"(anonymous 2):130":0,"loadContent:117":0,"_onPjaxIOComplete:174":0,"_onPjaxIOEnd:200":0,"(anonymous 1):1":0};
_yuitest_coverage["build/pjax-content/pjax-content.js"].coveredLines = 28;
@@ -105,7 +105,7 @@ var content = {},
titleNode;
_yuitest_coverline("build/pjax-content/pjax-content.js", 68);
-if (contentSelector) {
+if (contentSelector && frag) {
_yuitest_coverline("build/pjax-content/pjax-content.js", 69);
content.node = frag.all(contentSelector).toFrag();
} else {
@@ -114,7 +114,7 @@ content.node = frag;
}
_yuitest_coverline("build/pjax-content/pjax-content.js", 74);
-if (titleSelector) {
+if (titleSelector && frag) {
_yuitest_coverline("build/pjax-content/pjax-content.js", 75);
titleNode = frag.one(titleSelector);
View
4 build/pjax-content/pjax-content-debug.js
@@ -65,13 +65,13 @@ PjaxContent.prototype = {
titleSelector = this.get('titleSelector'),
titleNode;
- if (contentSelector) {
+ if (contentSelector && frag) {
content.node = frag.all(contentSelector).toFrag();
} else {
content.node = frag;
}
- if (titleSelector) {
+ if (titleSelector && frag) {
titleNode = frag.one(titleSelector);
if (titleNode) {
View
2 build/pjax-content/pjax-content-min.js
@@ -1 +1 @@
-YUI.add("pjax-content",function(e,t){function n(){}n.prototype={getContent:function(t){var n={},r=this.get("contentSelector"),i=e.Node.create(t||""),s=this.get("titleSelector"),o;return r?n.node=i.all(r).toFrag():n.node=i,s&&(o=i.one(s),o&&(n.title=o.get("text"))),n},loadContent:function(t,n,r){var i=t.url;this._request&&this._request.abort(),this.get("addPjaxParam")&&(i=i.replace(/([^#]*)(#.*)?$/,function(e,t,n){return t+=(t.indexOf("?")>-1?"&":"?")+"pjax=1",t+(n||"")})),this._request=e.io(i,{arguments:{route:{req:t,res:n,next:r},url:i},context:this,headers:{"X-PJAX":"true"},timeout:this.get("timeout"),on:{complete:this._onPjaxIOComplete,end:this._onPjaxIOEnd}})},_onPjaxIOComplete:function(e,t,n){var r=this.getContent(t.responseText),i=n.route,s=i.req,o=i.res;s.ioURL=n.url,o.content=r,o.ioResponse=t,i.next()},_onPjaxIOEnd:function(){this._request=null}},n.ATTRS={addPjaxParam:{value:!0},contentSelector:{value:null},titleSelector:{value:"title"},timeout:{value:3e4}},e.PjaxContent=n},"@VERSION@",{requires:["io-base","node-base","router"]});
+YUI.add("pjax-content",function(e,t){function n(){}n.prototype={getContent:function(t){var n={},r=this.get("contentSelector"),i=e.Node.create(t||""),s=this.get("titleSelector"),o;return r&&i?n.node=i.all(r).toFrag():n.node=i,s&&i&&(o=i.one(s),o&&(n.title=o.get("text"))),n},loadContent:function(t,n,r){var i=t.url;this._request&&this._request.abort(),this.get("addPjaxParam")&&(i=i.replace(/([^#]*)(#.*)?$/,function(e,t,n){return t+=(t.indexOf("?")>-1?"&":"?")+"pjax=1",t+(n||"")})),this._request=e.io(i,{arguments:{route:{req:t,res:n,next:r},url:i},context:this,headers:{"X-PJAX":"true"},timeout:this.get("timeout"),on:{complete:this._onPjaxIOComplete,end:this._onPjaxIOEnd}})},_onPjaxIOComplete:function(e,t,n){var r=this.getContent(t.responseText),i=n.route,s=i.req,o=i.res;s.ioURL=n.url,o.content=r,o.ioResponse=t,i.next()},_onPjaxIOEnd:function(){this._request=null}},n.ATTRS={addPjaxParam:{value:!0},contentSelector:{value:null},titleSelector:{value:"title"},timeout:{value:3e4}},e.PjaxContent=n},"@VERSION@",{requires:["io-base","node-base","router"]});
View
4 build/pjax-content/pjax-content.js
@@ -65,13 +65,13 @@ PjaxContent.prototype = {
titleSelector = this.get('titleSelector'),
titleNode;
- if (contentSelector) {
+ if (contentSelector && frag) {
content.node = frag.all(contentSelector).toFrag();
} else {
content.node = frag;
}
- if (titleSelector) {
+ if (titleSelector && frag) {
titleNode = frag.one(titleSelector);
if (titleNode) {

0 comments on commit 04aa96d

Please sign in to comment.
Something went wrong with that request. Please try again.