From: Michael M Slusarz Date: Fri, 3 Sep 2010 21:56:23 +0000 (-0600) Subject: Tooltips tweaks. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9bd7df72b9c23df59d20208537266a2f718ba666;p=horde.git Tooltips tweaks. Automatically add JS file when calling linkTooltip(). Move tooltips JS file to horde/Core. --- diff --git a/agora/lib/Messages.php b/agora/lib/Messages.php index a62620eaf..2214fce94 100644 --- a/agora/lib/Messages.php +++ b/agora/lib/Messages.php @@ -1652,9 +1652,6 @@ class Agora_Messages { return $files; } - /* Make sure we have the tooltips javascript. */ - Horde::addScriptFile('tooltips.js', 'horde', true); - /* Constuct the link with a tooltip for further info on the download. */ $html = '
'; $view_url = Horde::url('view.php'); diff --git a/framework/Core/js/tooltips.js b/framework/Core/js/tooltips.js new file mode 100644 index 000000000..737efb826 --- /dev/null +++ b/framework/Core/js/tooltips.js @@ -0,0 +1,143 @@ +/** + * Horde tooltips javascript. + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + */ + +var Horde_ToolTips = +{ + // Vars used and defaulting to null: element, timeout + + attachBehavior: function() + { + $$('a').each(this.attach.bind(this)); + }, + + attach: function(e) + { + var t = e.readAttribute('title'); + if (!t) { + return; + } + e.store('nicetitle', t); + try { + e.removeAttribute('title'); + } catch (e) {} + e.observe('mouseover', this.onMouseover.bindAsEventListener(this)); + e.observe('mouseout', this.out.bind(this)); + e.observe('focus', this.onFocus.bindAsEventListener(this)); + e.observe('blur', this.out.bind(this)); + }, + + detach: function(e) + { + e.stopObserving('mouseover'); + e.stopObserving('mouseout'); + e.stopObserving('focus'); + e.stopObserving('blur'); + }, + + onMouseover: function(e) + { + this.onOver(e, [ e.pointerX(), e.pointerY() ]); + }, + + onFocus: function(e) + { + this.onOver(e, e.element().cumulativeOffset()); + }, + + onOver: function(e, p) + { + if (this.timeout) { + clearTimeout(this.timeout); + } + + this.element = e.element(); + this.timeout = this.show.bind(this, p).delay(0.3); + }, + + out: function() + { + var iframe, t = $('toolTip'); + + if (this.timeout) { + clearTimeout(this.timeout); + } + + if (t) { + t.hide(); + + iframe = $('iframe_tt'); + if (iframe) { + iframe.hide(); + } + } + }, + + show: function(pos) + { + var iframe, left, link, nicetitle, w, + d = $('toolTip'), + s_offset = document.viewport.getScrollOffsets(), + v_dimens = document.viewport.getDimensions(); + + if (d) { + this.out(); + } + + link = this.element; + while (!link.retrieve('nicetitle') && link.match('BODY')) { + link = link.up(); + } + + nicetitle = link.retrieve('nicetitle'); + if (!nicetitle) { + return; + } + + if (!d) { + d = new Element('DIV', { id: 'toolTip', className: 'nicetitle' }).hide(); + document.body.appendChild(d); + } + + d.update(nicetitle); + + // Make sure all of the tooltip is visible. + left = pos[0] + 10; + w = d.getWidth(); + if ((left + w) > (v_dimens.width + s_offset.left)) { + left = v_dimens.width - w - 40 + s_offset.left; + } + if (document.body.scrollWidth && ((left + w) > (document.body.scrollWidth + s_offset.left))) { + left = document.body.scrollWidth - w - 25 + s_offset.left; + } + + d.setStyle({ + left: Math.max(left, 5) + 'px', + top: (pos[1] + 10) + 'px' + }).show(); + + // IE 6 only. + if (Prototype.Browser.IE && !window.XMLHttpRequest) { + iframe = $('iframe_tt'); + if (!iframe) { + iframe = new Element('IFRAME', { name: 'iframe_tt', id: 'iframe_tt', src: 'javascript:false;', scrolling: 'no', frameborder: 0 }).hide(); + document.body.appendChild(iframe); + } + iframe.clonePosition(d).setStyle({ + position: 'absolute', + display: 'block', + zIndex: 99 + }); + d.setStyle({ zIndex: 100 }); + } + } + +}; + +if (typeof Horde_ToolTips_Autoload == 'undefined' || !Horde_ToolTips_Autoload) { + Event.observe(window, 'load', Horde_ToolTips.attachBehavior.bind(Horde_ToolTips)); + Event.observe(window, 'unload', Horde_ToolTips.out.bind(Horde_ToolTips)); +} diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 2c69ade51..87e4e05ef 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -1178,6 +1178,8 @@ HTML; $old_error = error_reporting(0); $title = '<pre>' . preg_replace(array('/\n/', '/((?))/em', '/

/', '/
/'), array('', 'str_repeat(" ", strlen("$1"))', '<br /> <br />', '<br />'), nl2br(htmlspecialchars(htmlspecialchars($title, ENT_QUOTES, $charset), ENT_QUOTES, $charset))) . '</pre>'; error_reporting($old_error); + + Horde::addScriptFile('tooltips.js', 'horde'); } return self::link($url, $title, $class, $target, $onclick, null, $accesskey, $attributes, false); diff --git a/framework/Core/package.xml b/framework/Core/package.xml index ba2b3e823..6ba9af0f7 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -68,6 +68,7 @@ Application Framework. + @@ -409,6 +410,7 @@ Application Framework. + diff --git a/horde/js/tooltips.js b/horde/js/tooltips.js deleted file mode 100644 index 737efb826..000000000 --- a/horde/js/tooltips.js +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Horde tooltips javascript. - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - */ - -var Horde_ToolTips = -{ - // Vars used and defaulting to null: element, timeout - - attachBehavior: function() - { - $$('a').each(this.attach.bind(this)); - }, - - attach: function(e) - { - var t = e.readAttribute('title'); - if (!t) { - return; - } - e.store('nicetitle', t); - try { - e.removeAttribute('title'); - } catch (e) {} - e.observe('mouseover', this.onMouseover.bindAsEventListener(this)); - e.observe('mouseout', this.out.bind(this)); - e.observe('focus', this.onFocus.bindAsEventListener(this)); - e.observe('blur', this.out.bind(this)); - }, - - detach: function(e) - { - e.stopObserving('mouseover'); - e.stopObserving('mouseout'); - e.stopObserving('focus'); - e.stopObserving('blur'); - }, - - onMouseover: function(e) - { - this.onOver(e, [ e.pointerX(), e.pointerY() ]); - }, - - onFocus: function(e) - { - this.onOver(e, e.element().cumulativeOffset()); - }, - - onOver: function(e, p) - { - if (this.timeout) { - clearTimeout(this.timeout); - } - - this.element = e.element(); - this.timeout = this.show.bind(this, p).delay(0.3); - }, - - out: function() - { - var iframe, t = $('toolTip'); - - if (this.timeout) { - clearTimeout(this.timeout); - } - - if (t) { - t.hide(); - - iframe = $('iframe_tt'); - if (iframe) { - iframe.hide(); - } - } - }, - - show: function(pos) - { - var iframe, left, link, nicetitle, w, - d = $('toolTip'), - s_offset = document.viewport.getScrollOffsets(), - v_dimens = document.viewport.getDimensions(); - - if (d) { - this.out(); - } - - link = this.element; - while (!link.retrieve('nicetitle') && link.match('BODY')) { - link = link.up(); - } - - nicetitle = link.retrieve('nicetitle'); - if (!nicetitle) { - return; - } - - if (!d) { - d = new Element('DIV', { id: 'toolTip', className: 'nicetitle' }).hide(); - document.body.appendChild(d); - } - - d.update(nicetitle); - - // Make sure all of the tooltip is visible. - left = pos[0] + 10; - w = d.getWidth(); - if ((left + w) > (v_dimens.width + s_offset.left)) { - left = v_dimens.width - w - 40 + s_offset.left; - } - if (document.body.scrollWidth && ((left + w) > (document.body.scrollWidth + s_offset.left))) { - left = document.body.scrollWidth - w - 25 + s_offset.left; - } - - d.setStyle({ - left: Math.max(left, 5) + 'px', - top: (pos[1] + 10) + 'px' - }).show(); - - // IE 6 only. - if (Prototype.Browser.IE && !window.XMLHttpRequest) { - iframe = $('iframe_tt'); - if (!iframe) { - iframe = new Element('IFRAME', { name: 'iframe_tt', id: 'iframe_tt', src: 'javascript:false;', scrolling: 'no', frameborder: 0 }).hide(); - document.body.appendChild(iframe); - } - iframe.clonePosition(d).setStyle({ - position: 'absolute', - display: 'block', - zIndex: 99 - }); - d.setStyle({ zIndex: 100 }); - } - } - -}; - -if (typeof Horde_ToolTips_Autoload == 'undefined' || !Horde_ToolTips_Autoload) { - Event.observe(window, 'load', Horde_ToolTips.attachBehavior.bind(Horde_ToolTips)); - Event.observe(window, 'unload', Horde_ToolTips.out.bind(Horde_ToolTips)); -} diff --git a/imp/mailbox.php b/imp/mailbox.php index 2479ba943..5a346cb39 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -304,9 +304,7 @@ $sort_url = $mailbox_imp_url->copy()->add('sortdir', ($sortpref['dir']) ? 0 : 1) $preview_tooltip = $show_preview ? $prefs->getValue('preview_show_tooltip') : false; -if ($preview_tooltip) { - Horde::addScriptFile('tooltips.js', 'horde'); -} else { +if (!$preview_tooltip) { $strip_preview = $prefs->getValue('preview_strip_nl'); } diff --git a/ingo/filters.php b/ingo/filters.php index 6cbb4444c..ac9dd7f05 100644 --- a/ingo/filters.php +++ b/ingo/filters.php @@ -133,7 +133,6 @@ case 'apply_filters': /* Get the list of rules now. */ $filter_list = $filters->getFilterList(); -Horde::addScriptFile('tooltips.js', 'horde'); Horde::addScriptFile('stripe.js', 'horde'); Horde::addScriptFile('filters.js', 'ingo'); Ingo::prepareMenu(); diff --git a/kronolith/lib/Block/month.php b/kronolith/lib/Block/month.php index 9365d8c85..112ca1928 100644 --- a/kronolith/lib/Block/month.php +++ b/kronolith/lib/Block/month.php @@ -70,8 +70,6 @@ class Horde_Block_Kronolith_month extends Horde_Block } } - Horde::addScriptFile('tooltips.js', 'horde'); - $year = date('Y'); $month = date('m'); $startday = new Horde_Date(array('mday' => 1, diff --git a/kronolith/year.php b/kronolith/year.php index 92a3ea9e5..a1fc159f4 100644 --- a/kronolith/year.php +++ b/kronolith/year.php @@ -20,7 +20,6 @@ if (Kronolith::showAjaxView()) { $view = Kronolith::getView('Year'); $title = $view->year; -Horde::addScriptFile('tooltips.js', 'horde'); require KRONOLITH_TEMPLATES . '/common-header.inc'; require KRONOLITH_TEMPLATES . '/menu.inc'; diff --git a/mnemo/list.php b/mnemo/list.php index b315aa65d..559cfba2f 100644 --- a/mnemo/list.php +++ b/mnemo/list.php @@ -54,7 +54,6 @@ case 'search_memos': break; } -Horde::addScriptFile('tooltips.js', 'horde', true); Horde::addScriptFile('tables.js', 'horde', true); Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('quickfinder.js', 'horde', true); diff --git a/mnemo/notes/index.php b/mnemo/notes/index.php index 44173e753..5202808a2 100644 --- a/mnemo/notes/index.php +++ b/mnemo/notes/index.php @@ -38,7 +38,6 @@ if (count($search_results) == 1) { $title = _("Search Results"); $memos = $search_results; -Horde::addScriptFile('tooltips.js', 'horde', true); Horde::addScriptFile('tables.js', 'horde', true); Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('quickfinder.js', 'horde', true);