From 72da3175839c287465ac02814e25ce51e5b7d7fc Mon Sep 17 00:00:00 2001 From: Joman Chu Date: Sun, 3 Mar 2013 21:49:48 -0500 Subject: [PATCH] Allow tooltip offset to be set by function call --- src/javascripts/jquery.tipsy.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index f95c063..e89a56c 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -42,19 +42,20 @@ actualHeight = $tip[0].offsetHeight, gravity = maybeCall(this.options.gravity, this.$element[0]); + var offset = this.getOffset(); var tp; switch (gravity.charAt(0)) { case 'n': - tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}; + tp = {top: pos.top + pos.height + offset, left: pos.left + pos.width / 2 - actualWidth / 2}; break; case 's': - tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}; + tp = {top: pos.top - actualHeight - offset, left: pos.left + pos.width / 2 - actualWidth / 2}; break; case 'e': - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset}; + tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - offset}; break; case 'w': - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset}; + tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + offset}; break; } @@ -94,6 +95,17 @@ $e.attr('original-title', $e.attr('title') || '').removeAttr('title'); } }, + + getOffset: function() { + var offset, $e = this.$element, o = this.options; + if (typeof o.offset == 'number') { + return o.offset; + } else if (typeof o.offset == 'string') { + return +o.offset; + } else if (typeof o.offset == 'function') { + return o.offset.call($e[0]); + } + }, getTitle: function() { var title, $e = this.$element, o = this.options;