annotate static/bootstrap/js/bootstrap-tooltip.js @ 88:a5a3d454eac9

Updated Bootstrap.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 05 Apr 2013 08:08:12 -0700
parents 130eccd396d8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 /* ===========================================================
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
2 * bootstrap-tooltip.js v2.3.1
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 * http://twitter.github.com/bootstrap/javascript.html#tooltips
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 * Inspired by the original jQuery.tipsy by Jason Frame
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 * ===========================================================
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 * Copyright 2012 Twitter, Inc.
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 *
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 * Licensed under the Apache License, Version 2.0 (the "License");
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 * you may not use this file except in compliance with the License.
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 * You may obtain a copy of the License at
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 *
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 * http://www.apache.org/licenses/LICENSE-2.0
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 *
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 * Unless required by applicable law or agreed to in writing, software
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 * distributed under the License is distributed on an "AS IS" BASIS,
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 * See the License for the specific language governing permissions and
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 * limitations under the License.
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 * ========================================================== */
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 !function ($) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 "use strict"; // jshint ;_;
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 /* TOOLTIP PUBLIC CLASS DEFINITION
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 * =============================== */
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 var Tooltip = function (element, options) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 this.init('tooltip', element, options)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 Tooltip.prototype = {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 constructor: Tooltip
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 , init: function (type, element, options) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 var eventIn
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 , eventOut
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
41 , triggers
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
42 , trigger
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
43 , i
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 this.type = type
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 this.$element = $(element)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 this.options = this.getOptions(options)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 this.enabled = true
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
50 triggers = this.options.trigger.split(' ')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
51
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
52 for (i = triggers.length; i--;) {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
53 trigger = triggers[i]
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
54 if (trigger == 'click') {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
55 this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
56 } else if (trigger != 'manual') {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
57 eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
58 eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
59 this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
60 this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
61 }
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 this.options.selector ?
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 this.fixTitle()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 , getOptions: function (options) {
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
70 options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options)
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 if (options.delay && typeof options.delay == 'number') {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 options.delay = {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 show: options.delay
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 , hide: options.delay
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 return options
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 , enter: function (e) {
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
83 var defaults = $.fn[this.type].defaults
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
84 , options = {}
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
85 , self
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
86
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
87 this._options && $.each(this._options, function (key, value) {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
88 if (defaults[key] != value) options[key] = value
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
89 }, this)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
90
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
91 self = $(e.currentTarget)[this.type](options).data(this.type)
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 if (!self.options.delay || !self.options.delay.show) return self.show()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 clearTimeout(this.timeout)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 self.hoverState = 'in'
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 this.timeout = setTimeout(function() {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 if (self.hoverState == 'in') self.show()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 }, self.options.delay.show)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 , leave: function (e) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 var self = $(e.currentTarget)[this.type](this._options).data(this.type)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 if (this.timeout) clearTimeout(this.timeout)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 if (!self.options.delay || !self.options.delay.hide) return self.hide()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 self.hoverState = 'out'
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 this.timeout = setTimeout(function() {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 if (self.hoverState == 'out') self.hide()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 }, self.options.delay.hide)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 , show: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 var $tip
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 , pos
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 , actualWidth
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 , actualHeight
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 , placement
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 , tp
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
121 , e = $.Event('show')
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 if (this.hasContent() && this.enabled) {
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
124 this.$element.trigger(e)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
125 if (e.isDefaultPrevented()) return
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 $tip = this.tip()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 this.setContent()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 if (this.options.animation) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 $tip.addClass('fade')
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 placement = typeof this.options.placement == 'function' ?
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 this.options.placement.call(this, $tip[0], this.$element[0]) :
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 this.options.placement
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 $tip
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 .detach()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 .css({ top: 0, left: 0, display: 'block' })
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
141 this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
142
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
143 pos = this.getPosition()
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 actualWidth = $tip[0].offsetWidth
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 actualHeight = $tip[0].offsetHeight
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
148 switch (placement) {
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 case 'bottom':
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 break
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 case 'top':
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 break
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155 case 'left':
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 break
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158 case 'right':
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 break
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
163 this.applyPlacement(tp, placement)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
164 this.$element.trigger('shown')
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
168 , applyPlacement: function(offset, placement){
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
169 var $tip = this.tip()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
170 , width = $tip[0].offsetWidth
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
171 , height = $tip[0].offsetHeight
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
172 , actualWidth
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
173 , actualHeight
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
174 , delta
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
175 , replace
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
176
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
177 $tip
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
178 .offset(offset)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
179 .addClass(placement)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
180 .addClass('in')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
181
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
182 actualWidth = $tip[0].offsetWidth
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
183 actualHeight = $tip[0].offsetHeight
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
184
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
185 if (placement == 'top' && actualHeight != height) {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
186 offset.top = offset.top + height - actualHeight
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
187 replace = true
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
188 }
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
189
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
190 if (placement == 'bottom' || placement == 'top') {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
191 delta = 0
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
192
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
193 if (offset.left < 0){
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
194 delta = offset.left * -2
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
195 offset.left = 0
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
196 $tip.offset(offset)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
197 actualWidth = $tip[0].offsetWidth
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
198 actualHeight = $tip[0].offsetHeight
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
199 }
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
200
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
201 this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
202 } else {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
203 this.replaceArrow(actualHeight - height, actualHeight, 'top')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
204 }
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
205
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
206 if (replace) $tip.offset(offset)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
207 }
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
208
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
209 , replaceArrow: function(delta, dimension, position){
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
210 this
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
211 .arrow()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
212 .css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
213 }
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
214
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 , setContent: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 var $tip = this.tip()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 , title = this.getTitle()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220 $tip.removeClass('fade in top bottom left right')
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223 , hide: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 var that = this
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225 , $tip = this.tip()
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
226 , e = $.Event('hide')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
227
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
228 this.$element.trigger(e)
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
229 if (e.isDefaultPrevented()) return
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 $tip.removeClass('in')
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 function removeWithAnimation() {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234 var timeout = setTimeout(function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235 $tip.off($.support.transition.end).detach()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 }, 500)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 $tip.one($.support.transition.end, function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 clearTimeout(timeout)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 $tip.detach()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 })
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 $.support.transition && this.$tip.hasClass('fade') ?
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 removeWithAnimation() :
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246 $tip.detach()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
248 this.$element.trigger('hidden')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
249
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 return this
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253 , fixTitle: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254 var $e = this.$element
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
255 if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256 $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
258 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
259
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
260 , hasContent: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
261 return this.getTitle()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
264 , getPosition: function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
265 var el = this.$element[0]
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
266 return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
267 width: el.offsetWidth
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
268 , height: el.offsetHeight
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
269 }, this.$element.offset())
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
272 , getTitle: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 var title
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
274 , $e = this.$element
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
275 , o = this.options
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
276
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277 title = $e.attr('data-original-title')
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278 || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
279
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
280 return title
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
281 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
282
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
283 , tip: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
284 return this.$tip = this.$tip || $(this.options.template)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
285 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
286
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
287 , arrow: function(){
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
288 return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
289 }
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
290
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
291 , validate: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
292 if (!this.$element[0].parentNode) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
293 this.hide()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
294 this.$element = null
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
295 this.options = null
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
296 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
297 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
298
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
299 , enable: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
300 this.enabled = true
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
302
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
303 , disable: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
304 this.enabled = false
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
305 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
306
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
307 , toggleEnabled: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
308 this.enabled = !this.enabled
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
309 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
310
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
311 , toggle: function (e) {
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
312 var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
313 self.tip().hasClass('in') ? self.hide() : self.show()
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
314 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
315
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
316 , destroy: function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
317 this.hide().$element.off('.' + this.type).removeData(this.type)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
318 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
320 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
321
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
322
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
323 /* TOOLTIP PLUGIN DEFINITION
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
324 * ========================= */
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
325
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
326 var old = $.fn.tooltip
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
327
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
328 $.fn.tooltip = function ( option ) {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
329 return this.each(function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
330 var $this = $(this)
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
331 , data = $this.data('tooltip')
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
332 , options = typeof option == 'object' && option
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
333 if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
334 if (typeof option == 'string') data[option]()
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
335 })
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
336 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
337
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
338 $.fn.tooltip.Constructor = Tooltip
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
339
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
340 $.fn.tooltip.defaults = {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
341 animation: true
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
342 , placement: 'top'
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
343 , selector: false
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
344 , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
345 , trigger: 'hover focus'
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
346 , title: ''
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
347 , delay: 0
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
348 , html: false
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
349 , container: false
61
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
350 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
351
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
352
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
353 /* TOOLTIP NO CONFLICT
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
354 * =================== */
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
355
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
356 $.fn.tooltip.noConflict = function () {
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
357 $.fn.tooltip = old
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
358 return this
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
359 }
130eccd396d8 Now using Boostrap with LESS.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
360
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents: 61
diff changeset
361 }(window.jQuery);