1// tipsy, facebook style tooltips for jquery 2// version 1.0.0a 3// (c) 2008-2010 jason frame [[email protected]] 4// released under the MIT license 5 6(function($) { 7 8 function maybeCall(thing, ctx) { 9 return (typeof thing == 'function') ? (thing.call(ctx)) : thing; 10 }; 11 12 function Tipsy(element, options) { 13 this.$element = $(element); 14 this.options = options; 15 this.enabled = true; 16 this.fixTitle(); 17 }; 18 19 Tipsy.prototype = { 20 show: function() { 21 var title = this.getTitle(); 22 if (title && this.enabled) { 23 var $tip = this.tip(); 24 25 $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title); 26 $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity 27 $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body); 28 29 var pos = $.extend({}, this.$element.offset(), { 30 width: this.$element[0].offsetWidth, 31 height: this.$element[0].offsetHeight 32 }); 33 34 var actualWidth = $tip[0].offsetWidth, 35 actualHeight = $tip[0].offsetHeight, 36 gravity = maybeCall(this.options.gravity, this.$element[0]); 37 38 var tp; 39 switch (gravity.charAt(0)) { 40 case 'n': 41 tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}; 42 break; 43 case 's': 44 tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2}; 45 break; 46 case 'e': 47 tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset}; 48 break; 49 case 'w': 50 tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset}; 51 break; 52 } 53 54 if (gravity.length == 2) { 55 if (gravity.charAt(1) == 'w') { 56 tp.left = pos.left + pos.width / 2 - 15; 57 } else { 58 tp.left = pos.left + pos.width / 2 - actualWidth + 15; 59 } 60 } 61 62 $tip.css(tp).addClass('tipsy-' + gravity); 63 $tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0); 64 if (this.options.className) { 65 $tip.addClass(maybeCall(this.options.className, this.$element[0])); 66 } 67 68 if (this.options.fade) { 69 $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity}); 70 } else { 71 $tip.css({visibility: 'visible', opacity: this.options.opacity}); 72 } 73 } 74 }, 75 76 hide: function() { 77 if (this.options.fade) { 78 this.tip().stop().fadeOut(function() { $(this).remove(); }); 79 } else { 80 this.tip().remove(); 81 } 82 }, 83 84 fixTitle: function() { 85 var $e = this.$element; 86 if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') { 87 $e.attr('original-title', $e.attr('title') || '').removeAttr('title'); 88 } 89 }, 90 91 getTitle: function() { 92 var title, $e = this.$element, o = this.options; 93 this.fixTitle(); 94 var title, o = this.options; 95 if (typeof o.title == 'string') { 96 title = $e.attr(o.title == 'title' ? 'original-title' : o.title); 97 } else if (typeof o.title == 'function') { 98 title = o.title.call($e[0]); 99 } 100 title = ('' + title).replace(/(^\s*|\s*$)/, ""); 101 return title || o.fallback; 102 }, 103 104 tip: function() { 105 if (!this.$tip) { 106 this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>'); 107 } 108 return this.$tip; 109 }, 110 111 validate: function() { 112 if (!this.$element[0].parentNode) { 113 this.hide(); 114 this.$element = null; 115 this.options = null; 116 } 117 }, 118 119 enable: function() { this.enabled = true; }, 120 disable: function() { this.enabled = false; }, 121 toggleEnabled: function() { this.enabled = !this.enabled; } 122 }; 123 124 $.fn.tipsy = function(options) { 125 126 if (options === true) { 127 return this.data('tipsy'); 128 } else if (typeof options == 'string') { 129 var tipsy = this.data('tipsy'); 130 if (tipsy) tipsy[options](); 131 return this; 132 } 133 134 options = $.extend({}, $.fn.tipsy.defaults, options); 135 136 function get(ele) { 137 var tipsy = $.data(ele, 'tipsy'); 138 if (!tipsy) { 139 tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options)); 140 $.data(ele, 'tipsy', tipsy); 141 } 142 return tipsy; 143 } 144 145 function enter() { 146 var tipsy = get(this); 147 tipsy.hoverState = 'in'; 148 if (options.delayIn == 0) { 149 tipsy.show(); 150 } else { 151 tipsy.fixTitle(); 152 setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn); 153 } 154 }; 155 156 function leave() { 157 var tipsy = get(this); 158 tipsy.hoverState = 'out'; 159 if (options.delayOut == 0) { 160 tipsy.hide(); 161 } else { 162 setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut); 163 } 164 }; 165 166 if (!options.live) this.each(function() { get(this); }); 167 168 if (options.trigger != 'manual') { 169 var binder = options.live ? 'live' : 'bind', 170 eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus', 171 eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur'; 172 this[binder](eventIn, enter)[binder](eventOut, leave); 173 } 174 175 return this; 176 177 }; 178 179 $.fn.tipsy.defaults = { 180 className: null, 181 delayIn: 0, 182 delayOut: 0, 183 fade: false, 184 fallback: '', 185 gravity: 'n', 186 html: false, 187 live: false, 188 offset: 0, 189 opacity: 0.8, 190 title: 'title',
191 trigger: 'hover' 192 }; 193 194 // Overwrite this method to provide options on a per-element basis. 195 // For example, you could store the gravity in a 'tipsy-gravity' attribute: 196 // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' }); 197 // (remember - do not modify 'options' in place!) 198 $.fn.tipsy.elementOptions = function(ele, options) { 199 return $.metadata ? $.extend({}, options, $(ele).metadata()) : options; 200 }; 201 202 $.fn.tipsy.autoNS = function() { 203 return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n'; 204 }; 205 206 $.fn.tipsy.autoWE = function() { 207 return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w'; 208 }; 209 210 /** 211 * yields a closure of the supplied parameters, producing a function that takes 212 * no arguments and is suitable for use as an autogravity function like so: 213 * 214 * @param margin (int) - distance from the viewable region edge that an 215 * element should be before setting its tooltip's gravity to be away 216 * from that edge. 217 * @param prefer (string, e.g. 'n', 'sw', 'w') - the direction to prefer 218 * if there are no viewable region edges effecting the tooltip's 219 * gravity. It will try to vary from this minimally, for example, 220 * if 'sw' is preferred and an element is near the right viewable 221 * region edge, but not the top edge, it will set the gravity for 222 * that element's tooltip to be 'se', preserving the southern 223 * component. 224 */ 225 $.fn.tipsy.autoBounds = function(margin, prefer) { 226 return function() { 227 var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)}, 228 boundTop = $(document).scrollTop() + margin, 229 boundLeft = $(document).scrollLeft() + margin, 230 $this = $(this); 231 232 if ($this.offset().top < boundTop) dir.ns = 'n'; 233 if ($this.offset().left < boundLeft) dir.ew = 'w'; 234 if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e'; 235 if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's'; 236 237 return dir.ns + (dir.ew ? dir.ew : ''); 238 } 239 }; 240 241})(jQuery); 242 243 244 245(function( $ ) { 246 $.widget( "ui.combobox", { 247 _create: function() { 248 var elwidth = this.element.width(); 249 var elheight = this.element.height(); 250 var input, 251 self = this, 252 select = this.element, 253 internal = false, 254 selected = select.children( ":selected" ), 255 value = selected.val() ? selected.text() : "", 256 wrapper = this.wrapper = $( "<span>" ) 257 .addClass( "ui-combobox" ) 258 .insertAfter( select ); 259 260 input = $( "<input>" ).css( { "width": (select.is(':visible') ? (elwidth > 15 ? elwidth - 15 : 1) : 350), "height": (elheight > 0 ? elheight : 16) }); 261 select.hide(); 262 input.appendTo( wrapper ) 263 .val( value ) 264 .addClass( "ui-state-default ui-combobox-input" ) 265 .autocomplete({ 266 delay: 0, 267 minLength: 0, 268 source: function( request, response ) { 269 var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); 270 response( select.children( "option" ).map(function() { 271 var text = $( this ).text(); 272 //if ( this.value && ( !request.term || matcher.test(text) ) ) 273 if ( (!request.term || matcher.test(text)) && $(this).css('display') != 'none' ) 274 return { 275 label: (text == "" ? " " : text.replace( 276 new RegExp( 277 "(?![^&;]+;)(?!<[^<>]*)(" + 278 $.ui.autocomplete.escapeRegex(request.term) + 279 ")(?![^<>]*>)(?![^&;]+;)", "gi" 280 ), "<strong>$1</strong>" )), 281 'value': (text ? text : ''), 282 'class': (select.hasClass('flags') ? 'country-' + ($(this).val() ? $(this).val().toUpperCase() : '') : $(this).attr('class')), 283 option: this 284 }; 285 }) ); 286 }, 287 select: function( event, ui ) { 288 ui.item.option.selected = true; 289 self._trigger( "selected", event, { 290 item: ui.item.option 291 }); 292 if((select.onchange || false) && typeof select.onchange == 'function') { 293 select.onchange( { target: select } ); 294 } else if($(select).attr('onchange')) { 295 eval($(select).attr('onchange'));
296 } else { 297 if(!ui.item.internal) { 298 internal = true; 299 $(select).change(); 300 } 301 } 302 if (jQuery(".panel #Filter").length > 0) { 303 jQuery(".panel #Filter").trigger('click'); 304 } 305 }, 306 change: function( event, ui ) { 307 if ( !ui.item ) { 308 var matcher = new RegExp( "" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "", "i" ), 309 matchtext = $(this).val(); 310 valid = false; 311 select.children( "option" ).each(function() { 312 if( (($(this).text() == "" && matchtext == "") || $( this ).text().match( matcher )) && $(this).css('display') != 'none' ) { 313 select.val($(this).val()); 314 this.selected = valid = true; 315 return false; 316 } 317 }); 318 if ( !valid ) { 319 // remove invalid value, as it didn't match anything 320 $( this ).val( "" ); 321 select.val( "" ); 322 input.data( "autocomplete" ).term = ""; 323 return false; 324 } 325 } 326 } 327 }) 328 .keypress(function(event) { 329 if(select.attr('disabled')) { 330 event.preventDefault(); 331 return false; 332 } 333 if(event.keyCode == 13) { 334 event.preventDefault(); 335 var matcher = new RegExp( "" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "", "i" ), 336 matchtext = $(this).val(); 337 valid = false, 338 selected = false; 339 select.children( "option" ).each(function() { 340 if( (($(this).val() == "" && matchtext == "") || $( this ).text().match( matcher )) && $(this).css('display') != 'none' ) { 341 valid = true; 342 selected = $(this); 343 return false; 344 } 345 }); 346 if(!valid) return false; 347 348 $(this).autocomplete('option','select').call($(this), event, { item: { option: selected.get(0), internal: true } }); 349 } 350 }) 351 .addClass( "ui-widget ui-widget-content ui-corner-left" ) 352 .click(function() { 353 if(select.attr('disabled')) { 354 event.preventDefault(); 355 return false; 356 } 357 // close if already visible 358 if ( input.autocomplete( "widget" ).is( ":visible" ) ) { 359 //input.autocomplete( "close" ); 360 return; 361 } 362 363 // pass empty string as value to search for, displaying all results 364 input.autocomplete( "search", "" ); 365 input.focus(); 366 }); 367 if(select.hasClass('flags')) input.addClass('flags'); 368 369 input.data( "autocomplete" )._renderItem = function( ul, item ) { 370 var el = $( "<li></li>" ) 371 .data( "item.autocomplete", item ) 372 .append( "<a>" + item.label + "</a>" ) 373 .appendTo( ul ); 374 if(item && item['class'] && el) el.addClass(item['class']); 375 return el; 376 }; 377 select.change(function(e) { 378 if(internal == true) { 379 internal = false; 380 return; 381 } 382 var matchtext = $(this).val().toLowerCase(); 383 valid = false, 384 selected = false, 385 selected_val = ""; 386 select.children( "option" ).each(function() { 387 if( (($(this).val() == "" && matchtext == "") || $( this ).val().toLowerCase() == matchtext) && $(this).css('display') != 'none' ) { 388 valid = true; 389 selected = $(this); 390 selected_val = $(this).text(); 391 return false; 392 } 393 }); 394 if(!valid) return false; 395 396 input.val(selected_val).autocomplete('option','select').call(input, (e ? e : {target: select}), { item: { option: selected.get(0), internal: true } }); 397 }); 398 399 $( "<a>" ) 400 .attr( "tabIndex", -1 ) 401 .attr( "title", "Show All Items" ) 402 .appendTo( wrapper ) 403 .button({ 404 icons: { 405 primary: "ui-icon-triangle-1-s" 406 }, 407 text: false 408 }) 409 .removeClass( "ui-corner-all" ) 410 .addClass( "ui-corner-right ui-combobox-toggle" ) 411 .css( { "width": 15, "height": (elheight > 0 ? elheight : 16) }) 412 .click(function() { 413 if(select.attr('disabled')) { 414 event.preventDefault(); 415 return false; 416 } 417 // close if already visible 418 if ( input.autocomplete( "widget" ).is( ":visible" ) ) { 419 input.autocomplete( "close" ); 420 return; 421 } 422 423 // work around a bug (likely same cause as #5265) 424 $( this ).blur(); 425 426 // pass empty string as value to search for, displaying all results 427 input.autocomplete( "search", "" ); 428 input.focus(); 429 }); 430 }, 431 432 destroy: function() { 433 this.wrapper.remove(); 434 this.element.show(); 435 $.Widget.prototype.destroy.call( this ); 436 } 437 });
438})( 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.