[geeklog-cvs] geeklog: Fix bug #0001304: Autotag tooltips are sometimes outsid...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Fri Apr 8 10:09:12 EDT 2011


changeset 8217:8e7793726f51
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/8e7793726f51
user: Rouslan Placella <rouslan at placella.com>
date: Fri Apr 08 15:08:44 2011 +0100
description:
Fix bug #0001304: Autotag tooltips are sometimes outside the viewport

diffstat:

 public_html/javascript/fix_tooltips.js |  32 ++++++++++++++++++++++++++++++++
 public_html/lib-common.php             |   8 +++++++-
 2 files changed, 39 insertions(+), 1 deletions(-)

diffs (55 lines):

diff -r 5690ebfce920 -r 8e7793726f51 public_html/javascript/fix_tooltips.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/public_html/javascript/fix_tooltips.js	Fri Apr 08 15:08:44 2011 +0100
@@ -0,0 +1,32 @@
+/* Prevents the tooltips from disappearing outside the viewport */
+$(document).ready(function() {
+    var fix_tooltips = function() {
+        // fix each tooltip
+        $('.tooltip').each(function() {
+            // size of the viewport
+            var $w = $(window);
+            var viewport_height = parseInt($w.height());
+            var viewport_width  = parseInt($w.width());
+             // cache the tooltip element
+            var $s = $(this).find('span');
+            // estimate the bottom and right coordinates of the tooltip
+            var tooltip_bottom  = parseInt($(this).offset().top + $s.outerHeight() - $w.scrollTop() + 30);
+            var tooltip_right   = parseInt($(this).offset().left + $s.outerWidth() - $w.scrollLeft() + 30);
+            // move the element around as necessary
+            if (tooltip_bottom >= viewport_height) {
+                var top = parseInt(($s.outerHeight() + 22) * -1) + 'px';
+                $s.css('top', top);
+            } else {
+                $s.css('top', '2.2em');
+            }
+            if (tooltip_right >= viewport_width) {
+                var left = parseInt($s.width() * -1) + 'px';
+                $s.css('left', left);
+            } else {
+                $s.css('left', '2.2em');
+            }
+        });
+    };
+    // repeat all of the above every 200 mS
+    setInterval(fix_tooltips, 200);
+});
diff -r 5690ebfce920 -r 8e7793726f51 public_html/lib-common.php
--- a/public_html/lib-common.php	Wed Apr 06 23:53:20 2011 +0100
+++ b/public_html/lib-common.php	Fri Apr 08 15:08:44 2011 +0100
@@ -6754,8 +6754,14 @@
 */
 function COM_Tooltip($hoverover = '', $text = '', $link = '', $title = '', $template = 'classic', $class = 'tooltip') 
 {
-    global $_CONF, $_IMAGE_TYPE;
+    global $_CONF, $_IMAGE_TYPE, $_SCRIPTS;
     
+    if (! defined('TOOLTIPS_FIXED')) {
+        define('TOOLTIPS_FIXED', true);
+        $_SCRIPTS->setJavaScriptLibrary('jquery');
+        $_SCRIPTS->setJavaScriptFile('fix_tooltips', '/javascript/fix_tooltips.js');
+    }
+
     if ($hoverover == '') {
         $hoverover = '<img alt="?" id="tooltip-icon" src="' . $_CONF['layout_url'] . '/tooltips/images/tooltip.' . $_IMAGE_TYPE . '"' . XHTML . '>';   
     }



More information about the geeklog-cvs mailing list