2 * Interface Elements for jQuery
\r
5 * http://interface.eyecon.ro
\r
7 * Copyright (c) 2006 Stefan Petre
\r
8 * Dual licensed under the MIT (MIT-LICENSE.txt)
\r
9 * and GPL (GPL-LICENSE.txt) licenses.
\r
15 * Creates tooltips using title attribute
\r
20 * @description Creates tooltips using title attribute
\r
21 * @param Hash hash A hash of parameters
\r
22 * @option String position tooltip's position ['top'|'left'|'right'|'bottom'|'mouse']
\r
23 * @options Function onShow (optional) A function to be executed whenever the tooltip is displayed
\r
24 * @options Function onHide (optional) A function to be executed whenever the tooltip is hidden
\r
27 * @cat Plugins/Interface
\r
28 * @author Stefan Petre
\r
36 jQuery.iTooltip.focused = true;
\r
37 jQuery.iTooltip.show(e, this, true);
\r
39 hidefocused : function(e)
\r
41 if (jQuery.iTooltip.current != this)
\r
43 jQuery.iTooltip.focused = false;
\r
44 jQuery.iTooltip.hide(e, this);
\r
46 show : function(e, el, focused)
\r
48 if (jQuery.iTooltip.current != null)
\r
54 jQuery.iTooltip.current = el;
\r
55 pos = jQuery.extend(
\r
56 jQuery.iUtil.getPosition(el),
\r
57 jQuery.iUtil.getSize(el)
\r
60 title = jEl.attr('title');
\r
61 href = jEl.attr('href');
\r
63 jQuery.iTooltip.oldTitle = title;
\r
64 jEl.attr('title','');
\r
65 jQuery('#tooltipTitle').html(title);
\r
67 jQuery('#tooltipURL').html(href.replace('http://', ''));
\r
69 jQuery('#tooltipURL').html('');
\r
70 helper = jQuery('#tooltipHelper');
\r
71 if(el.tooltipCFG.className){
\r
72 helper.get(0).className = el.tooltipCFG.className;
\r
74 helper.get(0).className = '';
\r
76 helperSize = jQuery.iUtil.getSize(helper.get(0));
\r
77 filteredPosition = focused && el.tooltipCFG.position == 'mouse' ? 'bottom' : el.tooltipCFG.position;
\r
79 switch (filteredPosition) {
\r
81 ny = pos.y - helperSize.hb;
\r
86 nx = pos.x - helperSize.wb;
\r
90 nx = pos.x + pos.wb;
\r
93 jQuery('body').bind('mousemove', jQuery.iTooltip.mousemove);
\r
94 pointer = jQuery.iUtil.getPointer(e);
\r
95 ny = pointer.y + 15;
\r
96 nx = pointer.x + 15;
\r
99 ny = pos.y + pos.hb;
\r
109 if (el.tooltipCFG.delay == false) {
\r
112 helper.fadeIn(el.tooltipCFG.delay);
\r
114 if (el.tooltipCFG.onShow)
\r
115 el.tooltipCFG.onShow.apply(el);
\r
116 jEl.bind('mouseout',jQuery.iTooltip.hide)
\r
117 .bind('blur',jQuery.iTooltip.hidefocused);
\r
120 mousemove : function(e)
\r
122 if (jQuery.iTooltip.current == null) {
\r
123 jQuery('body').unbind('mousemove', jQuery.iTooltip.mousemove);
\r
126 pointer = jQuery.iUtil.getPointer(e);
\r
127 jQuery('#tooltipHelper').css(
\r
129 top : pointer.y + 15 + 'px',
\r
130 left : pointer.x + 15 + 'px'
\r
134 hide : function(e, el)
\r
139 if (jQuery.iTooltip.focused != true && jQuery.iTooltip.current == el) {
\r
140 jQuery.iTooltip.current = null;
\r
141 jQuery('#tooltipHelper').fadeOut(1);
\r
143 .attr('title',jQuery.iTooltip.oldTitle)
\r
144 .unbind('mouseout', jQuery.iTooltip.hide)
\r
145 .unbind('blur', jQuery.iTooltip.hidefocused);
\r
146 if (el.tooltipCFG.onHide)
\r
147 el.tooltipCFG.onHide.apply(el);
\r
148 jQuery.iTooltip.oldTitle = null;
\r
151 build : function(options)
\r
153 if (!jQuery.iTooltip.helper)
\r
155 jQuery('body').append('<div id="tooltipHelper"><div id="tooltipTitle"></div><div id="tooltipURL"></div></div>');
\r
156 jQuery('#tooltipHelper').css(
\r
158 position: 'absolute',
\r
163 jQuery.iTooltip.helper = true;
\r
167 if(jQuery.attr(this,'title')) {
\r
168 this.tooltipCFG = {
\r
169 position : /top|bottom|left|right|mouse/.test(options.position) ? options.position : 'bottom',
\r
170 className : options.className ? options.className : false,
\r
171 delay : options.delay ? options.delay : false,
\r
172 onShow : options.onShow && options.onShow.constructor == Function ? options.onShow : false,
\r
173 onHide : options.onHide && options.onHide.constructor == Function ? options.onHide : false
\r
175 var el = jQuery(this);
\r
176 el.bind('mouseover',jQuery.iTooltip.show);
\r
177 el.bind('focus',jQuery.iTooltip.focus);
\r
184 jQuery.fn.ToolTip = jQuery.iTooltip.build;