From 3b044ba347ef7597dbaece15e60c0d054c0f667d Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 6 Feb 2010 15:08:12 +0000 Subject: [PATCH] MDL-21400 converting help tooltips to YUI3/2 --- lib/ajax/ajaxlib.php | 2 +- lib/javascript-static.js | 127 ++++++++++++++++++++------------------- 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 2de25c9d1bd..9df6aad7fde 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -252,7 +252,7 @@ class page_requirements_manager { $this->string_for_js('confirmation', 'admin'); $this->string_for_js('cancel', 'moodle'); $this->string_for_js('yes', 'moodle'); - $this->js_function_call('init_help_icons'); + $this->js_init_call('M.util.init_help_icons'); } /** diff --git a/lib/javascript-static.js b/lib/javascript-static.js index ea9466e1bde..b6a007f5bec 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -50,13 +50,13 @@ M.util.create_UFO_object = function (eid, FO) { */ M.util.init_collapsible_region = function(Y, id, userpref, strtooltip) { Y.use('anim', function(Y) { - new M.util.CollapsibleRegion(Y, id, userpref, strtooltip); + new M.util.CollapsibleRegion(Y, id, userpref, strtooltip); }); }; /** * Object to handle a collapsible region : instantiate and forget styled object - * + * * @class * @constructor * @param {YUI} Y YUI3 instance with all libraries loaded @@ -107,7 +107,7 @@ M.util.CollapsibleRegion = function(Y, id, userpref, strtooltip) { to: {height:caption.get('offsetHeight')}, from: {height:height} }); - + // Handler for the animation finishing. animation.on('end', function() { this.div.toggleClass('collapsed'); @@ -155,6 +155,66 @@ M.util.CollapsibleRegion.prototype.div = null; */ M.util.CollapsibleRegion.prototype.icon = null; +/** + * Finds all help icons on the page and initiates YUI tooltips for + * each of them, which load a truncated version of the help's content + * on-the-fly asynchronously + */ +M.util.init_help_icons = function(Y) { + Y.use('yui2-dom, yui2-container, io', function(Y) { + // remove all titles, they would obscure the YUI tooltip + Y.all('span.helplink a').each(function(node) { + node.set('title', ''); + }); + + var iconspans = YAHOO.util.Dom.getElementsByClassName('helplink', 'span'); + var tooltip = new YAHOO.widget.Tooltip('help_icon_tooltip', { + context: iconspans, + showdelay: 1000, + hidedelay: 150, + autodismissdelay: 50000, + underlay: 'none', + zIndex: '1000' + }); + + tooltip.contextTriggerEvent.subscribe( + function(type, args) { + // Fetch help page contents asynchronously + // Load spinner icon while content is loading + var spinner = document.createElement('img'); + spinner.src = M.cfg.loadingicon; + + this.cfg.setProperty('text', spinner); + + var context = args[0]; + + var link = context.getElementsByTagName('a')[0]; + var thistooltip = this; + var ajaxurl = link.href + '&fortooltip=1'; + + + var cfg = { + method: 'get', + on: { + success: function(id, o, args) { + thistooltip.cfg.setProperty('text', o.responseText); + }, + failure: function(id, o, args) { + var debuginfo = o.statusText; + if (M.cfg.developerdebug) { + o.statusText += ' (' + ajaxurl + ')'; + } + thistooltip.cfg.setProperty('text', debuginfo); + } + } + }; + + var conn = Y.io(ajaxurl, cfg); + } + ); + }); +}; + //=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code === function popupchecker(msg) { @@ -1203,65 +1263,6 @@ function stripHTML(str) { return ret; } -/** - * Finds all help icons on the page and initiates YUI tooltips for - * each of them, which load a truncated version of the help's content - * on-the-fly asynchronously - */ -function init_help_icons() { - // var logger = new YAHOO.widget.LogReader(document.body, {draggable: true}); - - var iconspans = YAHOO.util.Dom.getElementsByClassName('helplink', 'span'); - - var tooltip = new YAHOO.widget.Tooltip('help_icon_tooltip', { - context: iconspans, - showdelay: 1000, - hidedelay: 150, - autodismissdelay: 50000, - underlay: 'none', - zIndex: '1000' - }); - - // remove all titles, they would obscure the YUI tooltip - for (var i = 0; i < iconspans.length; i++) { - iconspans[i].getElementsByTagName('a')[0].title = ''; - } - - tooltip.contextTriggerEvent.subscribe( - function(type, args) { - // Fetch help page contents asynchronously - // Load spinner icon while content is loading - var spinner = document.createElement('img'); - spinner.src = M.cfg.loadingicon; - - this.cfg.setProperty('text', spinner); - - var context = args[0]; - context.title = ''; - - var link = context.getElementsByTagName('a')[0]; - var thistooltip = this; - var ajaxurl = link.href + '&fortooltip=1'; - - - var callback = { - success: function(o) { - thistooltip.cfg.setProperty('text', o.responseText); - }, - failure: function(o) { - var debuginfo = o.statusText; - if (M.cfg.developerdebug) { - o.statusText += ' (' + ajaxurl + ')'; - } - thistooltip.cfg.setProperty('text', debuginfo); - } - }; - - var conn = YAHOO.util.Connect.asyncRequest("get", ajaxurl, callback); - } - ); -} - /** * Prints a confirmation dialog in the style of DOM.confirm(). * @param object event A DOM event @@ -1385,7 +1386,7 @@ function submitFormById(id) { * Used in a couple of modules to hide navigation areas when using AJAX */ function hide_item(itemid) { - // use class='hiddenifjs' instead + // use class='hiddenifjs' instead var item = document.getElementById(itemid); if (item) { item.style.display = "none";