From 39908c02ada318a04c9721583884ed87d5ed8be7 Mon Sep 17 00:00:00 2001 From: Roi Kingon Date: Thu, 14 Jul 2016 17:38:37 -0700 Subject: [PATCH] apply classes to tip element prior to calculating widths --- src/javascripts/jquery.tipsy.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js index f95c063..e1032d0 100644 --- a/src/javascripts/jquery.tipsy.js +++ b/src/javascripts/jquery.tipsy.js @@ -27,10 +27,18 @@ show: function() { var title = this.getTitle(); if (title && this.enabled) { - var $tip = this.tip(); + var $tip = this.tip(), + gravity = maybeCall(this.options.gravity, this.$element[0]); $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title); + $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity + if (this.options.className) { + $tip.addClass(maybeCall(this.options.className, this.$element[0])); + } + $tip.addClass('tipsy-' + gravity); + $tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0); + $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body); var pos = $.extend({}, this.$element.offset(), { @@ -39,8 +47,7 @@ }); var actualWidth = $tip[0].offsetWidth, - actualHeight = $tip[0].offsetHeight, - gravity = maybeCall(this.options.gravity, this.$element[0]); + actualHeight = $tip[0].offsetHeight; var tp; switch (gravity.charAt(0)) { @@ -66,11 +73,7 @@ } } - $tip.css(tp).addClass('tipsy-' + gravity); - $tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0); - if (this.options.className) { - $tip.addClass(maybeCall(this.options.className, this.$element[0])); - } + $tip.css(tp) if (this.options.fade) { $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});