MDL 38508 JavaScript: Split out AJAX and non-AJAX help
[moodle.git] / lib / yui / build / moodle-core-tooltip / moodle-core-tooltip-coverage.js
CommitLineData
e2798523
ARN
1if (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};
56d465b2
ARN
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;
e2798523
ARN
34_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 1);
35YUI.add('moodle-core-tooltip', function (Y, NAME) {
36
c5952e06
ARN
37/**
38 * Provides the base tooltip class.
39 *
40 * @module moodle-core-tooltip
41 */
42
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);
e2798523
ARN
52_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 17);
53function TOOLTIP(config) {
c5952e06 54 _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "TOOLTIP", 17);
e2798523
ARN
55_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 18);
56if (!config) {
c5952e06 57 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 19);
e2798523 58config = {};
c5952e06 59 }
e2798523 60
c5952e06
ARN
61 // Override the default options provided by the parent class.
62 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 23);
e2798523 63if (typeof config.draggable === 'undefined') {
c5952e06 64 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 24);
e2798523 65config.draggable = true;
c5952e06 66 }
e2798523 67
c5952e06 68 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 27);
e2798523 69if (typeof config.constrain === 'undefined') {
c5952e06 70 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 28);
e2798523 71config.constrain = true;
c5952e06 72 }
e2798523 73
c5952e06 74 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 31);
e2798523 75if (typeof config.lightbox === 'undefined') {
c5952e06 76 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 32);
e2798523 77config.lightbox = false;
c5952e06 78 }
e2798523 79
c5952e06 80 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 35);
e2798523 81TOOLTIP.superclass.constructor.apply(this, [config]);
c5952e06 82}
e2798523 83
c5952e06 84_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 38);
e2798523 85var SELECTORS = {
c5952e06
ARN
86 CLOSEBUTTON: '.closebutton'
87 },
88
89 CSS = {
90 PANELTEXT: 'tooltiptext'
91 },
92 RESOURCES = {
93 WAITICON: {
94 pix: 'i/loading_small',
95 component: 'moodle'
96 }
97 },
98 ATTRS = {};
99
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);
e2798523
ARN
108TOOLTIP.NAME = 'moodle-core-tooltip';
109
c5952e06
ARN
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);
e2798523
ARN
118TOOLTIP.CSS_PREFIX = 'moodle-dialogue';
119
c5952e06
ARN
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);
e2798523
ARN
128TOOLTIP.ATTRS = ATTRS;
129
c5952e06
ARN
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);
e2798523 139ATTRS.initialheadertext = {
c5952e06
ARN
140 value: ''
141};
e2798523 142
c5952e06
ARN
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);
e2798523 155ATTRS.initialbodytext = {
c5952e06
ARN
156 value: '',
157 setter: function(content) {
158 _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "setter", 105);
e2798523
ARN
159_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 106);
160var parentnode,
c5952e06
ARN
161 spinner;
162 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 108);
e2798523 163parentnode = Y.Node.create('<div />')
c5952e06 164 .addClass(CSS.PANELTEXT);
e2798523 165
c5952e06 166 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 111);
e2798523 167spinner = Y.Node.create('<img />')
c5952e06
ARN
168 .setAttribute('src', M.util.image_url(RESOURCES.WAITICON.pix, RESOURCES.WAITICON.component))
169 .addClass('spinner');
e2798523 170
c5952e06 171 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 115);
e2798523 172if (content) {
c5952e06
ARN
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);
e2798523 176parentnode.set('text', content);
c5952e06 177 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 119);
e2798523 178spinner.addClass('iconsmall');
c5952e06
ARN
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);
e2798523 182parentnode.addClass('content-lightbox');
c5952e06 183 }
e2798523 184
c5952e06 185 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 125);
e2798523 186parentnode.append(spinner);
c5952e06 187 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 126);
e2798523 188return parentnode;
c5952e06
ARN
189 }
190};
e2798523 191
c5952e06
ARN
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);
e2798523 203ATTRS.initialfootertext = {
c5952e06
ARN
204 value: null,
205 setter: function(content) {
206 _yuitest_coverfunc("build/moodle-core-tooltip/moodle-core-tooltip.js", "setter", 142);
e2798523
ARN
207_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 143);
208if (content) {
c5952e06 209 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 144);
e2798523 210return Y.Node.create('<div />')
c5952e06 211 .set('text', content);
e2798523 212 }
c5952e06
ARN
213 }
214};
e2798523 215
c5952e06
ARN
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);
e2798523 227ATTRS.headerhandler = {
c5952e06
ARN
228 value: 'set_header_content'
229};
e2798523 230
c5952e06
ARN
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);
e2798523 243ATTRS.bodyhandler = {
c5952e06
ARN
244 value: 'set_body_content'
245};
e2798523 246
c5952e06
ARN
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);
e2798523 258ATTRS.footerhandler = {
c5952e06
ARN
259 value: null
260};
e2798523 261
56d465b2
ARN
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);
272ATTRS.urlmodifier = {
273 value: null
274};
275
c5952e06
ARN
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 */
56d465b2 288_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 218);
e2798523 289ATTRS.textcache = {
c5952e06
ARN
290 value: null
291};
e2798523 292
c5952e06
ARN
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 */
56d465b2 302_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 231);
e2798523 303ATTRS.textcachesize = {
c5952e06
ARN
304 value: 10
305};
e2798523 306
56d465b2 307_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 235);
e2798523 308Y.extend(TOOLTIP, M.core.dialogue, {
c5952e06
ARN
309 // The bounding box.
310 bb: null,
e2798523 311
c5952e06
ARN
312 // Any event listeners we may need to cancel later.
313 listenevents: [],
e2798523 314
c5952e06
ARN
315 // Cache of objects we've already retrieved.
316 textcache: null,
e2798523 317
c5952e06
ARN
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 ],
e2798523 323
c5952e06
ARN
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.
56d465b2
ARN
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);
e2798523 329if (!this.get('headerhandler')) {
56d465b2 330 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 255);
e2798523 331this.set('headerhandler', this.set_header_content);
c5952e06 332 }
56d465b2 333 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 257);
e2798523 334if (!this.get('bodyhandler')) {
56d465b2 335 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 258);
e2798523 336this.set('bodyhandler', this.set_body_content);
c5952e06 337 }
56d465b2 338 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 260);
e2798523 339if (!this.get('footerhandler')) {
56d465b2 340 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 261);
e2798523 341this.set('footerhandler', function() {});
c5952e06 342 }
56d465b2
ARN
343 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 263);
344if (!this.get('urlmodifier')) {
345 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 264);
346this.set('urlmodifier', this.modify_url);
347 }
e2798523 348
c5952e06 349 // Set up the dialogue with initial content.
56d465b2 350 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 268);
e2798523 351this.setAttrs({
c5952e06
ARN
352 headerContent: this.get('initialheadertext'),
353 bodyContent: this.get('initialbodytext'),
354 footerContent: this.get('initialfootertext'),
355 zIndex: 150
356 });
357
358 // Hide and then render the dialogue.
56d465b2 359 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 276);
e2798523 360this.hide();
56d465b2 361 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 277);
e2798523
ARN
362this.render();
363
c5952e06 364 // Hook into a few useful areas.
56d465b2 365 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 280);
e2798523
ARN
366this.bb = this.get('boundingBox');
367
c5952e06 368 // Change the alignment if this is an RTL language.
56d465b2 369 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 283);
e2798523 370if (right_to_left()) {
56d465b2 371 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 284);
e2798523 372this.alignpoints = [
c5952e06
ARN
373 Y.WidgetPositionAlign.TR,
374 Y.WidgetPositionAlign.LC
375 ];
376 }
e2798523 377
c5952e06 378 // Set up the text cache if it's not set up already.
56d465b2 379 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 291);
e2798523 380if (!this.get('textcache')) {
56d465b2 381 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 292);
e2798523 382this.set('textcache', new Y.Cache({
c5952e06
ARN
383 // Set a reasonable maximum cache size to prevent memory growth.
384 max: this.get('textcachesize')
385 }));
386 }
e2798523 387
c5952e06 388 // Disable the textcache when in developerdebug.
56d465b2 389 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 299);
e2798523 390if (M.cfg.developerdebug) {
56d465b2 391 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 300);
e2798523 392this.get('textcache').set('max', 0);
c5952e06 393 }
e2798523 394
56d465b2 395 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 303);
e2798523 396return this;
c5952e06
ARN
397 },
398
399 /**
400 * Display the tooltip for the clicked link.
401 *
56d465b2 402 * The anchor for the clicked link is used.
c5952e06
ARN
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) {
56d465b2
ARN
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);
e2798523
ARN
410var clickedlink, thisevent, ajaxurl, config, cacheentry;
411
c5952e06 412 // Prevent the default click action and prevent the event triggering anything else.
56d465b2 413 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 318);
e2798523 414e.preventDefault();
56d465b2 415 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 319);
e2798523
ARN
416e.stopPropagation();
417
c5952e06 418 // Cancel any existing listeners and close the panel if it's already open.
56d465b2 419 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 322);
e2798523
ARN
420this.cancel_events();
421
c5952e06 422 // Grab the clickedlink - this contains the URL we fetch and we align the panel to it.
56d465b2 423 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 325);
e2798523
ARN
424clickedlink = e.target.ancestor('a', true);
425
c5952e06 426 // Align with the link that was clicked.
56d465b2 427 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 328);
e2798523
ARN
428this.align(clickedlink, this.alignpoints);
429
c5952e06 430 // Reset the initial text to a spinner while we retrieve the text.
56d465b2 431 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 331);
e2798523 432this.setAttrs({
c5952e06
ARN
433 headerContent: this.get('initialheadertext'),
434 bodyContent: this.get('initialbodytext'),
435 footerContent: this.get('initialfootertext')
436 });
e2798523 437
c5952e06 438 // Now that initial setup has begun, show the panel.
56d465b2 439 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 338);
e2798523
ARN
440this.show();
441
c5952e06 442 // Add some listen events to close on.
56d465b2 443 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 341);
e2798523 444thisevent = this.bb.delegate('click', this.close_panel, SELECTORS.CLOSEBUTTON, this);
56d465b2 445 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 342);
e2798523
ARN
446this.listenevents.push(thisevent);
447
56d465b2 448 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 344);
e2798523 449thisevent = Y.one('body').on('key', this.close_panel, 'esc', this);
56d465b2 450 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 345);
e2798523
ARN
451this.listenevents.push(thisevent);
452
c5952e06 453 // Listen for mousedownoutside events - clickoutside is broken on IE.
56d465b2 454 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 348);
e2798523 455thisevent = this.bb.on('mousedownoutside', this.close_panel, this);
56d465b2 456 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 349);
e2798523
ARN
457this.listenevents.push(thisevent);
458
56d465b2
ARN
459 // Modify the URL as required.
460 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 352);
461ajaxurl = Y.bind(this.get('urlmodifier'), this, clickedlink.get('href'))();
e2798523 462
56d465b2 463 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 354);
e2798523 464cacheentry = this.get('textcache').retrieve(ajaxurl);
56d465b2 465 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 355);
e2798523 466if (cacheentry) {
c5952e06 467 // The data from this help call was already cached so use that and avoid an AJAX call.
56d465b2 468 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 357);
e2798523 469this._set_panel_contents(cacheentry.response);
c5952e06
ARN
470 } else {
471 // Retrieve the actual help text we should use.
56d465b2 472 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 360);
e2798523 473config = {
c5952e06
ARN
474 method: 'get',
475 context: this,
476 sync: false,
c5952e06
ARN
477 on: {
478 complete: function(tid, response) {
56d465b2
ARN
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);
e2798523 481this._set_panel_contents(response.responseText, ajaxurl);
e2798523 482 }
c5952e06
ARN
483 }
484 };
e2798523 485
56d465b2
ARN
486 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 371);
487Y.io(ajaxurl, config);
c5952e06
ARN
488 }
489 },
e2798523 490
c5952e06 491 _set_panel_contents: function(response, ajaxurl) {
56d465b2
ARN
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);
e2798523
ARN
494var responseobject;
495
c5952e06 496 // Attempt to parse the response into an object.
56d465b2 497 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 379);
e2798523 498try {
56d465b2 499 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 380);
e2798523 500responseobject = Y.JSON.parse(response);
56d465b2 501 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 381);
e2798523 502if (responseobject.error) {
56d465b2 503 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 382);
e2798523 504this.close_panel();
56d465b2 505 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 383);
e2798523 506return new M.core.ajaxException(responseobject);
c5952e06
ARN
507 }
508 } catch (error) {
56d465b2 509 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 386);
e2798523 510this.close_panel();
56d465b2
ARN
511 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 387);
512return new M.core.exception(error);
c5952e06 513 }
e2798523 514
c5952e06
ARN
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.
56d465b2 517 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 392);
e2798523 518Y.bind(this.get('headerhandler'), this, responseobject)();
56d465b2 519 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 393);
e2798523 520Y.bind(this.get('bodyhandler'), this, responseobject)();
56d465b2 521 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 394);
e2798523
ARN
522Y.bind(this.get('footerhandler'), this, responseobject)();
523
56d465b2 524 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 396);
e2798523 525if (ajaxurl) {
c5952e06 526 // Ensure that this data is added to the cache.
56d465b2 527 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 398);
e2798523 528this.get('textcache').add(ajaxurl, response);
c5952e06 529 }
e2798523 530
56d465b2 531 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 401);
e2798523 532this.get('buttons').header[0].focus();
c5952e06 533 },
e2798523 534
c5952e06 535 set_header_content: function(responseobject) {
56d465b2
ARN
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);
e2798523 538this.set('headerContent', responseobject.heading);
c5952e06 539 },
e2798523 540
c5952e06 541 set_body_content: function(responseobject) {
56d465b2
ARN
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);
e2798523 544var bodycontent = Y.Node.create('<div />')
c5952e06
ARN
545 .set('innerHTML', responseobject.text)
546 .setAttribute('role', 'alert')
547 .addClass(CSS.PANELTEXT);
56d465b2 548 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 413);
e2798523 549this.set('bodyContent', bodycontent);
c5952e06 550 },
e2798523 551
56d465b2
ARN
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);
555return url.replace(/\.php\?/, '_ajax.php?');
556 },
557
c5952e06
ARN
558 close_panel: function(e) {
559 // Hide the panel first.
56d465b2
ARN
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);
e2798523
ARN
562this.hide();
563
c5952e06 564 // Cancel the listeners that we added in display_panel.
56d465b2 565 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 425);
e2798523
ARN
566this.cancel_events();
567
c5952e06 568 // Prevent any default click that the close button may have.
56d465b2 569 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 428);
e2798523 570if (e) {
56d465b2 571 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 429);
e2798523 572e.preventDefault();
c5952e06
ARN
573 }
574 },
e2798523 575
c5952e06
ARN
576 cancel_events: function() {
577 // Detach all listen events to prevent duplicate triggers.
56d465b2
ARN
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);
e2798523 580var thisevent;
56d465b2 581 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 436);
e2798523 582while (this.listenevents.length) {
56d465b2 583 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 437);
e2798523 584thisevent = this.listenevents.shift();
56d465b2 585 _yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 438);
e2798523 586thisevent.detach();
e2798523 587 }
c5952e06
ARN
588 }
589});
56d465b2 590_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 442);
e2798523 591M.core = M.core || {};
56d465b2 592_yuitest_coverline("build/moodle-core-tooltip/moodle-core-tooltip.js", 443);
e2798523
ARN
593M.core.tooltip = M.core.tooltip = TOOLTIP;
594
595
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});