2 * qTip2 - Pretty powerful tooltips - v2.2.0
5 * Copyright (c) 2013 Craig Michael Thompson
6 * Released under the MIT, GPL licenses
7 * http://jquery.org/license
9 * Date: Mon Dec 16 2013 04:37 EST-0500
13 /*global window: false, jQuery: false, console: false, define: false */
15 /* Cache window, document, undefined */
16 (function( window, document, undefined ) {
18 // Uses AMD or browser globals to create a jQuery plugin.
19 (function( factory ) {
21 if(typeof define === 'function' && define.amd) {
22 define(['jquery'], factory);
24 else if(jQuery && !jQuery.fn.qtip) {
29 "use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
31 ;// Munge the primitives - Paul Irish tip
48 // Position adjustment types
50 FLIPINVERT = 'flipinvert',
54 QTIP, PROTOTYPE, CORNER, CHECKS,
57 ATTR_HAS = 'data-hasqtip',
58 ATTR_ID = 'data-qtip-id',
59 WIDGET = ['ui-widget', 'ui-tooltip'],
60 SELECTOR = '.'+NAMESPACE,
61 INACTIVE_EVENTS = 'click dblclick mousedown mouseup mousemove mouseleave mouseenter'.split(' '),
63 CLASS_FIXED = NAMESPACE+'-fixed',
64 CLASS_DEFAULT = NAMESPACE + '-default',
65 CLASS_FOCUS = NAMESPACE + '-focus',
66 CLASS_HOVER = NAMESPACE + '-hover',
67 CLASS_DISABLED = NAMESPACE+'-disabled',
69 replaceSuffix = '_replacedByqTip',
70 oldtitle = 'oldtitle',
76 * IE version detection
78 * Adapted from: http://ajaxian.com/archives/attack-of-the-ie-conditional-comment
79 * Credit to James Padolsey for the original implemntation!
82 var v = 3, div = document.createElement('div');
83 while ((div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->')) {
84 if(!div.getElementsByTagName('i')[0]) { break; }
86 return v > 4 ? v : NaN;
90 * iOS version detection
93 ('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1])
94 .replace('undefined', '3_2').replace('_', '.').replace('_', '')
98 ;function QTip(target, options, id, attr) {
\r
101 this.target = target;
\r
102 this.tooltip = NULL;
\r
103 this.elements = { target: target };
\r
105 // Internal constructs
\r
106 this._id = NAMESPACE + '-' + id;
\r
107 this.timers = { img: {} };
\r
108 this.options = options;
\r
121 // Set the initial flags
\r
122 this.rendered = this.destroyed = this.disabled = this.waiting =
\r
123 this.hiddenDuringWait = this.positioning = this.triggering = FALSE;
\r
125 PROTOTYPE = QTip.prototype;
\r
127 PROTOTYPE._when = function(deferreds) {
\r
128 return $.when.apply($, deferreds);
\r
131 PROTOTYPE.render = function(show) {
\r
132 if(this.rendered || this.destroyed) { return this; } // If tooltip has already been rendered, exit
\r
135 options = this.options,
\r
136 cache = this.cache,
\r
137 elements = this.elements,
\r
138 text = options.content.text,
\r
139 title = options.content.title,
\r
140 button = options.content.button,
\r
141 posOptions = options.position,
\r
142 namespace = '.'+this._id+' ',
\r
146 // Add ARIA attributes to target
\r
147 $.attr(this.target[0], 'aria-describedby', this._id);
\r
149 // Create tooltip element
\r
150 this.tooltip = elements.tooltip = tooltip = $('<div/>', {
\r
152 'class': [ NAMESPACE, CLASS_DEFAULT, options.style.classes, NAMESPACE + '-pos-' + options.position.my.abbrev() ].join(' '),
\r
153 'width': options.style.width || '',
\r
154 'height': options.style.height || '',
\r
155 'tracking': posOptions.target === 'mouse' && posOptions.adjust.mouse,
\r
157 /* ARIA specific attributes */
\r
159 'aria-live': 'polite',
\r
160 'aria-atomic': FALSE,
\r
161 'aria-describedby': this._id + '-content',
\r
162 'aria-hidden': TRUE
\r
164 .toggleClass(CLASS_DISABLED, this.disabled)
\r
165 .attr(ATTR_ID, this.id)
\r
166 .data(NAMESPACE, this)
\r
167 .appendTo(posOptions.container)
\r
169 // Create content element
\r
170 elements.content = $('<div />', {
\r
171 'class': NAMESPACE + '-content',
\r
172 'id': this._id + '-content',
\r
173 'aria-atomic': TRUE
\r
177 // Set rendered flag and prevent redundant reposition calls for now
\r
178 this.rendered = -1;
\r
179 this.positioning = TRUE;
\r
183 this._createTitle();
\r
185 // Update title only if its not a callback (called in toggle if so)
\r
186 if(!$.isFunction(title)) {
\r
187 deferreds.push( this._updateTitle(title, FALSE) );
\r
192 if(button) { this._createButton(); }
\r
194 // Set proper rendered flag and update content if not a callback function (called in toggle)
\r
195 if(!$.isFunction(text)) {
\r
196 deferreds.push( this._updateContent(text, FALSE) );
\r
198 this.rendered = TRUE;
\r
200 // Setup widget classes
\r
203 // Initialize 'render' plugins
\r
204 $.each(PLUGINS, function(name) {
\r
206 if(this.initialize === 'render' && (instance = this(self))) {
\r
207 self.plugins[name] = instance;
\r
211 // Unassign initial events and assign proper events
\r
212 this._unassignEvents();
\r
213 this._assignEvents();
\r
215 // When deferreds have completed
\r
216 this._when(deferreds).then(function() {
\r
217 // tooltiprender event
\r
218 self._trigger('render');
\r
221 self.positioning = FALSE;
\r
223 // Show tooltip if not hidden during wait period
\r
224 if(!self.hiddenDuringWait && (options.show.ready || show)) {
\r
225 self.toggle(TRUE, cache.event, FALSE);
\r
227 self.hiddenDuringWait = FALSE;
\r
231 QTIP.api[this.id] = this;
\r
236 PROTOTYPE.destroy = function(immediate) {
\r
237 // Set flag the signify destroy is taking place to plugins
\r
238 // and ensure it only gets destroyed once!
\r
239 if(this.destroyed) { return this.target; }
\r
241 function process() {
\r
242 if(this.destroyed) { return; }
\r
243 this.destroyed = TRUE;
\r
245 var target = this.target,
\r
246 title = target.attr(oldtitle);
\r
248 // Destroy tooltip if rendered
\r
249 if(this.rendered) {
\r
250 this.tooltip.stop(1,0).find('*').remove().end().remove();
\r
253 // Destroy all plugins
\r
254 $.each(this.plugins, function(name) {
\r
255 this.destroy && this.destroy();
\r
258 // Clear timers and remove bound events
\r
259 clearTimeout(this.timers.show);
\r
260 clearTimeout(this.timers.hide);
\r
261 this._unassignEvents();
\r
263 // Remove api object and ARIA attributes
\r
264 target.removeData(NAMESPACE)
\r
265 .removeAttr(ATTR_ID)
\r
266 .removeAttr(ATTR_HAS)
\r
267 .removeAttr('aria-describedby');
\r
269 // Reset old title attribute if removed
\r
270 if(this.options.suppress && title) {
\r
271 target.attr('title', title).removeAttr(oldtitle);
\r
274 // Remove qTip events associated with this API
\r
275 this._unbind(target);
\r
277 // Remove ID from used id objects, and delete object references
\r
278 // for better garbage collection and leak protection
\r
279 this.options = this.elements = this.cache = this.timers =
\r
280 this.plugins = this.mouse = NULL;
\r
282 // Delete epoxsed API object
\r
283 delete QTIP.api[this.id];
\r
286 // If an immediate destory is needed
\r
287 if((immediate !== TRUE || this.triggering === 'hide') && this.rendered) {
\r
288 this.tooltip.one('tooltiphidden', $.proxy(process, this));
\r
289 !this.triggering && this.hide();
\r
292 // If we're not in the process of hiding... process
\r
293 else { process.call(this); }
\r
295 return this.target;
\r
298 ;function invalidOpt(a) {
299 return a === NULL || $.type(a) !== 'object';
302 function invalidContent(c) {
303 return !( $.isFunction(c) || (c && c.attr) || c.length || ($.type(c) === 'object' && (c.jquery || c.then) ));
306 // Option object sanitizer
307 function sanitizeOptions(opts) {
308 var content, text, ajax, once;
310 if(invalidOpt(opts)) { return FALSE; }
312 if(invalidOpt(opts.metadata)) {
313 opts.metadata = { type: opts.metadata };
316 if('content' in opts) {
317 content = opts.content;
319 if(invalidOpt(content) || content.jquery || content.done) {
320 content = opts.content = {
321 text: (text = invalidContent(content) ? FALSE : content)
324 else { text = content.text; }
326 // DEPRECATED - Old content.ajax plugin functionality
327 // Converts it into the proper Deferred syntax
328 if('ajax' in content) {
330 once = ajax && ajax.once !== FALSE;
333 content.text = function(event, api) {
334 var loading = text || $(this).attr(api.options.content.attr) || 'Loading...',
337 $.extend({}, ajax, { context: api })
339 .then(ajax.success, NULL, ajax.error)
340 .then(function(content) {
341 if(content && once) { api.set('content.text', content); }
344 function(xhr, status, error) {
345 if(api.destroyed || xhr.status === 0) { return; }
346 api.set('content.text', status + ': ' + error);
349 return !once ? (api.set('content.text', loading), deferred) : loading;
353 if('title' in content) {
354 if(!invalidOpt(content.title)) {
355 content.button = content.title.button;
356 content.title = content.title.text;
359 if(invalidContent(content.title || FALSE)) {
360 content.title = FALSE;
365 if('position' in opts && invalidOpt(opts.position)) {
366 opts.position = { my: opts.position, at: opts.position };
369 if('show' in opts && invalidOpt(opts.show)) {
370 opts.show = opts.show.jquery ? { target: opts.show } :
371 opts.show === TRUE ? { ready: TRUE } : { event: opts.show };
374 if('hide' in opts && invalidOpt(opts.hide)) {
375 opts.hide = opts.hide.jquery ? { target: opts.hide } : { event: opts.hide };
378 if('style' in opts && invalidOpt(opts.style)) {
379 opts.style = { classes: opts.style };
382 // Sanitize plugin options
383 $.each(PLUGINS, function() {
384 this.sanitize && this.sanitize(opts);
390 // Setup builtin .set() option checks
391 CHECKS = PROTOTYPE.checks = {
394 '^id$': function(obj, o, v, prev) {
395 var id = v === TRUE ? QTIP.nextid : v,
396 new_id = NAMESPACE + '-' + id;
398 if(id !== FALSE && id.length > 0 && !$('#'+new_id).length) {
402 this.tooltip[0].id = this._id;
403 this.elements.content[0].id = this._id + '-content';
404 this.elements.title[0].id = this._id + '-title';
407 else { obj[o] = prev; }
409 '^prerender': function(obj, o, v) {
410 v && !this.rendered && this.render(this.options.show.ready);
414 '^content.text$': function(obj, o, v) {
415 this._updateContent(v);
417 '^content.attr$': function(obj, o, v, prev) {
418 if(this.options.content.text === this.target.attr(prev)) {
419 this._updateContent( this.target.attr(v) );
422 '^content.title$': function(obj, o, v) {
423 // Remove title if content is null
424 if(!v) { return this._removeTitle(); }
426 // If title isn't already created, create it now and update
427 v && !this.elements.title && this._createTitle();
428 this._updateTitle(v);
430 '^content.button$': function(obj, o, v) {
431 this._updateButton(v);
433 '^content.title.(text|button)$': function(obj, o, v) {
434 this.set('content.'+o, v); // Backwards title.text/button compat
438 '^position.(my|at)$': function(obj, o, v){
439 'string' === typeof v && (obj[o] = new CORNER(v, o === 'at'));
441 '^position.container$': function(obj, o, v){
442 this.rendered && this.tooltip.appendTo(v);
446 '^show.ready$': function(obj, o, v) {
447 v && (!this.rendered && this.render(TRUE) || this.toggle(TRUE));
451 '^style.classes$': function(obj, o, v, p) {
452 this.rendered && this.tooltip.removeClass(p).addClass(v);
454 '^style.(width|height)': function(obj, o, v) {
455 this.rendered && this.tooltip.css(o, v);
457 '^style.widget|content.title': function() {
458 this.rendered && this._setWidget();
460 '^style.def': function(obj, o, v) {
461 this.rendered && this.tooltip.toggleClass(CLASS_DEFAULT, !!v);
465 '^events.(render|show|move|hide|focus|blur)$': function(obj, o, v) {
466 this.rendered && this.tooltip[($.isFunction(v) ? '' : 'un') + 'bind']('tooltip'+o, v);
469 // Properties which require event reassignment
470 '^(show|hide|position).(event|target|fixed|inactive|leave|distance|viewport|adjust)': function() {
471 if(!this.rendered) { return; }
474 var posOptions = this.options.position;
475 this.tooltip.attr('tracking', posOptions.target === 'mouse' && posOptions.adjust.mouse);
478 this._unassignEvents();
479 this._assignEvents();
484 // Dot notation converter
485 function convertNotation(options, notation) {
486 var i = 0, obj, option = options,
488 // Split notation into array
489 levels = notation.split('.');
492 while( option = option[ levels[i++] ] ) {
493 if(i < levels.length) { obj = option; }
496 return [obj || options, levels.pop()];
499 PROTOTYPE.get = function(notation) {
500 if(this.destroyed) { return this; }
502 var o = convertNotation(this.options, notation.toLowerCase()),
503 result = o[0][ o[1] ];
505 return result.precedance ? result.string() : result;
508 function setCallback(notation, args) {
509 var category, rule, match;
511 for(category in this.checks) {
512 for(rule in this.checks[category]) {
513 if(match = (new RegExp(rule, 'i')).exec(notation)) {
516 if(category === 'builtin' || this.plugins[category]) {
517 this.checks[category][rule].apply(
518 this.plugins[category] || this, args
526 var rmove = /^position\.(my|at|adjust|target|container|viewport)|style|content|show\.ready/i,
527 rrender = /^prerender|show\.ready/i;
529 PROTOTYPE.set = function(option, value) {
530 if(this.destroyed) { return this; }
532 var rendered = this.rendered,
534 options = this.options,
535 checks = this.checks,
538 // Convert singular option/value pair into object form
539 if('string' === typeof option) {
540 name = option; option = {}; option[name] = value;
542 else { option = $.extend({}, option); }
544 // Set all of the defined options to their new values
545 $.each(option, function(notation, value) {
546 if(rendered && rrender.test(notation)) {
547 delete option[notation]; return;
551 var obj = convertNotation(options, notation.toLowerCase()), previous;
552 previous = obj[0][ obj[1] ];
553 obj[0][ obj[1] ] = value && value.nodeType ? $(value) : value;
555 // Also check if we need to reposition
556 reposition = rmove.test(notation) || reposition;
558 // Set the new params for the callback
559 option[notation] = [obj[0], obj[1], value, previous];
562 // Re-sanitize options
563 sanitizeOptions(options);
566 * Execute any valid callbacks for the set options
567 * Also set positioning flag so we don't get loads of redundant repositioning calls.
569 this.positioning = TRUE;
570 $.each(option, $.proxy(setCallback, this));
571 this.positioning = FALSE;
573 // Update position if needed
574 if(this.rendered && this.tooltip[0].offsetWidth > 0 && reposition) {
575 this.reposition( options.position.target === 'mouse' ? NULL : this.cache.event );
581 ;PROTOTYPE._update = function(content, element, reposition) {
585 // Make sure tooltip is rendered and content is defined. If not return
586 if(!this.rendered || !content) { return FALSE; }
588 // Use function to parse content
589 if($.isFunction(content)) {
590 content = content.call(this.elements.target, cache.event, this) || '';
593 // Handle deferred content
594 if($.isFunction(content.then)) {
595 cache.waiting = TRUE;
596 return content.then(function(c) {
597 cache.waiting = FALSE;
598 return self._update(c, element);
599 }, NULL, function(e) {
600 return self._update(e, element);
604 // If content is null... return false
605 if(content === FALSE || (!content && content !== '')) { return FALSE; }
607 // Append new content if its a DOM array and show it if hidden
608 if(content.jquery && content.length > 0) {
609 element.empty().append(
610 content.css({ display: 'block', visibility: 'visible' })
614 // Content is a regular string, insert the new content
615 else { element.html(content); }
617 // Wait for content to be loaded, and reposition
618 return this._waitForContent(element).then(function(images) {
619 if(images.images && images.images.length && self.rendered && self.tooltip[0].offsetWidth > 0) {
620 self.reposition(cache.event, !images.length);
625 PROTOTYPE._waitForContent = function(element) {
626 var cache = this.cache;
629 cache.waiting = TRUE;
631 // If imagesLoaded is included, ensure images have loaded and return promise
632 return ( $.fn.imagesLoaded ? element.imagesLoaded() : $.Deferred().resolve([]) )
633 .done(function() { cache.waiting = FALSE; })
637 PROTOTYPE._updateContent = function(content, reposition) {
638 this._update(content, this.elements.content, reposition);
641 PROTOTYPE._updateTitle = function(content, reposition) {
642 if(this._update(content, this.elements.title, reposition) === FALSE) {
643 this._removeTitle(FALSE);
647 PROTOTYPE._createTitle = function()
649 var elements = this.elements,
650 id = this._id+'-title';
652 // Destroy previous title element, if present
653 if(elements.titlebar) { this._removeTitle(); }
655 // Create title bar and title elements
656 elements.titlebar = $('<div />', {
657 'class': NAMESPACE + '-titlebar ' + (this.options.style.widget ? createWidgetClass('header') : '')
660 elements.title = $('<div />', {
662 'class': NAMESPACE + '-title',
666 .insertBefore(elements.content)
668 // Button-specific events
669 .delegate('.qtip-close', 'mousedown keydown mouseup keyup mouseout', function(event) {
670 $(this).toggleClass('ui-state-active ui-state-focus', event.type.substr(-4) === 'down');
672 .delegate('.qtip-close', 'mouseover mouseout', function(event){
673 $(this).toggleClass('ui-state-hover', event.type === 'mouseover');
676 // Create button if enabled
677 if(this.options.content.button) { this._createButton(); }
680 PROTOTYPE._removeTitle = function(reposition)
682 var elements = this.elements;
685 elements.titlebar.remove();
686 elements.titlebar = elements.title = elements.button = NULL;
688 // Reposition if enabled
689 if(reposition !== FALSE) { this.reposition(); }
693 ;PROTOTYPE.reposition = function(event, effect) {
694 if(!this.rendered || this.positioning || this.destroyed) { return this; }
696 // Set positioning flag
697 this.positioning = TRUE;
699 var cache = this.cache,
700 tooltip = this.tooltip,
701 posOptions = this.options.position,
702 target = posOptions.target,
705 viewport = posOptions.viewport,
706 container = posOptions.container,
707 adjust = posOptions.adjust,
708 method = adjust.method.split(' '),
709 tooltipWidth = tooltip.outerWidth(FALSE),
710 tooltipHeight = tooltip.outerHeight(FALSE),
713 type = tooltip.css('position'),
714 position = { left: 0, top: 0 },
715 visible = tooltip[0].offsetWidth > 0,
716 isScroll = event && event.type === 'scroll',
718 doc = container[0].ownerDocument,
720 pluginCalculations, offset;
722 // Check if absolute position was passed
723 if($.isArray(target) && target.length === 2) {
724 // Force left top and set position
725 at = { x: LEFT, y: TOP };
726 position = { left: target[0], top: target[1] };
729 // Check if mouse was the target
730 else if(target === 'mouse') {
731 // Force left top to allow flipping
732 at = { x: LEFT, y: TOP };
734 // Use the cached mouse coordinates if available, or passed event has no coordinates
735 if(mouse && mouse.pageX && (adjust.mouse || !event || !event.pageX) ) {
739 // If the passed event has no coordinates (such as a scroll event)
740 else if(!event || !event.pageX) {
741 // Use the mouse origin that caused the show event, if distance hiding is enabled
742 if((!adjust.mouse || this.options.show.distance) && cache.origin && cache.origin.pageX) {
743 event = cache.origin;
746 // Use cached event for resize/scroll events
747 else if(!event || (event && (event.type === 'resize' || event.type === 'scroll'))) {
752 // Calculate body and container offset and take them into account below
753 if(type !== 'static') { position = container.offset(); }
754 if(doc.body.offsetWidth !== (window.innerWidth || doc.documentElement.clientWidth)) {
755 offset = $(document.body).offset();
758 // Use event coordinates for position
760 left: event.pageX - position.left + (offset && offset.left || 0),
761 top: event.pageY - position.top + (offset && offset.top || 0)
764 // Scroll events are a pain, some browsers
765 if(adjust.mouse && isScroll && mouse) {
766 position.left -= (mouse.scrollX || 0) - win.scrollLeft();
767 position.top -= (mouse.scrollY || 0) - win.scrollTop();
771 // Target wasn't mouse or absolute...
773 // Check if event targetting is being used
774 if(target === 'event') {
775 if(event && event.target && event.type !== 'scroll' && event.type !== 'resize') {
776 cache.target = $(event.target);
778 else if(!event.target) {
779 cache.target = this.elements.target;
782 else if(target !== 'event'){
783 cache.target = $(target.jquery ? target : this.elements.target);
785 target = cache.target;
787 // Parse the target into a jQuery object and make sure there's an element present
788 target = $(target).eq(0);
789 if(target.length === 0) { return this; }
791 // Check if window or document is the target
792 else if(target[0] === document || target[0] === window) {
793 targetWidth = BROWSER.iOS ? window.innerWidth : target.width();
794 targetHeight = BROWSER.iOS ? window.innerHeight : target.height();
796 if(target[0] === window) {
798 top: (viewport || target).scrollTop(),
799 left: (viewport || target).scrollLeft()
804 // Check if the target is an <AREA> element
805 else if(PLUGINS.imagemap && target.is('area')) {
806 pluginCalculations = PLUGINS.imagemap(this, target, at, PLUGINS.viewport ? method : FALSE);
809 // Check if the target is an SVG element
810 else if(PLUGINS.svg && target && target[0].ownerSVGElement) {
811 pluginCalculations = PLUGINS.svg(this, target, at, PLUGINS.viewport ? method : FALSE);
814 // Otherwise use regular jQuery methods
816 targetWidth = target.outerWidth(FALSE);
817 targetHeight = target.outerHeight(FALSE);
818 position = target.offset();
821 // Parse returned plugin values into proper variables
822 if(pluginCalculations) {
823 targetWidth = pluginCalculations.width;
824 targetHeight = pluginCalculations.height;
825 offset = pluginCalculations.offset;
826 position = pluginCalculations.position;
829 // Adjust position to take into account offset parents
830 position = this.reposition.offset(target, position, container);
832 // Adjust for position.fixed tooltips (and also iOS scroll bug in v3.2-4.0 & v4.3-4.3.2)
833 if((BROWSER.iOS > 3.1 && BROWSER.iOS < 4.1) ||
834 (BROWSER.iOS >= 4.3 && BROWSER.iOS < 4.33) ||
835 (!BROWSER.iOS && type === 'fixed')
837 position.left -= win.scrollLeft();
838 position.top -= win.scrollTop();
841 // Adjust position relative to target
842 if(!pluginCalculations || (pluginCalculations && pluginCalculations.adjustable !== FALSE)) {
843 position.left += at.x === RIGHT ? targetWidth : at.x === CENTER ? targetWidth / 2 : 0;
844 position.top += at.y === BOTTOM ? targetHeight : at.y === CENTER ? targetHeight / 2 : 0;
848 // Adjust position relative to tooltip
849 position.left += adjust.x + (my.x === RIGHT ? -tooltipWidth : my.x === CENTER ? -tooltipWidth / 2 : 0);
850 position.top += adjust.y + (my.y === BOTTOM ? -tooltipHeight : my.y === CENTER ? -tooltipHeight / 2 : 0);
852 // Use viewport adjustment plugin if enabled
853 if(PLUGINS.viewport) {
854 position.adjusted = PLUGINS.viewport(
855 this, position, posOptions, targetWidth, targetHeight, tooltipWidth, tooltipHeight
858 // Apply offsets supplied by positioning plugin (if used)
859 if(offset && position.adjusted.left) { position.left += offset.left; }
860 if(offset && position.adjusted.top) { position.top += offset.top; }
863 // Viewport adjustment is disabled, set values to zero
864 else { position.adjusted = { left: 0, top: 0 }; }
867 if(!this._trigger('move', [position, viewport.elem || viewport], event)) { return this; }
868 delete position.adjusted;
870 // If effect is disabled, target it mouse, no animation is defined or positioning gives NaN out, set CSS directly
871 if(effect === FALSE || !visible || isNaN(position.left) || isNaN(position.top) || target === 'mouse' || !$.isFunction(posOptions.effect)) {
872 tooltip.css(position);
875 // Use custom function if provided
876 else if($.isFunction(posOptions.effect)) {
877 posOptions.effect.call(tooltip, this, $.extend({}, position));
878 tooltip.queue(function(next) {
879 // Reset attributes to avoid cross-browser rendering bugs
880 $(this).css({ opacity: '', height: '' });
881 if(BROWSER.ie) { this.style.removeAttribute('filter'); }
887 // Set positioning flag
888 this.positioning = FALSE;
893 // Custom (more correct for qTip!) offset calculator
894 PROTOTYPE.reposition.offset = function(elem, pos, container) {
895 if(!container[0]) { return pos; }
897 var ownerDocument = $(elem[0].ownerDocument),
898 quirks = !!BROWSER.ie && document.compatMode !== 'CSS1Compat',
899 parent = container[0],
900 scrolled, position, parentOffset, overflow;
902 function scroll(e, i) {
903 pos.left += i * e.scrollLeft();
904 pos.top += i * e.scrollTop();
907 // Compensate for non-static containers offset
909 if((position = $.css(parent, 'position')) !== 'static') {
910 if(position === 'fixed') {
911 parentOffset = parent.getBoundingClientRect();
912 scroll(ownerDocument, -1);
915 parentOffset = $(parent).position();
916 parentOffset.left += (parseFloat($.css(parent, 'borderLeftWidth')) || 0);
917 parentOffset.top += (parseFloat($.css(parent, 'borderTopWidth')) || 0);
920 pos.left -= parentOffset.left + (parseFloat($.css(parent, 'marginLeft')) || 0);
921 pos.top -= parentOffset.top + (parseFloat($.css(parent, 'marginTop')) || 0);
923 // If this is the first parent element with an overflow of "scroll" or "auto", store it
924 if(!scrolled && (overflow = $.css(parent, 'overflow')) !== 'hidden' && overflow !== 'visible') { scrolled = $(parent); }
927 while((parent = parent.offsetParent));
929 // Compensate for containers scroll if it also has an offsetParent (or in IE quirks mode)
930 if(scrolled && (scrolled[0] !== ownerDocument[0] || quirks)) {
938 var C = (CORNER = PROTOTYPE.reposition.Corner = function(corner, forceY) {
939 corner = ('' + corner).replace(/([A-Z])/, ' $1').replace(/middle/gi, CENTER).toLowerCase();
940 this.x = (corner.match(/left|right/i) || corner.match(/center/) || ['inherit'])[0].toLowerCase();
941 this.y = (corner.match(/top|bottom|center/i) || ['inherit'])[0].toLowerCase();
942 this.forceY = !!forceY;
944 var f = corner.charAt(0);
945 this.precedance = (f === 't' || f === 'b' ? Y : X);
948 C.invert = function(z, center) {
949 this[z] = this[z] === LEFT ? RIGHT : this[z] === RIGHT ? LEFT : center || this[z];
952 C.string = function() {
953 var x = this.x, y = this.y;
954 return x === y ? x : this.precedance === Y || (this.forceY && y !== 'center') ? y+' '+x : x+' '+y;
957 C.abbrev = function() {
958 var result = this.string().split(' ');
959 return result[0].charAt(0) + (result[1] && result[1].charAt(0) || '');
962 C.clone = function() {
963 return new CORNER( this.string(), this.forceY );
965 PROTOTYPE.toggle = function(state, event) {
966 var cache = this.cache,
967 options = this.options,
968 tooltip = this.tooltip;
970 // Try to prevent flickering when tooltip overlaps show element
972 if((/over|enter/).test(event.type) && (/out|leave/).test(cache.event.type) &&
973 options.show.target.add(event.target).length === options.show.target.length &&
974 tooltip.has(event.relatedTarget).length) {
979 cache.event = cloneEvent(event);
982 // If we're currently waiting and we've just hidden... stop it
983 this.waiting && !state && (this.hiddenDuringWait = TRUE);
985 // Render the tooltip if showing and it isn't already
986 if(!this.rendered) { return state ? this.render(1) : this; }
987 else if(this.destroyed || this.disabled) { return this; }
989 var type = state ? 'show' : 'hide',
990 opts = this.options[type],
991 otherOpts = this.options[ !state ? 'show' : 'hide' ],
992 posOptions = this.options.position,
993 contentOptions = this.options.content,
994 width = this.tooltip.css('width'),
995 visible = this.tooltip.is(':visible'),
996 animate = state || opts.target.length === 1,
997 sameTarget = !event || opts.target.length < 2 || cache.target[0] === event.target,
998 identicalState, allow, showEvent, delay, after;
1000 // Detect state if valid one isn't provided
1001 if((typeof state).search('boolean|number')) { state = !visible; }
1003 // Check if the tooltip is in an identical state to the new would-be state
1004 identicalState = !tooltip.is(':animated') && visible === state && sameTarget;
1006 // Fire tooltip(show/hide) event and check if destroyed
1007 allow = !identicalState ? !!this._trigger(type, [90]) : NULL;
1009 // Check to make sure the tooltip wasn't destroyed in the callback
1010 if(this.destroyed) { return this; }
1012 // If the user didn't stop the method prematurely and we're showing the tooltip, focus it
1013 if(allow !== FALSE && state) { this.focus(event); }
1015 // If the state hasn't changed or the user stopped it, return early
1016 if(!allow || identicalState) { return this; }
1018 // Set ARIA hidden attribute
1019 $.attr(tooltip[0], 'aria-hidden', !!!state);
1021 // Execute state specific properties
1023 // Store show origin coordinates
1024 cache.origin = cloneEvent(this.mouse);
1026 // Update tooltip content & title if it's a dynamic function
1027 if($.isFunction(contentOptions.text)) { this._updateContent(contentOptions.text, FALSE); }
1028 if($.isFunction(contentOptions.title)) { this._updateTitle(contentOptions.title, FALSE); }
1030 // Cache mousemove events for positioning purposes (if not already tracking)
1031 if(!trackingBound && posOptions.target === 'mouse' && posOptions.adjust.mouse) {
1032 $(document).bind('mousemove.'+NAMESPACE, this._storeMouse);
1033 trackingBound = TRUE;
1036 // Update the tooltip position (set width first to prevent viewport/max-width issues)
1037 if(!width) { tooltip.css('width', tooltip.outerWidth(FALSE)); }
1038 this.reposition(event, arguments[2]);
1039 if(!width) { tooltip.css('width', ''); }
1041 // Hide other tooltips if tooltip is solo
1043 (typeof opts.solo === 'string' ? $(opts.solo) : $(SELECTOR, opts.solo))
1044 .not(tooltip).not(opts.target).qtip('hide', $.Event('tooltipsolo'));
1048 // Clear show timer if we're hiding
1049 clearTimeout(this.timers.show);
1051 // Remove cached origin on hide
1052 delete cache.origin;
1054 // Remove mouse tracking event if not needed (all tracking qTips are hidden)
1055 if(trackingBound && !$(SELECTOR+'[tracking="true"]:visible', opts.solo).not(tooltip).length) {
1056 $(document).unbind('mousemove.'+NAMESPACE);
1057 trackingBound = FALSE;
1064 // Define post-animation, state specific properties
1065 after = $.proxy(function() {
1067 // Prevent antialias from disappearing in IE by removing filter
1068 if(BROWSER.ie) { tooltip[0].style.removeAttribute('filter'); }
1070 // Remove overflow setting to prevent tip bugs
1071 tooltip.css('overflow', '');
1073 // Autofocus elements if enabled
1074 if('string' === typeof opts.autofocus) {
1075 $(this.options.show.autofocus, tooltip).focus();
1078 // If set, hide tooltip when inactive for delay period
1079 this.options.show.target.trigger('qtip-'+this.id+'-inactive');
1092 // tooltipvisible/tooltiphidden events
1093 this._trigger(state ? 'visible' : 'hidden');
1096 // If no effect type is supplied, use a simple toggle
1097 if(opts.effect === FALSE || animate === FALSE) {
1102 // Use custom function if provided
1103 else if($.isFunction(opts.effect)) {
1105 opts.effect.call(tooltip, this);
1106 tooltip.queue('fx', function(n) {
1111 // Use basic fade function by default
1112 else { tooltip.fadeTo(90, state ? 1 : 0, after); }
1114 // If inactive hide method is set, active it
1115 if(state) { opts.target.trigger('qtip-'+this.id+'-inactive'); }
1120 PROTOTYPE.show = function(event) { return this.toggle(TRUE, event); };
1122 PROTOTYPE.hide = function(event) { return this.toggle(FALSE, event); };
1124 ;PROTOTYPE.focus = function(event) {
1125 if(!this.rendered || this.destroyed) { return this; }
1127 var qtips = $(SELECTOR),
1128 tooltip = this.tooltip,
1129 curIndex = parseInt(tooltip[0].style.zIndex, 10),
1130 newIndex = QTIP.zindex + qtips.length,
1133 // Only update the z-index if it has changed and tooltip is not already focused
1134 if(!tooltip.hasClass(CLASS_FOCUS)) {
1135 // tooltipfocus event
1136 if(this._trigger('focus', [newIndex], event)) {
1137 // Only update z-index's if they've changed
1138 if(curIndex !== newIndex) {
1139 // Reduce our z-index's and keep them properly ordered
1140 qtips.each(function() {
1141 if(this.style.zIndex > curIndex) {
1142 this.style.zIndex = this.style.zIndex - 1;
1146 // Fire blur event for focused tooltip
1147 qtips.filter('.' + CLASS_FOCUS).qtip('blur', event);
1150 // Set the new z-index
1151 tooltip.addClass(CLASS_FOCUS)[0].style.zIndex = newIndex;
1158 PROTOTYPE.blur = function(event) {
1159 if(!this.rendered || this.destroyed) { return this; }
1161 // Set focused status to FALSE
1162 this.tooltip.removeClass(CLASS_FOCUS);
1164 // tooltipblur event
1165 this._trigger('blur', [ this.tooltip.css('zIndex') ], event);
1170 ;PROTOTYPE.disable = function(state) {
1171 if(this.destroyed) { return this; }
1173 // If 'toggle' is passed, toggle the current state
1174 if(state === 'toggle') {
1175 state = !(this.rendered ? this.tooltip.hasClass(CLASS_DISABLED) : this.disabled);
1178 // Disable if no state passed
1179 else if('boolean' !== typeof state) {
1184 this.tooltip.toggleClass(CLASS_DISABLED, state)
1185 .attr('aria-disabled', state);
1188 this.disabled = !!state;
1193 PROTOTYPE.enable = function() { return this.disable(FALSE); };
1195 ;PROTOTYPE._createButton = function()
1198 elements = this.elements,
1199 tooltip = elements.tooltip,
1200 button = this.options.content.button,
1201 isString = typeof button === 'string',
1202 close = isString ? button : 'Close tooltip';
1204 if(elements.button) { elements.button.remove(); }
1206 // Use custom button if one was supplied by user, else use default
1208 elements.button = button;
1211 elements.button = $('<a />', {
1212 'class': 'qtip-close ' + (this.options.style.widget ? '' : NAMESPACE+'-icon'),
1218 'class': 'ui-icon ui-icon-close',
1224 // Create button and setup attributes
1225 elements.button.appendTo(elements.titlebar || tooltip)
1226 .attr('role', 'button')
1227 .click(function(event) {
1228 if(!tooltip.hasClass(CLASS_DISABLED)) { self.hide(event); }
1233 PROTOTYPE._updateButton = function(button)
1235 // Make sure tooltip is rendered and if not, return
1236 if(!this.rendered) { return FALSE; }
1238 var elem = this.elements.button;
1239 if(button) { this._createButton(); }
1240 else { elem.remove(); }
1243 ;// Widget class creator
1244 function createWidgetClass(cls) {
1245 return WIDGET.concat('').join(cls ? '-'+cls+' ' : ' ');
1248 // Widget class setter method
1249 PROTOTYPE._setWidget = function()
1251 var on = this.options.style.widget,
1252 elements = this.elements,
1253 tooltip = elements.tooltip,
1254 disabled = tooltip.hasClass(CLASS_DISABLED);
1256 tooltip.removeClass(CLASS_DISABLED);
1257 CLASS_DISABLED = on ? 'ui-state-disabled' : 'qtip-disabled';
1258 tooltip.toggleClass(CLASS_DISABLED, disabled);
1260 tooltip.toggleClass('ui-helper-reset '+createWidgetClass(), on).toggleClass(CLASS_DEFAULT, this.options.style.def && !on);
1262 if(elements.content) {
1263 elements.content.toggleClass( createWidgetClass('content'), on);
1265 if(elements.titlebar) {
1266 elements.titlebar.toggleClass( createWidgetClass('header'), on);
1268 if(elements.button) {
1269 elements.button.toggleClass(NAMESPACE+'-icon', !on);
1271 };;function cloneEvent(event) {
1276 target: event.target,
1277 relatedTarget: event.relatedTarget,
1278 scrollX: event.scrollX || window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft,
1279 scrollY: event.scrollY || window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop
1283 function delay(callback, duration) {
1284 // If tooltip has displayed, start hide timer
1287 $.proxy(callback, this), duration
1290 else{ callback.call(this); }
1293 function showMethod(event) {
1294 if(this.tooltip.hasClass(CLASS_DISABLED)) { return FALSE; }
1296 // Clear hide timers
1297 clearTimeout(this.timers.show);
1298 clearTimeout(this.timers.hide);
1301 this.timers.show = delay.call(this,
1302 function() { this.toggle(TRUE, event); },
1303 this.options.show.delay
1307 function hideMethod(event) {
1308 if(this.tooltip.hasClass(CLASS_DISABLED)) { return FALSE; }
1310 // Check if new target was actually the tooltip element
1311 var relatedTarget = $(event.relatedTarget),
1312 ontoTooltip = relatedTarget.closest(SELECTOR)[0] === this.tooltip[0],
1313 ontoTarget = relatedTarget[0] === this.options.show.target[0];
1315 // Clear timers and stop animation queue
1316 clearTimeout(this.timers.show);
1317 clearTimeout(this.timers.hide);
1319 // Prevent hiding if tooltip is fixed and event target is the tooltip.
1320 // Or if mouse positioning is enabled and cursor momentarily overlaps
1321 if(this !== relatedTarget[0] &&
1322 (this.options.position.target === 'mouse' && ontoTooltip) ||
1323 (this.options.hide.fixed && (
1324 (/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget))
1328 event.preventDefault();
1329 event.stopImmediatePropagation();
1335 // If tooltip has displayed, start hide timer
1336 this.timers.hide = delay.call(this,
1337 function() { this.toggle(FALSE, event); },
1338 this.options.hide.delay,
1343 function inactiveMethod(event) {
1344 if(this.tooltip.hasClass(CLASS_DISABLED) || !this.options.hide.inactive) { return FALSE; }
1347 clearTimeout(this.timers.inactive);
1349 this.timers.inactive = delay.call(this,
1350 function(){ this.hide(event); },
1351 this.options.hide.inactive
1355 function repositionMethod(event) {
1356 if(this.rendered && this.tooltip[0].offsetWidth > 0) { this.reposition(event); }
1359 // Store mouse coordinates
1360 PROTOTYPE._storeMouse = function(event) {
1361 (this.mouse = cloneEvent(event)).type = 'mousemove';
1365 PROTOTYPE._bind = function(targets, events, method, suffix, context) {
1366 var ns = '.' + this._id + (suffix ? '-'+suffix : '');
1367 events.length && $(targets).bind(
1368 (events.split ? events : events.join(ns + ' ')) + ns,
1369 $.proxy(method, context || this)
1372 PROTOTYPE._unbind = function(targets, suffix) {
1373 $(targets).unbind('.' + this._id + (suffix ? '-'+suffix : ''));
1376 // Apply common event handlers using delegate (avoids excessive .bind calls!)
1377 var ns = '.'+NAMESPACE;
1378 function delegate(selector, events, method) {
1379 $(document.body).delegate(selector,
1380 (events.split ? events : events.join(ns + ' ')) + ns,
1382 var api = QTIP.api[ $.attr(this, ATTR_ID) ];
1383 api && !api.disabled && method.apply(api, arguments);
1389 delegate(SELECTOR, ['mouseenter', 'mouseleave'], function(event) {
1390 var state = event.type === 'mouseenter',
1391 tooltip = $(event.currentTarget),
1392 target = $(event.relatedTarget || event.target),
1393 options = this.options;
1397 // Focus the tooltip on mouseenter (z-index stacking)
1400 // Clear hide timer on tooltip hover to prevent it from closing
1401 tooltip.hasClass(CLASS_FIXED) && !tooltip.hasClass(CLASS_DISABLED) && clearTimeout(this.timers.hide);
1406 // Hide when we leave the tooltip and not onto the show target (if a hide event is set)
1407 if(options.position.target === 'mouse' && options.hide.event &&
1408 options.show.target && !target.closest(options.show.target[0]).length) {
1414 tooltip.toggleClass(CLASS_HOVER, state);
1417 // Define events which reset the 'inactive' event handler
1418 delegate('['+ATTR_ID+']', INACTIVE_EVENTS, inactiveMethod);
1422 PROTOTYPE._trigger = function(type, args, event) {
1423 var callback = $.Event('tooltip'+type);
1424 callback.originalEvent = (event && $.extend({}, event)) || this.cache.event || NULL;
1426 this.triggering = type;
1427 this.tooltip.trigger(callback, [this].concat(args || []));
1428 this.triggering = FALSE;
1430 return !callback.isDefaultPrevented();
1433 PROTOTYPE._bindEvents = function(showEvents, hideEvents, showTarget, hideTarget, showMethod, hideMethod) {
1434 // If hide and show targets are the same...
1435 if(hideTarget.add(showTarget).length === hideTarget.length) {
1436 var toggleEvents = [];
1438 // Filter identical show/hide events
1439 hideEvents = $.map(hideEvents, function(type) {
1440 var showIndex = $.inArray(type, showEvents);
1442 // Both events are identical, remove from both hide and show events
1443 // and append to toggleEvents
1444 if(showIndex > -1) {
1445 toggleEvents.push( showEvents.splice( showIndex, 1 )[0] );
1452 // Toggle events are special case of identical show/hide events, which happen in sequence
1453 toggleEvents.length && this._bind(showTarget, toggleEvents, function(event) {
1454 var state = this.rendered ? this.tooltip[0].offsetWidth > 0 : false;
1455 (state ? hideMethod : showMethod).call(this, event);
1459 // Apply show/hide/toggle events
1460 this._bind(showTarget, showEvents, showMethod);
1461 this._bind(hideTarget, hideEvents, hideMethod);
1464 PROTOTYPE._assignInitialEvents = function(event) {
1465 var options = this.options,
1466 showTarget = options.show.target,
1467 hideTarget = options.hide.target,
1468 showEvents = options.show.event ? $.trim('' + options.show.event).split(' ') : [],
1469 hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : [];
1472 * Make sure hoverIntent functions properly by using mouseleave as a hide event if
1473 * mouseenter/mouseout is used for show.event, even if it isn't in the users options.
1475 if(/mouse(over|enter)/i.test(options.show.event) && !/mouse(out|leave)/i.test(options.hide.event)) {
1476 hideEvents.push('mouseleave');
1480 * Also make sure initial mouse targetting works correctly by caching mousemove coords
1481 * on show targets before the tooltip has rendered. Also set onTarget when triggered to
1482 * keep mouse tracking working.
1484 this._bind(showTarget, 'mousemove', function(event) {
1485 this._storeMouse(event);
1486 this.cache.onTarget = TRUE;
1489 // Define hoverIntent function
1490 function hoverIntent(event) {
1491 // Only continue if tooltip isn't disabled
1492 if(this.disabled || this.destroyed) { return FALSE; }
1494 // Cache the event data
1495 this.cache.event = cloneEvent(event);
1496 this.cache.target = event ? $(event.target) : [undefined];
1498 // Start the event sequence
1499 clearTimeout(this.timers.show);
1500 this.timers.show = delay.call(this,
1501 function() { this.render(typeof event === 'object' || options.show.ready); },
1506 // Filter and bind events
1507 this._bindEvents(showEvents, hideEvents, showTarget, hideTarget, hoverIntent, function() {
1508 clearTimeout(this.timers.show);
1511 // Prerendering is enabled, create tooltip now
1512 if(options.show.ready || options.prerender) { hoverIntent.call(this, event); }
1515 // Event assignment method
1516 PROTOTYPE._assignEvents = function() {
1518 options = this.options,
1519 posOptions = options.position,
1521 tooltip = this.tooltip,
1522 showTarget = options.show.target,
1523 hideTarget = options.hide.target,
1524 containerTarget = posOptions.container,
1525 viewportTarget = posOptions.viewport,
1526 documentTarget = $(document),
1527 bodyTarget = $(document.body),
1528 windowTarget = $(window),
1530 showEvents = options.show.event ? $.trim('' + options.show.event).split(' ') : [],
1531 hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : [];
1534 // Assign passed event callbacks
1535 $.each(options.events, function(name, callback) {
1536 self._bind(tooltip, name === 'toggle' ? ['tooltipshow','tooltiphide'] : ['tooltip'+name], callback, null, tooltip);
1539 // Hide tooltips when leaving current window/frame (but not select/option elements)
1540 if(/mouse(out|leave)/i.test(options.hide.event) && options.hide.leave === 'window') {
1541 this._bind(documentTarget, ['mouseout', 'blur'], function(event) {
1542 if(!/select|option/.test(event.target.nodeName) && !event.relatedTarget) {
1548 // Enable hide.fixed by adding appropriate class
1549 if(options.hide.fixed) {
1550 hideTarget = hideTarget.add( tooltip.addClass(CLASS_FIXED) );
1554 * Make sure hoverIntent functions properly by using mouseleave to clear show timer if
1555 * mouseenter/mouseout is used for show.event, even if it isn't in the users options.
1557 else if(/mouse(over|enter)/i.test(options.show.event)) {
1558 this._bind(hideTarget, 'mouseleave', function() {
1559 clearTimeout(this.timers.show);
1563 // Hide tooltip on document mousedown if unfocus events are enabled
1564 if(('' + options.hide.event).indexOf('unfocus') > -1) {
1565 this._bind(containerTarget.closest('html'), ['mousedown', 'touchstart'], function(event) {
1566 var elem = $(event.target),
1567 enabled = this.rendered && !this.tooltip.hasClass(CLASS_DISABLED) && this.tooltip[0].offsetWidth > 0,
1568 isAncestor = elem.parents(SELECTOR).filter(this.tooltip[0]).length > 0;
1570 if(elem[0] !== this.target[0] && elem[0] !== this.tooltip[0] && !isAncestor &&
1571 !this.target.has(elem[0]).length && enabled
1578 // Check if the tooltip hides when inactive
1579 if('number' === typeof options.hide.inactive) {
1580 // Bind inactive method to show target(s) as a custom event
1581 this._bind(showTarget, 'qtip-'+this.id+'-inactive', inactiveMethod);
1583 // Define events which reset the 'inactive' event handler
1584 this._bind(hideTarget.add(tooltip), QTIP.inactiveEvents, inactiveMethod, '-inactive');
1587 // Filter and bind events
1588 this._bindEvents(showEvents, hideEvents, showTarget, hideTarget, showMethod, hideMethod);
1590 // Mouse movement bindings
1591 this._bind(showTarget.add(tooltip), 'mousemove', function(event) {
1592 // Check if the tooltip hides when mouse is moved a certain distance
1593 if('number' === typeof options.hide.distance) {
1594 var origin = this.cache.origin || {},
1595 limit = this.options.hide.distance,
1598 // Check if the movement has gone beyond the limit, and hide it if so
1599 if(abs(event.pageX - origin.pageX) >= limit || abs(event.pageY - origin.pageY) >= limit) {
1604 // Cache mousemove coords on show targets
1605 this._storeMouse(event);
1608 // Mouse positioning events
1609 if(posOptions.target === 'mouse') {
1610 // If mouse adjustment is on...
1611 if(posOptions.adjust.mouse) {
1612 // Apply a mouseleave event so we don't get problems with overlapping
1613 if(options.hide.event) {
1614 // Track if we're on the target or not
1615 this._bind(showTarget, ['mouseenter', 'mouseleave'], function(event) {
1616 this.cache.onTarget = event.type === 'mouseenter';
1620 // Update tooltip position on mousemove
1621 this._bind(documentTarget, 'mousemove', function(event) {
1622 // Update the tooltip position only if the tooltip is visible and adjustment is enabled
1623 if(this.rendered && this.cache.onTarget && !this.tooltip.hasClass(CLASS_DISABLED) && this.tooltip[0].offsetWidth > 0) {
1624 this.reposition(event);
1630 // Adjust positions of the tooltip on window resize if enabled
1631 if(posOptions.adjust.resize || viewportTarget.length) {
1632 this._bind( $.event.special.resize ? viewportTarget : windowTarget, 'resize', repositionMethod );
1635 // Adjust tooltip position on scroll of the window or viewport element if present
1636 if(posOptions.adjust.scroll) {
1637 this._bind( windowTarget.add(posOptions.container), 'scroll', repositionMethod );
1641 // Un-assignment method
1642 PROTOTYPE._unassignEvents = function() {
1644 this.options.show.target[0],
1645 this.options.hide.target[0],
1646 this.rendered && this.tooltip[0],
1647 this.options.position.container[0],
1648 this.options.position.viewport[0],
1649 this.options.position.container.closest('html')[0], // unfocus
1654 this._unbind($([]).pushStack( $.grep(targets, function(i) {
1655 return typeof i === 'object';
1659 ;// Initialization method
1660 function init(elem, id, opts) {
1661 var obj, posOptions, attr, config, title,
1663 // Setup element references
1664 docBody = $(document.body),
1666 // Use document body instead of document element if needed
1667 newTarget = elem[0] === document ? docBody : elem,
1669 // Grab metadata from element if plugin is present
1670 metadata = (elem.metadata) ? elem.metadata(opts.metadata) : NULL,
1672 // If metadata type if HTML5, grab 'name' from the object instead, or use the regular data object otherwise
1673 metadata5 = opts.metadata.type === 'html5' && metadata ? metadata[opts.metadata.name] : NULL,
1675 // Grab data from metadata.name (or data-qtipopts as fallback) using .data() method,
1676 html5 = elem.data(opts.metadata.name || 'qtipopts');
1678 // If we don't get an object returned attempt to parse it manualyl without parseJSON
1679 try { html5 = typeof html5 === 'string' ? $.parseJSON(html5) : html5; } catch(e) {}
1681 // Merge in and sanitize metadata
1682 config = $.extend(TRUE, {}, QTIP.defaults, opts,
1683 typeof html5 === 'object' ? sanitizeOptions(html5) : NULL,
1684 sanitizeOptions(metadata5 || metadata));
1686 // Re-grab our positioning options now we've merged our metadata and set id to passed value
1687 posOptions = config.position;
1690 // Setup missing content if none is detected
1691 if('boolean' === typeof config.content.text) {
1692 attr = elem.attr(config.content.attr);
1694 // Grab from supplied attribute if available
1695 if(config.content.attr !== FALSE && attr) { config.content.text = attr; }
1697 // No valid content was found, abort render
1698 else { return FALSE; }
1701 // Setup target options
1702 if(!posOptions.container.length) { posOptions.container = docBody; }
1703 if(posOptions.target === FALSE) { posOptions.target = newTarget; }
1704 if(config.show.target === FALSE) { config.show.target = newTarget; }
1705 if(config.show.solo === TRUE) { config.show.solo = posOptions.container.closest('body'); }
1706 if(config.hide.target === FALSE) { config.hide.target = newTarget; }
1707 if(config.position.viewport === TRUE) { config.position.viewport = posOptions.container; }
1709 // Ensure we only use a single container
1710 posOptions.container = posOptions.container.eq(0);
1712 // Convert position corner values into x and y strings
1713 posOptions.at = new CORNER(posOptions.at, TRUE);
1714 posOptions.my = new CORNER(posOptions.my);
1716 // Destroy previous tooltip if overwrite is enabled, or skip element if not
1717 if(elem.data(NAMESPACE)) {
1718 if(config.overwrite) {
1719 elem.qtip('destroy', true);
1721 else if(config.overwrite === FALSE) {
1726 // Add has-qtip attribute
1727 elem.attr(ATTR_HAS, id);
1729 // Remove title attribute and store it if present
1730 if(config.suppress && (title = elem.attr('title'))) {
1731 // Final attr call fixes event delegatiom and IE default tooltip showing problem
1732 elem.removeAttr('title').attr(oldtitle, title).attr('title', '');
1735 // Initialize the tooltip and add API reference
1736 obj = new QTip(elem, config, id, !!attr);
1737 elem.data(NAMESPACE, obj);
1739 // Catch remove/removeqtip events on target element to destroy redundant tooltip
1740 elem.one('remove.qtip-'+id+' removeqtip.qtip-'+id, function() {
1741 var api; if((api = $(this).data(NAMESPACE))) { api.destroy(true); }
1747 // jQuery $.fn extension method
1748 QTIP = $.fn.qtip = function(options, notation, newValue)
1750 var command = ('' + options).toLowerCase(), // Parse command
1752 args = $.makeArray(arguments).slice(1),
1753 event = args[args.length - 1],
1754 opts = this[0] ? $.data(this[0], NAMESPACE) : NULL;
1756 // Check for API request
1757 if((!arguments.length && opts) || command === 'api') {
1761 // Execute API command if present
1762 else if('string' === typeof options) {
1763 this.each(function() {
1764 var api = $.data(this, NAMESPACE);
1765 if(!api) { return TRUE; }
1767 // Cache the event if possible
1768 if(event && event.timeStamp) { api.cache.event = event; }
1770 // Check for specific API commands
1771 if(notation && (command === 'option' || command === 'options')) {
1772 if(newValue !== undefined || $.isPlainObject(notation)) {
1773 api.set(notation, newValue);
1776 returned = api.get(notation);
1781 // Execute API command
1782 else if(api[command]) {
1783 api[command].apply(api, args);
1787 return returned !== NULL ? returned : this;
1790 // No API commands. validate provided options and setup qTips
1791 else if('object' === typeof options || !arguments.length) {
1792 // Sanitize options first
1793 opts = sanitizeOptions($.extend(TRUE, {}, options));
1795 return this.each(function(i) {
1798 // Find next available ID, or use custom ID if provided
1799 id = $.isArray(opts.id) ? opts.id[i] : opts.id;
1800 id = !id || id === FALSE || id.length < 1 || QTIP.api[id] ? QTIP.nextid++ : id;
1802 // Initialize the qTip and re-grab newly sanitized options
1803 api = init($(this), id, opts);
1804 if(api === FALSE) { return TRUE; }
1805 else { QTIP.api[id] = api; }
1807 // Initialize plugins
1808 $.each(PLUGINS, function() {
1809 if(this.initialize === 'initialize') { this(api); }
1812 // Assign initial pre-render events
1813 api._assignInitialEvents(event);
1821 // Populated in render method
1824 /* Allow other plugins to successfully retrieve the title of an element with a qTip applied */
1825 attr: function(attr, val) {
1829 api = $.data(self, 'qtip');
1831 if(attr === title && api && 'object' === typeof api && api.options.suppress) {
1832 if(arguments.length < 2) {
1833 return $.attr(self, oldtitle);
1836 // If qTip is rendered and title was originally used as content, update it
1837 if(api && api.options.content.attr === title && api.cache.attr) {
1838 api.set('content.text', val);
1841 // Use the regular attr method to set, then cache the result
1842 return this.attr(oldtitle, val);
1846 return $.fn['attr'+replaceSuffix].apply(this, arguments);
1849 /* Allow clone to correctly retrieve cached title attributes */
1850 clone: function(keepData) {
1851 var titles = $([]), title = 'title',
1853 // Clone our element using the real clone method
1854 elems = $.fn['clone'+replaceSuffix].apply(this, arguments);
1856 // Grab all elements with an oldtitle set, and change it to regular title attribute, if keepData is false
1858 elems.filter('['+oldtitle+']').attr('title', function() {
1859 return $.attr(this, oldtitle);
1861 .removeAttr(oldtitle);
1866 }, function(name, func) {
1867 if(!func || $.fn[name+replaceSuffix]) { return TRUE; }
1869 var old = $.fn[name+replaceSuffix] = $.fn[name];
1870 $.fn[name] = function() {
1871 return func.apply(this, arguments) || old.apply(this, arguments);
1875 /* Fire off 'removeqtip' handler in $.cleanData if jQuery UI not present (it already does similar).
1876 * This snippet is taken directly from jQuery UI source code found here:
1877 * http://code.jquery.com/ui/jquery-ui-git.js
1880 $['cleanData'+replaceSuffix] = $.cleanData;
1881 $.cleanData = function( elems ) {
1882 for(var i = 0, elem; (elem = $( elems[i] )).length; i++) {
1883 if(elem.attr(ATTR_HAS)) {
1884 try { elem.triggerHandler('removeqtip'); }
1888 $['cleanData'+replaceSuffix].apply(this, arguments);
1893 QTIP.version = '2.2.0';
1895 // Base ID for all qTips
1898 // Inactive events array
1899 QTIP.inactiveEvents = INACTIVE_EVENTS;
1901 // Base z-index for all qTips
1902 QTIP.zindex = 15000;
1904 // Define configuration defaults
1927 method: 'flipinvert flipinvert'
1929 effect: function(api, pos, viewport) {
1930 $(this).animate(pos, {
1938 event: 'mouseenter',
1947 event: 'mouseleave',
1975 ;PLUGINS.viewport = function(api, position, posOptions, targetWidth, targetHeight, elemWidth, elemHeight)
1977 var target = posOptions.target,
1978 tooltip = api.elements.tooltip,
1981 adjust = posOptions.adjust,
1982 method = adjust.method.split(' '),
1983 methodX = method[0],
1984 methodY = method[1] || method[0],
1985 viewport = posOptions.viewport,
1986 container = posOptions.container,
1988 adjusted = { left: 0, top: 0 },
1989 fixed, newMy, newClass, containerOffset, containerStatic,
1990 viewportWidth, viewportHeight, viewportScroll, viewportOffset;
1992 // If viewport is not a jQuery element, or it's the window/document, or no adjustment method is used... return
1993 if(!viewport.jquery || target[0] === window || target[0] === document.body || adjust.method === 'none') {
1997 // Cach container details
1998 containerOffset = container.offset() || adjusted;
1999 containerStatic = container.css('position') === 'static';
2001 // Cache our viewport details
2002 fixed = tooltip.css('position') === 'fixed';
2003 viewportWidth = viewport[0] === window ? viewport.width() : viewport.outerWidth(FALSE);
2004 viewportHeight = viewport[0] === window ? viewport.height() : viewport.outerHeight(FALSE);
2005 viewportScroll = { left: fixed ? 0 : viewport.scrollLeft(), top: fixed ? 0 : viewport.scrollTop() };
2006 viewportOffset = viewport.offset() || adjusted;
2008 // Generic calculation method
2009 function calculate(side, otherSide, type, adjust, side1, side2, lengthName, targetLength, elemLength) {
2010 var initialPos = position[side1],
2013 isShift = type === SHIFT,
2014 myLength = mySide === side1 ? elemLength : mySide === side2 ? -elemLength : -elemLength / 2,
2015 atLength = atSide === side1 ? targetLength : atSide === side2 ? -targetLength : -targetLength / 2,
2016 sideOffset = viewportScroll[side1] + viewportOffset[side1] - (containerStatic ? 0 : containerOffset[side1]),
2017 overflow1 = sideOffset - initialPos,
2018 overflow2 = initialPos + elemLength - (lengthName === WIDTH ? viewportWidth : viewportHeight) - sideOffset,
2019 offset = myLength - (my.precedance === side || mySide === my[otherSide] ? atLength : 0) - (atSide === CENTER ? targetLength / 2 : 0);
2023 offset = (mySide === side1 ? 1 : -1) * myLength;
2025 // Adjust position but keep it within viewport dimensions
2026 position[side1] += overflow1 > 0 ? overflow1 : overflow2 > 0 ? -overflow2 : 0;
2027 position[side1] = Math.max(
2028 -containerOffset[side1] + viewportOffset[side1],
2029 initialPos - offset,
2032 -containerOffset[side1] + viewportOffset[side1] + (lengthName === WIDTH ? viewportWidth : viewportHeight),
2037 // Make sure we don't adjust complete off the element when using 'center'
2038 mySide === 'center' ? initialPos - myLength : 1E9
2046 // Update adjustment amount depending on if using flipinvert or flip
2047 adjust *= (type === FLIPINVERT ? 2 : 0);
2049 // Check for overflow on the left/top
2050 if(overflow1 > 0 && (mySide !== side1 || overflow2 > 0)) {
2051 position[side1] -= offset + adjust;
2052 newMy.invert(side, side1);
2055 // Check for overflow on the bottom/right
2056 else if(overflow2 > 0 && (mySide !== side2 || overflow1 > 0) ) {
2057 position[side1] -= (mySide === CENTER ? -offset : offset) + adjust;
2058 newMy.invert(side, side2);
2061 // Make sure we haven't made things worse with the adjustment and reset if so
2062 if(position[side1] < viewportScroll && -position[side1] > overflow2) {
2063 position[side1] = initialPos; newMy = my.clone();
2067 return position[side1] - initialPos;
2070 // Set newMy if using flip or flipinvert methods
2071 if(methodX !== 'shift' || methodY !== 'shift') { newMy = my.clone(); }
2073 // Adjust position based onviewport and adjustment options
2075 left: methodX !== 'none' ? calculate( X, Y, methodX, adjust.x, LEFT, RIGHT, WIDTH, targetWidth, elemWidth ) : 0,
2076 top: methodY !== 'none' ? calculate( Y, X, methodY, adjust.y, TOP, BOTTOM, HEIGHT, targetHeight, elemHeight ) : 0
2079 // Set tooltip position class if it's changed
2080 if(newMy && cache.lastClass !== (newClass = NAMESPACE + '-pos-' + newMy.abbrev())) {
2081 tooltip.removeClass(api.cache.lastClass).addClass( (api.cache.lastClass = newClass) );
2087 }( window, document ));