1/* 2* qTip2 - Pretty powerful tooltips 3* http://craigsworks.com/projects/qtip2/ 4* 5* Version: 2.0.0pre 6* Copyright 2009-2010 Craig Michael Thompson - http://craigsworks.com 7* 8* Dual licensed under MIT or GPLv2 licenses 9* http://en.wikipedia.org/wiki/MIT_License 10* http://en.wikipedia.org/wiki/GNU_General_Public_License 11* 12* Date: Tue Feb 8 23:07:43 2011 +0000 13*/ 14 15"use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ 16/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */ 17/*global window: false, jQuery: false */ 18 19 20(function($, window, undefined) { 21 22 // Munge the primitives - Paul Irish tip 23 var TRUE = true, 24 FALSE = false, 25 NULL = null, 26 27 // Shortcut vars 28 QTIP, PLUGINS, MOUSE, 29 uitooltip = 'ui-tooltip', 30 widget = 'ui-widget', 31 disabled = 'ui-state-disabled', 32 selector = 'div.qtip.'+uitooltip, 33 focusClass = uitooltip + '-focus', 34 hideOffset = '-31000px', 35 replaceSuffix = '_replacedByqTip', 36 oldtitle = 'oldtitle'; 37 38 // Simple console.error wrapper 39 function debug() { 40 var c = window.console; 41 return c && (c.error || c.log || $.noop).apply(c, arguments); 42 } 43// Option object sanitizer 44function sanitizeOptions(opts) 45{ 46 var content; 47 48 if(!opts || 'object' !== typeof opts) { return FALSE; } 49 50 if('object' !== typeof opts.metadata) { 51 opts.metadata = { 52 type: opts.metadata 53 }; 54 } 55 56 if('content' in opts) { 57 if('object' !== typeof opts.content || opts.content.jquery) { 58 opts.content = { 59 text: opts.content 60 }; 61 } 62 63 content = opts.content.text || FALSE; 64 if(!$.isFunction(content) && ((!content && !content.attr) || content.length < 1 || ('object' === typeof content && !content.jquery))) { 65 opts.content.text = FALSE; 66 } 67 68 if('title' in opts.content) { 69 if('object' !== typeof opts.content.title) { 70 opts.content.title = { 71 text: opts.content.title 72 }; 73 } 74 75 content = opts.content.title.text || FALSE; 76 if(!$.isFunction(content) && ((!content && !content.attr) || content.length < 1 || ('object' === typeof content && !content.jquery))) { 77 opts.content.title.text = FALSE; 78 } 79 } 80 } 81 82 if('position' in opts) { 83 if('object' !== typeof opts.position) { 84 opts.position = { 85 my: opts.position, 86 at: opts.position 87 }; 88 } 89 } 90 91 if('show' in opts) { 92 if('object' !== typeof opts.show) { 93 if(opts.show.jquery) { 94 opts.show = { target: opts.show }; 95 } 96 else { 97 opts.show = { event: opts.show }; 98 } 99 } 100 } 101 102 if('hide' in opts) { 103 if('object' !== typeof opts.hide) { 104 if(opts.hide.jquery) { 105 opts.hide = { target: opts.hide }; 106 } 107 else { 108 opts.hide = { event: opts.hide }; 109 } 110 } 111 } 112 113 if('style' in opts) { 114 if('object' !== typeof opts.style) { 115 opts.style = { 116 classes: opts.style 117 }; 118 } 119 } 120 121 // Sanitize plugin options 122 $.each(PLUGINS, function() { 123 if(this.sanitize) { this.sanitize(opts); } 124 }); 125 126 return opts; 127} 128 129/* 130* Core plugin implementation 131*/ 132function QTip(target, options, id, attr) 133{ 134 // Declare this reference 135 var self = this, 136 docBody = document.body, 137 tooltipID = uitooltip + '-' + id, 138 isPositioning = 0, 139 tooltip, elements, cache; 140 141 // Setup class attributes 142 self.id = id; 143 self.rendered = FALSE; 144 self.elements = elements = { target: target }; 145 self.timers = { img: [] }; 146 self.options = options; 147 self.checks = {}; 148 self.plugins = {}; 149 self.cache = cache = { 150 event: {}, 151 target: NULL, 152 disabled: FALSE, 153 attr: attr 154 }; 155 156 /* 157 * Private core functions 158 */ 159 function convertNotation(notation) 160 { 161 var i, obj, 162 163 // Split notation into array 164 actual = notation.split('.'), 165 166 // Locate required option 167 option = options[ actual[0] ]; 168 169 // Loop through 170 for(i = 1; i < actual.length; i+=1) { 171 obj = option[ actual[i] ]; 172 if(typeof obj === 'object' && !obj.jquery && !obj.precedance && !obj.url) { 173 option = option[ actual[i] ]; 174 } 175 else { break; } 176 } 177 178 return actual[i] !== undefined ? [option, actual[i] ] : [options, actual[0]]; 179 } 180 181 function isVisible() { 182 return tooltip && tooltip.css('left') !== hideOffset && tooltip.css('visibility') !== 'hidden'; 183 } 184 185 function setWidget() { 186 var on = options.style.widget; 187 188 tooltip.toggleClass(widget, on); 189 elements.content.toggleClass(widget+'-content', on); 190 191 if(elements.titlebar){ 192 elements.titlebar.toggleClass(widget+'-header', on); 193 } 194 if(elements.button){ 195 elements.button.toggleClass(uitooltip+'-icon', !on); 196 } 197 } 198 199 function removeTitle() 200 { 201 if(elements.title) { 202 elements.titlebar.remove(); 203 elements.titlebar = elements.title = elements.button = NULL; 204 self.reposition(); 205 } 206 } 207 208 function createButton() 209 { 210 var button = options.content.title.button; 211 212 if(elements.button) { elements.button.remove(); } 213 214 // Use custom button if one was supplied by user, else use default 215 if(button.jquery) { 216 elements.button = button; 217 } 218 else { 219 elements.button = $('<a />', { 220 'class': 'ui-state-default ' + (options.style.widget ? '' : uitooltip+'-icon'), 221 'title': 'Close tooltip', 222 'aria-label': 'Close tooltip' 223 }) 224 .prepend( 225 $('<span />', { 226 'class': 'ui-icon ui-icon-close', 227 'html': '×' 228 }) 229 ); 230 } 231 232 // Create button and setup attributes 233 elements.button.appendTo(elements.titlebar) 234 .attr('role', 'button') 235 .hover(function(event){ $(this).toggleClass('ui-state-hover', event.type === 'mouseenter'); }) 236 .click(function(event) { 237 if(!tooltip.hasClass(disabled)) { self.hide(event); } 238 return FALSE; 239 }) 240 .bind('mousedown keydown mouseup keyup mouseout', function(event) { 241 $(this).toggleClass('ui-state-active ui-state-focus', event.type.substr(-4) === 'down'); 242 }); 243 244 // Redraw the tooltip when we're done 245 self.redraw(); 246 } 247 248 function createTitle() 249 { 250 var id = tooltipID+'-title'; 251 252 // Destroy previous title element, if present 253 if(elements.titlebar) { removeTitle(); } 254 255 // Create title bar and title elements 256 elements.titlebar = $('<div />', { 257 'class': uitooltip + '-titlebar ' + (options.style.widget ? 'ui-widget-header' : '') 258 }) 259 .append( 260 elements.title = $('<div />', { 261 'id': id, 262 'class': uitooltip + '-title', 263 'aria-atomic': TRUE 264 }) 265 ) 266 .insertBefore(elements.content); 267 268 // Create button if enabled 269 if(options.content.title.button) { createButton(); } 270 271 // Redraw the tooltip dimensions if it's rendered 272 else if(self.rendered){ self.redraw(); } 273 } 274 275 function updateButton(button) 276 { 277 var elem = elements.button, 278 title = elements.title; 279 280 // Make sure tooltip is rendered and if not, return 281 if(!self.rendered) { return FALSE; } 282 283 if(!button) { 284 elem.remove(); 285 } 286 else { 287 if(!title) { 288 createTitle(); 289 } 290 createButton(); 291 } 292 } 293 294 function updateTitle(content) 295 { 296 var elem = elements.title; 297 298 // Make sure tooltip is rendered and if not, return 299 if(!self.rendered || !content) { return FALSE; } 300 301 // Use function to parse content 302 if($.isFunction(content)) { 303 content = content.call(target, self) || ''; 304 } 305 306 // Append new content if its a DOM array and show it if hidden 307 if(content.jquery && content.length > 0) { 308 elem.empty().append(content.css({ display: 'block' })); 309 } 310 311 // Content is a regular string, insert the new content 312 else { elem.html(content); } 313 314 // Redraw and reposition 315 self.redraw(); 316 if(self.rendered && isVisible()) { 317 self.reposition(cache.event); 318 } 319 } 320 321 function updateContent(content, reposition) 322 { 323 var elem = elements.content; 324 325 // Make sure tooltip is rendered and content is defined. If not return 326 if(!self.rendered || !content) { return FALSE; } 327 328 // Use function to parse content 329 if($.isFunction(content)) { 330 content = content.call(target, self) || ''; 331 } 332 333 // Append new content if its a DOM array and show it if hidden 334 if(content.jquery && content.length > 0) { 335 elem.empty().append(content.css({ display: 'block' })); 336 } 337 338 // Content is a regular string, insert the new content 339 else { elem.html(content); } 340 341 // Insert into 'fx' queue our image dimension checker which will halt the showing of the tooltip until image dimensions can be detected 342 tooltip.queue('fx', function(next) { 343 // Find all content images without dimensions 344 var images = elem.find('img:not([height]):not([width])'); 345 346 // Update tooltip width and position when all images are loaded 347 function imageLoad(img) { 348 // Remove the image from the array 349 images = images.not(img); 350 351 // If queue is empty, update tooltip and continue the queue 352 if(images.length === 0) { 353 self.redraw(); 354 if(self.rendered && isVisible()) { 355 self.reposition(cache.event); 356 } 357 358 next(); 359 } 360 } 361 362 // Apply the callback to img events and height checker method to ensure queue continues no matter what! 363 images.each(function(i, elem) { 364 // Apply the imageLoad to regular events to make sure the queue continues 365 var events = ['abort','error','load','unload',''].join('.qtip-image '); 366 $(this).bind(events, function() { 367 clearTimeout(self.timers.img[i]); 368 imageLoad(this); 369 }); 370 371 // Apply a recursive method that polls the image for dimensions every 20ms 372 (function timer(){ 373 // When the dimensions are found, remove the image from the queue 374 if(elem.height && elem.width) { 375 return imageLoad(elem); 376 } 377 378 self.timers.img[i] = setTimeout(timer, 20); 379 }()); 380 381 return TRUE; 382 }); 383 384 // If no images were found, continue with queue 385 if(images.length === 0) { imageLoad(images); } 386 }); 387 388 return self; 389 } 390 391 function assignEvents(show, hide, tip, doc) 392 { 393 var namespace = '.qtip-'+id, 394 posOptions = options.position, 395 targets = { 396 show: options.show.target, 397 hide: options.hide.target, 398 container: posOptions.container[0] === docBody ? document : posOptions.container 399 }, 400 events = { show: String(options.show.event).split(' '), hide: String(options.hide.event).split(' ') },
401 $doc = $(document), 402 IE6 = $.browser.msie && parseInt($.browser.version, 10) === 6; 403 404 // Define show event method 405 function showMethod(event) 406 { 407 if(tooltip.hasClass(disabled)) { return FALSE; } 408 409 // If set, hide tooltip when inactive for delay period 410 targets.show.trigger('qtip-'+id+'-inactive'); 411 412 // Clear hide timers 413 clearTimeout(self.timers.show); 414 clearTimeout(self.timers.hide); 415 416 // Start show timer 417 var callback = function(){ self.show(event); }; 418 if(options.show.delay > 0) { 419 self.timers.show = setTimeout(callback, options.show.delay); 420 } 421 else{ callback(); } 422 } 423 424 // Define hide method 425 function hideMethod(event) 426 { 427 if(tooltip.hasClass(disabled)) { return FALSE; } 428 429 // Check if new target was actually the tooltip element 430 var relatedTarget = $(event.relatedTarget || event.target), 431 ontoTooltip = relatedTarget.closest(selector)[0] === tooltip[0], 432 ontoTarget = relatedTarget[0] === targets.show[0]; 433 434 // Clear timers and stop animation queue 435 clearTimeout(self.timers.show); 436 clearTimeout(self.timers.hide); 437 438 // Prevent hiding if tooltip is fixed and event target is the tooltip. Or if mouse positioning is enabled and cursor momentarily overlaps 439 if((posOptions.target === 'mouse' && ontoTooltip) || (options.hide.fixed && ((/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget)))) 440 { 441 // Prevent default and popagation 442 event.stopPropagation(); 443 event.preventDefault(); 444 return FALSE; 445 } 446 447 // If tooltip has displayed, start hide timer 448 tooltip.stop(1, 1); 449 450 if(options.hide.delay > 0) { 451 self.timers.hide = setTimeout(function(){ self.hide(event); }, options.hide.delay); 452 } 453 else{ self.hide(event); } 454 } 455 456 // Define inactive method 457 function inactiveMethod(event) 458 { 459 if(tooltip.hasClass(disabled)) { return FALSE; } 460 461 // Clear timer 462 clearTimeout(self.timers.inactive); 463 self.timers.inactive = setTimeout(function(){ self.hide(event); }, options.hide.inactive); 464 } 465 466 function repositionMethod(event) { 467 if(isVisible()) { self.reposition(event); } 468 } 469 470 // Assign tooltip events 471 if(tip) { 472 // Enable hide.fixed 473 if(options.hide.fixed) { 474 // Add tooltip as a hide target 475 targets.hide = targets.hide.add(tooltip); 476 477 // Clear hide timer on tooltip hover to prevent it from closing 478 tooltip.bind('mouseover'+namespace, function() { 479 if(!tooltip.hasClass(disabled)) { 480 clearTimeout(self.timers.hide); 481 } 482 }); 483 } 484 485 // Focus/blur the tooltip 486 tooltip.bind('mouseenter'+namespace+' mouseleave'+namespace, function(event) { 487 self[ event.type === 'mouseenter' ? 'focus' : 'blur' ](event); 488 }); 489 } 490 491 // Assign hide events 492 if(hide) { 493 // Check if the tooltip hides when inactive 494 if('number' === typeof options.hide.inactive) 495 { 496 // Bind inactive method to target as a custom event 497 targets.show.bind('qtip-'+id+'-inactive', inactiveMethod); 498 499 // Define events which reset the 'inactive' event handler 500 $.each(QTIP.inactiveEvents, function(index, type){ 501 targets.hide.add(elements.tooltip).bind(type+namespace+'-inactive', inactiveMethod); 502 }); 503 } 504 505 // Apply hide events 506 $.each(events.hide, function(index, type) { 507 var showIndex = $.inArray(type, events.show), 508 targetHide = $(targets.hide); 509 510 // Both events and targets are identical, apply events using a toggle 511 if((showIndex > -1 && targetHide.add(targets.show).length === targetHide.length) || type === 'unfocus') 512 { 513 targets.show.bind(type+namespace, function(event) 514 { 515 if(isVisible()) { hideMethod(event); } 516 else{ showMethod(event); } 517 }); 518 519 // Don't bind the event again 520 delete events.show[ showIndex ]; 521 } 522 523 // Events are not identical, bind normally 524 else{ targets.hide.bind(type+namespace, hideMethod); } 525 }); 526 } 527 528 // Apply show events 529 if(show) { 530 $.each(events.show, function(index, type) { 531 targets.show.bind(type+namespace, showMethod); 532 }); 533 } 534 535 // Apply document events 536 if(doc) { 537 // Adjust positions of the tooltip on window resize if enabled 538 if(posOptions.adjust.resize || posOptions.viewport) { 539 $($.event.special.resize ? posOptions.viewport : window).bind('resize'+namespace, repositionMethod); 540 } 541 542 // Adjust tooltip position on scroll if screen adjustment is enabled 543 if(posOptions.viewport || (IE6 && tooltip.css('position') === 'fixed')) { 544 $(posOptions.viewport).bind('scroll'+namespace, repositionMethod); 545 } 546 547 // Hide tooltip on document mousedown if unfocus events are enabled 548 if((/unfocus/i).test(options.hide.event)) { 549 $doc.bind('mousedown'+namespace, function(event) { 550 var $target = $(event.target); 551 552 if($target.parents(selector).length === 0 && $target.add(target).length > 1 && isVisible() && !tooltip.hasClass(disabled)) { 553 self.hide(event); 554 } 555 }); 556 } 557 558 // If mouse is the target, update tooltip position on document mousemove 559 if(posOptions.target === 'mouse') { 560 $doc.bind('mousemove'+namespace, function(event) { 561 // Update the tooltip position only if the tooltip is visible and adjustment is enabled 562 if(posOptions.adjust.mouse && !tooltip.hasClass(disabled) && isVisible()) { 563 self.reposition(event || MOUSE); 564 } 565 }); 566 } 567 } 568 } 569 570 function unassignEvents(show, hide, tooltip, doc) 571 { 572 doc = parseInt(doc, 10) !== 0; 573 var namespace = '.qtip-'+id, 574 targets = { 575 show: show ? options.show.target : NULL, 576 hide: hide ? options.hide.target : NULL, 577 tooltip: tooltip ? elements.tooltip : NULL, 578 content: tooltip ? elements.content : NULL, 579 container: doc ? options.position.container[0] === docBody ? document : options.position.container : NULL, 580 window: doc ? window : NULL 581 }; 582 583 // Check if tooltip is rendered 584 if(self.rendered) 585 { 586 $([]).pushStack( 587 $.grep( 588 [ targets.show, targets.hide, targets.tooltip, targets.container, targets.content, targets.window ], 589 function(){ return this !== null; } 590 ) 591 ) 592 .unbind(namespace); 593 } 594 595 // Tooltip isn't yet rendered, remove render event 596 else if(show) { targets.show.unbind(namespace+'-create'); } 597 } 598 599 // Setup builtin .set() option checks 600 self.checks.builtin = { 601 // Core checks 602 '^id$': function(obj, o, v) { 603 var id = v === TRUE ? QTIP.nextid : v, 604 tooltipID = uitooltip + '-' + id; 605 606 if(id !== FALSE && id.length > 0 && !$('#'+tooltipID).length) { 607 tooltip[0].id = tooltipID; 608 elements.content[0].id = tooltipID + '-content'; 609 elements.title[0].id = tooltipID + '-title'; 610 } 611 }, 612 613 // Content checks 614 '^content.text$': function(obj, o, v){ updateContent(v); }, 615 '^content.title.text$': function(obj, o, v) { 616 // Remove title if content is null 617 if(!v) { return removeTitle(); } 618 619 // If title isn't already created, create it now and update 620 if(!elements.title && v) { createTitle(); } 621 updateTitle(v); 622 }, 623 '^content.title.button$': function(obj, o, v){ updateButton(v); }, 624 625 // Position checks
626 '^position.(my|at)$': function(obj, o, v){ 627 // Parse new corner value into Corner objecct 628 if('string' === typeof v) { 629 obj[o] = new PLUGINS.Corner(v); 630 } 631 }, 632 633 '^position.container$': function(obj, o, v){ 634 if(self.rendered) { tooltip.appendTo(v); } 635 }, 636 637 // Show & hide checks 638 '^(show|hide).(event|target|fixed|delay|inactive)$': function(obj, o, v, p) { 639 var args = o.search(/fixed/i) > -1 ? [0, [0,1,1,1]] : [o.substr(0,3), o.charAt(0) === 's' ? [1,0,0,0] : [0,1,0,0]]; 640 641 if(args[0]) { obj[o] = p; } 642 unassignEvents.apply(self, args[1]); 643 644 if(args[0]) { obj[o] = v; } 645 assignEvents.apply(self, args[1]); 646 }, 647 '^show.ready$': function() { if(!self.rendered) { self.show(); } }, 648 649 // Style checks 650 '^style.classes$': function(obj, o, v) { 651 $.attr(tooltip[0], 'class', uitooltip + ' qtip ui-helper-reset ' + v); 652 }, 653 '^style.widget|content.title': setWidget, 654 655 // Events check 656 '^events.(render|show|move|hide|focus|blur)$': function(obj, o, v) { 657 tooltip[($.isFunction(v) ? '' : 'un') + 'bind']('tooltip'+o, v); 658 } 659 }; 660 661 /* 662 * Public API methods 663 */ 664 $.extend(self, { 665 render: function(show) 666 { 667 if(self.rendered) { return FALSE; } // If tooltip has already been rendered, exit 668 669 var content = options.content.text, 670 title = options.content.title.text, 671 callback = $.Event('tooltiprender'); 672 673 // Add ARIA attributes to target 674 $.attr(target[0], 'aria-describedby', tooltipID); 675 676 // Create tooltip element 677 tooltip = elements.tooltip = $('<div/>') 678 .attr({ 679 'id': tooltipID, 680 'class': uitooltip + ' qtip ui-helper-reset ' + options.style.classes, 681 682 /* ARIA specific attributes */ 683 'role': 'alert', 684 'aria-live': 'polite', 685 'aria-atomic': FALSE, 686 'aria-describedby': tooltipID + '-content', 687 'aria-hidden': TRUE 688 }) 689 .toggleClass(disabled, cache.disabled) 690 .data('qtip', self) 691 .appendTo(options.position.container) 692 .append( 693 // Create content element 694 elements.content = $('<div />', { 695 'class': uitooltip + '-content', 696 'id': tooltipID + '-content', 697 'aria-atomic': TRUE 698 }) 699 ); 700 701 // Set rendered status 702 self.rendered = TRUE; 703 704 // Update title and content 705 if(title) { 706 createTitle(); 707 updateTitle(title); 708 } 709 updateContent(content); 710 711 // Setup widget classes 712 setWidget(); 713 714 // Initialize 'render' plugins 715 $.each(PLUGINS, function() { 716 if(this.initialize === 'render') { this(self); } 717 }); 718 719 // Assign events 720 assignEvents(1, 1, 1, 1); 721 $.each(options.events, function(name, callback) { 722 if(callback) { 723 var events = name === 'toggle' ? 'tooltipshow tooltiphide' : 'tooltip'+name; 724 tooltip.bind(events, callback); 725 } 726 }); 727 728 // Set visibility AFTER plugin initialization to prevent issues in IE 729 tooltip.css('visibility', 'hidden') 730 731 /* Queue this part of the render process in our fx queue so we can 732 * load images before the tooltip renders fully. 733 * 734 * See: updateContent method 735 */ 736 .queue('fx', function(next) { 737 // Trigger tooltiprender event and pass original triggering event as original 738 callback.originalEvent = cache.event; 739 tooltip.trigger(callback, [self]); 740 741 // Update tooltip position and show tooltip if needed 742 if(options.show.ready || show) { 743 self.show(cache.event); 744 } 745 746 next(); // Move on 747 }); 748 749 return self; 750 }, 751 752 get: function(notation) 753 { 754 var result, o; 755 756 switch(notation.toLowerCase()) 757 { 758 case 'dimensions': 759 // Find initial dimensions 760 result = { 761 height: tooltip.outerHeight(), 762 width: tooltip.outerWidth() 763 }; 764 break; 765 766 case 'offset': 767 result = PLUGINS.offset(tooltip, options.position.container); 768 break; 769 770 default: 771 o = convertNotation(notation.toLowerCase()); 772 result = (o[0].precedance) ? o[0].string() : (o[0].jquery) ? o[0] : o[0][ o[1] ]; 773 break; 774 } 775 776 return result; 777 }, 778 779 set: function(option, value) 780 { 781 var rmove = /^position.(my|at|adjust|target|container)|style|content/i, 782 reposition = FALSE, 783 checks = self.checks, 784 name; 785 786 function set(notation, value) { 787 notation = notation.toLowerCase(); 788 789 var option = convertNotation(notation), previous, category, rule; 790 791 // Set new option value 792 previous = option[0][ option[1] ]; 793 option[0][ option[1] ] = value.nodeType ? $(value) : value; 794 795 // Execute any valid callbacks (if rendered) 796 if(self.rendered) { 797 for(category in checks) { 798 for(rule in checks[category]) { 799 if((new RegExp(rule, 'i')).test(notation)) { 800 checks[category][rule].call(self, option[0], option[1], value, previous); 801 } 802 } 803 } 804 } 805 806 // If we're not rendered and show.ready was set, render it 807 else if(notation === 'show.ready') { self.render(TRUE); } 808 } 809 810 // Convert singular option/value pair into object form 811 if('string' === typeof option) { 812 name = option; option = {}; option[name] = value; 813 } 814 815 /* 816 * Set each option/value pair in the object. 817 * Also set isPositioning so we don't get loads of redundant repositioning calls 818 */ 819 isPositioning = 1; 820 for(name in option) { 821 set(name, option[name]); 822 reposition = rmove.test(name) || reposition; 823 } 824 isPositioning = 0; 825 826 // Update position on ANY style/position/content change if shown and rendered 827 if(reposition && isVisible() && self.rendered) { self.reposition(); } 828 829 // Re-sanitize options 830 sanitizeOptions(options); 831 832 return self; 833 }, 834 835 toggle: function(state, event) 836 { 837 // Make sure tooltip is rendered 838 if(!self.rendered) { 839 if(state) { self.render(1); } // Render the tooltip if showing and it isn't already 840 else { return FALSE; } 841 } 842 843 var type = state ? 'show' : 'hide', 844 opts = options[type], 845 visible = isVisible(), 846 callback; 847 848 // Detect state if valid one isn't provided 849 if((typeof state).search('boolean|number')) { state = !visible; } 850 851 // Return if element is already in correct state 852 if(visible === state) { return self; } 853 854 // Try to prevent flickering when tooltip overlaps show element 855 if(event) { 856 if((/over|enter/).test(event.type) && (/out|leave/).test(cache.event.type) && 857 event.target === options.show.target[0] && tooltip.has(event.relatedTarget).length){ 858 return self; 859 } 860 861 // Cache event 862 cache.event = $.extend({}, event); 863 } 864 865 // Call API methods 866 callback = $.Event('tooltip'+type);
867 callback.originalEvent = event ? cache.event : NULL; 868 tooltip.trigger(callback, [self, 90]); 869 if(callback.isDefaultPrevented()){ return self; } 870 871 // Set ARIA hidden status attribute 872 $.attr(tooltip[0], 'aria-hidden', !!!state); 873 874 // Execute state specific properties 875 if(state) { 876 tooltip.hide().css({ visibility: '' }); // Hide it first so effects aren't skipped 877 878 // Focus the tooltip 879 self.focus(event); 880 881 // Update tooltip position (without animation) 882 self.reposition(event, 0); 883 884 // Hide other tooltips if tooltip is solo 885 if(opts.solo) { $(selector).not(tooltip).qtip('hide', callback); } 886 } 887 else { 888 // Clear show timer if we're hiding 889 clearTimeout(self.timers.show); 890 891 // Blur the tooltip 892 self.blur(event); 893 } 894 895 // Define post-animation state specific properties 896 function after() { 897 // Prevent antialias from disappearing in IE by removing filter 898 if(state) { 899 if($.browser.msie) { tooltip[0].style.removeAttribute('filter'); } 900 } 901 // Hide the tooltip using negative offset and reset opacity 902 else { 903 tooltip.css({ 904 display: '', 905 visibility: 'hidden', 906 width: '', 907 opacity: '', 908 left: '', 909 top: '' 910 }); 911 } 912 } 913 914 // Clear animation queue 915 tooltip.stop(1, 1); 916 917 // Use custom function if provided 918 if($.isFunction(opts.effect)) { 919 opts.effect.call(tooltip, self); 920 tooltip.queue('fx', function(next){ after.call(this, next); next(); }); 921 } 922 923 // If no effect type is supplied, use a simple toggle 924 else if(opts.effect === FALSE) { 925 tooltip[ type ](); 926 after.call(tooltip); 927 } 928 929 // Use basic fade function by default 930 else { tooltip.fadeTo(90, state ? 1 : 0, after); } 931 932 // If inactive hide method is set, active it 933 if(state) { opts.target.trigger('qtip-'+id+'-inactive'); } 934 935 return self; 936 }, 937 938 show: function(event){ return self.toggle(TRUE, event); }, 939 940 hide: function(event){ return self.toggle(FALSE, event); }, 941 942 focus: function(event) 943 { 944 if(!self.rendered) { return FALSE; } 945 946 var qtips = $(selector), 947 curIndex = parseInt(tooltip[0].style.zIndex, 10), 948 newIndex = QTIP.zindex + qtips.length, 949 cachedEvent = $.extend({}, event), 950 focusedElem, callback; 951 952 // Only update the z-index if it has changed and tooltip is not already focused 953 if(!tooltip.hasClass(focusClass)) 954 { 955 // Only update z-index's if they've changed' 956 if(curIndex !== newIndex) { 957 // Reduce our z-index's and keep them properly ordered 958 qtips.each(function() { 959 if(this.style.zIndex > curIndex) { 960 this.style.zIndex = this.style.zIndex - 1; 961 } 962 }); 963 964 // Fire blur event for focused tooltip 965 qtips.filter('.' + focusClass).qtip('blur', cachedEvent); 966 } 967 968 // Call API method 969 callback = $.Event('tooltipfocus'); 970 callback.originalEvent = cachedEvent; 971 tooltip.trigger(callback, [self, newIndex]); 972 973 // If callback wasn't FALSE 974 if(!callback.isDefaultPrevented()) { 975 // Set the new z-index 976 tooltip.addClass(focusClass)[0].style.zIndex = newIndex; 977 } 978 } 979 980 return self; 981 }, 982 983 blur: function(event) { 984 var cachedEvent = $.extend({}, event), 985 callback; 986 987 // Set focused status to FALSE 988 tooltip.removeClass(focusClass); 989 990 // Trigger blur event 991 callback = $.Event('tooltipblur'); 992 callback.originalEvent = cachedEvent; 993 tooltip.trigger(callback, [self]); 994 995 return self; 996 }, 997 998 reposition: function(event, effect) 999 { 1000 if(!self.rendered || isPositioning) { return FALSE; } 1001 1002 // Set positioning flag 1003 isPositioning = TRUE; 1004 1005 var target = options.position.target, 1006 posOptions = options.position, 1007 my = posOptions.my, 1008 at = posOptions.at, 1009 adjust = posOptions.adjust, 1010 elemWidth = tooltip.outerWidth(), 1011 elemHeight = tooltip.outerHeight(), 1012 targetWidth = 0, 1013 targetHeight = 0, 1014 callback = $.Event('tooltipmove'), 1015 fixed = tooltip.css('position') === 'fixed', 1016 viewport = posOptions.viewport.jquery ? posOptions.viewport : $(window), 1017 position = { left: 0, top: 0 }, 1018 tip = (self.plugins.tip || {}).corner, 1019 readjust = { 1020 left: function(posLeft) { 1021 var viewportScroll = viewport.scrollLeft, 1022 myWidth = my.x === 'left' ? elemWidth : my.x === 'right' ? -elemWidth : -elemWidth / 2, 1023 atWidth = at.x === 'left' ? targetWidth : at.x === 'right' ? -targetWidth : -targetWidth / 2, 1024 tipAdjust = tip && tip.precedance === 'x' ? QTIP.defaults.style.tip.width : 0, 1025 overflowLeft = viewportScroll - posLeft - tipAdjust, 1026 overflowRight = posLeft + elemWidth - viewport.width - viewportScroll + tipAdjust, 1027 offset = myWidth - (my.precedance === 'x' || my.x === my.y ? atWidth : 0), 1028 isCenter = my.x === 'center'; 1029 1030 if(overflowLeft > 0 && (my.x !== 'left' || overflowRight > 0)) { 1031 position.left -= offset + (isCenter ? 0 : 2 * adjust.x); 1032 } 1033 else if(overflowRight > 0 && (my.x !== 'right' || overflowLeft > 0) ) { 1034 position.left -= isCenter ? -offset : offset + (2 * adjust.x); 1035 } 1036 if(position.left !== posLeft && isCenter) { position.left -= adjust.x; } 1037 1038 // Make sure we haven't made things worse with the adjustment and return the adjusted difference 1039 if(position.left < 0 && -position.left > overflowRight) { position.left = posLeft; } 1040 return position.left - posLeft; 1041 }, 1042 top: function(posTop) { 1043 var viewportScroll = viewport.scrollTop, 1044 myHeight = my.y === 'top' ? elemHeight : my.y === 'bottom' ? -elemHeight : -elemHeight / 2, 1045 atHeight = at.y === 'top' ? targetHeight : at.y === 'bottom' ? -targetHeight : -targetHeight / 2, 1046 tipAdjust = tip && tip.precedance === 'y' ? QTIP.defaults.style.tip.height : 0,
1047 overflowTop = viewportScroll - posTop - tipAdjust, 1048 overflowBottom = posTop + elemHeight - viewport.height - viewportScroll + tipAdjust, 1049 offset = myHeight - (my.precedance === 'y' || my.x === my.y ? atHeight : 0), 1050 isCenter = my.y === 'center'; 1051 1052 if(overflowTop > 0 && (my.y !== 'top' || overflowBottom > 0)) { 1053 position.top -= offset + (isCenter ? 0 : 2 * adjust.y); 1054 } 1055 else if(overflowBottom > 0 && (my.y !== 'bottom' || overflowTop > 0) ) { 1056 position.top -= isCenter ? -offset : offset + (2 * adjust.y); 1057 } 1058 if(position.top !== posTop && isCenter) { position.top -= adjust.y; } 1059 1060 // Make sure we haven't made things worse with the adjustment and return the adjusted difference 1061 if(position.top < 0 && -position.top > overflowBottom) { position.top = posTop; } 1062 return position.top - posTop; 1063 } 1064 }; 1065 effect = effect === undefined || !!effect || FALSE; 1066 1067 // Cache our viewport details 1068 viewport = !viewport ? FALSE : { 1069 elem: viewport, 1070 height: viewport[ (viewport[0] === window ? 'h' : 'outerH') + 'eight' ](), 1071 width: viewport[ (viewport[0] === window ? 'w' : 'outerW') + 'idth' ](), 1072 scrollLeft: viewport.scrollLeft(), 1073 scrollTop: viewport.scrollTop() 1074 }; 1075 1076 // Check if mouse was the target 1077 if(target === 'mouse') { 1078 // Force left top to allow flipping 1079 at = { x: 'left', y: 'top' }; 1080 1081 // Use cached event if one isn't available for positioning 1082 event = event && (event.type === 'resize' || event.type === 'scroll') ? cache.event : 1083 adjust.mouse || !event || !event.pageX ? $.extend({}, MOUSE) : event; 1084 1085 // Use event coordinates for position 1086 position = { top: event.pageY, left: event.pageX }; 1087 } 1088 else { 1089 // Check if event targetting is being used 1090 if(target === 'event') { 1091 if(event && event.target && event.type !== 'scroll' && event.type !== 'resize') { 1092 target = cache.target = $(event.target); 1093 } 1094 else { 1095 target = cache.target; 1096 } 1097 } 1098 1099 // Parse the target into a jQuery object and make sure there's an element present 1100 target = $(target).eq(0); 1101 if(target.length === 0) { return self; } 1102 1103 // Check if window or document is the target 1104 else if(target[0] === document || target[0] === window) { 1105 targetWidth = target.width(); 1106 targetHeight = target.height(); 1107 1108 if(target[0] === window) { 1109 position = { 1110 top: fixed ? 0 : viewport.scrollTop, 1111 left: fixed ? 0 : viewport.scrollLeft 1112 }; 1113 } 1114 } 1115 1116 // Use Imagemap/SVG plugins if needed 1117 else if(target.is('area') && PLUGINS.imagemap) { 1118 position = PLUGINS.imagemap(target, at); 1119 } 1120 else if(target[0].namespaceURI == 'http://www.w3.org/2000/svg' && PLUGINS.svg) { 1121 position = PLUGINS.svg(target, at); 1122 } 1123 1124 else { 1125 targetWidth = target.outerWidth(); 1126 targetHeight = target.outerHeight(); 1127 1128 position = PLUGINS.offset(target, posOptions.container); 1129 } 1130 1131 // Parse returned plugin values into proper variables 1132 if(position.offset) { 1133 targetWidth = position.width; 1134 targetHeight = position.height; 1135 position = position.offset; 1136 } 1137 1138 // Adjust position relative to target 1139 position.left += at.x === 'right' ? targetWidth : at.x === 'center' ? targetWidth / 2 : 0; 1140 position.top += at.y === 'bottom' ? targetHeight : at.y === 'center' ? targetHeight / 2 : 0; 1141 } 1142 1143 // Adjust position relative to tooltip 1144 position.left += adjust.x + (my.x === 'right' ? -elemWidth : my.x === 'center' ? -elemWidth / 2 : 0); 1145 position.top += adjust.y + (my.y === 'bottom' ? -elemHeight : my.y === 'center' ? -elemHeight / 2 : 0); 1146 1147 // Calculate collision offset values 1148 if(posOptions.viewport.jquery && target[0] !== window && target[0] !== docBody) { 1149 position.adjusted = { left: readjust.left(position.left), top: readjust.top(position.top) }; 1150 } 1151 else { 1152 position.adjusted = { left: 0, top: 0 }; 1153 } 1154 1155 // Set tooltip position class 1156 tooltip.attr('class', function(i, val) { 1157 return $.attr(this, 'class').replace(/ui-tooltip-pos-\w+/i, ''); 1158 }) 1159 .addClass(uitooltip + '-pos-' + my.abbreviation()); 1160 1161 // Call API method 1162 callback.originalEvent = $.extend({}, event); 1163 tooltip.trigger(callback, [self, position, viewport.elem]); 1164 if(callback.isDefaultPrevented()){ return self; } 1165 delete position.adjusted; 1166 1167 // If effect is disabled or positioning gives NaN out, set CSS directly 1168 if(!effect || !isNaN(position.left, position.top)) { 1169 tooltip.css(position); 1170 } 1171 1172 // Use custom function if provided 1173 else if(isVisible() && $.isFunction(posOptions.effect)) { 1174 posOptions.effect.call(tooltip, self, position); 1175 tooltip.queue(function(next) { 1176 var elem = $(this); 1177 // Reset attributes to avoid cross-browser rendering bugs 1178 elem.css({ opacity: '', height: '' }); 1179 if($.browser.msie && this.style) { this.style.removeAttribute('filter'); } 1180 1181 next(); 1182 }); 1183 } 1184 1185 // Set positioning flag 1186 isPositioning = FALSE; 1187 1188 return self; 1189 }, 1190 1191 // IE max/min height/width simulartor function 1192 redraw: function() 1193 { 1194 // Make sure tooltip is rendered and the browser needs the redraw 1195 if(!self.rendered || !($.browser.msie && $.browser.version < 8)) { return FALSE; } 1196 1197 var fluid = uitooltip + '-fluid', dimensions; 1198 1199 // Reset the height and width and add the fluid class to reset max/min widths 1200 tooltip.css({ width: 'auto', height: 'auto' }).addClass(fluid); 1201 1202 // Grab our tooltip dimensions 1203 dimensions = { 1204 height: tooltip.outerHeight(), 1205 width: tooltip.outerWidth() 1206 }; 1207 1208 // Determine actual width 1209 $.each(['width', 'height'], function(i, prop) { 1210 // Parse our max/min properties 1211 var max = parseInt(tooltip.css('max-'+prop), 10) || 0, 1212 min = parseInt(tooltip.css('min-'+prop), 10) || 0; 1213 1214 // Determine new dimension size based on max/min/current values 1215 dimensions[prop] = max + min ? Math.min( Math.max( dimensions[prop], min ), max ) : dimensions[prop]; 1216 }); 1217 1218 // Set the newly calculated dimensions and remvoe fluid class 1219 tooltip.css(dimensions).removeClass(fluid); 1220 1221 return self; 1222 }, 1223 1224 enable: function() { self.disable(TRUE); }, 1225 disable: function(state) 1226 { 1227 var c = disabled; 1228 1229 if('boolean' !== typeof state) {
1230 state = !(tooltip.hasClass(c) || cache.disabled); 1231 } 1232 1233 if(self.rendered) { 1234 tooltip.toggleClass(c, state); 1235 $.attr(tooltip[0], 'aria-disabled', state); 1236 } 1237 else { 1238 cache.disabled = !!state; 1239 } 1240 1241 return self; 1242 }, 1243 1244 destroy: function() 1245 { 1246 var t = target[0], 1247 title = $.data(t, oldtitle); 1248 1249 // Destroy tooltip and any associated plugins if rendered 1250 if(self.rendered) { 1251 tooltip.remove(); 1252 1253 $.each(self.plugins, function() { 1254 if(this.destroy) { this.destroy(); } 1255 }); 1256 } 1257 1258 // Clear timers and remove bound events 1259 clearTimeout(self.timers.show); 1260 clearTimeout(self.timers.hide); 1261 unassignEvents(1, 1, 1, 1); 1262 1263 // Remove api object 1264 $.removeData(t, 'qtip'); 1265 1266 // Reset old title attribute if removed 1267 if(title) { 1268 $.attr(t, 'title', title); 1269 } 1270 1271 // Remove ARIA attributse 1272 target.removeAttr('aria-describedby'); 1273 1274 return target; 1275 } 1276 }); 1277} 1278 1279// Initialization method 1280function init(id, opts) 1281{ 1282 var obj, posOptions, attr, config, 1283 1284 // Setup element references 1285 elem = $(this), 1286 docBody = $(document.body), 1287 1288 // Use document body instead of document element if needed 1289 newTarget = this === document ? docBody : elem, 1290 1291 // Grab metadata from element if plugin is present 1292 metadata = (elem.metadata) ? elem.metadata(opts.metadata) : NULL, 1293 1294 // If metadata type if HTML5, grab 'name' from the object instead, or use the regular data object otherwise 1295 metadata5 = opts.metadata.type === 'html5' && metadata ? metadata[opts.metadata.name] : NULL, 1296 1297 // Grab data from metadata.name (or data-qtipopts as fallback) using .data() method, 1298 html5 = elem.data(opts.metadata.name || 'qtipopts'); 1299 1300 // If we don't get an object returned attempt to parse it manualyl without parseJSON 1301 try { html5 = typeof html5 === 'string' ? (new Function("return " + html5))() : html5; } 1302 catch(e) { debug('Unable to parse HTML5 attribute data: ' + html5); } 1303 1304 // Merge in and sanitize metadata 1305 config = $.extend(TRUE, {}, QTIP.defaults, opts, 1306 typeof html5 === 'object' ? sanitizeOptions(html5) : NULL, 1307 sanitizeOptions(metadata5 || metadata)); 1308 1309 // Remove metadata object so we don't interfere with other metadata calls 1310 if(metadata) { $.removeData(this, 'metadata'); } 1311 1312 // Re-grab our positioning options now we've merged our metadata and set id to passed value 1313 posOptions = config.position; 1314 config.id = id; 1315 1316 // Setup missing content if none is detected 1317 if('boolean' === typeof config.content.text) { 1318 attr = elem.attr(config.content.attr); 1319 1320 // Grab from supplied attribute if available 1321 if(config.content.attr !== FALSE && attr) { config.content.text = attr; } 1322 1323 // No valid content was found, abort render 1324 else { return FALSE; } 1325 } 1326 1327 // Setup target options 1328 if(posOptions.container === FALSE) { posOptions.container = docBody; } 1329 if(posOptions.target === FALSE) { posOptions.target = newTarget; } 1330 if(config.show.target === FALSE) { config.show.target = newTarget; } 1331 if(config.hide.target === FALSE) { config.hide.target = newTarget; } 1332 if(config.position.viewport === TRUE) { config.position.viewport = posOptions.container; } 1333 1334 // Convert position corner values into x and y strings 1335 posOptions.at = new PLUGINS.Corner(posOptions.at); 1336 posOptions.my = new PLUGINS.Corner(posOptions.my); 1337 1338 // Destroy previous tooltip if overwrite is enabled, or skip element if not 1339 if($.data(this, 'qtip')) { 1340 if(config.overwrite) { 1341 elem.qtip('destroy'); 1342 } 1343 else if(config.overwrite === FALSE) { 1344 return FALSE; 1345 } 1346 } 1347 1348 // Remove title attribute and store it if present 1349 if($.attr(this, 'title')) { 1350 $.data(this, oldtitle, $.attr(this, 'title')); 1351 elem.removeAttr('title'); 1352 } 1353 1354 // Initialize the tooltip and add API reference 1355 obj = new QTip(elem, config, id, !!attr); 1356 $.data(this, 'qtip', obj); 1357 1358 // Catch remove events on target element to destroy redundant tooltip 1359 elem.bind('remove.qtip', function(){ obj.destroy(); }); 1360 1361 return obj; 1362} 1363 1364// jQuery $.fn extension method 1365QTIP = $.fn.qtip = function(options, notation, newValue) 1366{ 1367 var command = String(options).toLowerCase(), // Parse command 1368 returned = NULL, 1369 args = command === 'disable' ? [TRUE] : $.makeArray(arguments).slice(1, 10), 1370 event = args[args.length - 1], 1371 opts = this[0] ? $.data(this[0], 'qtip') : NULL; 1372 1373 // Check for API request 1374 if((!arguments.length && opts) || command === 'api') { 1375 return opts; 1376 } 1377 1378 // Execute API command if present 1379 else if('string' === typeof options) 1380 { 1381 this.each(function() 1382 { 1383 var api = $.data(this, 'qtip'); 1384 if(!api) { return TRUE; } 1385 1386 // Cache the event if possible 1387 if(event && event.timeStamp) { api.cache.event = event; } 1388 1389 // Call APIcommand 1390 if((/option|set/).test(command) && notation) { 1391 if($.isPlainObject(notation) || newValue !== undefined) { 1392 api.set(notation, newValue); 1393 } 1394 else { 1395 returned = api.get(notation); 1396 } 1397 } 1398 1399 // Execute API command 1400 else if(api[command]) { 1401 api[command].apply(api[command], args); 1402 } 1403 }); 1404 1405 return returned !== NULL ? returned : this; 1406 } 1407 1408 // No API commands. validate provided options and setup qTips 1409 else if('object' === typeof options || !arguments.length) 1410 { 1411 opts = sanitizeOptions($.extend(TRUE, {}, options)); 1412 1413 // Bind the qTips 1414 return QTIP.bind.call(this, opts, event); 1415 } 1416}; 1417 1418// $.fn.qtip Bind method 1419QTIP.bind = function(opts, event) 1420{ 1421 return this.each(function(i) { 1422 var options, targets, events, 1423 1424 // Find next available ID, or use custom ID if provided 1425 id = (!opts.id || opts.id === FALSE || opts.id.length < 1 || $('#'+uitooltip+'-'+opts.id).length) ? QTIP.nextid++ : opts.id, 1426 1427 // Setup events namespace 1428 namespace = '.qtip-'+id+'-create', 1429 1430 // Initialize the qTip and re-grab newly sanitized options 1431 api = init.call(this, id, opts); 1432 if(api === FALSE) { return TRUE; } 1433 options = api.options; 1434 1435 // Initialize plugins 1436 $.each(PLUGINS, function() { 1437 if(this.initialize === 'initialize') { this(api); } 1438 }); 1439 1440 // Determine hide and show targets 1441 targets = { show: options.show.target, hide: options.hide.target }; 1442 events = { 1443 show: String(options.show.event).replace(' ', namespace+' ') + namespace, 1444 hide: String(options.hide.event).replace(' ', namespace+' ') + namespace 1445 }; 1446 1447 // Define hoverIntent function 1448 function hoverIntent(event) { 1449 function render() {
1450 // Cache mouse coords,render and render the tooltip 1451 api.render(typeof event === 'object' || options.show.ready); 1452 1453 // Unbind show and hide event 1454 targets.show.unbind(events.show); 1455 targets.hide.unbind(events.hide); 1456 } 1457 1458 // Only continue if tooltip isn't disabled 1459 if(api.cache.disabled) { return FALSE; } 1460 1461 // Cache the event data 1462 api.cache.event = $.extend({}, event); 1463 1464 // Start the event sequence 1465 if(options.show.delay > 0) { 1466 clearTimeout(api.timers.show); 1467 api.timers.show = setTimeout(render, options.show.delay); 1468 if(events.show !== events.hide) { 1469 targets.hide.bind(events.hide, function() { clearTimeout(api.timers.show); }); 1470 } 1471 } 1472 else { render(); } 1473 } 1474 1475 // Bind show events to target 1476 targets.show.bind(events.show, hoverIntent); 1477 1478 // Prerendering is enabled, create tooltip now 1479 if(options.show.ready || options.prerender) { hoverIntent(event); } 1480 }); 1481}; 1482 1483// Setup base plugins 1484PLUGINS = QTIP.plugins = { 1485 // Corner object parser 1486 Corner: function(corner) { 1487 corner = String(corner).replace(/([A-Z])/, ' $1').replace(/middle/gi, 'center').toLowerCase(); 1488 this.x = (corner.match(/left|right/i) || corner.match(/center/) || ['inherit'])[0].toLowerCase(); 1489 this.y = (corner.match(/top|bottom|center/i) || ['inherit'])[0].toLowerCase(); 1490 1491 this.precedance = (corner.charAt(0).search(/^(t|b)/) > -1) ? 'y' : 'x'; 1492 this.string = function() { return this.precedance === 'y' ? this.y+this.x : this.x+this.y; }; 1493 this.abbreviation = function() { 1494 var x = this.x.substr(0,1), y = this.y.substr(0,1); 1495 return x === y ? x : (x === 'c' || (x !== 'c' && y !== 'c')) ? y + x : x + y; 1496 }; 1497 }, 1498 1499 // Custom (more correct for qTip!) offset calculator 1500 offset: function(elem, container) { 1501 var pos = elem.offset(), 1502 parent = container, 1503 deep = 0, 1504 addScroll = !PLUGINS.iOS, 1505 coffset; 1506 1507 if(parent) { 1508 // Compensate for non-static containers offset 1509 do { 1510 if(parent[0] === document.body) { break; } 1511 else if(parent.css('position') !== 'static') { 1512 coffset = parent.position(); 1513 pos.left -= coffset.left; 1514 pos.top -= coffset.top; 1515 1516 deep++; 1517 } 1518 } 1519 while(parent = parent.offsetParent()); 1520 1521 // Compensate for containers scroll if it also has an offsetParent 1522 if(!addScroll || deep > 1) { 1523 coffset = addScroll ? 1 : -1; 1524 pos.left += coffset * container.scrollLeft(); 1525 pos.top += coffset * container.scrollTop(); 1526 } 1527 } 1528 1529 return pos; 1530 }, 1531 1532 /* 1533 * iOS 4.0 and below scroll fix detection used in offset() function. 1534 */ 1535 iOS: parseFloat(((/CPU.+OS ([0-9_]{3}).*AppleWebkit.*Mobile/i.exec(navigator.userAgent)) || [0,'4_2'])[1].replace('_','.')) < 4.1, 1536 1537 /* 1538 * jQuery-secpfic $.fn overrides 1539 */ 1540 fn: { 1541 /* Allow other plugins to successfully retrieve the title of an element with a qTip applied */ 1542 attr: function(attr, val) { 1543 if(!this.length) { return; } 1544 1545 var self = this[0], 1546 title = 'title', 1547 api = $.data(self, 'qtip'); 1548 1549 if(attr === title) { 1550 if(arguments.length < 2) { 1551 return $.data(self, oldtitle); 1552 } 1553 else if(typeof api === 'object') { 1554 // If qTip is rendered and title was originally used as content, update it 1555 if(api && api.rendered && api.options.content.attr === title && api.cache.attr) { 1556 api.set('content.text', val); 1557 } 1558 1559 // Use the regular attr method to set, then cache the result 1560 $.fn['attr'+replaceSuffix].apply(this, arguments); 1561 $.data(self, oldtitle, $.attr(self, title)); 1562 return this.removeAttr('title'); 1563 } 1564 } 1565 }, 1566 1567 /* Allow clone to correctly retrieve cached title attributes */ 1568 clone: function(keepData) { 1569 var titles = $([]), elem; 1570 1571 // Re-add cached titles before we clone 1572 $('*', this).add(this).each(function() { 1573 var title = $.data(this, oldtitle); 1574 if(title) { 1575 $.attr(this, 'title', title); 1576 titles = titles.add(this); 1577 } 1578 }); 1579 1580 // Clone our element using the real clone method 1581 elem = $.fn['clone'+replaceSuffix].apply(this, arguments); 1582 1583 // Remove the old titles again 1584 titles.removeAttr('title'); 1585 1586 return elem; 1587 }, 1588 1589 /* 1590 * Taken directly from jQuery 1.8.2 widget source code 1591 * Trigger 'remove' event on all elements on removal if jQuery UI isn't present 1592 */ 1593 remove: $.ui ? NULL : function( selector, keepData ) { 1594 $(this).each(function() { 1595 if (!keepData) { 1596 if (!selector || $.filter( selector, [ this ] ).length) { 1597 $('*', this).add(this).each(function() { 1598 $(this).triggerHandler('remove'); 1599 }); 1600 } 1601 } 1602 }); 1603 } 1604 } 1605}; 1606 1607// Apply the fn overrides above 1608$.each(PLUGINS.fn, function(name, func) { 1609 if(!func) { return TRUE; } 1610 1611 var old = $.fn[name+replaceSuffix] = $.fn[name]; 1612 $.fn[name] = function() { 1613 return func.apply(this, arguments) || old.apply(this, arguments); 1614 }; 1615}); 1616 1617// Cache mousemove events for positioning purposes 1618$(window).bind('load.qtip', function() { 1619 var type = 'mousemove'; 1620 $(document).bind(type+'.qtip', function(event) { 1621 MOUSE = { pageX: event.pageX, pageY: event.pageY, type: type }; 1622 }); 1623}); 1624 1625// Set global qTip properties 1626QTIP.version = '2.0.0pre'; 1627QTIP.nextid = 0; 1628QTIP.inactiveEvents = 'click dblclick mousedown mouseup mousemove mouseleave mouseenter'.split(' '); 1629QTIP.zindex = 15000; 1630 1631// Define configuration defaults 1632QTIP.defaults = { 1633 prerender: FALSE, 1634 id: FALSE, 1635 overwrite: TRUE, 1636 content: { 1637 text: TRUE, 1638 attr: 'title', 1639 title: { 1640 text: FALSE, 1641 button: FALSE 1642 } 1643 }, 1644 position: {
1645 my: 'top left', 1646 at: 'bottom right', 1647 target: FALSE, 1648 container: FALSE, 1649 viewport: FALSE, 1650 adjust: { 1651 x: 0, y: 0, 1652 mouse: TRUE, 1653 resize: TRUE 1654 }, 1655 effect: TRUE 1656 }, 1657 show: { 1658 target: FALSE, 1659 event: 'mouseenter', 1660 effect: TRUE, 1661 delay: 90, 1662 solo: FALSE, 1663 ready: FALSE 1664 }, 1665 hide: { 1666 target: FALSE, 1667 event: 'mouseleave', 1668 effect: TRUE, 1669 delay: 0, 1670 fixed: FALSE, 1671 inactive: FALSE 1672 }, 1673 style: { 1674 classes: '', 1675 widget: FALSE 1676 }, 1677 events: { 1678 render: NULL, 1679 move: NULL, 1680 show: NULL, 1681 hide: NULL, 1682 toggle: NULL, 1683 focus: NULL, 1684 blur: NULL 1685 } 1686};function Ajax(api) 1687{ 1688 var self = this, 1689 tooltip = api.elements.tooltip, 1690 opts = api.options.content.ajax, 1691 namespace = '.qtip-ajax', 1692 rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi; 1693 1694 api.checks.ajax = { 1695 '^content.ajax': function(obj, name) { 1696 if(name === 'once') { 1697 self.once(); 1698 } 1699 else if(opts && opts.url) { 1700 self.load(); 1701 } 1702 else { 1703 self.destroy(); 1704 } 1705 } 1706 }; 1707 1708 $.extend(self, { 1709 init: function() 1710 { 1711 // Make sure ajax options are enabled before proceeding 1712 if(opts && opts.url) { 1713 self.load(); 1714 tooltip.one('tooltipshow', self.once); 1715 } 1716 }, 1717 1718 once: function() 1719 { 1720 if(opts.once) { 1721 self.destroy(); 1722 } 1723 else { 1724 tooltip.bind('tooltipshow'+namespace, self.load); 1725 } 1726 }, 1727 1728 load: function() 1729 { 1730 var hasSelector = opts.url.indexOf(' '), 1731 url = opts.url, 1732 selector; 1733 1734 // Check if user delcared a content selector like in .load() 1735 if(hasSelector > -1) { 1736 selector = url.substr(hasSelector); 1737 url = url.substr(0, hasSelector); 1738 } 1739 1740 // Define success handler 1741 function successHandler(content) { 1742 if(selector) { 1743 // Create a dummy div to hold the results and grab the selector element 1744 content = $('<div/>') 1745 // inject the contents of the document in, removing the scripts 1746 // to avoid any 'Permission Denied' errors in IE 1747 .append(content.replace(rscript, "")) 1748 1749 // Locate the specified elements 1750 .find(selector); 1751 } 1752 1753 // Set the content 1754 api.set('content.text', content); 1755 } 1756 1757 // Error handler 1758 function errorHandler(xh, status, error){ api.set('content.text', status + ': ' + error); } 1759 1760 // Setup $.ajax option object and process the request 1761 $.ajax( $.extend({ success: successHandler, error: errorHandler, context: api }, opts, { url: url }) ); 1762 1763 return self; 1764 }, 1765 1766 destroy: function() 1767 { 1768 // Remove bound events 1769 tooltip.unbind(namespace); 1770 } 1771 }); 1772 1773 self.init(); 1774} 1775 1776 1777PLUGINS.ajax = function(api) 1778{ 1779 var self = api.plugins.ajax; 1780 1781 return 'object' === typeof self ? self : (api.plugins.ajax = new Ajax(api)); 1782}; 1783 1784PLUGINS.ajax.initialize = 'render'; 1785 1786// Setup plugin sanitization 1787PLUGINS.ajax.sanitize = function(options) 1788{ 1789 var content = options.content, opts; 1790 if(content && 'ajax' in content) { 1791 opts = content.ajax; 1792 if(typeof opts !== 'object') { opts = options.content.ajax = { url: opts }; } 1793 if('boolean' !== typeof opts.once && opts.once) { opts.once = !!opts.once; } 1794 } 1795}; 1796 1797// Extend original api defaults 1798$.extend(TRUE, QTIP.defaults, { 1799 content: { 1800 ajax: { 1801 once: TRUE 1802 } 1803 } 1804});// Tip coordinates calculator 1805function calculateTip(corner, width, height) 1806{ 1807 var width2 = Math.ceil(width / 2), height2 = Math.ceil(height / 2), 1808 1809 // Define tip coordinates in terms of height and width values 1810 tips = { 1811 bottomright: [[0,0], [width,height], [width,0]], 1812 bottomleft: [[0,0], [width,0], [0,height]], 1813 topright: [[0,height], [width,0], [width,height]], 1814 topleft: [[0,0], [0,height], [width,height]], 1815 topcenter: [[0,height], [width2,0], [width,height]], 1816 bottomcenter: [[0,0], [width,0], [width2,height]], 1817 rightcenter: [[0,0], [width,height2], [0,height]], 1818 leftcenter: [[width,0], [width,height], [0,height2]] 1819 }; 1820 1821 // Set common side shapes 1822 tips.lefttop = tips.bottomright; tips.righttop = tips.bottomleft; 1823 tips.leftbottom = tips.topright; tips.rightbottom = tips.topleft; 1824 1825 return tips[ corner.string() ]; 1826} 1827 1828 1829function Tip(qTip, command) 1830{ 1831 var self = this, 1832 opts = qTip.options.style.tip, 1833 elems = qTip.elements, 1834 tooltip = elems.tooltip, 1835 cache = { 1836 top: 0, 1837 left: 0, 1838 corner: '' 1839 }, 1840 size = { 1841 width: opts.width, 1842 height: opts.height 1843 }, 1844 color = { }, 1845 border = opts.border || 0, 1846 namespace = '.qtip-tip', 1847 hasCanvas = $('<canvas />')[0].getContext; 1848 1849 self.corner = NULL; 1850 self.mimic = NULL; 1851 1852 // Add new option checks for the plugin 1853 qTip.checks.tip = { 1854 '^position.my|style.tip.(corner|mimic|border)$': function() { 1855 // Make sure a tip can be drawn 1856 if(!self.init()) { 1857 self.destroy(); 1858 } 1859 1860 // Reposition the tooltip 1861 qTip.reposition(); 1862 }, 1863 '^style.tip.(height|width)$': function() { 1864 // Re-set dimensions and redraw the tip 1865 size = { 1866 width: opts.width, 1867 height: opts.height 1868 }; 1869 self.create();
1870 self.update(); 1871 1872 // Reposition the tooltip 1873 qTip.reposition(); 1874 }, 1875 '^content.title.text|style.(classes|widget)$': function() { 1876 if(elems.tip) { 1877 self.update(); 1878 } 1879 } 1880 }; 1881 1882 function reposition(event, api, pos, viewport) { 1883 if(!elems.tip) { return; } 1884 1885 var newCorner = $.extend({}, self.corner), 1886 adjusted = pos.adjusted, 1887 offset; 1888 1889 // Make sure our tip position isn't fixed e.g. doesn't adjust with adjust.screen 1890 if(self.corner.fixed !== TRUE) { 1891 // Adjust tip corners 1892 if(adjusted.left) { 1893 newCorner.x = newCorner.x === 'center' ? (adjusted.left > 0 ? 'left' : 'right') : (newCorner.x === 'left' ? 'right' : 'left'); 1894 } 1895 if(adjusted.top) { 1896 newCorner.y = newCorner.y === 'center' ? (adjusted.top > 0 ? 'top' : 'bottom') : (newCorner.y === 'top' ? 'bottom' : 'top'); 1897 } 1898 1899 // Update and redraw the tip if needed 1900 if(newCorner.string() !== cache.corner && (cache.top !== adjusted.top || cache.left !== adjusted.left)) { 1901 offset = self.update(newCorner); 1902 } 1903 } 1904 1905 // Adjust position to accomodate tip dimensions 1906 if(!offset) { offset = self.position(newCorner, 0); } 1907 if(offset.right !== undefined) { offset.left = offset.right; } 1908 if(offset.bottom !== undefined) { offset.top = offset.bottom; } 1909 offset.option = Math.max(0, opts.offset); 1910 1911 pos.left -= offset.left.charAt ? offset.option : (offset.right ? -1 : 1) * offset.left; 1912 pos.top -= offset.top.charAt ? offset.option : (offset.bottom ? -1 : 1) * offset.top; 1913 1914 // Cache details 1915 cache.left = adjusted.left; cache.top = adjusted.top; 1916 cache.corner = newCorner.string(); 1917 } 1918 1919 /* border width calculator */ 1920 function borderWidth(corner, side, backup) { 1921 side = !side ? corner[corner.precedance] : side; 1922 1923 var isTitleTop = elems.titlebar && corner.y === 'top', 1924 elem = isTitleTop ? elems.titlebar : elems.content, 1925 css = 'border-' + side + '-width', 1926 val = parseInt(elem.css(css), 10); 1927 1928 return (backup ? val || parseInt(tooltip.css(css), 10) : val) || 0; 1929 } 1930 1931 function borderRadius(corner) { 1932 var isTitleTop = elems.titlebar && corner.y === 'top', 1933 elem = isTitleTop ? elems.titlebar : elems.content, 1934 moz = $.browser.mozilla, 1935 prefix = moz ? '-moz-' : $.browser.webkit ? '-webkit-' : '', 1936 side = corner.y + (moz ? '' : '-') + corner.x, 1937 css = prefix + (moz ? 'border-radius-' + side : 'border-' + side + '-radius'); 1938 1939 return parseInt(elem.css(css), 10) || parseInt(tooltip.css(css), 10) || 0; 1940 } 1941 1942 function calculateSize(corner) { 1943 var y = corner.precedance === 'y', 1944 width = size [ y ? 'width' : 'height' ], 1945 height = size [ y ? 'height' : 'width' ], 1946 isCenter = corner.string().indexOf('center') > -1, 1947 base = width * (isCenter ? 0.5 : 1), 1948 pow = Math.pow, 1949 round = Math.round, 1950 bigHyp, ratio, result, 1951 1952 smallHyp = Math.sqrt( pow(base, 2) + pow(height, 2) ), 1953 1954 hyp = [ 1955 (border / base) * smallHyp, (border / height) * smallHyp 1956 ]; 1957 hyp[2] = Math.sqrt( pow(hyp[0], 2) - pow(border, 2) ); 1958 hyp[3] = Math.sqrt( pow(hyp[1], 2) - pow(border, 2) ); 1959 1960 bigHyp = smallHyp + hyp[2] + hyp[3] + (isCenter ? 0 : hyp[0]); 1961 ratio = bigHyp / smallHyp; 1962 1963 result = [ round(ratio * height), round(ratio * width) ]; 1964 return { height: result[ y ? 0 : 1 ], width: result[ y ? 1 : 0 ] }; 1965 } 1966 1967 $.extend(self, { 1968 init: function() 1969 { 1970 var enabled = self.detectCorner() && (hasCanvas || $.browser.msie); 1971 1972 // Determine tip corner and type 1973 if(enabled) { 1974 // Create a new tip and draw it 1975 self.create(); 1976 self.update(); 1977 1978 // Bind update events 1979 tooltip.unbind(namespace).bind('tooltipmove'+namespace, reposition); 1980 } 1981 1982 return enabled; 1983 }, 1984 1985 detectCorner: function() 1986 { 1987 var corner = opts.corner, 1988 posOptions = qTip.options.position, 1989 at = posOptions.at, 1990 my = posOptions.my.string ? posOptions.my.string() : posOptions.my; 1991 1992 // Detect corner and mimic properties 1993 if(corner === FALSE || (my === FALSE && at === FALSE)) { 1994 return FALSE; 1995 } 1996 else { 1997 if(corner === TRUE) { 1998 self.corner = new PLUGINS.Corner(my); 1999 } 2000 else if(!corner.string) { 2001 self.corner = new PLUGINS.Corner(corner); 2002 self.corner.fixed = TRUE; 2003 } 2004 } 2005 2006 return self.corner.string() !== 'centercenter'; 2007 }, 2008 2009 detectColours: function() { 2010 var tip = elems.tip.css({ backgroundColor: '', border: '' }), 2011 corner = self.corner, 2012 precedance = corner[ corner.precedance ], 2013 2014 borderSide = 'border-' + precedance + '-color', 2015 borderSideCamel = 'border' + precedance.charAt(0) + precedance.substr(1) + 'Color', 2016 2017 invalid = /rgba?\(0, 0, 0(, 0)?\)|transparent/i, 2018 backgroundColor = 'background-color', 2019 transparent = 'transparent', 2020 2021 useTitle = elems.titlebar && 2022 (corner.y === 'top' || (corner.y === 'center' && tip.position().top + (size.height / 2) + opts.offset < elems.titlebar.outerHeight(1))), 2023 colorElem = useTitle ? elems.titlebar : elems.content; 2024 2025 // Detect tip colours from CSS styles 2026 color.fill = tip.css(backgroundColor) || transparent; 2027 color.border = tip[0].style[ borderSideCamel ]; 2028 2029 // Make sure colours are valid 2030 if(!color.fill || invalid.test(color.fill)) { 2031 color.fill = colorElem.css(backgroundColor); 2032 if(invalid.test(color.fill)) { 2033 color.fill = tooltip.css(backgroundColor); 2034 } 2035 } 2036 if(!color.border || invalid.test(color.border)) { 2037 color.border = tooltip.css(borderSide); 2038 if(invalid.test(color.border) || color.border === $(document.body).css('color')) { 2039 color.border = (colorElem.css(borderSide) !== $(qTip.elements.content).css('color') ? 2040 colorElem.css(borderSide) : transparent); 2041 } 2042 } 2043 2044 // Reset background and border colours 2045 $('*', tip).add(tip).css(backgroundColor, transparent).css('border', '0px dashed transparent'); 2046 }, 2047 2048 create: function() 2049 { 2050 var width = size.width, 2051 height = size.height, 2052 vml; 2053 2054 // Remove previous tip element if present 2055 if(elems.tip) { elems.tip.remove(); } 2056 2057 // Create tip element and prepend to the tooltip 2058 elems.tip = $('<div />', { 'class': 'ui-tooltip-tip' }).css({ width: width, height: height }).prependTo(tooltip); 2059
2060 // Create tip drawing element(s) 2061 if(hasCanvas) { 2062 // save() as soon as we create the canvas element so FF2 doesn't bork on our first restore()! 2063 $('<canvas />').appendTo(elems.tip)[0].getContext('2d').save(); 2064 } 2065 else { 2066 vml = '<vml:shape coordorigin="0,0" style="display:block; position:absolute; behavior:url(#default#VML);"></vml:shape>'; 2067 elems.tip.html( border ? vml += vml : vml ); 2068 } 2069 }, 2070 2071 update: function(corner) 2072 { 2073 var tip = elems.tip, 2074 inner = tip.children(), 2075 width = size.width, 2076 height = size.height, 2077 regular = 'px solid ', 2078 transparent = 'px dashed transparent', // Dashed IE6 border-transparency hack. Awesome! 2079 mimic = opts.mimic, 2080 round = Math.round, 2081 precedance, context, coords, translate, newSize; 2082 2083 // Re-determine tip if not already set 2084 if(!corner) { corner = self.corner; } 2085 2086 // Use corner property if we detect an invalid mimic value 2087 if(mimic === FALSE) { mimic = corner; } 2088 2089 // Otherwise inherit mimic properties from the corner object as necessary 2090 else { 2091 mimic = new PLUGINS.Corner(mimic); 2092 mimic.precedance = corner.precedance; 2093 2094 if(mimic.x === 'inherit') { mimic.x = corner.x; } 2095 else if(mimic.y === 'inherit') { mimic.y = corner.y; } 2096 else if(mimic.x === mimic.y) { 2097 mimic[ corner.precedance ] = corner[ corner.precedance ]; 2098 } 2099 } 2100 precedance = mimic.precedance; 2101 2102 // Update our colours 2103 self.detectColours(); 2104 2105 // Detect border width, taking into account colours 2106 border = color.border === 'transparent' || color.border === '#123456' ? 0 : 2107 opts.border === TRUE ? borderWidth(corner, NULL, TRUE) : opts.border; 2108 2109 // Calculate coordinates 2110 coords = calculateTip(mimic, width , height); 2111 2112 // Determine tip size 2113 newSize = calculateSize(corner); 2114 tip.css(newSize); 2115 2116 // Calculate tip translation 2117 if(corner.precedance === 'y') { 2118 translate = [ 2119 round(mimic.x === 'left' ? border : mimic.x === 'right' ? newSize.width - width - border : (newSize.width - width) / 2), 2120 round(mimic.y === 'top' ? newSize.height - height : 0) 2121 ]; 2122 } 2123 else { 2124 translate = [ 2125 round(mimic.x === 'left' ? newSize.width - width : 0), 2126 round(mimic.y === 'top' ? border : mimic.y === 'bottom' ? newSize.height - height - border : (newSize.height - height) / 2) 2127 ]; 2128 } 2129 2130 // Canvas drawing implementation 2131 if(hasCanvas) { 2132 // Set the canvas size using calculated size 2133 inner.attr(newSize); 2134 2135 // Grab canvas context and clear/save it 2136 context = inner[0].getContext('2d'); 2137 context.restore(); context.save(); 2138 context.clearRect(0,0,3000,3000); 2139 2140 // Translate origin 2141 context.translate(translate[0], translate[1]); 2142 2143 // Draw the tip 2144 context.beginPath(); 2145 context.moveTo(coords[0][0], coords[0][1]); 2146 context.lineTo(coords[1][0], coords[1][1]); 2147 context.lineTo(coords[2][0], coords[2][1]); 2148 context.closePath(); 2149 context.fillStyle = color.fill; 2150 context.strokeStyle = color.border; 2151 context.lineWidth = border * 2; 2152 context.lineJoin = 'miter'; 2153 context.miterLimit = 100; 2154 context.stroke(); 2155 context.fill(); 2156 } 2157 2158 // VML (IE Proprietary implementation) 2159 else { 2160 // Setup coordinates string 2161 coords = 'm' + coords[0][0] + ',' + coords[0][1] + ' l' + coords[1][0] + 2162 ',' + coords[1][1] + ' ' + coords[2][0] + ',' + coords[2][1] + ' xe'; 2163 2164 // Setup VML-specific offset for pixel-perfection 2165 translate[2] = border && /^(r|b)/i.test(corner.string()) ? 1 : 0; 2166 2167 // Set initial CSS 2168 inner.css({ 2169 antialias: ''+(mimic.string().indexOf('center') > -1), 2170 left: translate[0] - (translate[2] * Number(precedance === 'x')), 2171 top: translate[1] - (translate[2] * Number(precedance === 'y')), 2172 width: width + border, 2173 height: height + border 2174 }) 2175 .each(function(i) { 2176 var $this = $(this); 2177 2178 // Set shape specific attributes 2179 $this.attr({ 2180 coordsize: (width+border) + ' ' + (height+border), 2181 path: coords, 2182 fillcolor: color.fill, 2183 filled: !!i, 2184 stroked: !!!i 2185 }) 2186 .css({ display: border || i ? 'block' : 'none' }); 2187 2188 // Check if border is enabled and add stroke element 2189 if(!i && border > 0 && $this.html() === '') { 2190 $this.html( 2191 '<vml:stroke weight="'+(border*2)+'px" color="'+color.border+'" miterlimit="1000" joinstyle="miter" ' + 2192 ' style="behavior:url(#default#VML); display:block;" />' 2193 ); 2194 } 2195 }); 2196 } 2197 2198 return self.position(corner, 1); 2199 }, 2200 2201 // Tip positioning method 2202 position: function(corner, set) 2203 { 2204 var tip = elems.tip, 2205 position = {}, 2206 offset = Math.max(0, opts.offset), 2207 precedance, dimensions, 2208 adjust; 2209 2210 // Return if tips are disabled or tip is not yet rendered 2211 if(opts.corner === FALSE || !tip) { return FALSE; } 2212 2213 // Inherit corner if not provided 2214 corner = corner || self.corner; 2215 precedance = corner.precedance; 2216
2217 // Determine which tip dimension to use for adjustment 2218 dimensions = calculateSize(corner); 2219 2220 // Setup IE specific dimension adjustment 2221 adjust = $.browser.msie && border && /^(b|r)/i.test(corner.string()) ? 1 : 0; 2222 2223 // Calculate tip position 2224 $.each( 2225 precedance === 'y' ? [ corner.x, corner.y ] : [ corner.y, corner.x ], 2226 function(i, side) 2227 { 2228 var b, br; 2229 2230 if(side === 'center') { 2231 b = precedance === 'y' ? 'left' : 'top'; 2232 position[ b ] = '50%'; 2233 position['margin-' + b] = -Math.round(dimensions[ precedance === 'y' ? 'width' : 'height' ] / 2) + offset; 2234 } 2235 else { 2236 b = borderWidth(corner, side, TRUE); 2237 br = borderRadius(corner); 2238 2239 position[ side ] = i || !border ? 2240 borderWidth(corner, side) + (!i ? br : 0) : 2241 offset + (br > b ? br : 0); 2242 } 2243 } 2244 ); 2245 position[ corner[precedance] ] -= dimensions[ precedance === 'x' ? 'width' : 'height' ] + adjust; 2246 2247 // Set and return new position 2248 if(set) { tip.css({ top: '', bottom: '', left: '', right: '', margin: '' }).css(position); } 2249 return position; 2250 }, 2251 2252 destroy: function() 2253 { 2254 // Remov tip and bound events 2255 if(elems.tip) { elems.tip.remove(); } 2256 tooltip.unbind(namespace); 2257 } 2258 }); 2259 2260 self.init(); 2261} 2262 2263PLUGINS.tip = function(api) 2264{ 2265 var self = api.plugins.tip; 2266 2267 return 'object' === typeof self ? self : (api.plugins.tip = new Tip(api)); 2268}; 2269 2270// Initialize tip on render 2271PLUGINS.tip.initialize = 'render'; 2272 2273// Setup plugin sanitization options 2274PLUGINS.tip.sanitize = function(options) 2275{ 2276 var style = options.style, opts; 2277 if(style && 'tip' in style) { 2278 opts = options.style.tip; 2279 if(typeof opts !== 'object'){ options.style.tip = { corner: opts }; } 2280 if(!(/string|boolean/i).test(typeof opts.corner)) { opts.corner = TRUE; } 2281 if(typeof opts.width !== 'number'){ delete opts.width; } 2282 if(typeof opts.height !== 'number'){ delete opts.height; } 2283 if(typeof opts.border !== 'number' && opts.border !== TRUE){ delete opts.border; } 2284 if(typeof opts.offset !== 'number'){ delete opts.offset; } 2285 } 2286}; 2287 2288// Extend original qTip defaults 2289$.extend(TRUE, QTIP.defaults, { 2290 style: { 2291 tip: { 2292 corner: TRUE, 2293 mimic: FALSE, 2294 width: 6, 2295 height: 6, 2296 border: TRUE, 2297 offset: 0 2298 } 2299 } 2300});PLUGINS.imagemap = function(area, corner) 2301{ 2302 var shape = area.attr('shape').toLowerCase(), 2303 baseCoords = area.attr('coords').split(','), 2304 coords = [], 2305 image = $('img[usemap="#'+area.parent('map').attr('name')+'"]'), 2306 imageOffset = image.offset(), 2307 result = { 2308 width: 0, height: 0, 2309 offset: { top: 1e10, right: 0, bottom: 0, left: 1e10 } 2310 }, 2311 i = 0, next = 0; 2312 2313 // POLY area coordinate calculator 2314 // Special thanks to Ed Cradock for helping out with this. 2315 // Uses a binary search algorithm to find suitable coordinates. 2316 function polyCoordinates(result, coords) 2317 { 2318 var i = 0, 2319 compareX = 1, compareY = 1, 2320 realX = 0, realY = 0, 2321 newWidth = result.width, 2322 newHeight = result.height; 2323 2324 // Use a binary search algorithm to locate most suitable coordinate (hopefully) 2325 while(newWidth > 0 && newHeight > 0 && compareX > 0 && compareY > 0) 2326 { 2327 newWidth = Math.floor(newWidth / 2); 2328 newHeight = Math.floor(newHeight / 2); 2329 2330 if(corner.x === 'left'){ compareX = newWidth; } 2331 else if(corner.x === 'right'){ compareX = result.width - newWidth; } 2332 else{ compareX += Math.floor(newWidth / 2); } 2333 2334 if(corner.y === 'top'){ compareY = newHeight; } 2335 else if(corner.y === 'bottom'){ compareY = result.height - newHeight; } 2336 else{ compareY += Math.floor(newHeight / 2); } 2337 2338 i = coords.length; while(i--) 2339 { 2340 if(coords.length < 2){ break; } 2341 2342 realX = coords[i][0] - result.offset.left; 2343 realY = coords[i][1] - result.offset.top; 2344 2345 if((corner.x === 'left' && realX >= compareX) || 2346 (corner.x === 'right' && realX <= compareX) || 2347 (corner.x === 'center' && (realX < compareX || realX > (result.width - compareX))) || 2348 (corner.y === 'top' && realY >= compareY) || 2349 (corner.y === 'bottom' && realY <= compareY) || 2350 (corner.y === 'center' && (realY < compareY || realY > (result.height - compareY)))) { 2351 coords.splice(i, 1); 2352 } 2353 } 2354 } 2355 2356 return { left: coords[0][0], top: coords[0][1] }; 2357 } 2358 2359 // Make sure we account for padding and borders on the image 2360 imageOffset.left += Math.ceil((image.outerWidth() - image.width()) / 2); 2361 imageOffset.top += Math.ceil((image.outerHeight() - image.height()) / 2); 2362 2363 // Parse coordinates into proper array 2364 if(shape === 'poly') {
2365 i = baseCoords.length; while(i--) 2366 { 2367 next = [ parseInt(baseCoords[--i], 10), parseInt(baseCoords[i+1], 10) ]; 2368 2369 if(next[0] > result.offset.right){ result.offset.right = next[0]; } 2370 if(next[0] < result.offset.left){ result.offset.left = next[0]; } 2371 if(next[1] > result.offset.bottom){ result.offset.bottom = next[1]; } 2372 if(next[1] < result.offset.top){ result.offset.top = next[1]; } 2373 2374 coords.push(next); 2375 } 2376 } 2377 else { 2378 coords = $.map(baseCoords, function(coord){ return parseInt(coord, 10); }); 2379 } 2380 2381 // Calculate details 2382 switch(shape) 2383 { 2384 case 'rect': 2385 result = { 2386 width: Math.abs(coords[2] - coords[0]), 2387 height: Math.abs(coords[3] - coords[1]), 2388 offset: { left: coords[0], top: coords[1] } 2389 }; 2390 break; 2391 2392 case 'circle': 2393 result = { 2394 width: coords[2] + 2, 2395 height: coords[2] + 2, 2396 offset: { left: coords[0], top: coords[1] } 2397 }; 2398 break; 2399 2400 case 'poly': 2401 $.extend(result, { 2402 width: Math.abs(result.offset.right - result.offset.left), 2403 height: Math.abs(result.offset.bottom - result.offset.top) 2404 }); 2405 2406 if(corner.string() === 'centercenter') { 2407 result.offset = { 2408 left: result.offset.left + (result.width / 2), 2409 top: result.offset.top + (result.height / 2) 2410 }; 2411 } 2412 else { 2413 result.offset = polyCoordinates(result, coords.slice()); 2414 } 2415 2416 result.width = result.height = 0; 2417 break; 2418 } 2419 2420 // Add image position to offset coordinates 2421 result.offset.left += imageOffset.left; 2422 result.offset.top += imageOffset.top; 2423 2424 return result; 2425}; 2426 2427PLUGINS.svg = function(svg, corner) 2428{ 2429 var doc = $(document), 2430 elem = svg[0], 2431 result = { 2432 width: 0, height: 0, 2433 offset: { top: 1e10, left: 1e10 } 2434 }, 2435 box, mtx, root, point, tPoint; 2436 2437 if (elem.getBBox && elem.parentNode) { 2438 box = elem.getBBox(); 2439 mtx = elem.getScreenCTM(); 2440 root = elem.farthestViewportElement || elem; 2441 2442 // Return if no method is found 2443 if(!root.createSVGPoint) { return result; } 2444 2445 // Create our point var 2446 point = root.createSVGPoint(); 2447 2448 // Adjust top and left 2449 point.x = box.x; 2450 point.y = box.y; 2451 tPoint = point.matrixTransform(mtx); 2452 result.offset.left = tPoint.x; 2453 result.offset.top = tPoint.y; 2454 2455 // Adjust width and height 2456 point.x += box.width; 2457 point.y += box.height; 2458 tPoint = point.matrixTransform(mtx); 2459 result.width = tPoint.x - result.offset.left; 2460 result.height = tPoint.y - result.offset.top; 2461 2462 // Adjust by scroll offset 2463 result.offset.left += doc.scrollLeft(); 2464 result.offset.top += doc.scrollTop(); 2465 } 2466 2467 return result; 2468}; 2469 2470function Modal(api) 2471{ 2472 var self = this, 2473 options = api.options.show.modal, 2474 elems = api.elements, 2475 tooltip = elems.tooltip, 2476 2477 selector = '#qtip-overlay', 2478 namespace = '.qtipmodal', 2479 events = 'tooltipshow'+namespace+' tooltiphide'+namespace; 2480 2481 // Setup option set checks 2482 api.checks.modal = { 2483 '^show.modal.(on|blur)$': function() { 2484 // Initialise 2485 self.init(); 2486 2487 // Show the modal if not visible already and tooltip is visible 2488 elems.overlay.toggle( tooltip.is(':visible') ); 2489 } 2490 }; 2491 2492 $.extend(self, { 2493 init: function() 2494 { 2495 if(options.on) { 2496 // Apply our modal events (unbind the mfirst so we don't duplicate) 2497 tooltip.unbind(namespace).bind(events, function(event, api, duration) { 2498 var type = event.type.replace('tooltip', ''); 2499 2500 if($.isFunction(options[type])) { 2501 options[type].call(elems.overlay, duration, api); 2502 } 2503 else { 2504 self[type](duration); 2505 } 2506 }); 2507 2508 // Create the overlay if needed 2509 self.create(); 2510 2511 // Hide tooltip on overlay click if enabled and toggle cursor style 2512 if(options.blur === TRUE) { 2513 elems.overlay.unbind(namespace+api.id).bind('click'+namespace+api.id, function(){ api.hide.call(api); }); 2514 } 2515 elems.overlay.css('cursor', options.blur ? 'pointer' : ''); 2516 } 2517 }, 2518 2519 create: function() 2520 { 2521 var elem = $(selector), overlay; 2522 2523 // Return if overlay is already rendered 2524 if(elem.length) { elems.overlay = elem; return elem; } 2525 2526 // Create document overlay 2527 overlay = elems.overlay = $('<div />', { 2528 id: selector.substr(1), 2529 css: { 2530 position: 'absolute', 2531 top: 0, 2532 left: 0, 2533 display: 'none' 2534 }, 2535 mousedown: function() { return FALSE; } 2536 })
2537 .appendTo(document.body); 2538 2539 // Update position on window resize or scroll 2540 $(window).bind('resize'+namespace, function() { 2541 overlay.css({ 2542 height: Math.max( $(window).height(), $(document).height() ), 2543 width: Math.max( $(window).width(), $(document).width() ) 2544 }); 2545 }) 2546 .trigger('resize'); 2547 2548 return overlay; 2549 }, 2550 2551 toggle: function(state) 2552 { 2553 var overlay = elems.overlay, 2554 effect = api.options.show.modal.effect, 2555 type = state ? 'show': 'hide', 2556 zindex; 2557 2558 // Create our overlay if it isn't present already 2559 if(!overlay) { overlay = self.create(); } 2560 2561 // Prevent modal from conflicting with show.solo 2562 if(overlay.is(':animated') && !state) { return; } 2563 2564 // Setop all animations 2565 overlay.stop(TRUE, FALSE); 2566 2567 // Set z-indx if we're showing it 2568 if(state) { 2569 zindex = parseInt( $.css(tooltip[0], 'z-index'), 10); 2570 overlay.css('z-index', (zindex || QTIP.zindex) - 1); 2571 } 2572 2573 // Use custom function if provided 2574 if($.isFunction(effect)) { 2575 effect.call(overlay, state); 2576 } 2577 2578 // If no effect type is supplied, use a simple toggle 2579 else if(effect === FALSE) { 2580 overlay[ type ](); 2581 } 2582 2583 // Use basic fade function 2584 else { 2585 overlay.fadeTo(90, state ? 0.7 : 0, function() { 2586 if(!state) { $(this).hide(); } 2587 }); 2588 } 2589 }, 2590 2591 show: function() { self.toggle(TRUE); }, 2592 hide: function() { self.toggle(FALSE); }, 2593 2594 destroy: function() 2595 { 2596 var delBlanket = elems.overlay; 2597 2598 if(delBlanket) { 2599 // Check if any other modal tooltips are present 2600 $(selector).each(function() { 2601 var api = $(this).data('qtip'); 2602 2603 // If another modal tooltip is present, leave overlay 2604 if(api && api.id !== api.id && api.options.show.modal) { 2605 return (delBlanket = FALSE); 2606 } 2607 }); 2608 2609 // Remove overlay if needed 2610 if(delBlanket) { 2611 elems.overlay.remove(); 2612 $(window).unbind(namespace); 2613 } 2614 else { 2615 elems.overlay.unbind(namespace+api.id); 2616 } 2617 } 2618 2619 // Remove bound events 2620 tooltip.unbind(events); 2621 } 2622 }); 2623 2624 self.init(); 2625} 2626 2627PLUGINS.modal = function(api) 2628{ 2629 var self = api.plugins.modal; 2630 2631 return 'object' === typeof self ? self : (api.plugins.modal = new Modal(api)); 2632}; 2633 2634// Plugin needs to be initialized on render 2635PLUGINS.modal.initialize = 'render'; 2636 2637// Setup sanitiztion rules 2638PLUGINS.modal.sanitize = function(opts) { 2639 if(opts.show) { 2640 if(typeof opts.show.modal !== 'object') { opts.show.modal = { on: !!opts.show.modal }; } 2641 else if(typeof opts.show.modal.on === 'undefined') { opts.show.modal.on = TRUE; } 2642 } 2643}; 2644 2645// Extend original api defaults 2646$.extend(TRUE, QTIP.defaults, { 2647 show: { 2648 modal: { 2649 on: FALSE, 2650 effect: TRUE, 2651 blur: TRUE 2652 } 2653 } 2654});/* 2655 * BGIFrame adaption (http://plugins.jquery.com/project/bgiframe) 2656 * Special thanks to Brandon Aaron 2657 */ 2658function BGIFrame(api) 2659{ 2660 var self = this, 2661 elems = api.elements, 2662 tooltip = elems.tooltip, 2663 namespace = '.bgiframe-' + api.id, 2664 events = 'tooltipmove'+namespace+' tooltipshow'+namespace; 2665 2666 $.extend(self, { 2667 init: function() 2668 { 2669 // Create the BGIFrame element 2670 elems.bgiframe = $('<iframe class="ui-tooltip-bgiframe" frameborder="0" tabindex="-1" src="javascript:\'\';" ' + 2671 ' style="display:block; position:absolute; z-index:-1; filter:alpha(opacity=0);"></iframe>'); 2672 2673 // Append the new element to the tooltip 2674 elems.bgiframe.appendTo(tooltip); 2675 2676 // Update BGIFrame on tooltip move 2677 tooltip.bind(events, self.adjust); 2678 }, 2679 2680 adjust: function() 2681 { 2682 var dimensions = api.get('dimensions'), // Determine current tooltip dimensions 2683 plugin = api.plugins.tip, 2684 tip = api.elements.tip, 2685 tipAdjust, offset; 2686 2687 // Adjust border offset 2688 offset = parseInt(tooltip.css('border-left-width'), 10) || 0; 2689 offset = { left: -offset, top: -offset }; 2690 2691 // Adjust for tips plugin 2692 if(plugin && tip) { 2693 tipAdjust = (plugin.corner.precedance === 'x') ? ['width', 'left'] : ['height', 'top']; 2694 offset[ tipAdjust[1] ] -= tip[ tipAdjust[0] ](); 2695 } 2696 2697 // Update bgiframe 2698 elems.bgiframe.css(offset).css(dimensions); 2699 }, 2700 2701 destroy: function() 2702 { 2703 // Remove iframe 2704 self.iframe.remove(); 2705 2706 // Remove bound events 2707 tooltip.unbind(events); 2708 } 2709 }); 2710 2711 self.init(); 2712} 2713 2714PLUGINS.bgiframe = function(api) 2715{ 2716 var browser = $.browser, 2717 self = api.plugins.bgiframe; 2718 2719 // Proceed only if the browser is IE6 and offending elements are present 2720 if(!PLUGINS.bgiframe.needBGI || !(browser.msie && browser.version.charAt(0) === '6')) { 2721 return FALSE; 2722 } 2723 2724 return 'object' === typeof self ? self : (api.plugins.bgiframe = new BGIFrame(api)); 2725}; 2726 2727// Plugin needs to be initialized on render 2728PLUGINS.bgiframe.initialize = 'render'; 2729 2730PLUGINS.bgiframe.needBGI = $('select, object').length > 0;}(jQuery, window));
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.