Your IP : 216.73.216.55


Current Path : /home/giteleslfp/www/plugins/system/tooltipgc/assets/
Upload File :
Current File : /home/giteleslfp/www/plugins/system/tooltipgc/assets/tooltipgc.js

/**
 * copyright	Copyright (C) since 2010 Cedric KEIFLIN alias ced1870 & Ghazal
 * http://www.joomlack.fr
 * license		GNU/GPL
 * Tooltip GC
 **/

(function($) {
	"use strict";
	var Tooltipgc = function(el, opts) {
		if (!(this instanceof Tooltipgc)) return new Tooltipgc(el, opts);

		var defaults = {
			fxtransition: 'linear',
			fxduration: 500,
			dureeIn: 0,
			dureeBulle: 500,
			ismobile: 0,
			opacite: 0.8
		};
		var opts = $.extend(defaults, opts);
		var t = this;
		t.tooltip = $(el);

		if (t.tooltip.length === 0) return;
		if (t.tooltip.length > 1) {
			var tooltipgcs = window.tooltipgcs || [];
			t.tooltip.each(function () {
				tooltipgcs.push(new Tooltipgc(this, opts));
			});
			window.tooltipgcs = tooltipgcs;
			return tooltipgcs;
		}

		t.tip = $('> .tooltipgc_tooltip', t.tooltip);

		getTooltipParams();
		t.tip.css({
			'opacity': '0',
			'width': '0',
			'height': '0',
			'marginTop': t.offsety,
			'marginLeft': t.offsetx
		});
		
		if (opts.ismobile === 1) {
			t.tooltip.click(function() {
				if (t.tooltip.data('status') != 'opened') {
					openTipForMobile();
					hideTipOutsideClick();
				} else {
					closeTipForMobile();
				}
			});
		} else {
			t.tooltip.mouseover(function() {
				showTip();
			});
			t.tooltip.mouseleave(function() {
				hideTip();
			});
		}

		function hideTipOutsideClick() {
			$(window).on('click', function(event){
				if ( 
					t.tooltip.data('status') == 'opened'
					&&
					t.tooltip.has(event.target).length == 0 //checks if descendants was clicked
					&&
					!t.tooltip.is(event.target) //checks if itself was clicked
					){
					// is outside
					if (opts.ismobile === 1) {
						closeTipForMobile();
					} else {
						hideTip();
					}
				} else {
					// is inside, do nothing
				}
			});
		}

		function getTooltipParams() {
			t.width = t.tip.width();
			t.height = t.tip.outerHeight();
			t.fxduration = opts.fxduration;
			t.dureeBulle = opts.dureeBulle;
			t.offsetx = 0;
			t.offsety = 0;
			if (t.tooltip.attr('data-params').length) {
				var params = t.tooltip.attr('data-params').split('|');
				for (var i = 0; i < params.length; i++) {
					var param = params[i];
					// old params
					if (param.indexOf('mood=') != -1)
						t.fxduration = param.replace("mood=", "");
					if (param.indexOf('tipd=') != -1)
						t.dureeBulle = param.replace("tipd=", "");
					if (param.indexOf('offsetx=') != -1)
						t.offsetx = parseInt(param.replace("offsetx=", ""));
					if (param.indexOf('offsety=') != -1)
						t.offsety = parseInt(param.replace("offsety=", ""));
					// new paramsif (param.indexOf('mood=') != -1)
					if (param.indexOf('time=') != -1)
						t.fxduration = param.replace("time=", "");
					if (param.indexOf('delayOut=') != -1)
						t.dureeBulle = param.replace("delayOut=", "");
				}
			}
		}

		function showTip() {
			clearTimeout(t.timeout);
			t.timeout = setTimeout(function() {
				openTip();
			}, opts.dureeIn);
		}

		function hideTip() {
			clearTimeout(t.timeout);
			t.timeout = setTimeout(function() {
				closeTip();
			}, t.dureeBulle);
		}

		function openTip() {
			if (t.tooltip.data('status') == 'opened')
				return;
			t.tip.css({
				'display': 'inline-block'
			});
			t.tip.animate({
				'opacity' : '1',
				'height' : t.height,
				'width' : t.width
				}, parseInt(t.fxduration), opts.fxtransition, 
				function() {
					if (t.tooltip.data('status') == 'opened')
						return;
					t.tip.css('height', '');
					if (t.height != t.tip.height()) t.height = t.tip.height();
					t.tooltip.data('status', 'opened');
					t.tip.stop(true,true);
				}
			);
		}

		function closeTip() {
			t.tip.stop(true,true);
			t.tip.css({
				'opacity': '0',
				'width': '0',
				'height': '0',
				'display' : 'none'
			});
			t.tooltip.data('status', 'closed');
		}

		function openTipForMobile() {
			if (t.tooltip.data('status') == 'opened')
				return;
			t.tip.css({
				'display': 'inline-block'
				,'width': ''
				,'height': ''
			});
			t.tip.addClass('tooltipgc_mobile');
			$(document.body).append('<div id="tooltipgc_overlay"></div>');
			$('#tooltipgc_overlay').append(t.tip);
			$('#tooltipgc_overlay').fadeIn(t.fxduration);
			t.tip.animate({
				'opacity' : '1',
				// 'height' : t.height,
				// 'width' : t.width
				}, parseInt(t.fxduration), opts.fxtransition, 
				function() {
					if (t.tooltip.data('status') == 'opened')
						return;
					// t.tip.css('height', '');
					// if (t.height != t.tip.height()) t.height = t.tip.height();
					t.tooltip.data('status', 'opened');
					t.tip.stop(true,true);
				}
			);
		}

		function closeTipForMobile() {
			t.tip.removeClass('tooltipgc_mobile');
			closeTip();
			t.tooltip.append(t.tip);
			$('#tooltipgc_overlay').fadeOut($('#tooltipgc_overlay').remove());
		}
	}
	window.Tooltipgc = Tooltipgc;
})(jQuery);