PageSourceSearch

https://www.scandorama.se/buspronet/javascript/jquery_tooltip.js

js scandorama.se collected 2026-10-07 16:47:55 UTC 8,095 bytes, 297 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.