Index: trunk/phase3/resources/jquery/jquery.tipsy.js |
— | — | @@ -1,202 +0,0 @@ |
2 | | -// tipsy, facebook style tooltips for jquery |
3 | | -// version 1.0.0a |
4 | | -// (c) 2008-2010 jason frame [jason@onehackoranother.com] |
5 | | -// released under the MIT license |
6 | | - |
7 | | -(function($) { |
8 | | - |
9 | | - function Tipsy(element, options) { |
10 | | - this.$element = $(element); |
11 | | - this.options = options; |
12 | | - this.enabled = true; |
13 | | - this.fixTitle(); |
14 | | - } |
15 | | - |
16 | | - Tipsy.prototype = { |
17 | | - show: function() { |
18 | | - var title = this.getTitle(); |
19 | | - if (title && this.enabled) { |
20 | | - var $tip = this.tip(); |
21 | | - |
22 | | - $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title); |
23 | | - $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity |
24 | | - $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body); |
25 | | - |
26 | | - var pos = $.extend({}, this.$element.offset(), { |
27 | | - width: this.$element[0].offsetWidth, |
28 | | - height: this.$element[0].offsetHeight |
29 | | - }); |
30 | | - |
31 | | - var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight; |
32 | | - var gravity = (typeof this.options.gravity == 'function') |
33 | | - ? this.options.gravity.call(this.$element[0]) |
34 | | - : this.options.gravity; |
35 | | - |
36 | | - var tp; |
37 | | - switch (gravity.charAt(0)) { |
38 | | - case 'n': |
39 | | - tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}; |
40 | | - break; |
41 | | - case 's': |
42 | | - tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}; |
43 | | - break; |
44 | | - case 'e': |
45 | | - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset}; |
46 | | - break; |
47 | | - case 'w': |
48 | | - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset}; |
49 | | - break; |
50 | | - } |
51 | | - |
52 | | - if (gravity.length == 2) { |
53 | | - if (gravity.charAt(1) == 'w') { |
54 | | - tp.left = pos.left + pos.width / 2 - 15; |
55 | | - } else { |
56 | | - tp.left = pos.left + pos.width / 2 - actualWidth + 15; |
57 | | - } |
58 | | - } |
59 | | - |
60 | | - $tip.css(tp).addClass('tipsy-' + gravity); |
61 | | - |
62 | | - if (this.options.fade) { |
63 | | - $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity}); |
64 | | - } else { |
65 | | - $tip.css({visibility: 'visible', opacity: this.options.opacity}); |
66 | | - } |
67 | | - } |
68 | | - }, |
69 | | - |
70 | | - hide: function() { |
71 | | - if (this.options.fade) { |
72 | | - this.tip().stop().fadeOut(function() { $(this).remove(); }); |
73 | | - } else { |
74 | | - this.tip().remove(); |
75 | | - } |
76 | | - }, |
77 | | - |
78 | | - fixTitle: function() { |
79 | | - var $e = this.$element; |
80 | | - if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') { |
81 | | - $e.attr('original-title', $e.attr('title') || '').removeAttr('title'); |
82 | | - } |
83 | | - }, |
84 | | - |
85 | | - getTitle: function() { |
86 | | - var title, $e = this.$element, o = this.options; |
87 | | - this.fixTitle(); |
88 | | - var title, o = this.options; |
89 | | - if (typeof o.title == 'string') { |
90 | | - title = $e.attr(o.title == 'title' ? 'original-title' : o.title); |
91 | | - } else if (typeof o.title == 'function') { |
92 | | - title = o.title.call($e[0]); |
93 | | - } |
94 | | - title = ('' + title).replace(/(^\s*|\s*$)/, ""); |
95 | | - return title || o.fallback; |
96 | | - }, |
97 | | - |
98 | | - tip: function() { |
99 | | - if (!this.$tip) { |
100 | | - this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>'); |
101 | | - } |
102 | | - return this.$tip; |
103 | | - }, |
104 | | - |
105 | | - validate: function() { |
106 | | - if (!this.$element[0].parentNode) { |
107 | | - this.hide(); |
108 | | - this.$element = null; |
109 | | - this.options = null; |
110 | | - } |
111 | | - }, |
112 | | - |
113 | | - enable: function() { this.enabled = true; }, |
114 | | - disable: function() { this.enabled = false; }, |
115 | | - toggleEnabled: function() { this.enabled = !this.enabled; } |
116 | | - }; |
117 | | - |
118 | | - $.fn.tipsy = function(options) { |
119 | | - |
120 | | - if (options === true) { |
121 | | - return this.data('tipsy'); |
122 | | - } else if (typeof options == 'string') { |
123 | | - var tipsy = this.data('tipsy'); |
124 | | - if (tipsy) tipsy[options](); |
125 | | - return this; |
126 | | - } |
127 | | - |
128 | | - options = $.extend({}, $.fn.tipsy.defaults, options); |
129 | | - |
130 | | - function get(ele) { |
131 | | - var tipsy = $.data(ele, 'tipsy'); |
132 | | - if (!tipsy) { |
133 | | - tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options)); |
134 | | - $.data(ele, 'tipsy', tipsy); |
135 | | - } |
136 | | - return tipsy; |
137 | | - } |
138 | | - |
139 | | - function enter() { |
140 | | - var tipsy = get(this); |
141 | | - tipsy.hoverState = 'in'; |
142 | | - if (options.delayIn == 0) { |
143 | | - tipsy.show(); |
144 | | - } else { |
145 | | - tipsy.fixTitle(); |
146 | | - setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn); |
147 | | - } |
148 | | - }; |
149 | | - |
150 | | - function leave() { |
151 | | - var tipsy = get(this); |
152 | | - tipsy.hoverState = 'out'; |
153 | | - if (options.delayOut == 0) { |
154 | | - tipsy.hide(); |
155 | | - } else { |
156 | | - setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut); |
157 | | - } |
158 | | - }; |
159 | | - |
160 | | - if (!options.live) this.each(function() { get(this); }); |
161 | | - |
162 | | - if (options.trigger != 'manual') { |
163 | | - var binder = options.live ? 'live' : 'bind', |
164 | | - eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus', |
165 | | - eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur'; |
166 | | - this[binder](eventIn, enter)[binder](eventOut, leave); |
167 | | - } |
168 | | - |
169 | | - return this; |
170 | | - |
171 | | - }; |
172 | | - |
173 | | - $.fn.tipsy.defaults = { |
174 | | - delayIn: 0, |
175 | | - delayOut: 0, |
176 | | - fade: false, |
177 | | - fallback: '', |
178 | | - gravity: 'n', |
179 | | - html: false, |
180 | | - live: false, |
181 | | - offset: 0, |
182 | | - opacity: 0.8, |
183 | | - title: 'title', |
184 | | - trigger: 'hover' |
185 | | - }; |
186 | | - |
187 | | - // Overwrite this method to provide options on a per-element basis. |
188 | | - // For example, you could store the gravity in a 'tipsy-gravity' attribute: |
189 | | - // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' }); |
190 | | - // (remember - do not modify 'options' in place!) |
191 | | - $.fn.tipsy.elementOptions = function(ele, options) { |
192 | | - return $.metadata ? $.extend({}, options, $(ele).metadata()) : options; |
193 | | - }; |
194 | | - |
195 | | - $.fn.tipsy.autoNS = function() { |
196 | | - return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n'; |
197 | | - }; |
198 | | - |
199 | | - $.fn.tipsy.autoWE = function() { |
200 | | - return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w'; |
201 | | - }; |
202 | | - |
203 | | -})(jQuery); |