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 = /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 isImage: false, 37 showURL: true, 38 extraClass: "", 39 top: 15, 40 left: 15, 41 id: "tooltip" 42 }, 43 block: function() { 44 $.tooltip.blocked = !$.tooltip.blocked; 45 } 46 }; 47 48 $.fn.extend({ 49 tooltip: function(settings) { 50 settings = $.extend({}, $.tooltip.defaults, settings); 51 createHelper(settings); 52 return this.each(function() { 53 $.data(this, "tooltip", settings); 54 this.tOpacity = helper.parent.css("opacity"); 55 // copy tooltip into its own expando and remove the title 56 this.tooltipText = this.title; 57 $(this).removeAttr("title"); 58 // also remove alt attribute to prevent default tooltip in IE 59 this.alt = ""; 60 }) 61 .mouseover(save) 62 .mouseout(hide) 63 .click(hide); 64 }, 65 fixPNG: IE ? function() { 66 return this.each(function () { 67 var image = $(this).css('backgroundImage'); 68 if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) { 69 image = RegExp.$1; 70 $(this).css({ 71 'backgroundImage': 'none', 72 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')" 73 }).each(function () { 74 var position = $(this).css('position'); 75 if (position != 'absolute' && position != 'relative') 76 $(this).css('position', 'relative'); 77 }); 78 } 79 }); 80 } : function() { return this; }, 81 unfixPNG: IE ? function() { 82 return this.each(function () { 83 $(this).css({'filter': '', backgroundImage: ''}); 84 }); 85 } : function() { return this; }, 86 hideWhenEmpty: function() { 87 return this.each(function() { 88 $(this)[ $(this).html() ? "show" : "hide" ](); 89 }); 90 }, 91 url: function() { 92 return this.attr('href') || this.attr('src'); 93 } 94 }); 95 96 function createHelper(settings) { 97 // there can be only one tooltip helper 98 if( helper.parent ) 99 return; 100 // create the helper, h3 for title, div for url 101 helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>') 102 // add to document 103 .appendTo(document.body) 104 // hide it at first 105 .hide(); 106 107 // apply bgiframe if available 108 if ( $.fn.bgiframe ) 109 helper.parent.bgiframe(); 110 111 // save references to title and url elements 112 helper.title = $('h3', helper.parent); 113 helper.body = $('div.body', helper.parent); 114 helper.url = $('div.url', 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 147 if ( settings(this).bodyHandler ) { 148 helper.title.hide(); 149 var bodyContent = settings(this).bodyHandler.call(this); 150 if (bodyContent.nodeType || bodyContent.jquery) { 151 helper.body.empty().append(bodyContent) 152 } else { 153 helper.body.html( bodyContent ); 154 } 155 helper.body.show(); 156 } else if ( settings(this).showBody ) { 157 var parts = title.split(settings(this).showBody); 158 helper.title.html(parts.shift()).show(); 159 helper.body.empty(); 160 for(var i = 0, part; (part = parts[i]); i++) { 161 if(i > 0) 162 helper.body.append("<br/>"); 163 helper.body.append(part); 164 } 165 helper.body.hideWhenEmpty(); 166 } else { 167 helper.title.html(title).show(); 168 helper.body.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 if(settings(current).isImage) 226 { 227 helper.parent.find('img').removeAttr("width").removeAttr("height"); 228 229 if( helper.parent.find('img').attr("height") > (0.7*$(window).height()) || 230 helper.parent.find('img').attr("height") > 400 231 ) 232 { 233 helper.parent.find('img').attr("height", Math.round(400>0.7*$(window).height()?0.7*$(window).height():400,0)); 234 }else 235 if( ! helper.parent.find('img').attr("height") > 0) 236 { 237// alert('not load'); 238// return; 239 } 240 } 241 242 // remove position helper classes 243 helper.parent.removeClass("viewport-right").removeClass("viewport-bottom"); 244
245 var left = helper.parent[0].offsetLeft; 246 var top = helper.parent[0].offsetTop; 247 if (event) { 248 249 // position the helper 15 pixel to bottom right, starting from mouse position 250 left = event.pageX + settings(current).left; 251 top = event.pageY + settings(current).top; 252 var right='auto'; 253 if (settings(current).positionLeft) { 254 right = $(window).width() - left; 255 left = 'auto'; 256 } 257 helper.parent.css({ 258 left: left, 259 right: right, 260 top: top 261 }); 262 } 263 264 var v = viewport(), 265 h = helper.parent[0]; 266 // check horizontal position 267 if (v.x + v.cx < h.offsetLeft + h.offsetWidth) { 268 left -= h.offsetWidth + 20 + settings(current).left; 269 helper.parent.css({left: left + 'px'}).addClass("viewport-right"); 270 } 271 // check vertical position 272 if(settings(current).isImage == false) 273 if (v.y + v.cy < h.offsetTop + h.offsetHeight) { 274 top -= h.offsetHeight + 20 + settings(current).top; 275 helper.parent.css({top: top + 'px'}).addClass("viewport-bottom"); 276 } 277 278 if(settings(current).isImage == true) 279 { 280 if (v.y + v.cy < h.offsetTop + h.offsetHeight) { 281 top -= h.offsetTop + h.offsetHeight - (v.y + v.cy); 282 helper.parent.css({top: top + 'px'}).addClass("viewport-bottom"); 283 } 284 } 285 } 286 287 function viewport() { 288 return { 289 x: $(window).scrollLeft(), 290 y: $(window).scrollTop(), 291 cx: $(window).width(), 292 cy: $(window).height() 293 }; 294 } 295 296 // hide helper and restore added classes and the title 297 function hide(event) { 298 if($.tooltip.blocked) 299 return; 300 // clear timeout if possible 301 if(tID) 302 clearTimeout(tID); 303 // no more current element 304 current = null; 305 306 var tsettings = settings(this); 307 function complete() { 308 if(tsettings != null) 309 helper.parent.removeClass( tsettings.extraClass ).hide().css("opacity", ""); 310 } 311 312 if ((!IE || !$.fn.bgiframe) && tsettings != null && tsettings.fade) { 313 if (helper.parent.is(':animated')) 314 helper.parent.stop().fadeTo(tsettings.fade, 0, complete); 315 else 316 helper.parent.stop().fadeOut(tsettings.fade, complete); 317 } else 318 complete(); 319 320 321 if( tsettings != null && settings(this).fixPNG ) 322 helper.parent.unfixPNG(); 323 } 324 325})(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.