PageSourceSearch

https://drjtbc.org/wp-content/plugins/tooltip-ck/assets/tooltipck.js?ver=7.1

js drjtbc.org collected 2026-10-02 10:27:16 UTC 13,089 bytes, 419 lines download raw bytes

1/**
2 * @name		Tooltip CK
3 * @copyright	Copyright (C) 2016. All rights reserved.
4 * @license		GNU General Public License version 2 or later; see LICENSE.txt
5 * @author		Cédric KEIFLIN - https://www.joomlack.fr - https://www.template-creator.com - https://www.ceikay.com
6 */
7 
8 /*
9 * Version 2.2.9 : Fix issue with WP5.6 and jQuery update
10 * Version 2.2.6 : Fix issue with fade effect, improve tipWidth setting with data attribute
11 */
12
13(function () {
14	'use strict';
15
16	var $;
17
18	/*===========================
19	Tooltipck
20	===========================*/
21	var Tooltipck = function (options) {
22		if (!(this instanceof Tooltipck)) return new Tooltipck(options);
23
24		if (typeof jQuery !== 'undefined'){
25			$ = jQuery;
26		}
27
28		if (typeof $ === 'undefined') {
29			console.log('Tooltip CK error : jQuery instance not found !');
30			return;
31		}
32
33		// Tooltipck
34		var t = this;
35
36		// Settings
37		var defaults = {
38			fxTransition: 'linear',
39			fxType: 'both',					// can be both, horizontal, vertical, fade
40			fxDuration: 500,
41			tipPosition: 'right',			// can be right, top, left, bottom
42			delayIn: 0,
43			delayOut: 500,
44			isMobile: 0,
45			opacity: 0.9,
46			offsetx: 0,
47			offsety: 0
48			};
49		options = options || {};
50		options = $.extend(defaults, options);
51
52		var tooltip;
53		$('.tooltipck').each(function(i, tooltip) {
54			tooltip = $(tooltip);
55			if (tooltip.attr('data-done') == '1') return;
56
57			tooltip = $.extend(tooltip, options);
58
59			// quick fix for the height of the element
60			tooltip.css('display', 'inline-block');
61			tooltip.height = tooltip.height();
62			tooltip.width = tooltip.width();
63			tooltip.css('display', '');
64			tooltip.attr('data-position', options.tipPosition);
65
66			tooltip.tip = $('> .tooltipck-tip', tooltip);
67			$(document.body).append(tooltip.tip);
68			// tooltip.tipWidth = tooltip.tip.outerWidth() + parseInt(tooltip.tip.css('border-left-width')) + parseInt(tooltip.tip.css('border-right-width'));
69			tooltip.tipWidth = parseInt(tooltip.tip.attr('data-width'));
70			tooltip.tipHeight = tooltip.tip.outerHeight();
71
72			tooltip.tip.css({
73				'opacity': '0',
74				'width': '0',
75				'height': '0'
76			});
77			getTooltipParams();
78
79			tooltip.attr('data-done', '1');
80
81			if (options.isMobile == 1) {
82				tooltip.click(function() {
83					if (tooltip.data('status') != 'open' && tooltip.data('status') != 'opened') {
84						showTip(tooltip);
85						hideTipOutsideClick();
86					} else {
87						hideTip(tooltip);
88					}
89				});
90				tooltip.tip.click(function() {
91					if (tooltip.data('status') == 'opened') {
92						hideTip(tooltip);
93					}
94				});
95			} else {
96				tooltip.mouseover(function() {
97					showTip(tooltip);
98				});
99				tooltip.mouseleave(function() {
100					hideTip(tooltip);
101				});
102			}
103
104			function hideTipOutsideClick() {
105				$(window).on('click', function(event){
106					if ( 
107						tooltip.data('status') == 'open'
108						&&
109						tooltip.has(event.target).length == 0 //checks if descendants was clicked
110						&&
111						!tooltip.is(event.target) //checks if itself was clicked
112						){
113						// is outside
114						hideTip(tooltip);
115					} else {
116						// is inside, do nothing
117					}
118				});
119			}
120
121			function getTipPosition() {
122				var prop1 ,val1, prop2, val2;
123
124				switch(tooltip.tipPosition) {
125					case 'right':
126					default:
127						prop1 = 'left';
128						val1 = (tooltip.pointer.offset().left + parseInt(tooltip.offsetx)) + 'px';
129						prop2 = 'top';
130						val2 = (tooltip.pointer.offset().top + parseInt(tooltip.offsety)) + 'px';
131						break;
132					case 'left':
133						prop1 = 'left';
134						val1 = (tooltip.pointer.offset().left + parseInt(tooltip.offsetx) - tooltip.tipWidth - tooltip.width) + 'px';
135						prop2 = 'top';
136						val2 = (tooltip.pointer.offset().top + parseInt(tooltip.offsety)) + 'px';
137						break;
138					case 'top':
139						prop1 = 'left';
140						val1 = (tooltip.pointer.offset().left + parseInt(tooltip.offsetx) - (tooltip.tipWidth / 2) - (tooltip.width / 2)) + 'px';
141						prop2 = 'top';
142						val2 = (tooltip.pointer.offset().top + parseInt(tooltip.offsety) - tooltip.tipHeight - tooltip.height) + 'px';
143						break;
144					case 'bottom':
145						prop1 = 'left';
146						val1 = (tooltip.pointer.offset().left + parseInt(tooltip.offsetx) - (tooltip.tipWidth / 2) - (tooltip.width / 2)) + 'px';
147						prop2 = 'top';
148						val2 = (tooltip.pointer.offset().top + tooltip.height + parseInt(tooltip.offsety)) + 'px';
149						break;
150				}
151				return Array(prop1, val1, prop2, val2);
152			}
153
154			function checkWithinBounds() {
155				var boundTop = $(document).scrollTop();
156				var boundBottom = boundTop + $(window).height();
157				var boundLeft = $(document).scrollLeft();
158				var boundRight = boundLeft + $(window).width();
159
160				if (tooltip.tipPosition == 'right') {
161					var tipPositionRight = tooltip.pointer.offset().left + parseInt(tooltip.tip.css('marginLeft')) + tooltip.tipWidth;
162					var hOffset = boundRight - tipPositionRight;
163					if (hOffset < 0) {
164						tooltip.tip.css('marginLeft', '+=' + hOffset + 'px');
165					}
166				}
167
168				// for position left, right, and bottom when the tip goes lower
169				if (tooltip.tipPosition != 'top') {
170					if (tooltip.tipPosition == 'bottom') {
171						var tipPositionBottom = tooltip.pointer.offset().top + tooltip.tipHeight + parseInt(tooltip.tip.css('marginTop')) + tooltip.height;
172					} else {
173						var tipPositionBottom = tooltip.pointer.offset().top + tooltip.tipHeight + parseInt(tooltip.tip.css('marginTop'));
174					}
175					var vOffset = boundBottom - tipPositionBottom;
176					if (vOffset < 0) {
177						tooltip.tip.css('marginTop', '+=' + vOffset + 'px');
178					}
179				}
180			}
181
182			function checkWithinBoundsAfterAnimation() {
183				var boundTop = $(document).scrollTop();
184				var left = parseInt(tooltip.tip.css('left'));
185				var marginLeft = parseInt(tooltip.tip.css('marginLeft'));
186				var top = parseInt(tooltip.tip.position().top);
187				var marginTop = parseInt(tooltip.tip.css('marginTop'));
188
189				// init the limit
190				tooltip.tip.css('max-width', '');
191				tooltip.tip.css('max-height', '');
192
193				if ((tooltip.tip.width() + 10) > $(window).width()) {
194					tooltip.tip.css({
195						'marginLeft': '0px'
196						,'left': '5px'
197						,'max-width': $(window).width() - 10 + 'px'
198					});
199				}
200				if ((tooltip.tip.height() + 10) > $(window).height()) {
201					tooltip.tip.css({
202						'marginTop': '0px'
203						,'top': '5px'
204						,'max-height': $(window).height() - 10 + 'px'
205					});
206				}
207
208				if (left + marginLeft < 0) {
209					tooltip.tip.css({
210						'left': '5px'
211						,'marginLeft': '0'
212					});
213				}
214				if (top + marginTop < boundTop) {
215					tooltip.tip.css({
216						'top': boundTop + 'px'
217						,'marginTop': '0'
218					});
219				}
220			}
221
222			function showTip(el) {
223				clearTimeout(el.timeout);
224				el.timeout = setTimeout(function() {
225					openTip(el);
226				}, options.delayIn);
227			}
228
229			function hideTip(el) {
230				clearTimeout(el.timeout);
231				el.timeout = setTimeout(function() {
232					if (tooltip.hasClass('tooltipck-paused')) return;
233					$(el).data('status', 'hide')
234					closeTip(el);
235				}, tooltip.delayOut);
236			}
237
238			function openTip(el) {
239				var tip = $(el.tip);
240				el.data('status', 'open');
241				if (el.data('status') == 'opened')
242					return;
243				
244				// tip.css('display' ,'inline-block');
245				tip.addClass('tooltipck-hover');
246				// add a html pointer to get the correct tip position
247				// if (! tooltip.find('.tooltipck-pointer').length) tooltip.append('<span class="tooltipck-pointer"></span>');
248				tooltip.pointer = tooltip.find('.tooltipck-pointer');
249				// check where to place the tooltip
250				tooltip.checkedPositions = [];
251				// empty the array
252				while (tooltip.checkedPositions.length) { tooltip.checkedPositions.pop(); }
253				tooltip.tipPosition = tooltip.attr('data-position');
254				var tipPositionCss = getTipPosition();
255				
256
257				// reset all positions to avoid issues
258				tip.css({
259					'top': '',
260					'bottom': '',
261					'left': '',
262					'right': '',
263					'marginLeft': '',
264					'marginTop': '',
265				});
266				tip.css(tipPositionCss[0], tipPositionCss[1]);
267				tip.css(tipPositionCss[2], tipPositionCss[3]);
268//				tip.css(tipPositionCss[4], tipPositionCss[5]);
269//				tip.css(tipPositionCss[6], tipPositionCss[7]);
270				checkWithinBounds();
271//				$(document.body).append(tip);
272
273				$('.tooltipck').removeClass('tooltipck-active');
274				tooltip.addClass('tooltipck-active');
275
276				switch(options.fxType) {
277					case 'both':
278					default:
279						tip.css('display' ,'inline-block');
280						tip.animate({
281							'opacity' : options.opacity,
282							'height' : el.tipHeight,
283							'width' : el.tipWidth,
284							// 'display' : 'inline-block',
285							// 'zIndex' : '6001'
286							}, {
287								duration: parseInt(tooltip.fxDuration),
288								transition:  options.fxTransition,
289								complete: function() {
290									el.data('status', 'opened');
291									tip.css('height' ,'auto');
292									checkWithinBoundsAfterAnimation();
293//									checkWithinBounds();
294								}
295						});
296						break;
297					case 'horizontal':
298						tip.css('height', el.tipHeight);
299						tip.css('display' ,'inline-block');
300						tip.animate({
301							'opacity' : options.opacity,
302							'width' : el.tipWidth,
303							// 'display' : 'inline-block'
304							}, {
305								duration: parseInt(tooltip.fxDuration),
306								transition:  options.fxTransition,
307								complete: function() {
308									el.data('status', 'opened');
309									tip.css('height' ,'auto');
310									checkWithinBoundsAfterAnimation();
311								}
312						});
313						break;
314					case 'vertical':
315						tip.css('width', el.tipWidth);
316						tip.css('display' ,'inline-block');
317						tip.animate({
318							'opacity' : options.opacity,
319							'height' : el.tipHeight,
320							// 'display' : 'inline-block'
321							}, {
322								duration: parseInt(tooltip.fxDuration),
323								transition:  options.fxTransition,
324								complete: function() {
325									el.data('status', 'opened');
326//									tip.css('height' ,'auto');
327									checkWithinBoundsAfterAnimation();
328								}
329						});
330						break;
331					case 'fade':
332						tip.css('height', el.tipHeight);
333						tip.css('width', el.tipWidth);
334						tip.css('display', 'inline-block');
335						tip.animate({
336							'opacity' : options.opacity
337							// 'display' : 'inline-block'
338							}, {
339								duration: parseInt(tooltip.fxDuration),
340								transition:  options.fxTransition,
341									complete: function() {
342									el.data('status', 'opened');
343									tip.css('height' ,'auto');
344									checkWithinBoundsAfterAnimation();
345								}
346						});
347						break;
348				}
349				if (options.isMobile == 1) {
350					
351				} else {
352					tip.mouseover(function() {
353						tooltip.addClass('tooltipck-paused');
354					}).mouseleave(function() {
355						tooltip.removeClass('tooltipck-paused').trigger('mouseleave');
356					});
357				}
358			}
359
360			function closeTip(el) {
361				var tip = $(el.tip);
362				el.data('status', 'close');
363				tip.stop(true, true);
364				tip.css({
365					'opacity': '0',
366					'width': '0',
367					'height': '0',
368					'display' : 'none'
369				});
370				tooltip.removeClass('tooltipck-active');
371				tip.removeClass('tooltipck-hover');
372//				tooltip.append(tip);
373				el.data('status', 'closed');
374			}
375
376			function getTooltipParams() {
377				if (tooltip.attr('rel')) {
378					var params = tooltip.attr('rel').split('|');
379					for (var i = 0; i < params.length; i++) {
380						var param = params[i];
381						if (param.indexOf('time=') != -1)
382							tooltip.fxDuration = parseInt(param.replace("time=", ""));
383						if (param.indexOf('delayOut=') != -1)
384							tooltip.delayOut = parseInt(param.replace("delayOut=", ""));
385						if (param.indexOf('offsetx=') != -1)
386							tooltip.offsetx = parseInt(param.replace("offsetx=", ""));
387						if (param.indexOf('offsety=') != -1)
388							tooltip.offsety = parseInt(param.replace("offsety=", ""));
389						if (param.indexOf('position=') != -1)
390							tooltip.tipPosition = param.replace("position=", "");
391						// Legacy
392						if (param.indexOf('mood=') != -1)
393							tooltip.fxDuration = param.replace("mood=", "");
394						if (param.indexOf('tipd=') != -1)
395							tooltip.delayOut = param.replace("tipd=", "");
396					}
397				}
398			}
399
400			// used when mobile window is switched between landscape and portrait
401			$(window).on('resize', function() { repositionTooltip(tooltip); });
402
403			function repositionTooltip(tooltip) {
404				if (tooltip.data('status') != 'open' || options.isMobile != '1') return;
405				tooltip.tipPosition = options.tipPosition;
406				var tipPositionCss = getTipPosition();
407				var tip = tooltip.tip;
408				// reset all positions to avoid issues
409				tip.css(tipPositionCss[0], tipPositionCss[1]);
410				tip.css(tipPositionCss[2], tipPositionCss[3]);
411				tip.css(tipPositionCss[4], tipPositionCss[5]);
412				tip.css(tipPositionCss[6], tipPositionCss[7]);
413				// checkWithinBounds();
414			}
415		});
416	};
417
418	window.Tooltipck = Tooltipck;
419})();

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.