MDL 38508 JavaScript: Split out AJAX and non-AJAX help
[moodle.git] / lib / yui / build / moodle-core-tooltip / moodle-core-tooltip-coverage.js
1 if (typeof _yuitest_coverage == "undefined"){
2     _yuitest_coverage = {};
3     _yuitest_coverline = function(src, line){
4         var coverage = _yuitest_coverage[src];
5         if (!coverage.lines[line]){
6             coverage.calledLines++;
7         }
8         coverage.lines[line]++;
9     };
10     _yuitest_coverfunc = function(src, name, line){
11         var coverage = _yuitest_coverage[src],
12             funcId = name + ":" + line;
13         if (!coverage.functions[funcId]){
14             coverage.calledFunctions++;
15         }
16         coverage.functions[funcId]++;
17     };
18 }
19 _yuitest_coverage["build/moodle-core-tooltip/moodle-core-tooltip.js"] = {
20     lines: {},
21     functions: {},
22     coveredLines: 0,
23     calledLines: 0,
24     coveredFunctions: 0,
25     calledFunctions: 0,
26     path: "build/moodle-core-tooltip/moodle-core-tooltip.js",
27     code: []
28 };
29 _yuitest_coverage["build/moodle-core-tooltip/moodle-core-tooltip.js"].code=["YUI.add('moodle-core-tooltip', function (Y, NAME) {","","/**"," * Provides the base tooltip class."," *"," * @module moodle-core-tooltip"," */","","/**"," * A base class for a tooltip."," *"," * @param {Object} config Object literal specifying tooltip configuration properties."," * @class M.core.tooltip"," * @constructor"," * @extends M.core.dialogue"," */","function TOOLTIP(config) {","    if (!config) {","        config = {};","    }","","    // Override the default options provided by the parent class.","    if (typeof config.draggable === 'undefined') {","        config.draggable = true;","    }","","    if (typeof config.constrain === 'undefined') {","        config.constrain = true;","    }","","    if (typeof config.lightbox === 'undefined') {","        config.lightbox = false;","    }","","    TOOLTIP.superclass.constructor.apply(this, [config]);","}","","var SELECTORS = {","        CLOSEBUTTON: '.closebutton'","    },","","    CSS = {","        PANELTEXT: 'tooltiptext'","    },","    RESOURCES = {","        WAITICON: {","            pix: 'i/loading_small',","            component: 'moodle'","        }","    },","    ATTRS = {};","","/**"," * Static property provides a string to identify the JavaScript class."," *"," * @property NAME"," * @type String"," * @static"," */","TOOLTIP.NAME = 'moodle-core-tooltip';","","/**"," * Static property used to define the CSS prefix applied to tooltip dialogues."," *"," * @property CSS_PREFIX"," * @type String"," * @static"," */","TOOLTIP.CSS_PREFIX = 'moodle-dialogue';","","/**"," * Static property used to define the default attribute configuration for the Tooltip."," *"," * @property ATTRS"," * @type String"," * @static"," */","TOOLTIP.ATTRS = ATTRS;","","/**"," * The initial value of the header region before the content finishes loading."," *"," * @attribute initialheadertext"," * @type String"," * @default ''"," * @writeOnce"," */","ATTRS.initialheadertext = {","    value: ''","};","","/**","  * The initial value of the body region before the content finishes loading.","  *","  * The supplid string will be wrapped in a div with the CSS.PANELTEXT class and a standard Moodle spinner","  * appended.","  *","  * @attribute initialbodytext","  * @type String","  * @default ''","  * @writeOnce","  */","ATTRS.initialbodytext = {","    value: '',","    setter: function(content) {","        var parentnode,","            spinner;","        parentnode = Y.Node.create('<div />')","            .addClass(CSS.PANELTEXT);","","        spinner = Y.Node.create('<img />')","            .setAttribute('src', M.util.image_url(RESOURCES.WAITICON.pix, RESOURCES.WAITICON.component))","            .addClass('spinner');","","        if (content) {","            // If we have been provided with content, add it to the parent and make","            // the spinner appear correctly inline","            parentnode.set('text', content);","            spinner.addClass('iconsmall');","        } else {","            // If there is no loading message, just make the parent node a lightbox","            parentnode.addClass('content-lightbox');","        }","","        parentnode.append(spinner);","        return parentnode;","    }","};","","/**"," * The initial value of the footer region before the content finishes loading."," *"," * If a value is supplied, it will be wrapped in a <div> first."," *"," * @attribute initialfootertext"," * @type String"," * @default ''"," * @writeOnce"," */","ATTRS.initialfootertext = {","    value: null,","    setter: function(content) {","        if (content) {","            return Y.Node.create('<div />')","                .set('text', content);","        }","    }","};","","/**"," * The function which handles setting the content of the title region."," * The specified function will be called with a context of the tooltip instance."," *"," * The default function will simply set the value of the title to object.heading as returned by the AJAX call."," *"," * @attribute headerhandler"," * @type Function|String|null"," * @default set_header_content"," */","ATTRS.headerhandler = {","    value: 'set_header_content'","};","","/**"," * The function which handles setting the content of the body region."," * The specified function will be called with a context of the tooltip instance."," *"," * The default function will simply set the value of the body area to a div containing object.text as returned"," * by the AJAX call."," *"," * @attribute bodyhandler"," * @type Function|String|null"," * @default set_body_content"," */","ATTRS.bodyhandler = {","    value: 'set_body_content'","};","","/**"," * The function which handles setting the content of the footer region."," * The specified function will be called with a context of the tooltip instance."," *"," * By default, the footer is not set."," *"," * @attribute footerhandler"," * @type Function|String|null"," * @default null"," */","ATTRS.footerhandler = {","    value: null","};","","/**"," * The function which handles modifying the URL that was clicked on."," *"," * The default function rewrites '.php' to '_ajax.php'."," *"," * @attribute urlmodifier"," * @type Function|String|null"," * @default null"," */","ATTRS.urlmodifier = {","    value: null","};","","/**"," * Set the Y.Cache object to use."," *"," * By default a new Y.Cache object will be created for each instance of the tooltip."," *"," * In certain situations, where multiple tooltips may share the same cache, it may be preferable to"," * seed this cache from the calling method."," *"," * @attribute textcache"," * @type Y.Cache|null"," * @default null"," */","ATTRS.textcache = {","    value: null","};","","/**"," * Set the default size of the Y.Cache object."," *"," * This is only used if no textcache is specified."," *"," * @attribute textcachesize"," * @type Number"," * @default 10"," */","ATTRS.textcachesize = {","    value: 10","};","","Y.extend(TOOLTIP, M.core.dialogue, {","    // The bounding box.","    bb: null,","","    // Any event listeners we may need to cancel later.","    listenevents: [],","","    // Cache of objects we've already retrieved.","    textcache: null,","","    // The align position. This differs for RTL languages so we calculate once and store.","    alignpoints: [","        Y.WidgetPositionAlign.TL,","        Y.WidgetPositionAlign.RC","    ],","","    initializer: function() {","        // Set the initial values for the handlers.","        // These cannot be set in the attributes section as context isn't present at that time.","        if (!this.get('headerhandler')) {","            this.set('headerhandler', this.set_header_content);","        }","        if (!this.get('bodyhandler')) {","            this.set('bodyhandler', this.set_body_content);","        }","        if (!this.get('footerhandler')) {","            this.set('footerhandler', function() {});","        }","        if (!this.get('urlmodifier')) {","            this.set('urlmodifier', this.modify_url);","        }","","        // Set up the dialogue with initial content.","        this.setAttrs({","            headerContent: this.get('initialheadertext'),","            bodyContent: this.get('initialbodytext'),","            footerContent: this.get('initialfootertext'),","            zIndex: 150","        });","","        // Hide and then render the dialogue.","        this.hide();","        this.render();","","        // Hook into a few useful areas.","        this.bb = this.get('boundingBox');","","        // Change the alignment if this is an RTL language.","        if (right_to_left()) {","            this.alignpoints = [","                Y.WidgetPositionAlign.TR,","                Y.WidgetPositionAlign.LC","            ];","        }","","        // Set up the text cache if it's not set up already.","        if (!this.get('textcache')) {","            this.set('textcache', new Y.Cache({","                // Set a reasonable maximum cache size to prevent memory growth.","                max: this.get('textcachesize')","            }));","        }","","        // Disable the textcache when in developerdebug.","        if (M.cfg.developerdebug) {","            this.get('textcache').set('max', 0);","        }","","        return this;","    },","","    /**","     * Display the tooltip for the clicked link.","     *","     * The anchor for the clicked link is used.","     *","     * @method display_panel","     * @param {EventFacade} e The event from the clicked link. This is used to determine the clicked URL.","     */","    display_panel: function(e) {","        var clickedlink, thisevent, ajaxurl, config, cacheentry;","","        // Prevent the default click action and prevent the event triggering anything else.","        e.preventDefault();","        e.stopPropagation();","","        // Cancel any existing listeners and close the panel if it's already open.","        this.cancel_events();","","        // Grab the clickedlink - this contains the URL we fetch and we align the panel to it.","        clickedlink = e.target.ancestor('a', true);","","        // Align with the link that was clicked.","        this.align(clickedlink, this.alignpoints);","","        // Reset the initial text to a spinner while we retrieve the text.","        this.setAttrs({","            headerContent: this.get('initialheadertext'),","            bodyContent: this.get('initialbodytext'),","            footerContent: this.get('initialfootertext')","        });","","        // Now that initial setup has begun, show the panel.","        this.show();","","        // Add some listen events to close on.","        thisevent = this.bb.delegate('click', this.close_panel, SELECTORS.CLOSEBUTTON, this);","        this.listenevents.push(thisevent);","","        thisevent = Y.one('body').on('key', this.close_panel, 'esc', this);","        this.listenevents.push(thisevent);","","        // Listen for mousedownoutside events - clickoutside is broken on IE.","        thisevent = this.bb.on('mousedownoutside', this.close_panel, this);","        this.listenevents.push(thisevent);","","        // Modify the URL as required.","        ajaxurl = Y.bind(this.get('urlmodifier'), this, clickedlink.get('href'))();","","        cacheentry = this.get('textcache').retrieve(ajaxurl);","        if (cacheentry) {","            // The data from this help call was already cached so use that and avoid an AJAX call.","            this._set_panel_contents(cacheentry.response);","        } else {","            // Retrieve the actual help text we should use.","            config = {","                method: 'get',","                context: this,","                sync: false,","                on: {","                    complete: function(tid, response) {","                        this._set_panel_contents(response.responseText, ajaxurl);","                    }","                }","            };","","            Y.io(ajaxurl, config);","        }","    },","","    _set_panel_contents: function(response, ajaxurl) {","        var responseobject;","","        // Attempt to parse the response into an object.","        try {","            responseobject = Y.JSON.parse(response);","            if (responseobject.error) {","                this.close_panel();","                return new M.core.ajaxException(responseobject);","            }","        } catch (error) {","            this.close_panel();","            return new M.core.exception(error);","        }","","        // Set the contents using various handlers.","        // We must use Y.bind to ensure that the correct context is used when the default handlers are overridden.","        Y.bind(this.get('headerhandler'), this, responseobject)();","        Y.bind(this.get('bodyhandler'), this, responseobject)();","        Y.bind(this.get('footerhandler'), this, responseobject)();","","        if (ajaxurl) {","            // Ensure that this data is added to the cache.","            this.get('textcache').add(ajaxurl, response);","        }","","        this.get('buttons').header[0].focus();","    },","","    set_header_content: function(responseobject) {","        this.set('headerContent', responseobject.heading);","    },","","    set_body_content: function(responseobject) {","        var bodycontent = Y.Node.create('<div />')","            .set('innerHTML', responseobject.text)","            .setAttribute('role', 'alert')","            .addClass(CSS.PANELTEXT);","        this.set('bodyContent', bodycontent);","    },","","    modify_url: function(url) {","        return url.replace(/\\.php\\?/, '_ajax.php?');","    },","","    close_panel: function(e) {","        // Hide the panel first.","        this.hide();","","        // Cancel the listeners that we added in display_panel.","        this.cancel_events();","","        // Prevent any default click that the close button may have.","        if (e) {","            e.preventDefault();","        }","    },","","    cancel_events: function() {","        // Detach all listen events to prevent duplicate triggers.","        var thisevent;","        while (this.listenevents.length) {","            thisevent = this.listenevents.shift();","            thisevent.detach();","        }","    }","});","M.core = M.core || {};","M.core.tooltip = M.core.tooltip = TOOLTIP;","","","}, '@VERSION@', {","    \"requires\": [","        \"base\",","        \"node\",","        \"io-base\",","        \"moodle-core-notification\",","        \"json-parse\",","        \"widget-position\",","        \"widget-position-align\",","        \"event-outside\",","        \"cache\"","    ]","});"];
30 _yuitest_coverage["build/moodle-core-tooltip/moodle-core-tooltip.js"].lines = {"1":0,"17":0,"18":0,"19":0,"23":0,"24":0,"27":0,"28":0,"31":0,"32":0,"35":0,"38":0,"60":0,"69":0,"78":0,"88":0,"103":0,"106":0,"108":0,"111":0,"115":0,"118":0,"119":0,"122":0,"125":0,"126":0,"140":0,"143":0,"144":0,"160":0,"175":0,"189":0,"202":0,"218":0,"231":0,"235":0,"254":0,"255":0,"257":0,"258":0,"260":0,"261":0,"263":0,"264":0,"268":0,"276":0,"277":0,"280":0,"283":0,"284":0,"291":0,"292":0,"299":0,"300":0,"303":0,"315":0,"318":0,"319":0,"322":0,"325":0,"328":0,"331":0,"338":0,"341":0,"342":0,"344":0,"345":0,"348":0,"349":0,"352":0,"354":0,"355":0,"357":0,"360":0,"366":0,"371":0,"376":0,"379":0,"380":0,"381":0,"382":0,"383":0,"386":0,"387":0,"392":0,"393":0,"394":0,"396":0,"398":0,"401":0,"405":0,"409":0,"413":0,"417":0,"422":0,"425":0,"428":0,"429":0,"435":0,"436":0,"437":0,"438":0,"442":0,"443":0};
31 _yuitest_coverage["build/moodle-core-tooltip/moodle-core-tooltip.js"].functions = {"TOOLTIP:17":0,"setter:105":0,"setter:142":0,"initializer:251":0,"complete:365":0,"display_panel:314":0,"_set_panel_contents:375":0,"set_header_content:404":0,"set_body_content:408":0,"modify_url:416":0,"close_panel:420":0,"cancel_events:433":0,"(anonymous 1):1":0};
32 _yuitest_coverage["build/moodle-core-tooltip/moodle-core-tooltip.js"].coveredLines = 104;
33 _yuitest_coverage["build/moodle-core-tooltip/moodle-core-tooltip.js"].coveredFunctions = 13;
34 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 1);
35 YUI.add('moodle-core-tooltip', function (Y, NAME) {
37 /**
38  * Provides the base tooltip class.
39  *
40  * @module moodle-core-tooltip
41  */
43 /**
44  * A base class for a tooltip.
45  *
46  * @param {Object} config Object literal specifying tooltip configuration properties.
47  * @class M.core.tooltip
48  * @constructor
49  * @extends M.core.dialogue
50  */
51 _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "(anonymous 1)", 1);
52 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 17);
53 function TOOLTIP(config) {
54     _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "TOOLTIP", 17);
55 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 18);
56 if (!config) {
57         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 19);
58 config = {};
59     }
61     // Override the default options provided by the parent class.
62     _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 23);
63 if (typeof config.draggable === 'undefined') {
64         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 24);
65 config.draggable = true;
66     }
68     _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 27);
69 if (typeof config.constrain === 'undefined') {
70         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 28);
71 config.constrain = true;
72     }
74     _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 31);
75 if (typeof config.lightbox === 'undefined') {
76         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 32);
77 config.lightbox = false;
78     }
80     _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 35);
81 TOOLTIP.superclass.constructor.apply(this, [config]);
82 }
84 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 38);
85 var SELECTORS = {
86         CLOSEBUTTON: '.closebutton'
87     },
89     CSS = {
90         PANELTEXT: 'tooltiptext'
91     },
92     RESOURCES = {
93         WAITICON: {
94             pix: 'i/loading_small',
95             component: 'moodle'
96         }
97     },
98     ATTRS = {};
100 /**
101  * Static property provides a string to identify the JavaScript class.
102  *
103  * @property NAME
104  * @type String
105  * @static
106  */
107 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 60);
108 TOOLTIP.NAME = 'moodle-core-tooltip';
110 /**
111  * Static property used to define the CSS prefix applied to tooltip dialogues.
112  *
113  * @property CSS_PREFIX
114  * @type String
115  * @static
116  */
117 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 69);
118 TOOLTIP.CSS_PREFIX = 'moodle-dialogue';
120 /**
121  * Static property used to define the default attribute configuration for the Tooltip.
122  *
123  * @property ATTRS
124  * @type String
125  * @static
126  */
127 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 78);
128 TOOLTIP.ATTRS = ATTRS;
130 /**
131  * The initial value of the header region before the content finishes loading.
132  *
133  * @attribute initialheadertext
134  * @type String
135  * @default ''
136  * @writeOnce
137  */
138 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 88);
139 ATTRS.initialheadertext = {
140     value: ''
141 };
143 /**
144   * The initial value of the body region before the content finishes loading.
145   *
146   * The supplid string will be wrapped in a div with the CSS.PANELTEXT class and a standard Moodle spinner
147   * appended.
148   *
149   * @attribute initialbodytext
150   * @type String
151   * @default ''
152   * @writeOnce
153   */
154 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 103);
155 ATTRS.initialbodytext = {
156     value: '',
157     setter: function(content) {
158         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "setter", 105);
159 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 106);
160 var parentnode,
161             spinner;
162         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 108);
163 parentnode = Y.Node.create('<div />')
164             .addClass(CSS.PANELTEXT);
166         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 111);
167 spinner = Y.Node.create('<img />')
168             .setAttribute('src', M.util.image_url(RESOURCES.WAITICON.pix, RESOURCES.WAITICON.component))
169             .addClass('spinner');
171         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 115);
172 if (content) {
173             // If we have been provided with content, add it to the parent and make
174             // the spinner appear correctly inline
175             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 118);
176 parentnode.set('text', content);
177             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 119);
178 spinner.addClass('iconsmall');
179         } else {
180             // If there is no loading message, just make the parent node a lightbox
181             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 122);
182 parentnode.addClass('content-lightbox');
183         }
185         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 125);
186 parentnode.append(spinner);
187         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 126);
188 return parentnode;
189     }
190 };
192 /**
193  * The initial value of the footer region before the content finishes loading.
194  *
195  * If a value is supplied, it will be wrapped in a <div> first.
196  *
197  * @attribute initialfootertext
198  * @type String
199  * @default ''
200  * @writeOnce
201  */
202 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 140);
203 ATTRS.initialfootertext = {
204     value: null,
205     setter: function(content) {
206         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "setter", 142);
207 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 143);
208 if (content) {
209             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 144);
210 return Y.Node.create('<div />')
211                 .set('text', content);
212         }
213     }
214 };
216 /**
217  * The function which handles setting the content of the title region.
218  * The specified function will be called with a context of the tooltip instance.
219  *
220  * The default function will simply set the value of the title to object.heading as returned by the AJAX call.
221  *
222  * @attribute headerhandler
223  * @type Function|String|null
224  * @default set_header_content
225  */
226 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 160);
227 ATTRS.headerhandler = {
228     value: 'set_header_content'
229 };
231 /**
232  * The function which handles setting the content of the body region.
233  * The specified function will be called with a context of the tooltip instance.
234  *
235  * The default function will simply set the value of the body area to a div containing object.text as returned
236  * by the AJAX call.
237  *
238  * @attribute bodyhandler
239  * @type Function|String|null
240  * @default set_body_content
241  */
242 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 175);
243 ATTRS.bodyhandler = {
244     value: 'set_body_content'
245 };
247 /**
248  * The function which handles setting the content of the footer region.
249  * The specified function will be called with a context of the tooltip instance.
250  *
251  * By default, the footer is not set.
252  *
253  * @attribute footerhandler
254  * @type Function|String|null
255  * @default null
256  */
257 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 189);
258 ATTRS.footerhandler = {
259     value: null
260 };
262 /**
263  * The function which handles modifying the URL that was clicked on.
264  *
265  * The default function rewrites '.php' to '_ajax.php'.
266  *
267  * @attribute urlmodifier
268  * @type Function|String|null
269  * @default null
270  */
271 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 202);
272 ATTRS.urlmodifier = {
273     value: null
274 };
276 /**
277  * Set the Y.Cache object to use.
278  *
279  * By default a new Y.Cache object will be created for each instance of the tooltip.
280  *
281  * In certain situations, where multiple tooltips may share the same cache, it may be preferable to
282  * seed this cache from the calling method.
283  *
284  * @attribute textcache
285  * @type Y.Cache|null
286  * @default null
287  */
288 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 218);
289 ATTRS.textcache = {
290     value: null
291 };
293 /**
294  * Set the default size of the Y.Cache object.
295  *
296  * This is only used if no textcache is specified.
297  *
298  * @attribute textcachesize
299  * @type Number
300  * @default 10
301  */
302 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 231);
303 ATTRS.textcachesize = {
304     value: 10
305 };
307 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 235);
308 Y.extend(TOOLTIP, M.core.dialogue, {
309     // The bounding box.
310     bb: null,
312     // Any event listeners we may need to cancel later.
313     listenevents: [],
315     // Cache of objects we've already retrieved.
316     textcache: null,
318     // The align position. This differs for RTL languages so we calculate once and store.
319     alignpoints: [
320         Y.WidgetPositionAlign.TL,
321         Y.WidgetPositionAlign.RC
322     ],
324     initializer: function() {
325         // Set the initial values for the handlers.
326         // These cannot be set in the attributes section as context isn't present at that time.
327         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "initializer", 251);
328 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 254);
329 if (!this.get('headerhandler')) {
330             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 255);
331 this.set('headerhandler', this.set_header_content);
332         }
333         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 257);
334 if (!this.get('bodyhandler')) {
335             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 258);
336 this.set('bodyhandler', this.set_body_content);
337         }
338         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 260);
339 if (!this.get('footerhandler')) {
340             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 261);
341 this.set('footerhandler', function() {});
342         }
343         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 263);
344 if (!this.get('urlmodifier')) {
345             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 264);
346 this.set('urlmodifier', this.modify_url);
347         }
349         // Set up the dialogue with initial content.
350         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 268);
351 this.setAttrs({
352             headerContent: this.get('initialheadertext'),
353             bodyContent: this.get('initialbodytext'),
354             footerContent: this.get('initialfootertext'),
355             zIndex: 150
356         });
358         // Hide and then render the dialogue.
359         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 276);
360 this.hide();
361         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 277);
362 this.render();
364         // Hook into a few useful areas.
365         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 280);
366 this.bb = this.get('boundingBox');
368         // Change the alignment if this is an RTL language.
369         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 283);
370 if (right_to_left()) {
371             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 284);
372 this.alignpoints = [
373                 Y.WidgetPositionAlign.TR,
374                 Y.WidgetPositionAlign.LC
375             ];
376         }
378         // Set up the text cache if it's not set up already.
379         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 291);
380 if (!this.get('textcache')) {
381             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 292);
382 this.set('textcache', new Y.Cache({
383                 // Set a reasonable maximum cache size to prevent memory growth.
384                 max: this.get('textcachesize')
385             }));
386         }
388         // Disable the textcache when in developerdebug.
389         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 299);
390 if (M.cfg.developerdebug) {
391             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 300);
392 this.get('textcache').set('max', 0);
393         }
395         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 303);
396 return this;
397     },
399     /**
400      * Display the tooltip for the clicked link.
401      *
402      * The anchor for the clicked link is used.
403      *
404      * @method display_panel
405      * @param {EventFacade} e The event from the clicked link. This is used to determine the clicked URL.
406      */
407     display_panel: function(e) {
408         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "display_panel", 314);
409 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 315);
410 var clickedlink, thisevent, ajaxurl, config, cacheentry;
412         // Prevent the default click action and prevent the event triggering anything else.
413         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 318);
414 e.preventDefault();
415         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 319);
416 e.stopPropagation();
418         // Cancel any existing listeners and close the panel if it's already open.
419         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 322);
420 this.cancel_events();
422         // Grab the clickedlink - this contains the URL we fetch and we align the panel to it.
423         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 325);
424 clickedlink = e.target.ancestor('a', true);
426         // Align with the link that was clicked.
427         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 328);
428 this.align(clickedlink, this.alignpoints);
430         // Reset the initial text to a spinner while we retrieve the text.
431         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 331);
432 this.setAttrs({
433             headerContent: this.get('initialheadertext'),
434             bodyContent: this.get('initialbodytext'),
435             footerContent: this.get('initialfootertext')
436         });
438         // Now that initial setup has begun, show the panel.
439         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 338);
440 this.show();
442         // Add some listen events to close on.
443         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 341);
444 thisevent = this.bb.delegate('click', this.close_panel, SELECTORS.CLOSEBUTTON, this);
445         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 342);
446 this.listenevents.push(thisevent);
448         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 344);
449 thisevent = Y.one('body').on('key', this.close_panel, 'esc', this);
450         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 345);
451 this.listenevents.push(thisevent);
453         // Listen for mousedownoutside events - clickoutside is broken on IE.
454         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 348);
455 thisevent = this.bb.on('mousedownoutside', this.close_panel, this);
456         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 349);
457 this.listenevents.push(thisevent);
459         // Modify the URL as required.
460         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 352);
461 ajaxurl = Y.bind(this.get('urlmodifier'), this, clickedlink.get('href'))();
463         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 354);
464 cacheentry = this.get('textcache').retrieve(ajaxurl);
465         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 355);
466 if (cacheentry) {
467             // The data from this help call was already cached so use that and avoid an AJAX call.
468             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 357);
469 this._set_panel_contents(cacheentry.response);
470         } else {
471             // Retrieve the actual help text we should use.
472             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 360);
473 config = {
474                 method: 'get',
475                 context: this,
476                 sync: false,
477                 on: {
478                     complete: function(tid, response) {
479                         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "complete", 365);
480 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 366);
481 this._set_panel_contents(response.responseText, ajaxurl);
482                     }
483                 }
484             };
486             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 371);
487 Y.io(ajaxurl, config);
488         }
489     },
491     _set_panel_contents: function(response, ajaxurl) {
492         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "_set_panel_contents", 375);
493 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 376);
494 var responseobject;
496         // Attempt to parse the response into an object.
497         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 379);
498 try {
499             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 380);
500 responseobject = Y.JSON.parse(response);
501             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 381);
502 if (responseobject.error) {
503                 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 382);
504 this.close_panel();
505                 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 383);
506 return new M.core.ajaxException(responseobject);
507             }
508         } catch (error) {
509             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 386);
510 this.close_panel();
511             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 387);
512 return new M.core.exception(error);
513         }
515         // Set the contents using various handlers.
516         // We must use Y.bind to ensure that the correct context is used when the default handlers are overridden.
517         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 392);
518 Y.bind(this.get('headerhandler'), this, responseobject)();
519         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 393);
520 Y.bind(this.get('bodyhandler'), this, responseobject)();
521         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 394);
522 Y.bind(this.get('footerhandler'), this, responseobject)();
524         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 396);
525 if (ajaxurl) {
526             // Ensure that this data is added to the cache.
527             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 398);
528 this.get('textcache').add(ajaxurl, response);
529         }
531         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 401);
532 this.get('buttons').header[0].focus();
533     },
535     set_header_content: function(responseobject) {
536         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "set_header_content", 404);
537 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 405);
538 this.set('headerContent', responseobject.heading);
539     },
541     set_body_content: function(responseobject) {
542         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "set_body_content", 408);
543 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 409);
544 var bodycontent = Y.Node.create('<div />')
545             .set('innerHTML', responseobject.text)
546             .setAttribute('role', 'alert')
547             .addClass(CSS.PANELTEXT);
548         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 413);
549 this.set('bodyContent', bodycontent);
550     },
552     modify_url: function(url) {
553         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "modify_url", 416);
554 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 417);
555 return url.replace(/\.php\?/, '_ajax.php?');
556     },
558     close_panel: function(e) {
559         // Hide the panel first.
560         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "close_panel", 420);
561 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 422);
562 this.hide();
564         // Cancel the listeners that we added in display_panel.
565         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 425);
566 this.cancel_events();
568         // Prevent any default click that the close button may have.
569         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 428);
570 if (e) {
571             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 429);
572 e.preventDefault();
573         }
574     },
576     cancel_events: function() {
577         // Detach all listen events to prevent duplicate triggers.
578         _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "cancel_events", 433);
579 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 435);
580 var thisevent;
581         _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 436);
582 while (this.listenevents.length) {
583             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 437);
584 thisevent = this.listenevents.shift();
585             _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 438);
586 thisevent.detach();
587         }
588     }
589 });
590 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 442);
591 M.core = M.core || {};
592 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 443);
593 M.core.tooltip = M.core.tooltip = TOOLTIP;
596 }, '@VERSION@', {
597     "requires": [
598         "base",
599         "node",
600         "io-base",
601         "moodle-core-notification",
602         "json-parse",
603         "widget-position",
604         "widget-position-align",
605         "event-outside",
606         "cache"
607     ]
608 });