[geeklog-cvs] geeklog: Use events, not polling, to fix tooltips.
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Apr 22 15:12:19 EDT 2012
changeset 8602:92b9809e7fd6
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/92b9809e7fd6
user: Rouslan Placella <rouslan at placella.com>
date: Sun Apr 22 20:12:05 2012 +0100
description:
Use events, not polling, to fix tooltips.
diffstat:
public_html/javascript/fix_tooltips.js | 63 +++++++++++++++++----------------
1 files changed, 32 insertions(+), 31 deletions(-)
diffs (68 lines):
diff -r b4b74762bb4b -r 92b9809e7fd6 public_html/javascript/fix_tooltips.js
--- a/public_html/javascript/fix_tooltips.js Sun Apr 22 18:48:02 2012 +0100
+++ b/public_html/javascript/fix_tooltips.js Sun Apr 22 20:12:05 2012 +0100
@@ -1,32 +1,33 @@
/* Prevents the tooltips from disappearing outside the viewport */
-$(document).ready(function() {
- var fix_tooltips = function() {
- // fix each tooltip
- $('.gl-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);
-});
+var fix_tooltips = function() {
+console.log(1);
+ var $w = $(window);
+ // fix each tooltip
+ $('a.gl-tooltip').each(function() {
+ // size of the viewport
+ 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');
+ }
+ });
+};
+// Bind tooltip-fixing function to relevant events
+$(document).ready(fix_tooltips);
+$(window).resize(fix_tooltips);
+$(window).scroll(fix_tooltips);
More information about the geeklog-cvs
mailing list