vendor/assets/javascripts/jquery.qtip.js in qtip2-jquery-rails-2.1.108 vs vendor/assets/javascripts/jquery.qtip.js in qtip2-jquery-rails-2.2.100
- old
+ new
@@ -1,36 +1,34 @@
/*
- * qTip2 - Pretty powerful tooltips - v2.1.1
+ * qTip2 - Pretty powerful tooltips - v2.2.1
* http://qtip2.com
*
- * Copyright (c) 2013 Craig Michael Thompson
- * Released under the MIT, GPL licenses
+ * Copyright (c) 2014
+ * Released under the MIT licenses
* http://jquery.org/license
*
- * Date: Thu Jul 11 2013 02:03 GMT+0100+0100
- * Plugins: tips modal viewport svg imagemap ie6
- * Styles: basic css3
+ * Date: Sat Sep 6 2014 06:25 EDT-0400
+ * Plugins: tips viewport imagemap svg modal ie6
+ * Styles: core basic css3
*/
/*global window: false, jQuery: false, console: false, define: false */
/* Cache window, document, undefined */
(function( window, document, undefined ) {
// Uses AMD or browser globals to create a jQuery plugin.
(function( factory ) {
"use strict";
if(typeof define === 'function' && define.amd) {
- define(['jquery', 'imagesloaded'], factory);
+ define(['jquery'], factory);
}
else if(jQuery && !jQuery.fn.qtip) {
factory(jQuery);
}
}
(function($) {
- /* This currently causes issues with Safari 6, so for it's disabled */
- //"use strict"; // (Dis)able ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
-
+ "use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
;// Munge the primitives - Paul Irish tip
var TRUE = true,
FALSE = false,
NULL = null,
@@ -67,237 +65,242 @@
CLASS_HOVER = NAMESPACE + '-hover',
CLASS_DISABLED = NAMESPACE+'-disabled',
replaceSuffix = '_replacedByqTip',
oldtitle = 'oldtitle',
-trackingBound;
+trackingBound,
// Browser detection
BROWSER = {
/*
* IE version detection
*
* Adapted from: http://ajaxian.com/archives/attack-of-the-ie-conditional-comment
* Credit to James Padolsey for the original implemntation!
*/
ie: (function(){
- var v = 3, div = document.createElement('div');
- while ((div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->')) {
- if(!div.getElementsByTagName('i')[0]) { break; }
- }
+ for (
+ var v = 4, i = document.createElement("div");
+ (i.innerHTML = "<!--[if gt IE " + v + "]><i></i><![endif]-->") && i.getElementsByTagName("i")[0];
+ v+=1
+ ) {}
return v > 4 ? v : NaN;
}()),
-
+
/*
* iOS version detection
*/
- iOS: parseFloat(
+ iOS: parseFloat(
('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1])
.replace('undefined', '3_2').replace('_', '.').replace('_', '')
) || FALSE
};
+;function QTip(target, options, id, attr) {
+ // Elements and ID
+ this.id = id;
+ this.target = target;
+ this.tooltip = NULL;
+ this.elements = { target: target };
-;function QTip(target, options, id, attr) {
- // Elements and ID
- this.id = id;
- this.target = target;
- this.tooltip = NULL;
- this.elements = elements = { target: target };
-
- // Internal constructs
- this._id = NAMESPACE + '-' + id;
- this.timers = { img: {} };
- this.options = options;
- this.plugins = {};
-
- // Cache object
- this.cache = cache = {
- event: {},
- target: $(),
- disabled: FALSE,
- attr: attr,
- onTooltip: FALSE,
- lastClass: ''
- };
-
- // Set the initial flags
- this.rendered = this.destroyed = this.disabled = this.waiting =
- this.hiddenDuringWait = this.positioning = this.triggering = FALSE;
-}
-PROTOTYPE = QTip.prototype;
-
-PROTOTYPE.render = function(show) {
- if(this.rendered || this.destroyed) { return this; } // If tooltip has already been rendered, exit
-
- var self = this,
- options = this.options,
- cache = this.cache,
- elements = this.elements,
- text = options.content.text,
- title = options.content.title,
- button = options.content.button,
- posOptions = options.position,
- namespace = '.'+this._id+' ',
- deferreds = [];
-
- // Add ARIA attributes to target
- $.attr(this.target[0], 'aria-describedby', this._id);
-
- // Create tooltip element
- this.tooltip = elements.tooltip = tooltip = $('<div/>', {
- 'id': this._id,
- 'class': [ NAMESPACE, CLASS_DEFAULT, options.style.classes, NAMESPACE + '-pos-' + options.position.my.abbrev() ].join(' '),
- 'width': options.style.width || '',
- 'height': options.style.height || '',
- 'tracking': posOptions.target === 'mouse' && posOptions.adjust.mouse,
-
- /* ARIA specific attributes */
- 'role': 'alert',
- 'aria-live': 'polite',
- 'aria-atomic': FALSE,
- 'aria-describedby': this._id + '-content',
- 'aria-hidden': TRUE
- })
- .toggleClass(CLASS_DISABLED, this.disabled)
- .attr(ATTR_ID, this.id)
- .data(NAMESPACE, this)
- .appendTo(posOptions.container)
- .append(
- // Create content element
- elements.content = $('<div />', {
- 'class': NAMESPACE + '-content',
- 'id': this._id + '-content',
- 'aria-atomic': TRUE
- })
- );
-
- // Set rendered flag and prevent redundant reposition calls for now
- this.rendered = -1;
- this.positioning = TRUE;
-
- // Create title...
- if(title) {
- this._createTitle();
-
- // Update title only if its not a callback (called in toggle if so)
- if(!$.isFunction(title)) {
- deferreds.push( this._updateTitle(title, FALSE) );
- }
- }
-
- // Create button
- if(button) { this._createButton(); }
-
- // Set proper rendered flag and update content if not a callback function (called in toggle)
- if(!$.isFunction(text)) {
- deferreds.push( this._updateContent(text, FALSE) );
- }
- this.rendered = TRUE;
-
- // Setup widget classes
- this._setWidget();
-
- // Assign passed event callbacks (before plugins!)
- $.each(options.events, function(name, callback) {
- $.isFunction(callback) && tooltip.bind(
- (name === 'toggle' ? ['tooltipshow','tooltiphide'] : ['tooltip'+name])
- .join(namespace)+namespace, callback
- );
- });
-
- // Initialize 'render' plugins
- $.each(PLUGINS, function(name) {
- var instance;
- if(this.initialize === 'render' && (instance = this(self))) {
- self.plugins[name] = instance;
- }
- });
-
- // Assign events
- this._assignEvents();
-
- // When deferreds have completed
- $.when.apply($, deferreds).then(function() {
- // tooltiprender event
- self._trigger('render');
-
- // Reset flags
- self.positioning = FALSE;
-
- // Show tooltip if not hidden during wait period
- if(!self.hiddenDuringWait && (options.show.ready || show)) {
- self.toggle(TRUE, cache.event, FALSE);
- }
- self.hiddenDuringWait = FALSE;
- });
-
- // Expose API
- QTIP.api[this.id] = this;
-
- return this;
-};
-
-PROTOTYPE.destroy = function(immediate) {
- // Set flag the signify destroy is taking place to plugins
- // and ensure it only gets destroyed once!
- if(this.destroyed) { return this.target; }
-
- function process() {
- if(this.destroyed) { return; }
- this.destroyed = TRUE;
-
- var target = this.target,
- title = target.attr(oldtitle);
-
- // Destroy tooltip if rendered
- if(this.rendered) {
- this.tooltip.stop(1,0).find('*').remove().end().remove();
- }
-
- // Destroy all plugins
- $.each(this.plugins, function(name) {
- this.destroy && this.destroy();
- });
-
- // Clear timers and remove bound events
- clearTimeout(this.timers.show);
- clearTimeout(this.timers.hide);
- this._unassignEvents();
-
- // Remove api object and ARIA attributes
- target.removeData(NAMESPACE).removeAttr(ATTR_ID)
- .removeAttr('aria-describedby');
-
- // Reset old title attribute if removed
- if(this.options.suppress && title) {
- target.attr('title', title).removeAttr(oldtitle);
- }
-
- // Remove qTip events associated with this API
- this._unbind(target);
-
- // Remove ID from used id objects, and delete object references
- // for better garbage collection and leak protection
- this.options = this.elements = this.cache = this.timers =
- this.plugins = this.mouse = NULL;
-
- // Delete epoxsed API object
- delete QTIP.api[this.id];
- }
-
- // If an immediate destory is needed
- if(immediate !== TRUE && this.rendered) {
- tooltip.one('tooltiphidden', $.proxy(process, this));
- !this.triggering && this.hide();
- }
-
- // If we're not in the process of hiding... process
- else { process.call(this); }
-
- return this.target;
-};
-
+ // Internal constructs
+ this._id = NAMESPACE + '-' + id;
+ this.timers = { img: {} };
+ this.options = options;
+ this.plugins = {};
+
+ // Cache object
+ this.cache = {
+ event: {},
+ target: $(),
+ disabled: FALSE,
+ attr: attr,
+ onTooltip: FALSE,
+ lastClass: ''
+ };
+
+ // Set the initial flags
+ this.rendered = this.destroyed = this.disabled = this.waiting =
+ this.hiddenDuringWait = this.positioning = this.triggering = FALSE;
+}
+PROTOTYPE = QTip.prototype;
+
+PROTOTYPE._when = function(deferreds) {
+ return $.when.apply($, deferreds);
+};
+
+PROTOTYPE.render = function(show) {
+ if(this.rendered || this.destroyed) { return this; } // If tooltip has already been rendered, exit
+
+ var self = this,
+ options = this.options,
+ cache = this.cache,
+ elements = this.elements,
+ text = options.content.text,
+ title = options.content.title,
+ button = options.content.button,
+ posOptions = options.position,
+ namespace = '.'+this._id+' ',
+ deferreds = [],
+ tooltip;
+
+ // Add ARIA attributes to target
+ $.attr(this.target[0], 'aria-describedby', this._id);
+
+ // Create public position object that tracks current position corners
+ cache.posClass = this._createPosClass(
+ (this.position = { my: posOptions.my, at: posOptions.at }).my
+ );
+
+ // Create tooltip element
+ this.tooltip = elements.tooltip = tooltip = $('<div/>', {
+ 'id': this._id,
+ 'class': [ NAMESPACE, CLASS_DEFAULT, options.style.classes, cache.posClass ].join(' '),
+ 'width': options.style.width || '',
+ 'height': options.style.height || '',
+ 'tracking': posOptions.target === 'mouse' && posOptions.adjust.mouse,
+
+ /* ARIA specific attributes */
+ 'role': 'alert',
+ 'aria-live': 'polite',
+ 'aria-atomic': FALSE,
+ 'aria-describedby': this._id + '-content',
+ 'aria-hidden': TRUE
+ })
+ .toggleClass(CLASS_DISABLED, this.disabled)
+ .attr(ATTR_ID, this.id)
+ .data(NAMESPACE, this)
+ .appendTo(posOptions.container)
+ .append(
+ // Create content element
+ elements.content = $('<div />', {
+ 'class': NAMESPACE + '-content',
+ 'id': this._id + '-content',
+ 'aria-atomic': TRUE
+ })
+ );
+
+ // Set rendered flag and prevent redundant reposition calls for now
+ this.rendered = -1;
+ this.positioning = TRUE;
+
+ // Create title...
+ if(title) {
+ this._createTitle();
+
+ // Update title only if its not a callback (called in toggle if so)
+ if(!$.isFunction(title)) {
+ deferreds.push( this._updateTitle(title, FALSE) );
+ }
+ }
+
+ // Create button
+ if(button) { this._createButton(); }
+
+ // Set proper rendered flag and update content if not a callback function (called in toggle)
+ if(!$.isFunction(text)) {
+ deferreds.push( this._updateContent(text, FALSE) );
+ }
+ this.rendered = TRUE;
+
+ // Setup widget classes
+ this._setWidget();
+
+ // Initialize 'render' plugins
+ $.each(PLUGINS, function(name) {
+ var instance;
+ if(this.initialize === 'render' && (instance = this(self))) {
+ self.plugins[name] = instance;
+ }
+ });
+
+ // Unassign initial events and assign proper events
+ this._unassignEvents();
+ this._assignEvents();
+
+ // When deferreds have completed
+ this._when(deferreds).then(function() {
+ // tooltiprender event
+ self._trigger('render');
+
+ // Reset flags
+ self.positioning = FALSE;
+
+ // Show tooltip if not hidden during wait period
+ if(!self.hiddenDuringWait && (options.show.ready || show)) {
+ self.toggle(TRUE, cache.event, FALSE);
+ }
+ self.hiddenDuringWait = FALSE;
+ });
+
+ // Expose API
+ QTIP.api[this.id] = this;
+
+ return this;
+};
+
+PROTOTYPE.destroy = function(immediate) {
+ // Set flag the signify destroy is taking place to plugins
+ // and ensure it only gets destroyed once!
+ if(this.destroyed) { return this.target; }
+
+ function process() {
+ if(this.destroyed) { return; }
+ this.destroyed = TRUE;
+
+ var target = this.target,
+ title = target.attr(oldtitle),
+ timer;
+
+ // Destroy tooltip if rendered
+ if(this.rendered) {
+ this.tooltip.stop(1,0).find('*').remove().end().remove();
+ }
+
+ // Destroy all plugins
+ $.each(this.plugins, function(name) {
+ this.destroy && this.destroy();
+ });
+
+ // Clear timers
+ for(timer in this.timers) {
+ clearTimeout(this.timers[timer]);
+ }
+
+ // Remove api object and ARIA attributes
+ target.removeData(NAMESPACE)
+ .removeAttr(ATTR_ID)
+ .removeAttr(ATTR_HAS)
+ .removeAttr('aria-describedby');
+
+ // Reset old title attribute if removed
+ if(this.options.suppress && title) {
+ target.attr('title', title).removeAttr(oldtitle);
+ }
+
+ // Remove qTip events associated with this API
+ this._unassignEvents();
+
+ // Remove ID from used id objects, and delete object references
+ // for better garbage collection and leak protection
+ this.options = this.elements = this.cache = this.timers =
+ this.plugins = this.mouse = NULL;
+
+ // Delete epoxsed API object
+ delete QTIP.api[this.id];
+ }
+
+ // If an immediate destory is needed
+ if((immediate !== TRUE || this.triggering === 'hide') && this.rendered) {
+ this.tooltip.one('tooltiphidden', $.proxy(process, this));
+ !this.triggering && this.hide();
+ }
+
+ // If we're not in the process of hiding... process
+ else { process.call(this); }
+
+ return this.target;
+};
;function invalidOpt(a) {
return a === NULL || $.type(a) !== 'object';
}
function invalidContent(c) {
@@ -350,11 +353,11 @@
return !once ? (api.set('content.text', loading), deferred) : loading;
};
}
if('title' in content) {
- if(!invalidOpt(content.title)) {
+ if($.isPlainObject(content.title)) {
content.button = content.title.button;
content.title = content.title.text;
}
if(invalidContent(content.title || FALSE)) {
@@ -366,11 +369,11 @@
if('position' in opts && invalidOpt(opts.position)) {
opts.position = { my: opts.position, at: opts.position };
}
if('show' in opts && invalidOpt(opts.show)) {
- opts.show = opts.show.jquery ? { target: opts.show } :
+ opts.show = opts.show.jquery ? { target: opts.show } :
opts.show === TRUE ? { ready: TRUE } : { event: opts.show };
}
if('hide' in opts && invalidOpt(opts.hide)) {
opts.hide = opts.hide.jquery ? { target: opts.hide } : { event: opts.hide };
@@ -431,50 +434,51 @@
'^content.button$': function(obj, o, v) {
this._updateButton(v);
},
'^content.title.(text|button)$': function(obj, o, v) {
this.set('content.'+o, v); // Backwards title.text/button compat
- },
+ },
// Position checks
'^position.(my|at)$': function(obj, o, v){
- 'string' === typeof v && (obj[o] = new CORNER(v, o === 'at'));
+ 'string' === typeof v && (this.position[o] = obj[o] = new CORNER(v, o === 'at'));
},
'^position.container$': function(obj, o, v){
- this.tooltip.appendTo(v);
+ this.rendered && this.tooltip.appendTo(v);
},
// Show checks
'^show.ready$': function(obj, o, v) {
v && (!this.rendered && this.render(TRUE) || this.toggle(TRUE));
},
// Style checks
'^style.classes$': function(obj, o, v, p) {
- this.tooltip.removeClass(p).addClass(v);
+ this.rendered && this.tooltip.removeClass(p).addClass(v);
},
- '^style.width|height': function(obj, o, v) {
- this.tooltip.css(o, v);
+ '^style.(width|height)': function(obj, o, v) {
+ this.rendered && this.tooltip.css(o, v);
},
'^style.widget|content.title': function() {
- this._setWidget();
+ this.rendered && this._setWidget();
},
'^style.def': function(obj, o, v) {
- this.tooltip.toggleClass(CLASS_DEFAULT, !!v);
+ this.rendered && this.tooltip.toggleClass(CLASS_DEFAULT, !!v);
},
// Events check
'^events.(render|show|move|hide|focus|blur)$': function(obj, o, v) {
- tooltip[($.isFunction(v) ? '' : 'un') + 'bind']('tooltip'+o, v);
+ this.rendered && this.tooltip[($.isFunction(v) ? '' : 'un') + 'bind']('tooltip'+o, v);
},
// Properties which require event reassignment
'^(show|hide|position).(event|target|fixed|inactive|leave|distance|viewport|adjust)': function() {
- var posOptions = this.options.position;
+ if(!this.rendered) { return; }
// Set tracking flag
- tooltip.attr('tracking', posOptions.target === 'mouse' && posOptions.adjust.mouse);
+ var posOptions = this.options.position;
+ this.tooltip.attr('tracking', posOptions.target === 'mouse' && posOptions.adjust.mouse);
// Reassign events
this._unassignEvents();
this._assignEvents();
}
@@ -541,11 +545,11 @@
}
else { option = $.extend({}, option); }
// Set all of the defined options to their new values
$.each(option, function(notation, value) {
- if(!rendered && !rrender.test(notation)) {
+ if(rendered && rrender.test(notation)) {
delete option[notation]; return;
}
// Set new obj value
var obj = convertNotation(options, notation.toLowerCase()), previous;
@@ -575,11 +579,10 @@
this.reposition( options.position.target === 'mouse' ? NULL : this.cache.event );
}
return this;
};
-
;PROTOTYPE._update = function(content, element, reposition) {
var self = this,
cache = this.cache;
// Make sure tooltip is rendered and content is defined. If not return
@@ -604,28 +607,35 @@
// If content is null... return false
if(content === FALSE || (!content && content !== '')) { return FALSE; }
// Append new content if its a DOM array and show it if hidden
if(content.jquery && content.length > 0) {
- element.children().detach().end().append( content.css({ display: 'block' }) );
+ element.empty().append(
+ content.css({ display: 'block', visibility: 'visible' })
+ );
}
// Content is a regular string, insert the new content
else { element.html(content); }
- // If imagesLoaded is included, ensure images have loaded and return promise
- cache.waiting = TRUE;
+ // Wait for content to be loaded, and reposition
+ return this._waitForContent(element).then(function(images) {
+ if(self.rendered && self.tooltip[0].offsetWidth > 0) {
+ self.reposition(cache.event, !images.length);
+ }
+ });
+};
- return ( $.fn.imagesLoaded ? element.imagesLoaded() : $.Deferred().resolve($([])) )
- .done(function(images) {
- cache.waiting = FALSE;
+PROTOTYPE._waitForContent = function(element) {
+ var cache = this.cache;
- // Reposition if rendered
- if(images.length && self.rendered && self.tooltip[0].offsetWidth > 0) {
- self.reposition(cache.event, !images.length);
- }
- })
+ // Set flag
+ cache.waiting = TRUE;
+
+ // If imagesLoaded is included, ensure images have loaded and return promise
+ return ( $.fn.imagesLoaded ? element.imagesLoaded() : $.Deferred().resolve([]) )
+ .done(function() { cache.waiting = FALSE; })
.promise();
};
PROTOTYPE._updateContent = function(content, reposition) {
this._update(content, this.elements.content, reposition);
@@ -680,12 +690,15 @@
// Reposition if enabled
if(reposition !== FALSE) { this.reposition(); }
}
};
+;PROTOTYPE._createPosClass = function(my) {
+ return NAMESPACE + '-pos-' + (my || this.options.position.my).abbrev();
+};
-;PROTOTYPE.reposition = function(event, effect) {
+PROTOTYPE.reposition = function(event, effect) {
if(!this.rendered || this.positioning || this.destroyed) { return this; }
// Set positioning flag
this.positioning = TRUE;
@@ -697,67 +710,82 @@
at = posOptions.at,
viewport = posOptions.viewport,
container = posOptions.container,
adjust = posOptions.adjust,
method = adjust.method.split(' '),
- elemWidth = tooltip.outerWidth(FALSE),
- elemHeight = tooltip.outerHeight(FALSE),
+ tooltipWidth = tooltip.outerWidth(FALSE),
+ tooltipHeight = tooltip.outerHeight(FALSE),
targetWidth = 0,
targetHeight = 0,
type = tooltip.css('position'),
position = { left: 0, top: 0 },
visible = tooltip[0].offsetWidth > 0,
isScroll = event && event.type === 'scroll',
win = $(window),
doc = container[0].ownerDocument,
mouse = this.mouse,
- pluginCalculations, offset;
+ pluginCalculations, offset, adjusted, newClass;
// Check if absolute position was passed
if($.isArray(target) && target.length === 2) {
// Force left top and set position
at = { x: LEFT, y: TOP };
position = { left: target[0], top: target[1] };
}
// Check if mouse was the target
- else if(target === 'mouse' && ((event && event.pageX) || cache.event.pageX)) {
+ else if(target === 'mouse') {
// Force left top to allow flipping
at = { x: LEFT, y: TOP };
- // Use cached event if one isn't available for positioning
- event = mouse && mouse.pageX && (adjust.mouse || !event || !event.pageX) ? mouse :
- (event && (event.type === 'resize' || event.type === 'scroll') ? cache.event :
- event && event.pageX && event.type === 'mousemove' ? event :
- (!adjust.mouse || this.options.show.distance) && cache.origin && cache.origin.pageX ? cache.origin :
- event) || event || cache.event || mouse || {};
+ // Use the mouse origin that caused the show event, if distance hiding is enabled
+ if((!adjust.mouse || this.options.hide.distance) && cache.origin && cache.origin.pageX) {
+ event = cache.origin;
+ }
+ // Use cached event for resize/scroll events
+ else if(!event || (event && (event.type === 'resize' || event.type === 'scroll'))) {
+ event = cache.event;
+ }
+
+ // Otherwise, use the cached mouse coordinates if available
+ else if(mouse && mouse.pageX) {
+ event = mouse;
+ }
+
// Calculate body and container offset and take them into account below
if(type !== 'static') { position = container.offset(); }
- if(doc.body.offsetWidth !== (window.innerWidth || doc.documentElement.clientWidth)) { offset = $(doc.body).offset(); }
+ if(doc.body.offsetWidth !== (window.innerWidth || doc.documentElement.clientWidth)) {
+ offset = $(document.body).offset();
+ }
// Use event coordinates for position
position = {
left: event.pageX - position.left + (offset && offset.left || 0),
top: event.pageY - position.top + (offset && offset.top || 0)
};
// Scroll events are a pain, some browsers
- if(adjust.mouse && isScroll) {
- position.left -= mouse.scrollX - win.scrollLeft();
- position.top -= mouse.scrollY - win.scrollTop();
+ if(adjust.mouse && isScroll && mouse) {
+ position.left -= (mouse.scrollX || 0) - win.scrollLeft();
+ position.top -= (mouse.scrollY || 0) - win.scrollTop();
}
}
// Target wasn't mouse or absolute...
else {
// Check if event targetting is being used
- if(target === 'event' && event && event.target && event.type !== 'scroll' && event.type !== 'resize') {
- cache.target = $(event.target);
+ if(target === 'event') {
+ if(event && event.target && event.type !== 'scroll' && event.type !== 'resize') {
+ cache.target = $(event.target);
+ }
+ else if(!event.target) {
+ cache.target = this.elements.target;
+ }
}
else if(target !== 'event'){
- cache.target = $(target.jquery ? target : elements.target);
+ cache.target = $(target.jquery ? target : this.elements.target);
}
target = cache.target;
// Parse the target into a jQuery object and make sure there's an element present
target = $(target).eq(0);
@@ -780,11 +808,11 @@
else if(PLUGINS.imagemap && target.is('area')) {
pluginCalculations = PLUGINS.imagemap(this, target, at, PLUGINS.viewport ? method : FALSE);
}
// Check if the target is an SVG element
- else if(PLUGINS.svg && target[0].ownerSVGElement) {
+ else if(PLUGINS.svg && target && target[0].ownerSVGElement) {
pluginCalculations = PLUGINS.svg(this, target, at, PLUGINS.viewport ? method : FALSE);
}
// Otherwise use regular jQuery methods
else {
@@ -803,12 +831,12 @@
// Adjust position to take into account offset parents
position = this.reposition.offset(target, position, container);
// Adjust for position.fixed tooltips (and also iOS scroll bug in v3.2-4.0 & v4.3-4.3.2)
- if((BROWSER.iOS > 3.1 && BROWSER.iOS < 4.1) ||
- (BROWSER.iOS >= 4.3 && BROWSER.iOS < 4.33) ||
+ if((BROWSER.iOS > 3.1 && BROWSER.iOS < 4.1) ||
+ (BROWSER.iOS >= 4.3 && BROWSER.iOS < 4.33) ||
(!BROWSER.iOS && type === 'fixed')
){
position.left -= win.scrollLeft();
position.top -= win.scrollTop();
}
@@ -819,27 +847,35 @@
position.top += at.y === BOTTOM ? targetHeight : at.y === CENTER ? targetHeight / 2 : 0;
}
}
// Adjust position relative to tooltip
- position.left += adjust.x + (my.x === RIGHT ? -elemWidth : my.x === CENTER ? -elemWidth / 2 : 0);
- position.top += adjust.y + (my.y === BOTTOM ? -elemHeight : my.y === CENTER ? -elemHeight / 2 : 0);
+ position.left += adjust.x + (my.x === RIGHT ? -tooltipWidth : my.x === CENTER ? -tooltipWidth / 2 : 0);
+ position.top += adjust.y + (my.y === BOTTOM ? -tooltipHeight : my.y === CENTER ? -tooltipHeight / 2 : 0);
// Use viewport adjustment plugin if enabled
if(PLUGINS.viewport) {
- position.adjusted = PLUGINS.viewport(
- this, position, posOptions, targetWidth, targetHeight, elemWidth, elemHeight
+ adjusted = position.adjusted = PLUGINS.viewport(
+ this, position, posOptions, targetWidth, targetHeight, tooltipWidth, tooltipHeight
);
// Apply offsets supplied by positioning plugin (if used)
- if(offset && position.adjusted.left) { position.left += offset.left; }
- if(offset && position.adjusted.top) { position.top += offset.top; }
+ if(offset && adjusted.left) { position.left += offset.left; }
+ if(offset && adjusted.top) { position.top += offset.top; }
+
+ // Apply any new 'my' position
+ if(adjusted.my) { this.position.my = adjusted.my; }
}
// Viewport adjustment is disabled, set values to zero
else { position.adjusted = { left: 0, top: 0 }; }
+ // Set tooltip position class if it's changed
+ if(cache.posClass !== (newClass = this._createPosClass(this.position.my))) {
+ tooltip.removeClass(cache.posClass).addClass( (cache.posClass = newClass) );
+ }
+
// tooltipmove event
if(!this._trigger('move', [position, viewport.elem || viewport], event)) { return this; }
delete position.adjusted;
// If effect is disabled, target it mouse, no animation is defined or positioning gives NaN out, set CSS directly
@@ -919,43 +955,52 @@
var f = corner.charAt(0);
this.precedance = (f === 't' || f === 'b' ? Y : X);
}).prototype;
C.invert = function(z, center) {
- this[z] = this[z] === LEFT ? RIGHT : this[z] === RIGHT ? LEFT : center || this[z];
+ this[z] = this[z] === LEFT ? RIGHT : this[z] === RIGHT ? LEFT : center || this[z];
};
-C.string = function() {
+C.string = function(join) {
var x = this.x, y = this.y;
- return x === y ? x : this.precedance === Y || (this.forceY && y !== 'center') ? y+' '+x : x+' '+y;
+
+ var result = x !== y ?
+ (x === 'center' || y !== 'center' && (this.precedance === Y || this.forceY) ?
+ [y,x] : [x,y]
+ ) :
+ [x];
+
+ return join !== false ? result.join(' ') : result;
};
C.abbrev = function() {
- var result = this.string().split(' ');
+ var result = this.string(false);
return result[0].charAt(0) + (result[1] && result[1].charAt(0) || '');
};
C.clone = function() {
return new CORNER( this.string(), this.forceY );
-};;
+};
+
+;
PROTOTYPE.toggle = function(state, event) {
var cache = this.cache,
options = this.options,
tooltip = this.tooltip;
// Try to prevent flickering when tooltip overlaps show element
if(event) {
- if((/over|enter/).test(event.type) && (/out|leave/).test(cache.event.type) &&
+ if((/over|enter/).test(event.type) && cache.event && (/out|leave/).test(cache.event.type) &&
options.show.target.add(event.target).length === options.show.target.length &&
tooltip.has(event.relatedTarget).length) {
return this;
}
// Cache event
- cache.event = $.extend({}, event);
+ cache.event = $.event.fix(event);
}
-
+
// If we're currently waiting and we've just hidden... stop it
this.waiting && !state && (this.hiddenDuringWait = TRUE);
// Render the tooltip if showing and it isn't already
if(!this.rendered) { return state ? this.render(1) : this; }
@@ -965,24 +1010,27 @@
opts = this.options[type],
otherOpts = this.options[ !state ? 'show' : 'hide' ],
posOptions = this.options.position,
contentOptions = this.options.content,
width = this.tooltip.css('width'),
- visible = this.tooltip[0].offsetWidth > 0,
+ visible = this.tooltip.is(':visible'),
animate = state || opts.target.length === 1,
sameTarget = !event || opts.target.length < 2 || cache.target[0] === event.target,
- identicalState, allow, showEvent, delay;
+ identicalState, allow, showEvent, delay, after;
// Detect state if valid one isn't provided
if((typeof state).search('boolean|number')) { state = !visible; }
// Check if the tooltip is in an identical state to the new would-be state
identicalState = !tooltip.is(':animated') && visible === state && sameTarget;
// Fire tooltip(show/hide) event and check if destroyed
allow = !identicalState ? !!this._trigger(type, [90]) : NULL;
+ // Check to make sure the tooltip wasn't destroyed in the callback
+ if(this.destroyed) { return this; }
+
// If the user didn't stop the method prematurely and we're showing the tooltip, focus it
if(allow !== FALSE && state) { this.focus(event); }
// If the state hasn't changed or the user stopped it, return early
if(!allow || identicalState) { return this; }
@@ -991,11 +1039,11 @@
$.attr(tooltip[0], 'aria-hidden', !!!state);
// Execute state specific properties
if(state) {
// Store show origin coordinates
- cache.origin = $.extend({}, this.mouse);
+ this.mouse && (cache.origin = $.event.fix(this.mouse));
// Update tooltip content & title if it's a dynamic function
if($.isFunction(contentOptions.text)) { this._updateContent(contentOptions.text, FALSE); }
if($.isFunction(contentOptions.title)) { this._updateTitle(contentOptions.title, FALSE); }
@@ -1090,11 +1138,10 @@
};
PROTOTYPE.show = function(event) { return this.toggle(TRUE, event); };
PROTOTYPE.hide = function(event) { return this.toggle(FALSE, event); };
-
;PROTOTYPE.focus = function(event) {
if(!this.rendered || this.destroyed) { return this; }
var qtips = $(SELECTOR),
tooltip = this.tooltip,
@@ -1136,18 +1183,23 @@
// tooltipblur event
this._trigger('blur', [ this.tooltip.css('zIndex') ], event);
return this;
};
-
;PROTOTYPE.disable = function(state) {
if(this.destroyed) { return this; }
- if('boolean' !== typeof state) {
- state = !(this.tooltip.hasClass(CLASS_DISABLED) || this.disabled);
+ // If 'toggle' is passed, toggle the current state
+ if(state === 'toggle') {
+ state = !(this.rendered ? this.tooltip.hasClass(CLASS_DISABLED) : this.disabled);
}
+ // Disable if no state passed
+ else if('boolean' !== typeof state) {
+ state = TRUE;
+ }
+
if(this.rendered) {
this.tooltip.toggleClass(CLASS_DISABLED, state)
.attr('aria-disabled', state);
}
@@ -1155,11 +1207,10 @@
return this;
};
PROTOTYPE.enable = function() { return this.disable(FALSE); };
-
;PROTOTYPE._createButton = function()
{
var self = this,
elements = this.elements,
tooltip = elements.tooltip,
@@ -1203,11 +1254,10 @@
var elem = this.elements.button;
if(button) { this._createButton(); }
else { elem.remove(); }
};
-
;// Widget class creator
function createWidgetClass(cls) {
return WIDGET.concat('').join(cls ? '-'+cls+' ' : ' ');
}
@@ -1222,37 +1272,47 @@
tooltip.removeClass(CLASS_DISABLED);
CLASS_DISABLED = on ? 'ui-state-disabled' : 'qtip-disabled';
tooltip.toggleClass(CLASS_DISABLED, disabled);
tooltip.toggleClass('ui-helper-reset '+createWidgetClass(), on).toggleClass(CLASS_DEFAULT, this.options.style.def && !on);
-
+
if(elements.content) {
elements.content.toggleClass( createWidgetClass('content'), on);
}
if(elements.titlebar) {
elements.titlebar.toggleClass( createWidgetClass('header'), on);
}
if(elements.button) {
elements.button.toggleClass(NAMESPACE+'-icon', !on);
}
-};;function showMethod(event) {
- if(this.tooltip.hasClass(CLASS_DISABLED)) { return FALSE; }
+};
+;function delay(callback, duration) {
+ // If tooltip has displayed, start hide timer
+ if(duration > 0) {
+ return setTimeout(
+ $.proxy(callback, this), duration
+ );
+ }
+ else{ callback.call(this); }
+}
+function showMethod(event) {
+ if(this.tooltip.hasClass(CLASS_DISABLED)) { return; }
+
// Clear hide timers
clearTimeout(this.timers.show);
clearTimeout(this.timers.hide);
// Start show timer
- var callback = $.proxy(function(){ this.toggle(TRUE, event); }, this);
- if(this.options.show.delay > 0) {
- this.timers.show = setTimeout(callback, this.options.show.delay);
- }
- else{ callback(); }
+ this.timers.show = delay.call(this,
+ function() { this.toggle(TRUE, event); },
+ this.options.show.delay
+ );
}
function hideMethod(event) {
- if(this.tooltip.hasClass(CLASS_DISABLED)) { return FALSE; }
+ if(this.tooltip.hasClass(CLASS_DISABLED) || this.destroyed) { return; }
// Check if new target was actually the tooltip element
var relatedTarget = $(event.relatedTarget),
ontoTooltip = relatedTarget.closest(SELECTOR)[0] === this.tooltip[0],
ontoTarget = relatedTarget[0] === this.options.show.target[0];
@@ -1261,12 +1321,12 @@
clearTimeout(this.timers.show);
clearTimeout(this.timers.hide);
// Prevent hiding if tooltip is fixed and event target is the tooltip.
// Or if mouse positioning is enabled and cursor momentarily overlaps
- if(this !== relatedTarget[0] &&
- (this.options.position.target === 'mouse' && ontoTooltip) ||
+ if(this !== relatedTarget[0] &&
+ (this.options.position.target === 'mouse' && ontoTooltip) ||
(this.options.hide.fixed && (
(/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget))
))
{
try {
@@ -1276,114 +1336,173 @@
return;
}
// If tooltip has displayed, start hide timer
- var callback = $.proxy(function(){ this.toggle(FALSE, event); }, this);
- if(this.options.hide.delay > 0) {
- this.timers.hide = setTimeout(callback, this.options.hide.delay);
- }
- else{ callback(); }
+ this.timers.hide = delay.call(this,
+ function() { this.toggle(FALSE, event); },
+ this.options.hide.delay,
+ this
+ );
}
function inactiveMethod(event) {
- if(this.tooltip.hasClass(CLASS_DISABLED) || !this.options.hide.inactive) { return FALSE; }
+ if(this.tooltip.hasClass(CLASS_DISABLED) || !this.options.hide.inactive) { return; }
// Clear timer
clearTimeout(this.timers.inactive);
- this.timers.inactive = setTimeout(
- $.proxy(function(){ this.hide(event); }, this), this.options.hide.inactive
+
+ this.timers.inactive = delay.call(this,
+ function(){ this.hide(event); },
+ this.options.hide.inactive
);
}
function repositionMethod(event) {
if(this.rendered && this.tooltip[0].offsetWidth > 0) { this.reposition(event); }
}
// Store mouse coordinates
PROTOTYPE._storeMouse = function(event) {
- this.mouse = {
- pageX: event.pageX,
- pageY: event.pageY,
- type: 'mousemove',
- scrollX: window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft,
- scrollY: window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop
- };
+ (this.mouse = $.event.fix(event)).type = 'mousemove';
+ return this;
};
// Bind events
PROTOTYPE._bind = function(targets, events, method, suffix, context) {
+ if(!targets || !method || !events.length) { return; }
var ns = '.' + this._id + (suffix ? '-'+suffix : '');
- events.length && $(targets).bind(
+ $(targets).bind(
(events.split ? events : events.join(ns + ' ')) + ns,
$.proxy(method, context || this)
);
+ return this;
};
PROTOTYPE._unbind = function(targets, suffix) {
- $(targets).unbind('.' + this._id + (suffix ? '-'+suffix : ''));
+ targets && $(targets).unbind('.' + this._id + (suffix ? '-'+suffix : ''));
+ return this;
};
-// Apply common event handlers using delegate (avoids excessive .bind calls!)
-var ns = '.'+NAMESPACE;
-function delegate(selector, events, method) {
+// Global delegation helper
+function delegate(selector, events, method) {
$(document.body).delegate(selector,
- (events.split ? events : events.join(ns + ' ')) + ns,
+ (events.split ? events : events.join('.'+NAMESPACE + ' ')) + '.'+NAMESPACE,
function() {
var api = QTIP.api[ $.attr(this, ATTR_ID) ];
api && !api.disabled && method.apply(api, arguments);
}
);
}
+// Event trigger
+PROTOTYPE._trigger = function(type, args, event) {
+ var callback = $.Event('tooltip'+type);
+ callback.originalEvent = (event && $.extend({}, event)) || this.cache.event || NULL;
-$(function() {
- delegate(SELECTOR, ['mouseenter', 'mouseleave'], function(event) {
- var state = event.type === 'mouseenter',
- tooltip = $(event.currentTarget),
- target = $(event.relatedTarget || event.target),
- options = this.options;
+ this.triggering = type;
+ this.tooltip.trigger(callback, [this].concat(args || []));
+ this.triggering = FALSE;
- // On mouseenter...
- if(state) {
- // Focus the tooltip on mouseenter (z-index stacking)
- this.focus(event);
+ return !callback.isDefaultPrevented();
+};
- // Clear hide timer on tooltip hover to prevent it from closing
- tooltip.hasClass(CLASS_FIXED) && !tooltip.hasClass(CLASS_DISABLED) && clearTimeout(this.timers.hide);
- }
+PROTOTYPE._bindEvents = function(showEvents, hideEvents, showTargets, hideTargets, showMethod, hideMethod) {
+ // Get tasrgets that lye within both
+ var similarTargets = showTargets.filter( hideTargets ).add( hideTargets.filter(showTargets) ),
+ toggleEvents = [];
- // On mouseleave...
- else {
- // Hide when we leave the tooltip and not onto the show target (if a hide event is set)
- if(options.position.target === 'mouse' && options.hide.event &&
- options.show.target && !target.closest(options.show.target[0]).length) {
- this.hide(event);
- }
+ // If hide and show targets are the same...
+ if(similarTargets.length) {
+
+ // Filter identical show/hide events
+ $.each(hideEvents, function(i, type) {
+ var showIndex = $.inArray(type, showEvents);
+
+ // Both events are identical, remove from both hide and show events
+ // and append to toggleEvents
+ showIndex > -1 && toggleEvents.push( showEvents.splice( showIndex, 1 )[0] );
+ });
+
+ // Toggle events are special case of identical show/hide events, which happen in sequence
+ if(toggleEvents.length) {
+ // Bind toggle events to the similar targets
+ this._bind(similarTargets, toggleEvents, function(event) {
+ var state = this.rendered ? this.tooltip[0].offsetWidth > 0 : false;
+ (state ? hideMethod : showMethod).call(this, event);
+ });
+
+ // Remove the similar targets from the regular show/hide bindings
+ showTargets = showTargets.not(similarTargets);
+ hideTargets = hideTargets.not(similarTargets);
}
+ }
- // Add hover class
- tooltip.toggleClass(CLASS_HOVER, state);
+ // Apply show/hide/toggle events
+ this._bind(showTargets, showEvents, showMethod);
+ this._bind(hideTargets, hideEvents, hideMethod);
+};
+
+PROTOTYPE._assignInitialEvents = function(event) {
+ var options = this.options,
+ showTarget = options.show.target,
+ hideTarget = options.hide.target,
+ showEvents = options.show.event ? $.trim('' + options.show.event).split(' ') : [],
+ hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : [];
+
+ // Catch remove/removeqtip events on target element to destroy redundant tooltips
+ this._bind(this.elements.target, ['remove', 'removeqtip'], function(event) {
+ this.destroy(true);
+ }, 'destroy');
+
+ /*
+ * Make sure hoverIntent functions properly by using mouseleave as a hide event if
+ * mouseenter/mouseout is used for show.event, even if it isn't in the users options.
+ */
+ if(/mouse(over|enter)/i.test(options.show.event) && !/mouse(out|leave)/i.test(options.hide.event)) {
+ hideEvents.push('mouseleave');
+ }
+
+ /*
+ * Also make sure initial mouse targetting works correctly by caching mousemove coords
+ * on show targets before the tooltip has rendered. Also set onTarget when triggered to
+ * keep mouse tracking working.
+ */
+ this._bind(showTarget, 'mousemove', function(event) {
+ this._storeMouse(event);
+ this.cache.onTarget = TRUE;
});
- // Define events which reset the 'inactive' event handler
- delegate('['+ATTR_ID+']', INACTIVE_EVENTS, inactiveMethod);
-});
+ // Define hoverIntent function
+ function hoverIntent(event) {
+ // Only continue if tooltip isn't disabled
+ if(this.disabled || this.destroyed) { return FALSE; }
-// Event trigger
-PROTOTYPE._trigger = function(type, args, event) {
- var callback = $.Event('tooltip'+type);
- callback.originalEvent = (event && $.extend({}, event)) || this.cache.event || NULL;
+ // Cache the event data
+ this.cache.event = event && $.event.fix(event);
+ this.cache.target = event && $(event.target);
- this.triggering = TRUE;
- this.tooltip.trigger(callback, [this].concat(args || []));
- this.triggering = FALSE;
+ // Start the event sequence
+ clearTimeout(this.timers.show);
+ this.timers.show = delay.call(this,
+ function() { this.render(typeof event === 'object' || options.show.ready); },
+ options.prerender ? 0 : options.show.delay
+ );
+ }
- return !callback.isDefaultPrevented();
+ // Filter and bind events
+ this._bindEvents(showEvents, hideEvents, showTarget, hideTarget, hoverIntent, function() {
+ if(!this.timers) { return FALSE; }
+ clearTimeout(this.timers.show);
+ });
+
+ // Prerendering is enabled, create tooltip now
+ if(options.show.ready || options.prerender) { hoverIntent.call(this, event); }
};
// Event assignment method
PROTOTYPE._assignEvents = function() {
- var options = this.options,
+ var self = this,
+ options = this.options,
posOptions = options.position,
tooltip = this.tooltip,
showTarget = options.show.target,
hideTarget = options.hide.target,
@@ -1392,13 +1511,18 @@
documentTarget = $(document),
bodyTarget = $(document.body),
windowTarget = $(window),
showEvents = options.show.event ? $.trim('' + options.show.event).split(' ') : [],
- hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : [],
- toggleEvents = [];
+ hideEvents = options.hide.event ? $.trim('' + options.hide.event).split(' ') : [];
+
+ // Assign passed event callbacks
+ $.each(options.events, function(name, callback) {
+ self._bind(tooltip, name === 'toggle' ? ['tooltipshow','tooltiphide'] : ['tooltip'+name], callback, null, tooltip);
+ });
+
// Hide tooltips when leaving current window/frame (but not select/option elements)
if(/mouse(out|leave)/i.test(options.hide.event) && options.hide.leave === 'window') {
this._bind(documentTarget, ['mouseout', 'blur'], function(event) {
if(!/select|option/.test(event.target.nodeName) && !event.relatedTarget) {
this.hide(event);
@@ -1437,36 +1561,19 @@
}
// Check if the tooltip hides when inactive
if('number' === typeof options.hide.inactive) {
// Bind inactive method to show target(s) as a custom event
- this._bind(showTarget, 'qtip-'+this.id+'-inactive', inactiveMethod);
+ this._bind(showTarget, 'qtip-'+this.id+'-inactive', inactiveMethod, 'inactive');
// Define events which reset the 'inactive' event handler
- this._bind(hideTarget.add(tooltip), QTIP.inactiveEvents, inactiveMethod, '-inactive');
+ this._bind(hideTarget.add(tooltip), QTIP.inactiveEvents, inactiveMethod);
}
- // Apply hide events (and filter identical show events)
- hideEvents = $.map(hideEvents, function(type) {
- var showIndex = $.inArray(type, showEvents);
+ // Filter and bind events
+ this._bindEvents(showEvents, hideEvents, showTarget, hideTarget, showMethod, hideMethod);
- // Both events and targets are identical, apply events using a toggle
- if((showIndex > -1 && hideTarget.add(showTarget).length === hideTarget.length)) {
- toggleEvents.push( showEvents.splice( showIndex, 1 )[0] ); return;
- }
-
- return type;
- });
-
- // Apply show/hide/toggle events
- this._bind(showTarget, showEvents, showMethod);
- this._bind(hideTarget, hideEvents, hideMethod);
- this._bind(showTarget, toggleEvents, function(event) {
- (this.tooltip[0].offsetWidth > 0 ? hideMethod : showMethod).call(this, event);
- });
-
-
// Mouse movement bindings
this._bind(showTarget.add(tooltip), 'mousemove', function(event) {
// Check if the tooltip hides when mouse is moved a certain distance
if('number' === typeof options.hide.distance) {
var origin = this.cache.origin || {},
@@ -1489,10 +1596,11 @@
if(posOptions.adjust.mouse) {
// Apply a mouseleave event so we don't get problems with overlapping
if(options.hide.event) {
// Track if we're on the target or not
this._bind(showTarget, ['mouseenter', 'mouseleave'], function(event) {
+ if(!this.cache) {return FALSE; }
this.cache.onTarget = event.type === 'mouseenter';
});
}
// Update tooltip position on mousemove
@@ -1516,35 +1624,74 @@
}
};
// Un-assignment method
PROTOTYPE._unassignEvents = function() {
- var targets = [
- this.options.show.target[0],
- this.options.hide.target[0],
- this.rendered && this.tooltip[0],
- this.options.position.container[0],
- this.options.position.viewport[0],
- this.options.position.container.closest('html')[0], // unfocus
- window,
- document
- ];
-
- // Check if tooltip is rendered
- if(this.rendered) {
- this._unbind($([]).pushStack( $.grep(targets, function(i) {
+ var options = this.options,
+ showTargets = options.show.target,
+ hideTargets = options.hide.target,
+ targets = $.grep([
+ this.elements.target[0],
+ this.rendered && this.tooltip[0],
+ options.position.container[0],
+ options.position.viewport[0],
+ options.position.container.closest('html')[0], // unfocus
+ window,
+ document
+ ], function(i) {
return typeof i === 'object';
- })));
+ });
+
+ // Add show and hide targets if they're valid
+ if(showTargets && showTargets.toArray) {
+ targets = targets.concat(showTargets.toArray());
}
+ if(hideTargets && hideTargets.toArray) {
+ targets = targets.concat(hideTargets.toArray());
+ }
- // Tooltip isn't yet rendered, remove render event
- else { $(targets[0]).unbind('.'+this._id+'-create'); }
+ // Unbind the events
+ this._unbind(targets)
+ ._unbind(targets, 'destroy')
+ ._unbind(targets, 'inactive');
};
+// Apply common event handlers using delegate (avoids excessive .bind calls!)
+$(function() {
+ delegate(SELECTOR, ['mouseenter', 'mouseleave'], function(event) {
+ var state = event.type === 'mouseenter',
+ tooltip = $(event.currentTarget),
+ target = $(event.relatedTarget || event.target),
+ options = this.options;
+
+ // On mouseenter...
+ if(state) {
+ // Focus the tooltip on mouseenter (z-index stacking)
+ this.focus(event);
+
+ // Clear hide timer on tooltip hover to prevent it from closing
+ tooltip.hasClass(CLASS_FIXED) && !tooltip.hasClass(CLASS_DISABLED) && clearTimeout(this.timers.hide);
+ }
+
+ // On mouseleave...
+ else {
+ // When mouse tracking is enabled, hide when we leave the tooltip and not onto the show target (if a hide event is set)
+ if(options.position.target === 'mouse' && options.position.adjust.mouse &&
+ options.hide.event && options.show.target && !target.closest(options.show.target[0]).length) {
+ this.hide(event);
+ }
+ }
+
+ // Add hover class
+ tooltip.toggleClass(CLASS_HOVER, state);
+ });
+
+ // Define events which reset the 'inactive' event handler
+ delegate('['+ATTR_ID+']', INACTIVE_EVENTS, inactiveMethod);
+});
;// Initialization method
-function init(elem, id, opts)
-{
+function init(elem, id, opts) {
var obj, posOptions, attr, config, title,
// Setup element references
docBody = $(document.body),
@@ -1599,11 +1746,11 @@
posOptions.my = new CORNER(posOptions.my);
// Destroy previous tooltip if overwrite is enabled, or skip element if not
if(elem.data(NAMESPACE)) {
if(config.overwrite) {
- elem.qtip('destroy');
+ elem.qtip('destroy', true);
}
else if(config.overwrite === FALSE) {
return FALSE;
}
}
@@ -1619,15 +1766,10 @@
// Initialize the tooltip and add API reference
obj = new QTip(elem, config, id, !!attr);
elem.data(NAMESPACE, obj);
- // Catch remove/removeqtip events on target element to destroy redundant tooltip
- elem.one('remove.qtip-'+id+' removeqtip.qtip-'+id, function() {
- var api; if((api = $(this).data(NAMESPACE))) { api.destroy(); }
- });
-
return obj;
}
// jQuery $.fn extension method
QTIP = $.fn.qtip = function(options, notation, newValue)
@@ -1642,14 +1784,12 @@
if((!arguments.length && opts) || command === 'api') {
return opts;
}
// Execute API command if present
- else if('string' === typeof options)
- {
- this.each(function()
- {
+ else if('string' === typeof options) {
+ this.each(function() {
var api = $.data(this, NAMESPACE);
if(!api) { return TRUE; }
// Cache the event if possible
if(event && event.timeStamp) { api.cache.event = event; }
@@ -1673,105 +1813,40 @@
return returned !== NULL ? returned : this;
}
// No API commands. validate provided options and setup qTips
- else if('object' === typeof options || !arguments.length)
- {
+ else if('object' === typeof options || !arguments.length) {
+ // Sanitize options first
opts = sanitizeOptions($.extend(TRUE, {}, options));
- // Bind the qTips
- return QTIP.bind.call(this, opts, event);
- }
-};
+ return this.each(function(i) {
+ var api, id;
-// $.fn.qtip Bind method
-QTIP.bind = function(opts, event)
-{
- return this.each(function(i) {
- var options, targets, events, namespace, api, id;
+ // Find next available ID, or use custom ID if provided
+ id = $.isArray(opts.id) ? opts.id[i] : opts.id;
+ id = !id || id === FALSE || id.length < 1 || QTIP.api[id] ? QTIP.nextid++ : id;
- // Find next available ID, or use custom ID if provided
- id = $.isArray(opts.id) ? opts.id[i] : opts.id;
- id = !id || id === FALSE || id.length < 1 || QTIP.api[id] ? QTIP.nextid++ : id;
+ // Initialize the qTip and re-grab newly sanitized options
+ api = init($(this), id, opts);
+ if(api === FALSE) { return TRUE; }
+ else { QTIP.api[id] = api; }
- // Setup events namespace
- namespace = '.qtip-'+id+'-create';
+ // Initialize plugins
+ $.each(PLUGINS, function() {
+ if(this.initialize === 'initialize') { this(api); }
+ });
- // Initialize the qTip and re-grab newly sanitized options
- api = init($(this), id, opts);
- if(api === FALSE) { return TRUE; }
- else { QTIP.api[id] = api; }
- options = api.options;
-
- // Initialize plugins
- $.each(PLUGINS, function() {
- if(this.initialize === 'initialize') { this(api); }
+ // Assign initial pre-render events
+ api._assignInitialEvents(event);
});
-
- // Determine hide and show targets
- targets = { show: options.show.target, hide: options.hide.target };
- events = {
- show: $.trim('' + options.show.event).replace(/ /g, namespace+' ') + namespace,
- hide: $.trim('' + options.hide.event).replace(/ /g, namespace+' ') + namespace
- };
-
- /*
- * Make sure hoverIntent functions properly by using mouseleave as a hide event if
- * mouseenter/mouseout is used for show.event, even if it isn't in the users options.
- */
- if(/mouse(over|enter)/i.test(events.show) && !/mouse(out|leave)/i.test(events.hide)) {
- events.hide += ' mouseleave' + namespace;
- }
-
- /*
- * Also make sure initial mouse targetting works correctly by caching mousemove coords
- * on show targets before the tooltip has rendered.
- *
- * Also set onTarget when triggered to keep mouse tracking working
- */
- targets.show.bind('mousemove'+namespace, function(event) {
- api._storeMouse(event);
- api.cache.onTarget = TRUE;
- });
-
- // Define hoverIntent function
- function hoverIntent(event) {
- function render() {
- // Cache mouse coords,render and render the tooltip
- api.render(typeof event === 'object' || options.show.ready);
-
- // Unbind show and hide events
- targets.show.add(targets.hide).unbind(namespace);
- }
-
- // Only continue if tooltip isn't disabled
- if(api.disabled) { return FALSE; }
-
- // Cache the event data
- api.cache.event = $.extend({}, event);
- api.cache.target = event ? $(event.target) : [undefined];
-
- // Start the event sequence
- if(options.show.delay > 0) {
- clearTimeout(api.timers.show);
- api.timers.show = setTimeout(render, options.show.delay);
- if(events.show !== events.hide) {
- targets.hide.bind(events.hide, function() { clearTimeout(api.timers.show); });
- }
- }
- else { render(); }
- }
-
- // Bind show events to target
- targets.show.bind(events.show, hoverIntent);
-
- // Prerendering is enabled, create tooltip now
- if(options.show.ready || options.prerender) { hoverIntent(event); }
- });
+ }
};
+// Expose class
+$.qtip = QTip;
+
// Populated in render method
QTIP.api = {};
;$.each({
/* Allow other plugins to successfully retrieve the title of an element with a qTip applied */
attr: function(attr, val) {
@@ -1831,20 +1906,19 @@
if(!$.ui) {
$['cleanData'+replaceSuffix] = $.cleanData;
$.cleanData = function( elems ) {
for(var i = 0, elem; (elem = $( elems[i] )).length; i++) {
if(elem.attr(ATTR_HAS)) {
- try { elem.triggerHandler('removeqtip'); }
+ try { elem.triggerHandler('removeqtip'); }
catch( e ) {}
}
}
$['cleanData'+replaceSuffix].apply(this, arguments);
};
}
-
;// qTip version
-QTIP.version = '2.1.1';
+QTIP.version = '2.2.1';
// Base ID for all qTips
QTIP.nextid = 0;
// Inactive events array
@@ -1921,11 +1995,10 @@
hidden: NULL,
focus: NULL,
blur: NULL
}
};
-
;var TIP,
// .bind()/.on() namespace
TIPNS = '.qtip-tip',
@@ -1967,22 +2040,32 @@
}
}
// Parse a given elements CSS property into an int
function intCss(elem, prop) {
- return parseInt(vendorCss(elem, prop), 10);
+ return Math.ceil(parseFloat(vendorCss(elem, prop)));
}
// VML creation (for IE only)
if(!HASCANVAS) {
- createVML = function(tag, props, style) {
+ var createVML = function(tag, props, style) {
return '<qtipvml:'+tag+' xmlns="urn:schemas-microsoft.com:vml" class="qtip-vml" '+(props||'')+
' style="behavior: url(#default#VML); '+(style||'')+ '" />';
};
}
+// Canvas only definitions
+else {
+ var PIXEL_RATIO = window.devicePixelRatio || 1,
+ BACKING_STORE_RATIO = (function() {
+ var context = document.createElement('canvas').getContext('2d');
+ return context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio ||
+ context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || 1;
+ }()),
+ SCALE = PIXEL_RATIO / BACKING_STORE_RATIO;
+}
function Tip(qtip, options) {
this._ns = 'tip';
this.options = options;
@@ -2005,11 +2088,11 @@
// save() as soon as we create the canvas element so FF2 doesn't bork on our first restore()!
context = $('<canvas />').appendTo(this.element)[0].getContext('2d');
// Setup constant parameters
context.lineJoin = 'miter';
- context.miterLimit = 100;
+ context.miterLimit = 100000;
context.save();
}
else {
context = createVML('shape', 'coordorigin="0,0"', 'position:absolute;');
this.element.html(context + context);
@@ -2064,20 +2147,20 @@
prop = BORDER + camel(side) + 'Width';
return (use ? intCss(use, prop) : (
intCss(elements.content, prop) ||
intCss(this._useTitle(corner) && elements.titlebar || elements.content, prop) ||
- intCss(tooltip, prop)
+ intCss(elements.tooltip, prop)
)) || 0;
},
_parseRadius: function(corner) {
var elements = this.qtip.elements,
prop = BORDER + camel(corner.y) + camel(corner.x) + 'Radius';
return BROWSER.ie < 9 ? 0 :
- intCss(this._useTitle(corner) && elements.titlebar || elements.content, prop) ||
+ intCss(this._useTitle(corner) && elements.titlebar || elements.content, prop) ||
intCss(elements.tooltip, prop) || 0;
},
_invalidColour: function(elem, prop, compare) {
var val = elem.css(prop);
@@ -2090,29 +2173,29 @@
borderSide = BORDER + camel(corner[ corner.precedance ]) + camel(COLOR),
colorElem = this._useTitle(corner) && elements.titlebar || elements.content,
css = this._invalidColour, color = [];
// Attempt to detect the background colour from various elements, left-to-right precedance
- color[0] = css(tip, BG_COLOR) || css(colorElem, BG_COLOR) || css(elements.content, BG_COLOR) ||
- css(tooltip, BG_COLOR) || tip.css(BG_COLOR);
+ color[0] = css(tip, BG_COLOR) || css(colorElem, BG_COLOR) || css(elements.content, BG_COLOR) ||
+ css(elements.tooltip, BG_COLOR) || tip.css(BG_COLOR);
// Attempt to detect the correct border side colour from various elements, left-to-right precedance
- color[1] = css(tip, borderSide, COLOR) || css(colorElem, borderSide, COLOR) ||
- css(elements.content, borderSide, COLOR) || css(tooltip, borderSide, COLOR) || tooltip.css(borderSide);
+ color[1] = css(tip, borderSide, COLOR) || css(colorElem, borderSide, COLOR) ||
+ css(elements.content, borderSide, COLOR) || css(elements.tooltip, borderSide, COLOR) || elements.tooltip.css(borderSide);
// Reset background and border colours
$('*', tip).add(tip).css('cssText', BG_COLOR+':'+TRANSPARENT+IMPORTANT+';'+BORDER+':0'+IMPORTANT+';');
return color;
},
_calculateSize: function(corner) {
var y = corner.precedance === Y,
- width = this.options[ y ? 'height' : 'width' ],
- height = this.options[ y ? 'width' : 'height' ],
+ width = this.options['width'],
+ height = this.options['height'],
isCenter = corner.abbrev() === 'c',
- base = width * (isCenter ? 0.5 : 1),
+ base = (y ? width: height) * (isCenter ? 0.5 : 1),
pow = Math.pow,
round = Math.round,
bigHyp, ratio, result,
smallHyp = Math.sqrt( pow(base, 2) + pow(height, 2) ),
@@ -2123,17 +2206,20 @@
bigHyp = smallHyp + hyp[2] + hyp[3] + (isCenter ? 0 : hyp[0]);
ratio = bigHyp / smallHyp;
result = [ round(ratio * width), round(ratio * height) ];
-
return y ? result : result.reverse();
},
// Tip coordinates calculator
- _calculateTip: function(corner) {
- var width = this.size[0], height = this.size[1],
+ _calculateTip: function(corner, size, scale) {
+ scale = scale || 1;
+ size = size || this.size;
+
+ var width = size[0] * scale,
+ height = size[1] * scale,
width2 = Math.ceil(width / 2), height2 = Math.ceil(height / 2),
// Define tip coordinates in terms of height and width values
tips = {
br: [0,0, width,height, width,0],
@@ -2151,14 +2237,23 @@
tips.lb = tips.tr; tips.rb = tips.tl;
return tips[ corner.abbrev() ];
},
+ // Tip coordinates drawer (canvas)
+ _drawCoords: function(context, coords) {
+ context.beginPath();
+ context.moveTo(coords[0], coords[1]);
+ context.lineTo(coords[2], coords[3]);
+ context.lineTo(coords[4], coords[5]);
+ context.closePath();
+ },
+
create: function() {
// Determine tip corner
var c = this.corner = (HASCANVAS || BROWSER.ie) && this._parseCorner(this.options.corner);
-
+
// If we have a tip corner...
if( (this.enabled = !!this.corner && this.corner.abbrev() !== 'c') ) {
// Cache it
this.qtip.cache.corner = c.clone();
@@ -2177,15 +2272,15 @@
var elements = this.qtip.elements,
tip = this.element,
inner = tip.children(),
options = this.options,
- size = this.size,
+ curSize = this.size,
mimic = options.mimic,
round = Math.round,
color, precedance, context,
- coords, translate, newSize, border;
+ coords, bigCoords, translate, newSize, border, BACKING_STORE_RATIO;
// Re-determine tip if not already set
if(!corner) { corner = this.qtip.cache.corner || this.corner; }
// Use corner property if we detect an invalid mimic value
@@ -2214,23 +2309,20 @@
// Detect border width, taking into account colours
if(color[1] !== TRANSPARENT) {
// Grab border width
border = this.border = this._parseWidth(corner, corner[corner.precedance]);
- // If border width isn't zero, use border color as fill (1.0 style tips)
- if(options.border && border < 1) { color[0] = color[1]; }
+ // If border width isn't zero, use border color as fill if it's not invalid (1.0 style tips)
+ if(options.border && border < 1 && !INVALID.test(color[1])) { color[0] = color[1]; }
// Set border width (use detected border width if options.border is true)
this.border = border = options.border !== TRUE ? options.border : border;
}
// Border colour was invalid, set border to zero
else { this.border = border = 0; }
- // Calculate coordinates
- coords = this._calculateTip(mimic);
-
// Determine tip size
newSize = this.size = this._calculateSize(corner);
tip.css({
width: newSize[0],
height: newSize[1],
@@ -2238,83 +2330,76 @@
});
// Calculate tip translation
if(corner.precedance === Y) {
translate = [
- round(mimic.x === LEFT ? border : mimic.x === RIGHT ? newSize[0] - size[0] - border : (newSize[0] - size[0]) / 2),
- round(mimic.y === TOP ? newSize[1] - size[1] : 0)
+ round(mimic.x === LEFT ? border : mimic.x === RIGHT ? newSize[0] - curSize[0] - border : (newSize[0] - curSize[0]) / 2),
+ round(mimic.y === TOP ? newSize[1] - curSize[1] : 0)
];
}
else {
translate = [
- round(mimic.x === LEFT ? newSize[0] - size[0] : 0),
- round(mimic.y === TOP ? border : mimic.y === BOTTOM ? newSize[1] - size[1] - border : (newSize[1] - size[1]) / 2)
+ round(mimic.x === LEFT ? newSize[0] - curSize[0] : 0),
+ round(mimic.y === TOP ? border : mimic.y === BOTTOM ? newSize[1] - curSize[1] - border : (newSize[1] - curSize[1]) / 2)
];
}
// Canvas drawing implementation
if(HASCANVAS) {
- // Set the canvas size using calculated size
- inner.attr(WIDTH, newSize[0]).attr(HEIGHT, newSize[1]);
-
// Grab canvas context and clear/save it
context = inner[0].getContext('2d');
context.restore(); context.save();
- context.clearRect(0,0,3000,3000);
+ context.clearRect(0,0,6000,6000);
- // Set properties
- context.fillStyle = color[0];
- context.strokeStyle = color[1];
- context.lineWidth = border * 2;
+ // Calculate coordinates
+ coords = this._calculateTip(mimic, curSize, SCALE);
+ bigCoords = this._calculateTip(mimic, this.size, SCALE);
- // Draw the tip
- context.translate(translate[0], translate[1]);
- context.beginPath();
- context.moveTo(coords[0], coords[1]);
- context.lineTo(coords[2], coords[3]);
- context.lineTo(coords[4], coords[5]);
- context.closePath();
+ // Set the canvas size using calculated size
+ inner.attr(WIDTH, newSize[0] * SCALE).attr(HEIGHT, newSize[1] * SCALE);
+ inner.css(WIDTH, newSize[0]).css(HEIGHT, newSize[1]);
- // Apply fill and border
- if(border) {
- // Make sure transparent borders are supported by doing a stroke
- // of the background colour before the stroke colour
- if(tooltip.css('background-clip') === 'border-box') {
- context.strokeStyle = color[0];
- context.stroke();
- }
- context.strokeStyle = color[1];
- context.stroke();
- }
+ // Draw the outer-stroke tip
+ this._drawCoords(context, bigCoords);
+ context.fillStyle = color[1];
context.fill();
+
+ // Draw the actual tip
+ context.translate(translate[0] * SCALE, translate[1] * SCALE);
+ this._drawCoords(context, coords);
+ context.fillStyle = color[0];
+ context.fill();
}
// VML (IE Proprietary implementation)
else {
+ // Calculate coordinates
+ coords = this._calculateTip(mimic);
+
// Setup coordinates string
coords = 'm' + coords[0] + ',' + coords[1] + ' l' + coords[2] +
',' + coords[3] + ' ' + coords[4] + ',' + coords[5] + ' xe';
// Setup VML-specific offset for pixel-perfection
- translate[2] = border && /^(r|b)/i.test(corner.string()) ?
+ translate[2] = border && /^(r|b)/i.test(corner.string()) ?
BROWSER.ie === 8 ? 2 : 1 : 0;
// Set initial CSS
inner.css({
- coordsize: (size[0]+border) + ' ' + (size[1]+border),
+ coordsize: (newSize[0]+border) + ' ' + (newSize[1]+border),
antialias: ''+(mimic.string().indexOf(CENTER) > -1),
left: translate[0] - (translate[2] * Number(precedance === X)),
top: translate[1] - (translate[2] * Number(precedance === Y)),
- width: size[0] + border,
- height: size[1] + border
+ width: newSize[0] + border,
+ height: newSize[1] + border
})
.each(function(i) {
var $this = $(this);
// Set shape specific attributes
$this[ $this.prop ? 'prop' : 'attr' ]({
- coordsize: (size[0]+border) + ' ' + (size[1]+border),
+ coordsize: (newSize[0]+border) + ' ' + (newSize[1]+border),
path: coords,
fillcolor: color[0],
filled: !!i,
stroked: !i
})
@@ -2325,31 +2410,40 @@
'stroke', 'weight="'+(border*2)+'px" color="'+color[1]+'" miterlimit="1000" joinstyle="miter"'
) );
});
}
+ // Opera bug #357 - Incorrect tip position
+ // https://github.com/Craga89/qTip2/issues/367
+ window.opera && setTimeout(function() {
+ elements.tip.css({
+ display: 'inline-block',
+ visibility: 'visible'
+ });
+ }, 1);
+
// Position if needed
- if(position !== FALSE) { this.calculate(corner); }
+ if(position !== FALSE) { this.calculate(corner, newSize); }
},
- calculate: function(corner) {
+ calculate: function(corner, size) {
if(!this.enabled) { return FALSE; }
var self = this,
elements = this.qtip.elements,
tip = this.element,
userOffset = this.options.offset,
- isWidget = this.qtip.tooltip.hasClass('ui-widget'),
+ isWidget = elements.tooltip.hasClass('ui-widget'),
position = { },
- precedance, size, corners;
+ precedance, corners;
// Inherit corner if not provided
corner = corner || this.corner;
precedance = corner.precedance;
// Determine which tip dimension to use for adjustment
- size = this._calculateSize(corner);
+ size = size || this._calculateSize(corner);
// Setup corners and offset array
corners = [ corner.x, corner.y ];
if(precedance === X) { corners.reverse(); }
@@ -2389,88 +2483,76 @@
horizontal = method[0],
vertical = method[1] || method[0],
shift = { left: FALSE, top: FALSE, x: 0, y: 0 },
offset, css = {}, props;
- // If our tip position isn't fixed e.g. doesn't adjust with viewport...
- if(this.corner.fixed !== TRUE) {
+ function shiftflip(direction, precedance, popposite, side, opposite) {
// Horizontal - Shift or flip method
- if(horizontal === SHIFT && newCorner.precedance === X && adjust.left && newCorner.y !== CENTER) {
+ if(direction === SHIFT && newCorner.precedance === precedance && adjust[side] && newCorner[popposite] !== CENTER) {
newCorner.precedance = newCorner.precedance === X ? Y : X;
}
- else if(horizontal !== SHIFT && adjust.left){
- newCorner.x = newCorner.x === CENTER ? (adjust.left > 0 ? LEFT : RIGHT) : (newCorner.x === LEFT ? RIGHT : LEFT);
+ else if(direction !== SHIFT && adjust[side]){
+ newCorner[precedance] = newCorner[precedance] === CENTER ?
+ (adjust[side] > 0 ? side : opposite) : (newCorner[precedance] === side ? opposite : side);
}
+ }
- // Vertical - Shift or flip method
- if(vertical === SHIFT && newCorner.precedance === Y && adjust.top && newCorner.x !== CENTER) {
- newCorner.precedance = newCorner.precedance === Y ? X : Y;
+ function shiftonly(xy, side, opposite) {
+ if(newCorner[xy] === CENTER) {
+ css[MARGIN+'-'+side] = shift[xy] = offset[MARGIN+'-'+side] - adjust[side];
}
- else if(vertical !== SHIFT && adjust.top) {
- newCorner.y = newCorner.y === CENTER ? (adjust.top > 0 ? TOP : BOTTOM) : (newCorner.y === TOP ? BOTTOM : TOP);
+ else {
+ props = offset[opposite] !== undefined ?
+ [ adjust[side], -offset[side] ] : [ -adjust[side], offset[side] ];
+
+ if( (shift[xy] = Math.max(props[0], props[1])) > props[0] ) {
+ pos[side] -= adjust[side];
+ shift[side] = FALSE;
+ }
+
+ css[ offset[opposite] !== undefined ? opposite : side ] = shift[xy];
}
+ }
+ // If our tip position isn't fixed e.g. doesn't adjust with viewport...
+ if(this.corner.fixed !== TRUE) {
+ // Perform shift/flip adjustments
+ shiftflip(horizontal, X, Y, LEFT, RIGHT);
+ shiftflip(vertical, Y, X, TOP, BOTTOM);
+
// Update and redraw the tip if needed (check cached details of last drawn tip)
- if(newCorner.string() !== cache.corner.string() && (cache.cornerTop !== adjust.top || cache.cornerLeft !== adjust.left)) {
+ if(newCorner.string() !== cache.corner.string() || cache.cornerTop !== adjust.top || cache.cornerLeft !== adjust.left) {
this.update(newCorner, FALSE);
}
}
// Setup tip offset properties
- offset = this.calculate(newCorner, adjust);
+ offset = this.calculate(newCorner);
// Readjust offset object to make it left/top
if(offset.right !== undefined) { offset.left = -offset.right; }
if(offset.bottom !== undefined) { offset.top = -offset.bottom; }
offset.user = this.offset;
- // Viewport "shift" specific adjustments
- if(shift.left = (horizontal === SHIFT && !!adjust.left)) {
- if(newCorner.x === CENTER) {
- css[MARGIN+'-left'] = shift.x = offset[MARGIN+'-left'] - adjust.left;
- }
- else {
- props = offset.right !== undefined ?
- [ adjust.left, -offset.left ] : [ -adjust.left, offset.left ];
+ // Perform shift adjustments
+ if(shift.left = (horizontal === SHIFT && !!adjust.left)) { shiftonly(X, LEFT, RIGHT); }
+ if(shift.top = (vertical === SHIFT && !!adjust.top)) { shiftonly(Y, TOP, BOTTOM); }
- if( (shift.x = Math.max(props[0], props[1])) > props[0] ) {
- pos.left -= adjust.left;
- shift.left = FALSE;
- }
-
- css[ offset.right !== undefined ? RIGHT : LEFT ] = shift.x;
- }
- }
- if(shift.top = (vertical === SHIFT && !!adjust.top)) {
- if(newCorner.y === CENTER) {
- css[MARGIN+'-top'] = shift.y = offset[MARGIN+'-top'] - adjust.top;
- }
- else {
- props = offset.bottom !== undefined ?
- [ adjust.top, -offset.top ] : [ -adjust.top, offset.top ];
-
- if( (shift.y = Math.max(props[0], props[1])) > props[0] ) {
- pos.top -= adjust.top;
- shift.top = FALSE;
- }
-
- css[ offset.bottom !== undefined ? BOTTOM : TOP ] = shift.y;
- }
- }
-
/*
* If the tip is adjusted in both dimensions, or in a
* direction that would cause it to be anywhere but the
* outer border, hide it!
*/
this.element.css(css).toggle(
!((shift.x && shift.y) || (newCorner.x === CENTER && shift.y) || (newCorner.y === CENTER && shift.x))
);
// Adjust position to accomodate tip dimensions
- pos.left -= offset.left.charAt ? offset.user : horizontal !== SHIFT || shift.top || !shift.left && !shift.top ? offset.left : 0;
- pos.top -= offset.top.charAt ? offset.user : vertical !== SHIFT || shift.left || !shift.left && !shift.top ? offset.top : 0;
+ pos.left -= offset.left.charAt ? offset.user :
+ horizontal !== SHIFT || shift.top || !shift.left && !shift.top ? offset.left + this.border : 0;
+ pos.top -= offset.top.charAt ? offset.user :
+ vertical !== SHIFT || shift.left || !shift.left && !shift.top ? offset.top + this.border : 0;
// Cache details
cache.cornerLeft = adjust.left; cache.cornerTop = adjust.top;
cache.corner = newCorner.clone();
},
@@ -2495,28 +2577,28 @@
TIP.initialize = 'render';
// Setup plugin sanitization options
TIP.sanitize = function(options) {
if(options.style && 'tip' in options.style) {
- opts = options.style.tip;
+ var opts = options.style.tip;
if(typeof opts !== 'object') { opts = options.style.tip = { corner: opts }; }
if(!(/string|boolean/i).test(typeof opts.corner)) { opts.corner = TRUE; }
}
};
// Add new option checks for the plugin
CHECKS.tip = {
'^position.my|style.tip.(corner|mimic|border)$': function() {
// Make sure a tip can be drawn
this.create();
-
+
// Reposition the tooltip
this.qtip.reposition();
},
'^style.tip.(height|width)$': function(obj) {
// Re-set dimensions and redraw the tip
- this.size = size = [ obj.width, obj.height ];
+ this.size = [ obj.width, obj.height ];
this.update();
// Reposition the tooltip
this.qtip.reposition();
},
@@ -2536,11 +2618,366 @@
border: TRUE,
offset: 0
}
}
});
+;PLUGINS.viewport = function(api, position, posOptions, targetWidth, targetHeight, elemWidth, elemHeight)
+{
+ var target = posOptions.target,
+ tooltip = api.elements.tooltip,
+ my = posOptions.my,
+ at = posOptions.at,
+ adjust = posOptions.adjust,
+ method = adjust.method.split(' '),
+ methodX = method[0],
+ methodY = method[1] || method[0],
+ viewport = posOptions.viewport,
+ container = posOptions.container,
+ cache = api.cache,
+ adjusted = { left: 0, top: 0 },
+ fixed, newMy, containerOffset, containerStatic,
+ viewportWidth, viewportHeight, viewportScroll, viewportOffset;
+ // If viewport is not a jQuery element, or it's the window/document, or no adjustment method is used... return
+ if(!viewport.jquery || target[0] === window || target[0] === document.body || adjust.method === 'none') {
+ return adjusted;
+ }
+
+ // Cach container details
+ containerOffset = container.offset() || adjusted;
+ containerStatic = container.css('position') === 'static';
+
+ // Cache our viewport details
+ fixed = tooltip.css('position') === 'fixed';
+ viewportWidth = viewport[0] === window ? viewport.width() : viewport.outerWidth(FALSE);
+ viewportHeight = viewport[0] === window ? viewport.height() : viewport.outerHeight(FALSE);
+ viewportScroll = { left: fixed ? 0 : viewport.scrollLeft(), top: fixed ? 0 : viewport.scrollTop() };
+ viewportOffset = viewport.offset() || adjusted;
+
+ // Generic calculation method
+ function calculate(side, otherSide, type, adjust, side1, side2, lengthName, targetLength, elemLength) {
+ var initialPos = position[side1],
+ mySide = my[side],
+ atSide = at[side],
+ isShift = type === SHIFT,
+ myLength = mySide === side1 ? elemLength : mySide === side2 ? -elemLength : -elemLength / 2,
+ atLength = atSide === side1 ? targetLength : atSide === side2 ? -targetLength : -targetLength / 2,
+ sideOffset = viewportScroll[side1] + viewportOffset[side1] - (containerStatic ? 0 : containerOffset[side1]),
+ overflow1 = sideOffset - initialPos,
+ overflow2 = initialPos + elemLength - (lengthName === WIDTH ? viewportWidth : viewportHeight) - sideOffset,
+ offset = myLength - (my.precedance === side || mySide === my[otherSide] ? atLength : 0) - (atSide === CENTER ? targetLength / 2 : 0);
+
+ // shift
+ if(isShift) {
+ offset = (mySide === side1 ? 1 : -1) * myLength;
+
+ // Adjust position but keep it within viewport dimensions
+ position[side1] += overflow1 > 0 ? overflow1 : overflow2 > 0 ? -overflow2 : 0;
+ position[side1] = Math.max(
+ -containerOffset[side1] + viewportOffset[side1],
+ initialPos - offset,
+ Math.min(
+ Math.max(
+ -containerOffset[side1] + viewportOffset[side1] + (lengthName === WIDTH ? viewportWidth : viewportHeight),
+ initialPos + offset
+ ),
+ position[side1],
+
+ // Make sure we don't adjust complete off the element when using 'center'
+ mySide === 'center' ? initialPos - myLength : 1E9
+ )
+ );
+
+ }
+
+ // flip/flipinvert
+ else {
+ // Update adjustment amount depending on if using flipinvert or flip
+ adjust *= (type === FLIPINVERT ? 2 : 0);
+
+ // Check for overflow on the left/top
+ if(overflow1 > 0 && (mySide !== side1 || overflow2 > 0)) {
+ position[side1] -= offset + adjust;
+ newMy.invert(side, side1);
+ }
+
+ // Check for overflow on the bottom/right
+ else if(overflow2 > 0 && (mySide !== side2 || overflow1 > 0) ) {
+ position[side1] -= (mySide === CENTER ? -offset : offset) + adjust;
+ newMy.invert(side, side2);
+ }
+
+ // Make sure we haven't made things worse with the adjustment and reset if so
+ if(position[side1] < viewportScroll && -position[side1] > overflow2) {
+ position[side1] = initialPos; newMy = my.clone();
+ }
+ }
+
+ return position[side1] - initialPos;
+ }
+
+ // Set newMy if using flip or flipinvert methods
+ if(methodX !== 'shift' || methodY !== 'shift') { newMy = my.clone(); }
+
+ // Adjust position based onviewport and adjustment options
+ adjusted = {
+ left: methodX !== 'none' ? calculate( X, Y, methodX, adjust.x, LEFT, RIGHT, WIDTH, targetWidth, elemWidth ) : 0,
+ top: methodY !== 'none' ? calculate( Y, X, methodY, adjust.y, TOP, BOTTOM, HEIGHT, targetHeight, elemHeight ) : 0,
+ my: newMy
+ };
+
+ return adjusted;
+};
+;PLUGINS.polys = {
+ // POLY area coordinate calculator
+ // Special thanks to Ed Cradock for helping out with this.
+ // Uses a binary search algorithm to find suitable coordinates.
+ polygon: function(baseCoords, corner) {
+ var result = {
+ width: 0, height: 0,
+ position: {
+ top: 1e10, right: 0,
+ bottom: 0, left: 1e10
+ },
+ adjustable: FALSE
+ },
+ i = 0, next,
+ coords = [],
+ compareX = 1, compareY = 1,
+ realX = 0, realY = 0,
+ newWidth, newHeight;
+
+ // First pass, sanitize coords and determine outer edges
+ i = baseCoords.length; while(i--) {
+ next = [ parseInt(baseCoords[--i], 10), parseInt(baseCoords[i+1], 10) ];
+
+ if(next[0] > result.position.right){ result.position.right = next[0]; }
+ if(next[0] < result.position.left){ result.position.left = next[0]; }
+ if(next[1] > result.position.bottom){ result.position.bottom = next[1]; }
+ if(next[1] < result.position.top){ result.position.top = next[1]; }
+
+ coords.push(next);
+ }
+
+ // Calculate height and width from outer edges
+ newWidth = result.width = Math.abs(result.position.right - result.position.left);
+ newHeight = result.height = Math.abs(result.position.bottom - result.position.top);
+
+ // If it's the center corner...
+ if(corner.abbrev() === 'c') {
+ result.position = {
+ left: result.position.left + (result.width / 2),
+ top: result.position.top + (result.height / 2)
+ };
+ }
+ else {
+ // Second pass, use a binary search algorithm to locate most suitable coordinate
+ while(newWidth > 0 && newHeight > 0 && compareX > 0 && compareY > 0)
+ {
+ newWidth = Math.floor(newWidth / 2);
+ newHeight = Math.floor(newHeight / 2);
+
+ if(corner.x === LEFT){ compareX = newWidth; }
+ else if(corner.x === RIGHT){ compareX = result.width - newWidth; }
+ else{ compareX += Math.floor(newWidth / 2); }
+
+ if(corner.y === TOP){ compareY = newHeight; }
+ else if(corner.y === BOTTOM){ compareY = result.height - newHeight; }
+ else{ compareY += Math.floor(newHeight / 2); }
+
+ i = coords.length; while(i--)
+ {
+ if(coords.length < 2){ break; }
+
+ realX = coords[i][0] - result.position.left;
+ realY = coords[i][1] - result.position.top;
+
+ if((corner.x === LEFT && realX >= compareX) ||
+ (corner.x === RIGHT && realX <= compareX) ||
+ (corner.x === CENTER && (realX < compareX || realX > (result.width - compareX))) ||
+ (corner.y === TOP && realY >= compareY) ||
+ (corner.y === BOTTOM && realY <= compareY) ||
+ (corner.y === CENTER && (realY < compareY || realY > (result.height - compareY)))) {
+ coords.splice(i, 1);
+ }
+ }
+ }
+ result.position = { left: coords[0][0], top: coords[0][1] };
+ }
+
+ return result;
+ },
+
+ rect: function(ax, ay, bx, by) {
+ return {
+ width: Math.abs(bx - ax),
+ height: Math.abs(by - ay),
+ position: {
+ left: Math.min(ax, bx),
+ top: Math.min(ay, by)
+ }
+ };
+ },
+
+ _angles: {
+ tc: 3 / 2, tr: 7 / 4, tl: 5 / 4,
+ bc: 1 / 2, br: 1 / 4, bl: 3 / 4,
+ rc: 2, lc: 1, c: 0
+ },
+ ellipse: function(cx, cy, rx, ry, corner) {
+ var c = PLUGINS.polys._angles[ corner.abbrev() ],
+ rxc = c === 0 ? 0 : rx * Math.cos( c * Math.PI ),
+ rys = ry * Math.sin( c * Math.PI );
+
+ return {
+ width: (rx * 2) - Math.abs(rxc),
+ height: (ry * 2) - Math.abs(rys),
+ position: {
+ left: cx + rxc,
+ top: cy + rys
+ },
+ adjustable: FALSE
+ };
+ },
+ circle: function(cx, cy, r, corner) {
+ return PLUGINS.polys.ellipse(cx, cy, r, r, corner);
+ }
+};
+;PLUGINS.imagemap = function(api, area, corner, adjustMethod)
+{
+ if(!area.jquery) { area = $(area); }
+
+ var shape = (area.attr('shape') || 'rect').toLowerCase().replace('poly', 'polygon'),
+ image = $('img[usemap="#'+area.parent('map').attr('name')+'"]'),
+ coordsString = $.trim(area.attr('coords')),
+ coordsArray = coordsString.replace(/,$/, '').split(','),
+ imageOffset, coords, i, next, result, len;
+
+ // If we can't find the image using the map...
+ if(!image.length) { return FALSE; }
+
+ // Pass coordinates string if polygon
+ if(shape === 'polygon') {
+ result = PLUGINS.polys.polygon(coordsArray, corner);
+ }
+
+ // Otherwise parse the coordinates and pass them as arguments
+ else if(PLUGINS.polys[shape]) {
+ for(i = -1, len = coordsArray.length, coords = []; ++i < len;) {
+ coords.push( parseInt(coordsArray[i], 10) );
+ }
+
+ result = PLUGINS.polys[shape].apply(
+ this, coords.concat(corner)
+ );
+ }
+
+ // If no shapre calculation method was found, return false
+ else { return FALSE; }
+
+ // Make sure we account for padding and borders on the image
+ imageOffset = image.offset();
+ imageOffset.left += Math.ceil((image.outerWidth(FALSE) - image.width()) / 2);
+ imageOffset.top += Math.ceil((image.outerHeight(FALSE) - image.height()) / 2);
+
+ // Add image position to offset coordinates
+ result.position.left += imageOffset.left;
+ result.position.top += imageOffset.top;
+
+ return result;
+};
+;PLUGINS.svg = function(api, svg, corner)
+{
+ var doc = $(document),
+ elem = svg[0],
+ root = $(elem.ownerSVGElement),
+ ownerDocument = elem.ownerDocument,
+ strokeWidth2 = (parseInt(svg.css('stroke-width'), 10) || 0) / 2,
+ frameOffset, mtx, transformed, viewBox,
+ len, next, i, points,
+ result, position, dimensions;
+
+ // Ascend the parentNode chain until we find an element with getBBox()
+ while(!elem.getBBox) { elem = elem.parentNode; }
+ if(!elem.getBBox || !elem.parentNode) { return FALSE; }
+
+ // Determine which shape calculation to use
+ switch(elem.nodeName) {
+ case 'ellipse':
+ case 'circle':
+ result = PLUGINS.polys.ellipse(
+ elem.cx.baseVal.value,
+ elem.cy.baseVal.value,
+ (elem.rx || elem.r).baseVal.value + strokeWidth2,
+ (elem.ry || elem.r).baseVal.value + strokeWidth2,
+ corner
+ );
+ break;
+
+ case 'line':
+ case 'polygon':
+ case 'polyline':
+ // Determine points object (line has none, so mimic using array)
+ points = elem.points || [
+ { x: elem.x1.baseVal.value, y: elem.y1.baseVal.value },
+ { x: elem.x2.baseVal.value, y: elem.y2.baseVal.value }
+ ];
+
+ for(result = [], i = -1, len = points.numberOfItems || points.length; ++i < len;) {
+ next = points.getItem ? points.getItem(i) : points[i];
+ result.push.apply(result, [next.x, next.y]);
+ }
+
+ result = PLUGINS.polys.polygon(result, corner);
+ break;
+
+ // Unknown shape or rectangle? Use bounding box
+ default:
+ result = elem.getBBox();
+ result = {
+ width: result.width,
+ height: result.height,
+ position: {
+ left: result.x,
+ top: result.y
+ }
+ };
+ break;
+ }
+
+ // Shortcut assignments
+ position = result.position;
+ root = root[0];
+
+ // Convert position into a pixel value
+ if(root.createSVGPoint) {
+ mtx = elem.getScreenCTM();
+ points = root.createSVGPoint();
+
+ points.x = position.left;
+ points.y = position.top;
+ transformed = points.matrixTransform( mtx );
+ position.left = transformed.x;
+ position.top = transformed.y;
+ }
+
+ // Check the element is not in a child document, and if so, adjust for frame elements offset
+ if(ownerDocument !== document && api.position.target !== 'mouse') {
+ frameOffset = $((ownerDocument.defaultView || ownerDocument.parentWindow).frameElement).offset();
+ if(frameOffset) {
+ position.left += frameOffset.left;
+ position.top += frameOffset.top;
+ }
+ }
+
+ // Adjust by scroll offset of owner document
+ ownerDocument = $(ownerDocument);
+ position.left += ownerDocument.scrollLeft();
+ position.top += ownerDocument.scrollTop();
+
+ return result;
+};
;var MODAL, OVERLAY,
MODALCLASS = 'qtip-modal',
MODALSELECTOR = '.'+MODALCLASS;
OVERLAY = function()
@@ -2569,12 +3006,12 @@
img = $('img[usemap=#' + mapName + ']')[0];
return !!img && img.is(':visible');
}
return (/input|select|textarea|button|object/.test( nodeName ) ?
!element.disabled :
- 'a' === nodeName ?
- element.href || isTabIndexNotNaN :
+ 'a' === nodeName ?
+ element.href || isTabIndexNotNaN :
isTabIndexNotNaN
);
}
// Focus inputs using cached focusable elements (see update())
@@ -2618,21 +3055,10 @@
html: '<div></div>',
mousedown: function() { return FALSE; }
})
.hide();
- // Update position on window resize or scroll
- function resize() {
- var win = $(this);
- elem.css({
- height: win.height(),
- width: win.width()
- });
- }
- $(window).bind('resize'+MODALSELECTOR, resize);
- resize(); // Fire it initially too
-
// Make sure we can't focus anything outside the tooltip
$(document.body).bind('focusin'+MODALSELECTOR, stealFocus);
// Apply keyboard "Escape key" close handler
$(document).bind('keydown'+MODALSELECTOR, function(event) {
@@ -2684,14 +3110,13 @@
}
// Toggle backdrop cursor style on show
elem.toggleClass('blurs', options.blur);
- // Set position and append to body on show
+ // Append to body on show
if(state) {
- elem.css({ left: 0, top: 0 })
- .appendTo(document.body);
+ elem.appendTo(document.body);
}
// Prevent modal from conflicting with show.solo, and don't hide backdrop is other modals are visible
if((elem.is(':animated') && visible === state && prevState !== FALSE) || (!state && visibleModals.length)) {
return self;
@@ -2732,11 +3157,11 @@
// If the tooltip is destroyed, set reference to null
if(current.destroyed) { current = NULL; }
return self;
}
- });
+ });
self.init();
};
OVERLAY = new OVERLAY();
@@ -2756,22 +3181,22 @@
// Set overlay reference
qtip.elements.overlay = OVERLAY.elem;
// Add unique attribute so we can grab modal tooltips easily via a SELECTOR, and set z-index
- tooltip.addClass(MODALCLASS).css('z-index', PLUGINS.modal.zindex + $(MODALSELECTOR).length);
-
+ tooltip.addClass(MODALCLASS).css('z-index', QTIP.modal_zindex + $(MODALSELECTOR).length);
+
// Apply our show/hide/focus modal events
qtip._bind(tooltip, ['tooltipshow', 'tooltiphide'], function(event, api, duration) {
var oEvent = event.originalEvent;
// Make sure mouseout doesn't trigger a hide when showing the modal and mousing onto backdrop
if(event.target === tooltip[0]) {
- if(oEvent && event.type === 'tooltiphide' && /mouse(leave|enter)/.test(oEvent.type) && $(oEvent.relatedTarget).closest(overlay[0]).length) {
+ if(oEvent && event.type === 'tooltiphide' && /mouse(leave|enter)/.test(oEvent.type) && $(oEvent.relatedTarget).closest(OVERLAY.elem[0]).length) {
try { event.preventDefault(); } catch(e) {}
}
- else if(!oEvent || (oEvent && !oEvent.solo)) {
+ else if(!oEvent || (oEvent && oEvent.type !== 'tooltipsolo')) {
this.toggle(event, event.type === 'tooltipshow', duration);
}
}
}, this._ns, this);
@@ -2781,11 +3206,11 @@
if(event.isDefaultPrevented() || event.target !== tooltip[0]) { return; }
var qtips = $(MODALSELECTOR),
// Keep the modal's lower than other, regular qtips
- newIndex = PLUGINS.modal.zindex + qtips.length,
+ newIndex = QTIP.modal_zindex + qtips.length,
curIndex = parseInt(tooltip[0].style.zIndex, 10);
// Set overlay z-index
OVERLAY.elem[0].style.zIndex = newIndex - 1;
@@ -2843,29 +3268,29 @@
return new Modal(api, api.options.show.modal);
};
// Setup sanitiztion rules
MODAL.sanitize = function(opts) {
- if(opts.show) {
+ if(opts.show) {
if(typeof opts.show.modal !== 'object') { opts.show.modal = { on: !!opts.show.modal }; }
else if(typeof opts.show.modal.on === 'undefined') { opts.show.modal.on = TRUE; }
}
};
// Base z-index for all modal tooltips (use qTip core z-index as a base)
-MODAL.zindex = QTIP.zindex - 200;
+QTIP.modal_zindex = QTIP.zindex - 200;
// Plugin needs to be initialized on render
MODAL.initialize = 'render';
// Setup option set checks
CHECKS.modal = {
'^show.modal.(on|blur)$': function() {
// Initialise
this.destroy();
this.init();
-
+
// Show the modal if not visible already and tooltip is visible
this.qtip.elems.overlay.toggle(
this.qtip.tooltip[0].offsetWidth > 0
);
}
@@ -2881,386 +3306,13 @@
stealfocus: TRUE,
escape: TRUE
}
}
});
-;PLUGINS.viewport = function(api, position, posOptions, targetWidth, targetHeight, elemWidth, elemHeight)
-{
- var target = posOptions.target,
- tooltip = api.elements.tooltip,
- my = posOptions.my,
- at = posOptions.at,
- adjust = posOptions.adjust,
- method = adjust.method.split(' '),
- methodX = method[0],
- methodY = method[1] || method[0],
- viewport = posOptions.viewport,
- container = posOptions.container,
- cache = api.cache,
- tip = api.plugins.tip,
- adjusted = { left: 0, top: 0 },
- fixed, newMy, newClass;
+;var IE6,
- // If viewport is not a jQuery element, or it's the window/document or no adjustment method is used... return
- if(!viewport.jquery || target[0] === window || target[0] === document.body || adjust.method === 'none') {
- return adjusted;
- }
-
- // Cache our viewport details
- fixed = tooltip.css('position') === 'fixed';
- viewport = {
- elem: viewport,
- width: viewport[0] === window ? viewport.width() : viewport.outerWidth(FALSE),
- height: viewport[0] === window ? viewport.height() : viewport.outerHeight(FALSE),
- scrollleft: fixed ? 0 : viewport.scrollLeft(),
- scrolltop: fixed ? 0 : viewport.scrollTop(),
- offset: viewport.offset() || { left: 0, top: 0 }
- };
- container = {
- elem: container,
- scrollLeft: container.scrollLeft(),
- scrollTop: container.scrollTop(),
- offset: container.offset() || { left: 0, top: 0 }
- };
-
- // Generic calculation method
- function calculate(side, otherSide, type, adjust, side1, side2, lengthName, targetLength, elemLength) {
- var initialPos = position[side1],
- mySide = my[side], atSide = at[side],
- isShift = type === SHIFT,
- viewportScroll = -container.offset[side1] + viewport.offset[side1] + viewport['scroll'+side1],
- myLength = mySide === side1 ? elemLength : mySide === side2 ? -elemLength : -elemLength / 2,
- atLength = atSide === side1 ? targetLength : atSide === side2 ? -targetLength : -targetLength / 2,
- tipLength = tip && tip.size ? tip.size[lengthName] || 0 : 0,
- tipAdjust = tip && tip.corner && tip.corner.precedance === side && !isShift ? tipLength : 0,
- overflow1 = viewportScroll - initialPos + tipAdjust,
- overflow2 = initialPos + elemLength - viewport[lengthName] - viewportScroll + tipAdjust,
- offset = myLength - (my.precedance === side || mySide === my[otherSide] ? atLength : 0) - (atSide === CENTER ? targetLength / 2 : 0);
-
- // shift
- if(isShift) {
- tipAdjust = tip && tip.corner && tip.corner.precedance === otherSide ? tipLength : 0;
- offset = (mySide === side1 ? 1 : -1) * myLength - tipAdjust;
-
- // Adjust position but keep it within viewport dimensions
- position[side1] += overflow1 > 0 ? overflow1 : overflow2 > 0 ? -overflow2 : 0;
- position[side1] = Math.max(
- -container.offset[side1] + viewport.offset[side1] + (tipAdjust && tip.corner[side] === CENTER ? tip.offset : 0),
- initialPos - offset,
- Math.min(
- Math.max(-container.offset[side1] + viewport.offset[side1] + viewport[lengthName], initialPos + offset),
- position[side1]
- )
- );
- }
-
- // flip/flipinvert
- else {
- // Update adjustment amount depending on if using flipinvert or flip
- adjust *= (type === FLIPINVERT ? 2 : 0);
-
- // Check for overflow on the left/top
- if(overflow1 > 0 && (mySide !== side1 || overflow2 > 0)) {
- position[side1] -= offset + adjust;
- newMy.invert(side, side1);
- }
-
- // Check for overflow on the bottom/right
- else if(overflow2 > 0 && (mySide !== side2 || overflow1 > 0) ) {
- position[side1] -= (mySide === CENTER ? -offset : offset) + adjust;
- newMy.invert(side, side2);
- }
-
- // Make sure we haven't made things worse with the adjustment and reset if so
- if(position[side1] < viewportScroll && -position[side1] > overflow2) {
- position[side1] = initialPos; newMy = my.clone();
- }
- }
-
- return position[side1] - initialPos;
- }
-
- // Set newMy if using flip or flipinvert methods
- if(methodX !== 'shift' || methodY !== 'shift') { newMy = my.clone(); }
-
- // Adjust position based onviewport and adjustment options
- adjusted = {
- left: methodX !== 'none' ? calculate( X, Y, methodX, adjust.x, LEFT, RIGHT, WIDTH, targetWidth, elemWidth ) : 0,
- top: methodY !== 'none' ? calculate( Y, X, methodY, adjust.y, TOP, BOTTOM, HEIGHT, targetHeight, elemHeight ) : 0
- };
-
- // Set tooltip position class if it's changed
- if(newMy && cache.lastClass !== (newClass = NAMESPACE + '-pos-' + newMy.abbrev())) {
- tooltip.removeClass(api.cache.lastClass).addClass( (api.cache.lastClass = newClass) );
- }
-
- return adjusted;
-};;PLUGINS.polys = {
- // POLY area coordinate calculator
- // Special thanks to Ed Cradock for helping out with this.
- // Uses a binary search algorithm to find suitable coordinates.
- polygon: function(baseCoords, corner) {
- var result = {
- width: 0, height: 0,
- position: {
- top: 1e10, right: 0,
- bottom: 0, left: 1e10
- },
- adjustable: FALSE
- },
- i = 0, next,
- coords = [],
- compareX = 1, compareY = 1,
- realX = 0, realY = 0,
- newWidth, newHeight;
-
- // First pass, sanitize coords and determine outer edges
- i = baseCoords.length; while(i--) {
- next = [ parseInt(baseCoords[--i], 10), parseInt(baseCoords[i+1], 10) ];
-
- if(next[0] > result.position.right){ result.position.right = next[0]; }
- if(next[0] < result.position.left){ result.position.left = next[0]; }
- if(next[1] > result.position.bottom){ result.position.bottom = next[1]; }
- if(next[1] < result.position.top){ result.position.top = next[1]; }
-
- coords.push(next);
- }
-
- // Calculate height and width from outer edges
- newWidth = result.width = Math.abs(result.position.right - result.position.left);
- newHeight = result.height = Math.abs(result.position.bottom - result.position.top);
-
- // If it's the center corner...
- if(corner.abbrev() === 'c') {
- result.position = {
- left: result.position.left + (result.width / 2),
- top: result.position.top + (result.height / 2)
- };
- }
- else {
- // Second pass, use a binary search algorithm to locate most suitable coordinate
- while(newWidth > 0 && newHeight > 0 && compareX > 0 && compareY > 0)
- {
- newWidth = Math.floor(newWidth / 2);
- newHeight = Math.floor(newHeight / 2);
-
- if(corner.x === LEFT){ compareX = newWidth; }
- else if(corner.x === RIGHT){ compareX = result.width - newWidth; }
- else{ compareX += Math.floor(newWidth / 2); }
-
- if(corner.y === TOP){ compareY = newHeight; }
- else if(corner.y === BOTTOM){ compareY = result.height - newHeight; }
- else{ compareY += Math.floor(newHeight / 2); }
-
- i = coords.length; while(i--)
- {
- if(coords.length < 2){ break; }
-
- realX = coords[i][0] - result.position.left;
- realY = coords[i][1] - result.position.top;
-
- if((corner.x === LEFT && realX >= compareX) ||
- (corner.x === RIGHT && realX <= compareX) ||
- (corner.x === CENTER && (realX < compareX || realX > (result.width - compareX))) ||
- (corner.y === TOP && realY >= compareY) ||
- (corner.y === BOTTOM && realY <= compareY) ||
- (corner.y === CENTER && (realY < compareY || realY > (result.height - compareY)))) {
- coords.splice(i, 1);
- }
- }
- }
- result.position = { left: coords[0][0], top: coords[0][1] };
- }
-
- return result;
- },
-
- rect: function(ax, ay, bx, by, corner) {
- return {
- width: Math.abs(bx - ax),
- height: Math.abs(by - ay),
- position: {
- left: Math.min(ax, bx),
- top: Math.min(ay, by)
- }
- };
- },
-
- _angles: {
- tc: 3 / 2, tr: 7 / 4, tl: 5 / 4,
- bc: 1 / 2, br: 1 / 4, bl: 3 / 4,
- rc: 2, lc: 1, c: 0
- },
- ellipse: function(cx, cy, rx, ry, corner) {
- var c = PLUGINS.polys._angles[ corner.abbrev() ],
- rxc = rx * Math.cos( c * Math.PI ),
- rys = ry * Math.sin( c * Math.PI );
-
- return {
- width: (rx * 2) - Math.abs(rxc),
- height: (ry * 2) - Math.abs(rys),
- position: {
- left: cx + rxc,
- top: cy + rys
- },
- adjustable: FALSE
- };
- },
- circle: function(cx, cy, r, corner) {
- return PLUGINS.polys.ellipse(cx, cy, r, r, corner);
- }
-};;PLUGINS.svg = function(api, svg, corner, adjustMethod)
-{
- var doc = $(document),
- elem = svg[0],
- result = {},
- name, box, position, dimensions;
-
- // Ascend the parentNode chain until we find an element with getBBox()
- while(!elem.getBBox) { elem = elem.parentNode; }
- if(!elem.getBBox || !elem.parentNode) { return FALSE; }
-
- // Determine which shape calculation to use
- switch(elem.nodeName) {
- case 'rect':
- position = PLUGINS.svg.toPixel(elem, elem.x.baseVal.value, elem.y.baseVal.value);
- dimensions = PLUGINS.svg.toPixel(elem,
- elem.x.baseVal.value + elem.width.baseVal.value,
- elem.y.baseVal.value + elem.height.baseVal.value
- );
-
- result = PLUGINS.polys.rect(
- position[0], position[1],
- dimensions[0], dimensions[1],
- corner
- );
- break;
-
- case 'ellipse':
- case 'circle':
- position = PLUGINS.svg.toPixel(elem,
- elem.cx.baseVal.value,
- elem.cy.baseVal.value
- );
-
- result = PLUGINS.polys.ellipse(
- position[0], position[1],
- (elem.rx || elem.r).baseVal.value,
- (elem.ry || elem.r).baseVal.value,
- corner
- );
- break;
-
- case 'line':
- case 'polygon':
- case 'polyline':
- points = elem.points || [
- { x: elem.x1.baseVal.value, y: elem.y1.baseVal.value },
- { x: elem.x2.baseVal.value, y: elem.y2.baseVal.value }
- ];
-
- for(result = [], i = -1, len = points.numberOfItems || points.length; ++i < len;) {
- next = points.getItem ? points.getItem(i) : points[i];
- result.push.apply(result, PLUGINS.svg.toPixel(elem, next.x, next.y));
- }
-
- result = PLUGINS.polys.polygon(result, corner);
- break;
-
- // Unknown shape... use bounding box as fallback
- default:
- box = elem.getBBox();
- mtx = elem.getScreenCTM();
- root = elem.farthestViewportElement || elem;
-
- // Return if no createSVGPoint method is found
- if(!root.createSVGPoint) { return FALSE; }
-
- // Create our point var
- point = root.createSVGPoint();
-
- // Adjust top and left
- point.x = box.x;
- point.y = box.y;
- tPoint = point.matrixTransform(mtx);
- result.position = {
- left: tPoint.x, top: tPoint.y
- };
-
- // Adjust width and height
- point.x += box.width;
- point.y += box.height;
- tPoint = point.matrixTransform(mtx);
- result.width = tPoint.x - result.position.left;
- result.height = tPoint.y - result.position.top;
- break;
- }
-
- // Adjust by scroll offset
- result.position.left += doc.scrollLeft();
- result.position.top += doc.scrollTop();
-
- return result;
-};
-
-PLUGINS.svg.toPixel = function(elem, x, y) {
- var mtx = elem.getScreenCTM(),
- root = elem.farthestViewportElement || elem,
- result, point;
-
- // Create SVG point
- if(!root.createSVGPoint) { return FALSE; }
- point = root.createSVGPoint();
-
- point.x = x; point.y = y;
- result = point.matrixTransform(mtx);
- return [ result.x, result.y ];
-};;PLUGINS.imagemap = function(api, area, corner, adjustMethod)
-{
- if(!area.jquery) { area = $(area); }
-
- var shape = area.attr('shape').toLowerCase().replace('poly', 'polygon'),
- image = $('img[usemap="#'+area.parent('map').attr('name')+'"]'),
- coordsString = area.attr('coords'),
- coordsArray = coordsString.split(','),
- imageOffset, coords, i, next;
-
- // If we can't find the image using the map...
- if(!image.length) { return FALSE; }
-
- // Pass coordinates string if polygon
- if(shape === 'polygon') {
- result = PLUGINS.polys.polygon(coordsArray, corner);
- }
-
- // Otherwise parse the coordinates and pass them as arguments
- else if(PLUGINS.polys[shape]) {
- for(i = -1, len = coordsArray.length, coords = []; ++i < len;) {
- coords.push( parseInt(coordsArray[i], 10) );
- }
-
- result = PLUGINS.polys[shape].apply(
- this, coords.concat(corner)
- );
- }
-
- // If no shapre calculation method was found, return false
- else { return FALSE; }
-
- // Make sure we account for padding and borders on the image
- imageOffset = image.offset();
- imageOffset.left += Math.ceil((image.outerWidth(FALSE) - image.width()) / 2);
- imageOffset.top += Math.ceil((image.outerHeight(FALSE) - image.height()) / 2);
-
- // Add image position to offset coordinates
- result.position.left += imageOffset.left;
- result.position.top += imageOffset.top;
-
- return result;
-};;var IE6,
-
-/*
+/*
* BGIFrame adaption (http://plugins.jquery.com/project/bgiframe)
* Special thanks to Brandon Aaron
*/
BGIFRAME = '<iframe class="qtip-bgiframe" frameborder="0" tabindex="-1" src="javascript:\'\';" ' +
' style="display:block; position:absolute; z-index:-1; filter:alpha(opacity=0); ' +
@@ -3327,11 +3379,11 @@
this.bgiframe.css(offset).css(dimensions);
},
// Max/min width simulator function
redraw: function() {
- if(this.qtip.rendered < 1 || this.drawing) { return self; }
+ if(this.qtip.rendered < 1 || this.drawing) { return this; }
var tooltip = this.qtip.tooltip,
style = this.qtip.options.style,
container = this.qtip.options.position.container,
perc, width, max, min;
@@ -3356,11 +3408,11 @@
max = tooltip.css('maxWidth') || '';
min = tooltip.css('minWidth') || '';
// Parse into proper pixel values
perc = (max + min).indexOf('%') > -1 ? container.width() / 100 : 0;
- max = ((max.indexOf('%') > -1 ? perc : 1) * parseInt(max, 10)) || width;
+ max = ((max.indexOf('%') > -1 ? perc : 1) * parseInt(max, 10)) || width;
min = ((min.indexOf('%') > -1 ? perc : 1) * parseInt(min, 10)) || 0;
// Determine new dimension size based on max/min/current values
width = max + min ? Math.min(Math.max(width, min), max) : width;
@@ -3369,11 +3421,11 @@
}
// Set drawing flag
this.drawing = 0;
- return self;
+ return this;
},
destroy: function() {
// Remove iframe
this.bgiframe && this.bgiframe.remove();
@@ -3389,12 +3441,11 @@
};
IE6.initialize = 'render';
CHECKS.ie6 = {
- '^content|style$': function() {
+ '^content|style$': function() {
this.redraw();
}
-};;}));
+};
+;}));
}( window, document ));
-
-