annotate DataTables-1.9.4/examples/examples_support/jquery.tooltip.js @ 0:ac5f9272033b draft

first upload
author saskia-hiltemann
date Tue, 01 Jul 2014 11:42:23 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2 * jQuery Tooltip plugin 1.3
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * http://docs.jquery.com/Plugins/Tooltip
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * Copyright (c) 2006 - 2008 Jörn Zaefferer
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 * $Id: jquery.tooltip.js 5741 2008-06-21 15:22:16Z joern.zaefferer $
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 * Dual licensed under the MIT and GPL licenses:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 * http://www.opensource.org/licenses/mit-license.php
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 * http://www.gnu.org/licenses/gpl.html
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 ;(function($) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 // the tooltip element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 var helper = {},
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 // the current tooltipped element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 current,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 // the title of the current element, used for restoring
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 title,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 // timeout id for delayed tooltips
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 tID,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 // IE 5.5 or 6
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 // flag for mouse tracking
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 track = false;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 $.tooltip = {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 blocked: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 defaults: {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 delay: 200,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 fade: false,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 showURL: true,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 extraClass: "",
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 top: 15,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 left: 15,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 id: "tooltip"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 block: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 $.tooltip.blocked = !$.tooltip.blocked;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 $.fn.extend({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 tooltip: function(settings) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 settings = $.extend({}, $.tooltip.defaults, settings);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 createHelper(settings);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 return this.each(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 $.data(this, "tooltip", settings);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 this.tOpacity = helper.parent.css("opacity");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 // copy tooltip into its own expando and remove the title
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 this.tooltipText = this.title;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 $(this).removeAttr("title");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 // also remove alt attribute to prevent default tooltip in IE
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 this.alt = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 })
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 .mouseover(save)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 .mouseout(hide)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 .click(hide);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 fixPNG: IE ? function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 return this.each(function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 var image = $(this).css('backgroundImage');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 image = RegExp.$1;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 $(this).css({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 'backgroundImage': 'none',
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 }).each(function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 var position = $(this).css('position');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 if (position != 'absolute' && position != 'relative')
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 $(this).css('position', 'relative');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 } : function() { return this; },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 unfixPNG: IE ? function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 return this.each(function () {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 $(this).css({'filter': '', backgroundImage: ''});
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 } : function() { return this; },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 hideWhenEmpty: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 return this.each(function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 $(this)[ $(this).html() ? "show" : "hide" ]();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89 },
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 url: function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 return this.attr('href') || this.attr('src');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 function createHelper(settings) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 // there can be only one tooltip helper
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 if( helper.parent )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 // create the helper, h3 for title, div for url
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>')
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 // add to document
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 .appendTo(document.body)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 // hide it at first
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 .hide();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 // apply bgiframe if available
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 if ( $.fn.bgiframe )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 helper.parent.bgiframe();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 // save references to title and url elements
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 helper.title = $('h3', helper.parent);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 helper.body = $('div.body', helper.parent);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 helper.url = $('div.url', helper.parent);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 function settings(element) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 return $.data(element, "tooltip");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 // main event handler to start showing tooltips
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 function handle(event) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 // show helper, either with timeout or on instant
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123 if( settings(this).delay )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 tID = setTimeout(show, settings(this).delay);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 show();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 // if selected, update the helper position when the mouse moves
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 track = !!settings(this).track;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130 $(document.body).bind('mousemove', update);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 // update at least once
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 update(event);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136 // save elements title before the tooltip is displayed
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 function save() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 // if this is the current source, or it has no title (occurs with click event), stop
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 if ( $.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142 // save current
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 current = this;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 title = this.tooltipText;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 if ( settings(this).bodyHandler ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 helper.title.hide();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 var bodyContent = settings(this).bodyHandler.call(this);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 if (bodyContent.nodeType || bodyContent.jquery) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 helper.body.empty().append(bodyContent)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 helper.body.html( bodyContent );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 helper.body.show();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 } else if ( settings(this).showBody ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 var parts = title.split(settings(this).showBody);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 helper.title.html(parts.shift()).show();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 helper.body.empty();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 for(var i = 0, part; (part = parts[i]); i++) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 if(i > 0)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 helper.body.append("<br/>");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 helper.body.append(part);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 helper.body.hideWhenEmpty();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 helper.title.html(title).show();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 helper.body.hide();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 // if element has href or src, add and show it, otherwise hide it
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171 if( settings(this).showURL && $(this).url() )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172 helper.url.html( $(this).url().replace('http://', '') ).show();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 helper.url.hide();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 // add an optional class for this tip
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 helper.parent.addClass(settings(this).extraClass);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 // fix PNG background for IE
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 if (settings(this).fixPNG )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 helper.parent.fixPNG();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 handle.apply(this, arguments);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 // delete timeout and show helper
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 function show() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 tID = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 if ((!IE || !$.fn.bgiframe) && settings(current).fade) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 if (helper.parent.is(":animated"))
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 helper.parent.stop().show().fadeTo(settings(current).fade, current.tOpacity);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 helper.parent.is(':visible') ? helper.parent.fadeTo(settings(current).fade, current.tOpacity) : helper.parent.fadeIn(settings(current).fade);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 } else {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 helper.parent.show();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 update();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 * callback for mousemove
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 * updates the helper position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 * removes itself when no current element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 function update(event) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 if($.tooltip.blocked)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 if (event && event.target.tagName == "OPTION") {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 // stop updating when tracking is disabled and the tooltip is visible
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 if ( !track && helper.parent.is(":visible")) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 $(document.body).unbind('mousemove', update)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 // if no current element is available, remove this listener
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 if( current == null ) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 $(document.body).unbind('mousemove', update);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 // remove position helper classes
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225 helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 var left = helper.parent[0].offsetLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 var top = helper.parent[0].offsetTop;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229 if (event) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 // position the helper 15 pixel to bottom right, starting from mouse position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 left = event.pageX + settings(current).left;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 top = event.pageY + settings(current).top;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 var right='auto';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 if (settings(current).positionLeft) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 right = $(window).width() - left;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 left = 'auto';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 helper.parent.css({
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239 left: left,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240 right: right,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 top: top
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 });
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 var v = viewport(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246 h = helper.parent[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 // check horizontal position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 if (v.x + v.cx < h.offsetLeft + h.offsetWidth) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 left -= h.offsetWidth + 20 + settings(current).left;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 helper.parent.css({left: left + 'px'}).addClass("viewport-right");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 // check vertical position
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253 if (v.y + v.cy < h.offsetTop + h.offsetHeight) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254 top -= h.offsetHeight + 20 + settings(current).top;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 helper.parent.css({top: top + 'px'}).addClass("viewport-bottom");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 function viewport() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 return {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261 x: $(window).scrollLeft(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 y: $(window).scrollTop(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 cx: $(window).width(),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 cy: $(window).height()
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268 // hide helper and restore added classes and the title
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 function hide(event) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 if($.tooltip.blocked)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 return;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 // clear timeout if possible
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 if(tID)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 clearTimeout(tID);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275 // no more current element
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 current = null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 var tsettings = settings(this);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 function complete() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 helper.parent.removeClass( tsettings.extraClass ).hide().css("opacity", "");
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 if (helper.parent.is(':animated'))
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 helper.parent.stop().fadeTo(tsettings.fade, 0, complete);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 helper.parent.stop().fadeOut(tsettings.fade, complete);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 } else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 complete();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 if( settings(this).fixPNG )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 helper.parent.unfixPNG();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 })(jQuery);