2011-09-11 01:24:31 -04:00
|
|
|
/* ==========================================================
|
2011-11-20 23:58:04 -05:00
|
|
|
* bootstrap-twipsy.js v2.0.0
|
2011-09-11 01:24:31 -04:00
|
|
|
* http://twitter.github.com/bootstrap/javascript.html#twipsy
|
|
|
|
* Adapted from the original jQuery.tipsy by Jason Frame
|
|
|
|
* ==========================================================
|
|
|
|
* Copyright 2011 Twitter, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* ========================================================== */
|
|
|
|
|
2011-10-05 00:48:53 -04:00
|
|
|
!function( $ ) {
|
2011-08-27 16:03:06 -04:00
|
|
|
|
2011-11-20 21:19:50 -05:00
|
|
|
"use strict"
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
/* TWIPSY PUBLIC CLASS DEFINITION
|
|
|
|
* ============================== */
|
|
|
|
|
|
|
|
var Twipsy = function ( element, options ) {
|
|
|
|
this.$element = $(element)
|
|
|
|
this.options = options
|
|
|
|
this.enabled = true
|
|
|
|
this.fixTitle()
|
|
|
|
}
|
|
|
|
|
|
|
|
Twipsy.prototype = {
|
|
|
|
|
|
|
|
show: function() {
|
2011-08-27 20:22:49 -04:00
|
|
|
var pos
|
2011-08-27 16:03:06 -04:00
|
|
|
, actualWidth
|
|
|
|
, actualHeight
|
|
|
|
, placement
|
|
|
|
, $tip
|
|
|
|
, tp
|
|
|
|
|
2011-11-20 21:19:50 -05:00
|
|
|
if (this.hasContent() && this.enabled) {
|
2011-08-27 16:03:06 -04:00
|
|
|
$tip = this.tip()
|
2011-08-27 20:22:49 -04:00
|
|
|
this.setContent()
|
2011-08-27 21:03:01 -04:00
|
|
|
|
|
|
|
if (this.options.animate) {
|
|
|
|
$tip.addClass('fade')
|
|
|
|
}
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
$tip
|
|
|
|
.remove()
|
|
|
|
.css({ top: 0, left: 0, display: 'block' })
|
|
|
|
.prependTo(document.body)
|
|
|
|
|
|
|
|
pos = $.extend({}, this.$element.offset(), {
|
|
|
|
width: this.$element[0].offsetWidth
|
|
|
|
, height: this.$element[0].offsetHeight
|
|
|
|
})
|
|
|
|
|
|
|
|
actualWidth = $tip[0].offsetWidth
|
|
|
|
actualHeight = $tip[0].offsetHeight
|
2011-11-20 21:19:50 -05:00
|
|
|
|
|
|
|
placement = maybeCall(this.options.placement, this, [ $tip[0], this.$element[0] ])
|
2011-08-27 16:03:06 -04:00
|
|
|
|
|
|
|
switch (placement) {
|
|
|
|
case 'below':
|
|
|
|
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}
|
|
|
|
break
|
|
|
|
case 'above':
|
|
|
|
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}
|
|
|
|
break
|
|
|
|
case 'left':
|
|
|
|
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset}
|
|
|
|
break
|
|
|
|
case 'right':
|
|
|
|
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
$tip
|
|
|
|
.css(tp)
|
|
|
|
.addClass(placement)
|
2011-08-27 21:03:01 -04:00
|
|
|
.addClass('in')
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 20:22:49 -04:00
|
|
|
, setContent: function () {
|
|
|
|
var $tip = this.tip()
|
2011-11-20 23:58:04 -05:00
|
|
|
$tip.find('.twipsy-inner').html(this.getTitle())
|
2011-08-27 20:22:49 -04:00
|
|
|
$tip[0].className = 'twipsy'
|
|
|
|
}
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
, hide: function() {
|
|
|
|
var that = this
|
|
|
|
, $tip = this.tip()
|
|
|
|
|
2011-08-27 21:03:01 -04:00
|
|
|
$tip.removeClass('in')
|
2011-08-27 16:03:06 -04:00
|
|
|
|
|
|
|
function removeElement () {
|
|
|
|
$tip.remove()
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:03:01 -04:00
|
|
|
$.support.transition && this.$tip.hasClass('fade') ?
|
2011-11-20 23:58:04 -05:00
|
|
|
$tip.bind( $.support.transition.end, removeElement) :
|
2011-08-27 16:03:06 -04:00
|
|
|
removeElement()
|
|
|
|
}
|
|
|
|
|
|
|
|
, fixTitle: function() {
|
|
|
|
var $e = this.$element
|
|
|
|
if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
|
|
|
|
$e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 21:19:50 -05:00
|
|
|
, hasContent: function () {
|
|
|
|
return this.getTitle()
|
|
|
|
}
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
, getTitle: function() {
|
|
|
|
var title
|
|
|
|
, $e = this.$element
|
|
|
|
, o = this.options
|
|
|
|
|
|
|
|
this.fixTitle()
|
|
|
|
|
|
|
|
if (typeof o.title == 'string') {
|
|
|
|
title = $e.attr(o.title == 'title' ? 'data-original-title' : o.title)
|
|
|
|
} else if (typeof o.title == 'function') {
|
|
|
|
title = o.title.call($e[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
title = ('' + title).replace(/(^\s*|\s*$)/, "")
|
|
|
|
|
2011-11-20 23:58:04 -05:00
|
|
|
return title
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
, tip: function() {
|
2011-11-20 21:19:50 -05:00
|
|
|
return this.$tip = this.$tip || $('<div class="twipsy" />').html(this.options.template)
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
, validate: function() {
|
|
|
|
if (!this.$element[0].parentNode) {
|
|
|
|
this.hide()
|
|
|
|
this.$element = null
|
|
|
|
this.options = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
, enable: function() {
|
|
|
|
this.enabled = true
|
|
|
|
}
|
|
|
|
|
|
|
|
, disable: function() {
|
|
|
|
this.enabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
, toggleEnabled: function() {
|
|
|
|
this.enabled = !this.enabled
|
|
|
|
}
|
|
|
|
|
2011-11-20 21:19:50 -05:00
|
|
|
, toggle: function () {
|
|
|
|
this[this.tip().hasClass('in') ? 'hide' : 'show']()
|
|
|
|
}
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* TWIPSY PRIVATE METHODS
|
|
|
|
* ====================== */
|
|
|
|
|
2011-11-20 21:19:50 -05:00
|
|
|
function maybeCall ( thing, ctx, args ) {
|
|
|
|
return typeof thing == 'function' ? thing.apply(ctx, args) : thing
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
2011-08-27 20:22:49 -04:00
|
|
|
/* TWIPSY PLUGIN DEFINITION
|
|
|
|
* ======================== */
|
2011-08-27 16:03:06 -04:00
|
|
|
|
2011-08-27 20:22:49 -04:00
|
|
|
$.fn.twipsy = function (options) {
|
2011-09-10 16:17:08 -04:00
|
|
|
$.fn.twipsy.initWith.call(this, options, Twipsy, 'twipsy')
|
2011-09-10 15:49:21 -04:00
|
|
|
return this
|
2011-08-27 20:22:49 -04:00
|
|
|
}
|
|
|
|
|
2011-09-10 16:17:08 -04:00
|
|
|
$.fn.twipsy.initWith = function (options, Constructor, name) {
|
2011-08-27 16:03:06 -04:00
|
|
|
var twipsy
|
|
|
|
, binder
|
|
|
|
, eventIn
|
|
|
|
, eventOut
|
|
|
|
|
2011-11-20 23:58:04 -05:00
|
|
|
if (typeof options == 'string') {
|
2011-11-21 00:06:32 -05:00
|
|
|
return this.each(function (){
|
|
|
|
twipsy = $.data(this, name)
|
|
|
|
if (twipsy) twipsy[options]()
|
|
|
|
})
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
2011-09-10 16:17:08 -04:00
|
|
|
options = $.extend({}, $.fn[name].defaults, options)
|
2011-08-27 16:03:06 -04:00
|
|
|
|
2011-11-20 23:58:04 -05:00
|
|
|
if (options.delay && typeof options.delay == 'number') {
|
|
|
|
options.delay = {
|
|
|
|
show: options.delay
|
|
|
|
, hide: options.delay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
function get(ele) {
|
2011-09-10 16:17:08 -04:00
|
|
|
var twipsy = $.data(ele, name)
|
2011-08-27 16:03:06 -04:00
|
|
|
|
|
|
|
if (!twipsy) {
|
2011-08-27 20:22:49 -04:00
|
|
|
twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options))
|
2011-09-10 16:17:08 -04:00
|
|
|
$.data(ele, name, twipsy)
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return twipsy
|
|
|
|
}
|
|
|
|
|
|
|
|
function enter() {
|
|
|
|
var twipsy = get(this)
|
|
|
|
twipsy.hoverState = 'in'
|
|
|
|
|
2011-11-20 23:58:04 -05:00
|
|
|
if (!options.delay || !options.delay.show) {
|
2011-08-27 16:03:06 -04:00
|
|
|
twipsy.show()
|
|
|
|
} else {
|
|
|
|
twipsy.fixTitle()
|
|
|
|
setTimeout(function() {
|
|
|
|
if (twipsy.hoverState == 'in') {
|
|
|
|
twipsy.show()
|
|
|
|
}
|
2011-11-20 23:58:04 -05:00
|
|
|
}, options.delay.show)
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function leave() {
|
|
|
|
var twipsy = get(this)
|
|
|
|
twipsy.hoverState = 'out'
|
2011-11-20 23:58:04 -05:00
|
|
|
if (!options.delay || !options.delay.hide) {
|
2011-08-27 16:03:06 -04:00
|
|
|
twipsy.hide()
|
|
|
|
} else {
|
|
|
|
setTimeout(function() {
|
|
|
|
if (twipsy.hoverState == 'out') {
|
|
|
|
twipsy.hide()
|
|
|
|
}
|
2011-11-20 23:58:04 -05:00
|
|
|
}, options.delay.hide)
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.live) {
|
|
|
|
this.each(function() {
|
|
|
|
get(this)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.trigger != 'manual') {
|
|
|
|
binder = options.live ? 'live' : 'bind'
|
|
|
|
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus'
|
|
|
|
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur'
|
|
|
|
this[binder](eventIn, enter)[binder](eventOut, leave)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2011-08-27 20:22:49 -04:00
|
|
|
$.fn.twipsy.Twipsy = Twipsy
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
$.fn.twipsy.defaults = {
|
2011-08-27 21:03:01 -04:00
|
|
|
animate: true
|
2011-11-20 23:58:04 -05:00
|
|
|
, delay: 0
|
2011-08-27 16:03:06 -04:00
|
|
|
, placement: 'above'
|
|
|
|
, live: false
|
|
|
|
, offset: 0
|
|
|
|
, trigger: 'hover'
|
2011-11-20 23:58:04 -05:00
|
|
|
, title: 'title'
|
2011-11-20 21:19:50 -05:00
|
|
|
, template: '<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>'
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
2011-11-20 21:19:50 -05:00
|
|
|
$.fn.twipsy.rejectAttrOptions = [ 'title' ]
|
|
|
|
|
2011-08-27 16:03:06 -04:00
|
|
|
$.fn.twipsy.elementOptions = function(ele, options) {
|
2011-11-20 21:19:50 -05:00
|
|
|
var data = $(ele).data()
|
|
|
|
, rejects = $.fn.twipsy.rejectAttrOptions
|
|
|
|
, i = rejects.length
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
delete data[rejects[i]]
|
|
|
|
}
|
|
|
|
|
|
|
|
return $.extend({}, options, data)
|
2011-08-27 16:03:06 -04:00
|
|
|
}
|
|
|
|
|
2011-11-27 19:01:26 -05:00
|
|
|
}( window.jQuery || window.ender )
|