MDL-21400 converting help tooltips to YUI3/2

This commit is contained in:
Petr Skoda
2010-02-06 15:08:12 +00:00
parent 593f9b8703
commit 3b044ba347
2 changed files with 65 additions and 64 deletions

View File

@@ -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";