From 87ac818253a26bcf09fa55f78ae3f55759c54e64 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 22 Dec 2011 19:10:32 -0800 Subject: change above below to top bottom and add "inside" placement option --- js/README.md | 2 +- js/bootstrap-twipsy.js | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'js') diff --git a/js/README.md b/js/README.md index 0d8d163a2..2f8e1716f 100644 --- a/js/README.md +++ b/js/README.md @@ -49,7 +49,7 @@ examples: backdrop: true keyboard: false - placement: 'above' + placement: 'top' --- diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 018edb97e..21cf7d20b 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -99,6 +99,7 @@ , show: function () { var $tip + , inside , pos , actualWidth , actualHeight @@ -113,12 +114,18 @@ $tip.addClass('fade') } + placement = typeof this.options.placement == 'function' ? + thing.call(this, $tip[0], this.$element[0]) : + this.options.placement + + inside = /in/.test(placement) + $tip .remove() .css({ top: 0, left: 0, display: 'block' }) - .prependTo(document.body) + .prependTo(inside ? this.$element : document.body) - pos = $.extend({}, this.$element.offset(), { + pos = $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), { width: this.$element[0].offsetWidth , height: this.$element[0].offsetHeight }) @@ -126,13 +133,11 @@ actualWidth = $tip[0].offsetWidth actualHeight = $tip[0].offsetHeight - placement = maybeCall(this.options.placement, this, [ $tip[0], this.$element[0] ]) - - switch (placement) { - case 'below': + switch (inside ? placement.split(' ')[1] : placement) { + case 'bottom': tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2} break - case 'above': + case 'top': tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2} break case 'left': @@ -226,14 +231,6 @@ } - /* TWIPSY PRIVATE METHODS - * ====================== */ - - function maybeCall ( thing, ctx, args ) { - return typeof thing == 'function' ? thing.apply(ctx, args) : thing - } - - /* TWIPSY PLUGIN DEFINITION * ======================== */ @@ -253,7 +250,7 @@ animation: true , delay: 0 , selector: false - , placement: 'above' + , placement: 'top' , trigger: 'hover' , title: '' , template: '
' -- cgit v1.2.3