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 html"></div><div class="url"></div><div class="tooltip-footer"></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 helper.footer = $('div.tooltip-footer', helper.parent); 115 } 116 117 function settings(element) { 118 return $.data(element, "tooltip"); 119 } 120 121 // main event handler to start showing tooltips 122 function handle(event) { 123 // show helper, either with timeout or on instant 124 if( settings(this).delay ) 125 tID = setTimeout(show, settings(this).delay); 126 else 127 show(); 128 129 // if selected, update the helper position when the mouse moves 130 track = !!settings(this).track; 131 $(document.body).bind('mousemove', update); 132 133 // update at least once 134 update(event); 135 } 136 137 // save elements title before the tooltip is displayed 138 function save() { 139 // if this is the current source, or it has no title (occurs with click event), stop 140 if ( $.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler) ) 141 return; 142 143 // save current 144 current = this; 145 title = this.tooltipText; 146 var strBody = this.tooltipText; 147 var strTitle = ""; 148 var strFooter = ""; 149 150 if ( settings(this).bodyHandler ) 151 strBody = settings(this).bodyHandler.call(this); 152 if ( settings(this).showBody ) { 153 var parts = strBody.split(settings(this).showBody,3); 154 if ( parts.length > 1 ) 155 strTitle = parts.shift(); 156 strBody = parts.shift(); 157 if ( parts.length > 0 ) 158 strFooter = parts[0]; 159 } 160 161 if ( settings(this).bodyHandler ) { 162 helper.title.html( strTitle ).toggle( strTitle != "" ); 163 helper.body.html( strBody ).show(); 164 helper.footer.html( strFooter ).toggle( strFooter != "" ); 165 } else { 166 helper.title.html(title).show(); 167 helper.body.hide(); 168 helper.footer.hide(); 169 } 170 171 // if element has href or src, add and show it, otherwise hide it 172 if( settings(this).showURL && $(this).url() ) 173 helper.url.html( $(this).url().replace('http://', '') ).show(); 174 else 175 helper.url.hide(); 176 177 // add an optional class for this tip 178 helper.parent.addClass(settings(this).extraClass); 179 180 // fix PNG background for IE 181 if (settings(this).fixPNG ) 182 helper.parent.fixPNG(); 183 184 handle.apply(this, arguments); 185 } 186 187 // delete timeout and show helper 188 function show() { 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 update(); 199 } 200 201 /** 202 * callback for mousemove 203 * updates the helper position 204 * removes itself when no current element 205 */ 206 function update(event) { 207 if($.tooltip.blocked) 208 return; 209 210 if (event && event.target.tagName == "OPTION") { 211 return; 212 } 213 214 // stop updating when tracking is disabled and the tooltip is visible 215 if ( !track && helper.parent.is(":visible")) { 216 $(document.body).unbind('mousemove', update) 217 } 218 219 // if no current element is available, remove this listener 220 if( current == null ) { 221 $(document.body).unbind('mousemove', update); 222 return; 223 } 224 225 // remove position helper classes 226 helper.parent.removeClass("viewport-right").removeClass("viewport-bottom"); 227
228 var left = helper.parent[0].offsetLeft; 229 var top = helper.parent[0].offsetTop; 230 if (event) { 231 // position the helper 15 pixel to bottom right, starting from mouse position 232 left = event.pageX + settings(current).left; 233 top = event.pageY + settings(current).top; 234 var right='auto'; 235 if (settings(current).positionLeft) { 236 right = $(window).width() - left; 237 left = 'auto'; 238 } 239 if ( settings(current).opacity !== undefined ) 240 helper.parent.css( "opacity", settings(current).opacity ); 241 if ( settings(current).width !== undefined ) 242 helper.parent.css( "width", settings(current).width ); 243 helper.parent.css({ 244 left: left, 245 right: right, 246 top: top 247 }); 248 } 249 250 var v = viewport(), 251 h = helper.parent[0]; 252 // check horizontal position 253 if (v.x + v.cx < h.offsetLeft + h.offsetWidth) { 254 left -= h.offsetWidth + 20 + settings(current).left; 255 helper.parent.css({left: left + 'px'}).addClass("viewport-right"); 256 } 257 // check vertical position 258 if ( v.y + v.cy < h.offsetTop + h.offsetHeight) { 259 top -= h.offsetHeight + 20 + settings(current).top; 260 helper.parent.css({top: top + 'px'}).addClass("viewport-bottom"); 261 } 262 } 263 264 function viewport() { 265 return { 266 x: $(window).scrollLeft(), 267 y: $(window).scrollTop(), 268 cx: $(window).width(), 269 cy: $(window).height() 270 }; 271 } 272 273 // hide helper and restore added classes and the title 274 function hide(event) { 275 // return; // KLUDGE never hide 276 if($.tooltip.blocked) 277 return; 278 // clear timeout if possible 279 if(tID) 280 clearTimeout(tID); 281 // no more current element 282 current = null; 283 284 var tsettings = settings(this); 285 function complete() { 286 helper.parent.removeClass( tsettings.extraClass ).hide().css("opacity", ""); 287 } 288 if ((!IE || !$.fn.bgiframe) && tsettings.fade) { 289 if (helper.parent.is(':animated')) 290 helper.parent.stop().fadeTo(tsettings.fade, 0, complete); 291 else 292 helper.parent.stop().fadeOut(tsettings.fade, complete); 293 } else 294 complete(); 295 296 if( settings(this).fixPNG ) 297 helper.parent.unfixPNG(); 298 } 299 300})(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.