From 9adef362c06eb1dc278e9c9a0b4ebafdd124b194 Mon Sep 17 00:00:00 2001 From: Nicolas Schaller Date: Mon, 8 Jul 2013 09:39:03 +0200 Subject: [PATCH 1/4] [fix] Restore title on tipsy.disable --- src/javascripts/jquery.tipsy.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index f95c063..79a687e 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -95,6 +95,11 @@ } }, + restoreTitle: function() { + var $e = this.$element; + $e.attr('title', $e.attr('original-title') ); + }, + getTitle: function() { var title, $e = this.$element, o = this.options; this.fixTitle(); @@ -124,8 +129,19 @@ } }, - enable: function() { this.enabled = true; }, - disable: function() { this.enabled = false; }, + enable: function() { + if( !this.enabled ) { + this.fixTitle(); + this.enabled = true; + } + }, + disable: function() { + if( this.enabled ) { + this.restoreTitle(); + this.enabled = false; + } + }, + toggleEnabled: function() { this.enabled = !this.enabled; } }; From 6e8790b127baaa1fd1f7ac5f3f682f4c11f8693b Mon Sep 17 00:00:00 2001 From: Nicolas Schaller Date: Mon, 8 Jul 2013 09:41:06 +0200 Subject: [PATCH 2/4] [feature] Tooltip dimensions passed as argument to gravity function --- src/javascripts/jquery.tipsy.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index 79a687e..fcb3c9c 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -5,8 +5,8 @@ (function($) { - function maybeCall(thing, ctx) { - return (typeof thing == 'function') ? (thing.call(ctx)) : thing; + function maybeCall(thing, ctx, info) { + return (typeof thing == 'function') ? (thing.call(ctx, info)) : thing; }; function isElementInDOM(ele) { @@ -37,10 +37,13 @@ width: this.$element[0].offsetWidth, height: this.$element[0].offsetHeight }); - var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight, - gravity = maybeCall(this.options.gravity, this.$element[0]); + gravity = maybeCall( + this.options.gravity, this.$element[0], { + width: actualWidth, + height: actualHeight + }); var tp; switch (gravity.charAt(0)) { From 16aa4fb2aa145151ebcd523786bbdcbcc939e5a9 Mon Sep 17 00:00:00 2001 From: Nicolas Schaller Date: Mon, 8 Jul 2013 10:14:58 +0200 Subject: [PATCH 3/4] [feature] hoverHold option added to keep tooltip visible if hovered --- src/javascripts/jquery.tipsy.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index fcb3c9c..97fc3bb 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -20,6 +20,7 @@ this.$element = $(element); this.options = options; this.enabled = true; + this.tipHover = false; this.fixTitle(); }; @@ -31,7 +32,7 @@ $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title); $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity - $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body); + $tip.detach().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body); var pos = $.extend({}, this.$element.offset(), { width: this.$element[0].offsetWidth, @@ -85,9 +86,9 @@ hide: function() { if (this.options.fade) { - this.tip().stop().fadeOut(function() { $(this).remove(); }); + this.tip().stop().fadeOut(function() { $(this).detach(); }); } else { - this.tip().remove(); + this.tip().detach(); } }, @@ -117,9 +118,20 @@ }, tip: function() { + var tipsy = this; if (!this.$tip) { this.$tip = $('
').html('
'); this.$tip.data('tipsy-pointee', this.$element[0]); + if( this.options.hoverHold ) { + this.$tip. + on( 'mouseenter', function() { + tipsy.tipHover = true; + } ). + on( 'mouseleave', function() { + tipsy.tipHover = false; + tipsy.$element.trigger( 'mouseleave' ); + } ); + } } return this.$tip; }, @@ -186,7 +198,12 @@ if (options.delayOut == 0) { tipsy.hide(); } else { - setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut); + setTimeout(function() { + if( !tipsy.tipHover && tipsy.hoverState == 'out' ) { + tipsy.hide(); + } + }, + options.delayOut); } }; @@ -215,7 +232,8 @@ offset: 0, opacity: 0.8, title: 'title', - trigger: 'hover' + trigger: 'hover', + hoverHold: false }; $.fn.tipsy.revalidate = function() { From cb02a58223f889836135513115a01520e313f246 Mon Sep 17 00:00:00 2001 From: Nicolas Schaller Date: Mon, 8 Jul 2013 10:15:08 +0200 Subject: [PATCH 4/4] [feature] fade option can now be a duration --- src/javascripts/jquery.tipsy.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index 97fc3bb..300e6b8 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -77,7 +77,11 @@ } if (this.options.fade) { - $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity}); + $tip.stop(). + css({opacity: 0, display: 'block', visibility: 'visible'} ). + animate( + {opacity: this.options.opacity}, + typeof this.options.fade === 'number' ? this.options.fade : 300 ); } else { $tip.css({visibility: 'visible', opacity: this.options.opacity}); } @@ -86,7 +90,10 @@ hide: function() { if (this.options.fade) { - this.tip().stop().fadeOut(function() { $(this).detach(); }); + this.tip().stop().fadeOut( { + duration: typeof this.options.fade === 'number' ? this.options.fade : 300, + complete: function() { $(this).detach(); } + } ); } else { this.tip().detach(); }