MDL-35616 import YUI 3.7.2
[moodle.git] / lib / yuilib / 3.7.2 / build / pjax / pjax-coverage.js
blob5da798ceaf2308087e89e7df3b96ec21ad0732bc
1 /*
2 YUI 3.7.2 (build 5639)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 if (typeof _yuitest_coverage == "undefined"){
8     _yuitest_coverage = {};
9     _yuitest_coverline = function(src, line){
10         var coverage = _yuitest_coverage[src];
11         if (!coverage.lines[line]){
12             coverage.calledLines++;
13         }
14         coverage.lines[line]++;
15     };
16     _yuitest_coverfunc = function(src, name, line){
17         var coverage = _yuitest_coverage[src],
18             funcId = name + ":" + line;
19         if (!coverage.functions[funcId]){
20             coverage.calledFunctions++;
21         }
22         coverage.functions[funcId]++;
23     };
25 _yuitest_coverage["build/pjax/pjax.js"] = {
26     lines: {},
27     functions: {},
28     coveredLines: 0,
29     calledLines: 0,
30     coveredFunctions: 0,
31     calledFunctions: 0,
32     path: "build/pjax/pjax.js",
33     code: []
35 _yuitest_coverage["build/pjax/pjax.js"].code=["YUI.add('pjax', function (Y, NAME) {","","/**","Provides seamless, gracefully degrading Pjax (pushState + Ajax) functionality,","which makes it easy to progressively enhance standard links on the page so that","they can be loaded normally in old browsers, or via Ajax (with HTML5 history","support) in newer browsers.","","@module pjax","@main","@since 3.5.0","**/","","/**","A stack of middleware which forms the default Pjax route.","","@property defaultRoute","@type Array","@static","@since 3.7.0","**/","var defaultRoute = ['loadContent', '_defaultRoute'],","","/**","Fired when an error occurs while attempting to load a URL via Ajax.","","@event error","@param {Object} content Content extracted from the response, if any.","    @param {Node} content.node A `Y.Node` instance for a document fragment","        containing the extracted HTML content.","    @param {String} [content.title] The title of the HTML page, if any,","        extracted using the `titleSelector` attribute. If `titleSelector` is","        not set or if a title could not be found, this property will be","        `undefined`.","@param {String} responseText Raw Ajax response text.","@param {Number} status HTTP status code for the Ajax response.","@param {String} url The absolute URL that failed to load.","@since 3.5.0","**/","EVT_ERROR = 'error',","","/**","Fired when a URL is successfully loaded via Ajax.","","@event load","@param {Object} content Content extracted from the response, if any.","    @param {Node} content.node A `Y.Node` instance for a document fragment","        containing the extracted HTML content.","    @param {String} [content.title] The title of the HTML page, if any,","        extracted using the `titleSelector` attribute. If `titleSelector` is","        not set or if a title could not be found, this property will be","        `undefined`.","@param {String} responseText Raw Ajax response text.","@param {Number} status HTTP status code for the Ajax response.","@param {String} url The absolute URL that was loaded.","@since 3.5.0","**/","EVT_LOAD = 'load';","","/**","Provides seamless, gracefully degrading Pjax (pushState + Ajax) functionality,","which makes it easy to progressively enhance standard links on the page so that","they can be loaded normally in old browsers, or via Ajax (with HTML5 history","support) in newer browsers.","","@class Pjax","@extends Router","@uses PjaxBase","@uses PjaxContent","@constructor","@param {Object} [config] Config attributes.","@since 3.5.0","**/","Y.Pjax = Y.Base.create('pjax', Y.Router, [Y.PjaxBase, Y.PjaxContent], {","    // -- Lifecycle Methods ----------------------------------------------------","    initializer: function () {","        this.publish(EVT_ERROR, {defaultFn: this._defCompleteFn});","        this.publish(EVT_LOAD,  {defaultFn: this._defCompleteFn});","    },","","    // -- Protected Methods ----------------------------------------------------","","    /**","    Default Pjax route callback. Fires either the `load` or `error` event based","    on the status of the `Y.io` request made by the `loadContent()` middleware.","","    **Note:** This route callback assumes that it's called after the","    `loadContent()` middleware.","","    @method _defaultRoute","    @param {Object} req Request object.","    @param {Object} res Response Object.","    @param {Function} next Function to pass control to the next route callback.","    @protected","    @since 3.5.0","    @see Y.Pjax.defaultRoute","    **/","    _defaultRoute: function (req, res, next) {","        var ioResponse = res.ioResponse,","            status     = ioResponse.status,","            event      = status >= 200 && status < 300 ? EVT_LOAD : EVT_ERROR;","","        this.fire(event, {","            content     : res.content,","            responseText: ioResponse.responseText,","            status      : status,","            url         : req.ioURL","        });","","        next();","    },","","    // -- Event Handlers -------------------------------------------------------","","    /**","    Default event handler for both the `error` and `load` events. Attempts to","    insert the loaded content into the `container` node and update the page's","    title.","","    @method _defCompleteFn","    @param {EventFacade} e","    @protected","    @since 3.5.0","    **/","    _defCompleteFn: function (e) {","        var container = this.get('container'),","            content   = e.content;","","        if (container && content.node) {","            container.setHTML(content.node);","        }","","        if (content.title && Y.config.doc) {","            Y.config.doc.title = content.title;","        }","    }","}, {","    ATTRS: {","        /**","        Node into which content should be inserted when a page is loaded via","        Pjax. This node's existing contents will be removed to make way for the","        new content.","","        If not set, loaded content will not be automatically inserted into the","        page.","","        @attribute container","        @type Node","        @default null","        @since 3.5.0","        **/","        container: {","            value : null,","            setter: Y.one","        },","","        // Inherited from Router and already documented there.","        routes: {","            value: [","                {path: '*', callbacks: defaultRoute}","            ]","        }","    },","","    // Documented towards the top of this file.","    defaultRoute: defaultRoute","});","","","}, '3.7.2', {\"requires\": [\"pjax-base\", \"pjax-content\"]});"];
36 _yuitest_coverage["build/pjax/pjax.js"].lines = {"1":0,"22":0,"74":0,"77":0,"78":0,"99":0,"103":0,"110":0,"126":0,"129":0,"130":0,"133":0,"134":0};
37 _yuitest_coverage["build/pjax/pjax.js"].functions = {"initializer:76":0,"_defaultRoute:98":0,"_defCompleteFn:125":0,"(anonymous 1):1":0};
38 _yuitest_coverage["build/pjax/pjax.js"].coveredLines = 13;
39 _yuitest_coverage["build/pjax/pjax.js"].coveredFunctions = 4;
40 _yuitest_coverline("build/pjax/pjax.js", 1);
41 YUI.add('pjax', function (Y, NAME) {
43 /**
44 Provides seamless, gracefully degrading Pjax (pushState + Ajax) functionality,
45 which makes it easy to progressively enhance standard links on the page so that
46 they can be loaded normally in old browsers, or via Ajax (with HTML5 history
47 support) in newer browsers.
49 @module pjax
50 @main
51 @since 3.5.0
52 **/
54 /**
55 A stack of middleware which forms the default Pjax route.
57 @property defaultRoute
58 @type Array
59 @static
60 @since 3.7.0
61 **/
62 _yuitest_coverfunc("build/pjax/pjax.js", "(anonymous 1)", 1);
63 _yuitest_coverline("build/pjax/pjax.js", 22);
64 var defaultRoute = ['loadContent', '_defaultRoute'],
66 /**
67 Fired when an error occurs while attempting to load a URL via Ajax.
69 @event error
70 @param {Object} content Content extracted from the response, if any.
71     @param {Node} content.node A `Y.Node` instance for a document fragment
72         containing the extracted HTML content.
73     @param {String} [content.title] The title of the HTML page, if any,
74         extracted using the `titleSelector` attribute. If `titleSelector` is
75         not set or if a title could not be found, this property will be
76         `undefined`.
77 @param {String} responseText Raw Ajax response text.
78 @param {Number} status HTTP status code for the Ajax response.
79 @param {String} url The absolute URL that failed to load.
80 @since 3.5.0
81 **/
82 EVT_ERROR = 'error',
84 /**
85 Fired when a URL is successfully loaded via Ajax.
87 @event load
88 @param {Object} content Content extracted from the response, if any.
89     @param {Node} content.node A `Y.Node` instance for a document fragment
90         containing the extracted HTML content.
91     @param {String} [content.title] The title of the HTML page, if any,
92         extracted using the `titleSelector` attribute. If `titleSelector` is
93         not set or if a title could not be found, this property will be
94         `undefined`.
95 @param {String} responseText Raw Ajax response text.
96 @param {Number} status HTTP status code for the Ajax response.
97 @param {String} url The absolute URL that was loaded.
98 @since 3.5.0
99 **/
100 EVT_LOAD = 'load';
103 Provides seamless, gracefully degrading Pjax (pushState + Ajax) functionality,
104 which makes it easy to progressively enhance standard links on the page so that
105 they can be loaded normally in old browsers, or via Ajax (with HTML5 history
106 support) in newer browsers.
108 @class Pjax
109 @extends Router
110 @uses PjaxBase
111 @uses PjaxContent
112 @constructor
113 @param {Object} [config] Config attributes.
114 @since 3.5.0
116 _yuitest_coverline("build/pjax/pjax.js", 74);
117 Y.Pjax = Y.Base.create('pjax', Y.Router, [Y.PjaxBase, Y.PjaxContent], {
118     // -- Lifecycle Methods ----------------------------------------------------
119     initializer: function () {
120         _yuitest_coverfunc("build/pjax/pjax.js", "initializer", 76);
121 _yuitest_coverline("build/pjax/pjax.js", 77);
122 this.publish(EVT_ERROR, {defaultFn: this._defCompleteFn});
123         _yuitest_coverline("build/pjax/pjax.js", 78);
124 this.publish(EVT_LOAD,  {defaultFn: this._defCompleteFn});
125     },
127     // -- Protected Methods ----------------------------------------------------
129     /**
130     Default Pjax route callback. Fires either the `load` or `error` event based
131     on the status of the `Y.io` request made by the `loadContent()` middleware.
133     **Note:** This route callback assumes that it's called after the
134     `loadContent()` middleware.
136     @method _defaultRoute
137     @param {Object} req Request object.
138     @param {Object} res Response Object.
139     @param {Function} next Function to pass control to the next route callback.
140     @protected
141     @since 3.5.0
142     @see Y.Pjax.defaultRoute
143     **/
144     _defaultRoute: function (req, res, next) {
145         _yuitest_coverfunc("build/pjax/pjax.js", "_defaultRoute", 98);
146 _yuitest_coverline("build/pjax/pjax.js", 99);
147 var ioResponse = res.ioResponse,
148             status     = ioResponse.status,
149             event      = status >= 200 && status < 300 ? EVT_LOAD : EVT_ERROR;
151         _yuitest_coverline("build/pjax/pjax.js", 103);
152 this.fire(event, {
153             content     : res.content,
154             responseText: ioResponse.responseText,
155             status      : status,
156             url         : req.ioURL
157         });
159         _yuitest_coverline("build/pjax/pjax.js", 110);
160 next();
161     },
163     // -- Event Handlers -------------------------------------------------------
165     /**
166     Default event handler for both the `error` and `load` events. Attempts to
167     insert the loaded content into the `container` node and update the page's
168     title.
170     @method _defCompleteFn
171     @param {EventFacade} e
172     @protected
173     @since 3.5.0
174     **/
175     _defCompleteFn: function (e) {
176         _yuitest_coverfunc("build/pjax/pjax.js", "_defCompleteFn", 125);
177 _yuitest_coverline("build/pjax/pjax.js", 126);
178 var container = this.get('container'),
179             content   = e.content;
181         _yuitest_coverline("build/pjax/pjax.js", 129);
182 if (container && content.node) {
183             _yuitest_coverline("build/pjax/pjax.js", 130);
184 container.setHTML(content.node);
185         }
187         _yuitest_coverline("build/pjax/pjax.js", 133);
188 if (content.title && Y.config.doc) {
189             _yuitest_coverline("build/pjax/pjax.js", 134);
190 Y.config.doc.title = content.title;
191         }
192     }
193 }, {
194     ATTRS: {
195         /**
196         Node into which content should be inserted when a page is loaded via
197         Pjax. This node's existing contents will be removed to make way for the
198         new content.
200         If not set, loaded content will not be automatically inserted into the
201         page.
203         @attribute container
204         @type Node
205         @default null
206         @since 3.5.0
207         **/
208         container: {
209             value : null,
210             setter: Y.one
211         },
213         // Inherited from Router and already documented there.
214         routes: {
215             value: [
216                 {path: '*', callbacks: defaultRoute}
217             ]
218         }
219     },
221     // Documented towards the top of this file.
222     defaultRoute: defaultRoute
226 }, '3.7.2', {"requires": ["pjax-base", "pjax-content"]});