|
Packit Service |
50c9f2 |
/*!
|
|
Packit Service |
50c9f2 |
PowerTip - v1.2.0 - 2013-04-03
|
|
Packit Service |
50c9f2 |
http://stevenbenner.github.com/jquery-powertip/
|
|
Packit Service |
50c9f2 |
Copyright (c) 2013 Steven Benner (http://stevenbenner.com/).
|
|
Packit Service |
50c9f2 |
Released under MIT license.
|
|
Packit Service |
50c9f2 |
https://raw.github.com/stevenbenner/jquery-powertip/master/LICENSE.txt
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
(function(factory) {
|
|
Packit Service |
50c9f2 |
if (typeof define === 'function' && define.amd) {
|
|
Packit Service |
50c9f2 |
// AMD. Register as an anonymous module.
|
|
Packit Service |
50c9f2 |
define(['jquery'], factory);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
// Browser globals
|
|
Packit Service |
50c9f2 |
factory(jQuery);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}(function($) {
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// useful private variables
|
|
Packit Service |
50c9f2 |
var $document = $(document),
|
|
Packit Service |
50c9f2 |
$window = $(window),
|
|
Packit Service |
50c9f2 |
$body = $('body');
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// constants
|
|
Packit Service |
50c9f2 |
var DATA_DISPLAYCONTROLLER = 'displayController',
|
|
Packit Service |
50c9f2 |
DATA_HASACTIVEHOVER = 'hasActiveHover',
|
|
Packit Service |
50c9f2 |
DATA_FORCEDOPEN = 'forcedOpen',
|
|
Packit Service |
50c9f2 |
DATA_HASMOUSEMOVE = 'hasMouseMove',
|
|
Packit Service |
50c9f2 |
DATA_MOUSEONTOTIP = 'mouseOnToPopup',
|
|
Packit Service |
50c9f2 |
DATA_ORIGINALTITLE = 'originalTitle',
|
|
Packit Service |
50c9f2 |
DATA_POWERTIP = 'powertip',
|
|
Packit Service |
50c9f2 |
DATA_POWERTIPJQ = 'powertipjq',
|
|
Packit Service |
50c9f2 |
DATA_POWERTIPTARGET = 'powertiptarget',
|
|
Packit Service |
50c9f2 |
RAD2DEG = 180 / Math.PI;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Session data
|
|
Packit Service |
50c9f2 |
* Private properties global to all powerTip instances
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
var session = {
|
|
Packit Service |
50c9f2 |
isTipOpen: false,
|
|
Packit Service |
50c9f2 |
isFixedTipOpen: false,
|
|
Packit Service |
50c9f2 |
isClosing: false,
|
|
Packit Service |
50c9f2 |
tipOpenImminent: false,
|
|
Packit Service |
50c9f2 |
activeHover: null,
|
|
Packit Service |
50c9f2 |
currentX: 0,
|
|
Packit Service |
50c9f2 |
currentY: 0,
|
|
Packit Service |
50c9f2 |
previousX: 0,
|
|
Packit Service |
50c9f2 |
previousY: 0,
|
|
Packit Service |
50c9f2 |
desyncTimeout: null,
|
|
Packit Service |
50c9f2 |
mouseTrackingActive: false,
|
|
Packit Service |
50c9f2 |
delayInProgress: false,
|
|
Packit Service |
50c9f2 |
windowWidth: 0,
|
|
Packit Service |
50c9f2 |
windowHeight: 0,
|
|
Packit Service |
50c9f2 |
scrollTop: 0,
|
|
Packit Service |
50c9f2 |
scrollLeft: 0
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Collision enumeration
|
|
Packit Service |
50c9f2 |
* @enum {number}
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
var Collision = {
|
|
Packit Service |
50c9f2 |
none: 0,
|
|
Packit Service |
50c9f2 |
top: 1,
|
|
Packit Service |
50c9f2 |
bottom: 2,
|
|
Packit Service |
50c9f2 |
left: 4,
|
|
Packit Service |
50c9f2 |
right: 8
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Display hover tooltips on the matched elements.
|
|
Packit Service |
50c9f2 |
* @param {(Object|string)} opts The options object to use for the plugin, or
|
|
Packit Service |
50c9f2 |
* the name of a method to invoke on the first matched element.
|
|
Packit Service |
50c9f2 |
* @param {*=} [arg] Argument for an invoked method (optional).
|
|
Packit Service |
50c9f2 |
* @return {jQuery} jQuery object for the matched selectors.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
$.fn.powerTip = function(opts, arg) {
|
|
Packit Service |
50c9f2 |
// don't do any work if there were no matched elements
|
|
Packit Service |
50c9f2 |
if (!this.length) {
|
|
Packit Service |
50c9f2 |
return this;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// handle api method calls on the plugin, e.g. powerTip('hide')
|
|
Packit Service |
50c9f2 |
if ($.type(opts) === 'string' && $.powerTip[opts]) {
|
|
Packit Service |
50c9f2 |
return $.powerTip[opts].call(this, this, arg);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// extend options and instantiate TooltipController
|
|
Packit Service |
50c9f2 |
var options = $.extend({}, $.fn.powerTip.defaults, opts),
|
|
Packit Service |
50c9f2 |
tipController = new TooltipController(options);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// hook mouse and viewport dimension tracking
|
|
Packit Service |
50c9f2 |
initTracking();
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// setup the elements
|
|
Packit Service |
50c9f2 |
this.each(function elementSetup() {
|
|
Packit Service |
50c9f2 |
var $this = $(this),
|
|
Packit Service |
50c9f2 |
dataPowertip = $this.data(DATA_POWERTIP),
|
|
Packit Service |
50c9f2 |
dataElem = $this.data(DATA_POWERTIPJQ),
|
|
Packit Service |
50c9f2 |
dataTarget = $this.data(DATA_POWERTIPTARGET),
|
|
Packit Service |
50c9f2 |
title;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// handle repeated powerTip calls on the same element by destroying the
|
|
Packit Service |
50c9f2 |
// original instance hooked to it and replacing it with this call
|
|
Packit Service |
50c9f2 |
if ($this.data(DATA_DISPLAYCONTROLLER)) {
|
|
Packit Service |
50c9f2 |
$.powerTip.destroy($this);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// attempt to use title attribute text if there is no data-powertip,
|
|
Packit Service |
50c9f2 |
// data-powertipjq or data-powertiptarget. If we do use the title
|
|
Packit Service |
50c9f2 |
// attribute, delete the attribute so the browser will not show it
|
|
Packit Service |
50c9f2 |
title = $this.attr('title');
|
|
Packit Service |
50c9f2 |
if (!dataPowertip && !dataTarget && !dataElem && title) {
|
|
Packit Service |
50c9f2 |
$this.data(DATA_POWERTIP, title);
|
|
Packit Service |
50c9f2 |
$this.data(DATA_ORIGINALTITLE, title);
|
|
Packit Service |
50c9f2 |
$this.removeAttr('title');
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// create hover controllers for each element
|
|
Packit Service |
50c9f2 |
$this.data(
|
|
Packit Service |
50c9f2 |
DATA_DISPLAYCONTROLLER,
|
|
Packit Service |
50c9f2 |
new DisplayController($this, options, tipController)
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// attach events to matched elements if the manual options is not enabled
|
|
Packit Service |
50c9f2 |
if (!options.manual) {
|
|
Packit Service |
50c9f2 |
this.on({
|
|
Packit Service |
50c9f2 |
// mouse events
|
|
Packit Service |
50c9f2 |
'mouseenter.powertip': function elementMouseEnter(event) {
|
|
Packit Service |
50c9f2 |
$.powerTip.show(this, event);
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
'mouseleave.powertip': function elementMouseLeave() {
|
|
Packit Service |
50c9f2 |
$.powerTip.hide(this);
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
// keyboard events
|
|
Packit Service |
50c9f2 |
'focus.powertip': function elementFocus() {
|
|
Packit Service |
50c9f2 |
$.powerTip.show(this);
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
'blur.powertip': function elementBlur() {
|
|
Packit Service |
50c9f2 |
$.powerTip.hide(this, true);
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
'keydown.powertip': function elementKeyDown(event) {
|
|
Packit Service |
50c9f2 |
// close tooltip when the escape key is pressed
|
|
Packit Service |
50c9f2 |
if (event.keyCode === 27) {
|
|
Packit Service |
50c9f2 |
$.powerTip.hide(this, true);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return this;
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Default options for the powerTip plugin.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
$.fn.powerTip.defaults = {
|
|
Packit Service |
50c9f2 |
fadeInTime: 200,
|
|
Packit Service |
50c9f2 |
fadeOutTime: 100,
|
|
Packit Service |
50c9f2 |
followMouse: false,
|
|
Packit Service |
50c9f2 |
popupId: 'powerTip',
|
|
Packit Service |
50c9f2 |
intentSensitivity: 7,
|
|
Packit Service |
50c9f2 |
intentPollInterval: 100,
|
|
Packit Service |
50c9f2 |
closeDelay: 100,
|
|
Packit Service |
50c9f2 |
placement: 'n',
|
|
Packit Service |
50c9f2 |
smartPlacement: false,
|
|
Packit Service |
50c9f2 |
offset: 10,
|
|
Packit Service |
50c9f2 |
mouseOnToPopup: false,
|
|
Packit Service |
50c9f2 |
manual: false
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Default smart placement priority lists.
|
|
Packit Service |
50c9f2 |
* The first item in the array is the highest priority, the last is the lowest.
|
|
Packit Service |
50c9f2 |
* The last item is also the default, which will be used if all previous options
|
|
Packit Service |
50c9f2 |
* do not fit.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
$.fn.powerTip.smartPlacementLists = {
|
|
Packit Service |
50c9f2 |
n: ['n', 'ne', 'nw', 's'],
|
|
Packit Service |
50c9f2 |
e: ['e', 'ne', 'se', 'w', 'nw', 'sw', 'n', 's', 'e'],
|
|
Packit Service |
50c9f2 |
s: ['s', 'se', 'sw', 'n'],
|
|
Packit Service |
50c9f2 |
w: ['w', 'nw', 'sw', 'e', 'ne', 'se', 'n', 's', 'w'],
|
|
Packit Service |
50c9f2 |
nw: ['nw', 'w', 'sw', 'n', 's', 'se', 'nw'],
|
|
Packit Service |
50c9f2 |
ne: ['ne', 'e', 'se', 'n', 's', 'sw', 'ne'],
|
|
Packit Service |
50c9f2 |
sw: ['sw', 'w', 'nw', 's', 'n', 'ne', 'sw'],
|
|
Packit Service |
50c9f2 |
se: ['se', 'e', 'ne', 's', 'n', 'nw', 'se'],
|
|
Packit Service |
50c9f2 |
'nw-alt': ['nw-alt', 'n', 'ne-alt', 'sw-alt', 's', 'se-alt', 'w', 'e'],
|
|
Packit Service |
50c9f2 |
'ne-alt': ['ne-alt', 'n', 'nw-alt', 'se-alt', 's', 'sw-alt', 'e', 'w'],
|
|
Packit Service |
50c9f2 |
'sw-alt': ['sw-alt', 's', 'se-alt', 'nw-alt', 'n', 'ne-alt', 'w', 'e'],
|
|
Packit Service |
50c9f2 |
'se-alt': ['se-alt', 's', 'sw-alt', 'ne-alt', 'n', 'nw-alt', 'e', 'w']
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Public API
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
$.powerTip = {
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Attempts to show the tooltip for the specified element.
|
|
Packit Service |
50c9f2 |
* @param {jQuery|Element} element The element to open the tooltip for.
|
|
Packit Service |
50c9f2 |
* @param {jQuery.Event=} event jQuery event for hover intent and mouse
|
|
Packit Service |
50c9f2 |
* tracking (optional).
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
show: function apiShowTip(element, event) {
|
|
Packit Service |
50c9f2 |
if (event) {
|
|
Packit Service |
50c9f2 |
trackMouse(event);
|
|
Packit Service |
50c9f2 |
session.previousX = event.pageX;
|
|
Packit Service |
50c9f2 |
session.previousY = event.pageY;
|
|
Packit Service |
50c9f2 |
$(element).data(DATA_DISPLAYCONTROLLER).show();
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
$(element).first().data(DATA_DISPLAYCONTROLLER).show(true, true);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
return element;
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Repositions the tooltip on the element.
|
|
Packit Service |
50c9f2 |
* @param {jQuery|Element} element The element the tooltip is shown for.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
reposition: function apiResetPosition(element) {
|
|
Packit Service |
50c9f2 |
$(element).first().data(DATA_DISPLAYCONTROLLER).resetPosition();
|
|
Packit Service |
50c9f2 |
return element;
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Attempts to close any open tooltips.
|
|
Packit Service |
50c9f2 |
* @param {(jQuery|Element)=} element The element with the tooltip that
|
|
Packit Service |
50c9f2 |
* should be closed (optional).
|
|
Packit Service |
50c9f2 |
* @param {boolean=} immediate Disable close delay (optional).
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
hide: function apiCloseTip(element, immediate) {
|
|
Packit Service |
50c9f2 |
if (element) {
|
|
Packit Service |
50c9f2 |
$(element).first().data(DATA_DISPLAYCONTROLLER).hide(immediate);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
if (session.activeHover) {
|
|
Packit Service |
50c9f2 |
session.activeHover.data(DATA_DISPLAYCONTROLLER).hide(true);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
return element;
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Destroy and roll back any powerTip() instance on the specified element.
|
|
Packit Service |
50c9f2 |
* @param {jQuery|Element} element The element with the powerTip instance.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
destroy: function apiDestroy(element) {
|
|
Packit Service |
50c9f2 |
$(element).off('.powertip').each(function destroy() {
|
|
Packit Service |
50c9f2 |
var $this = $(this),
|
|
Packit Service |
50c9f2 |
dataAttributes = [
|
|
Packit Service |
50c9f2 |
DATA_ORIGINALTITLE,
|
|
Packit Service |
50c9f2 |
DATA_DISPLAYCONTROLLER,
|
|
Packit Service |
50c9f2 |
DATA_HASACTIVEHOVER,
|
|
Packit Service |
50c9f2 |
DATA_FORCEDOPEN
|
|
Packit Service |
50c9f2 |
];
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
if ($this.data(DATA_ORIGINALTITLE)) {
|
|
Packit Service |
50c9f2 |
$this.attr('title', $this.data(DATA_ORIGINALTITLE));
|
|
Packit Service |
50c9f2 |
dataAttributes.push(DATA_POWERTIP);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
$this.removeData(dataAttributes);
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
return element;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// API aliasing
|
|
Packit Service |
50c9f2 |
$.powerTip.showTip = $.powerTip.show;
|
|
Packit Service |
50c9f2 |
$.powerTip.closeTip = $.powerTip.hide;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Creates a new CSSCoordinates object.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @constructor
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function CSSCoordinates() {
|
|
Packit Service |
50c9f2 |
var me = this;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// initialize object properties
|
|
Packit Service |
50c9f2 |
me.top = 'auto';
|
|
Packit Service |
50c9f2 |
me.left = 'auto';
|
|
Packit Service |
50c9f2 |
me.right = 'auto';
|
|
Packit Service |
50c9f2 |
me.bottom = 'auto';
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Set a property to a value.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {string} property The name of the property.
|
|
Packit Service |
50c9f2 |
* @param {number} value The value of the property.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
me.set = function(property, value) {
|
|
Packit Service |
50c9f2 |
if ($.isNumeric(value)) {
|
|
Packit Service |
50c9f2 |
me[property] = Math.round(value);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Creates a new tooltip display controller.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @constructor
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that this controller will handle.
|
|
Packit Service |
50c9f2 |
* @param {Object} options Options object containing settings.
|
|
Packit Service |
50c9f2 |
* @param {TooltipController} tipController The TooltipController object for
|
|
Packit Service |
50c9f2 |
* this instance.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function DisplayController(element, options, tipController) {
|
|
Packit Service |
50c9f2 |
var hoverTimer = null;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Begins the process of showing a tooltip.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {boolean=} immediate Skip intent testing (optional).
|
|
Packit Service |
50c9f2 |
* @param {boolean=} forceOpen Ignore cursor position and force tooltip to
|
|
Packit Service |
50c9f2 |
* open (optional).
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function openTooltip(immediate, forceOpen) {
|
|
Packit Service |
50c9f2 |
cancelTimer();
|
|
Packit Service |
50c9f2 |
if (!element.data(DATA_HASACTIVEHOVER)) {
|
|
Packit Service |
50c9f2 |
if (!immediate) {
|
|
Packit Service |
50c9f2 |
session.tipOpenImminent = true;
|
|
Packit Service |
50c9f2 |
hoverTimer = setTimeout(
|
|
Packit Service |
50c9f2 |
function intentDelay() {
|
|
Packit Service |
50c9f2 |
hoverTimer = null;
|
|
Packit Service |
50c9f2 |
checkForIntent();
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
options.intentPollInterval
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
if (forceOpen) {
|
|
Packit Service |
50c9f2 |
element.data(DATA_FORCEDOPEN, true);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
tipController.showTip(element);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Begins the process of closing a tooltip.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {boolean=} disableDelay Disable close delay (optional).
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function closeTooltip(disableDelay) {
|
|
Packit Service |
50c9f2 |
cancelTimer();
|
|
Packit Service |
50c9f2 |
session.tipOpenImminent = false;
|
|
Packit Service |
50c9f2 |
if (element.data(DATA_HASACTIVEHOVER)) {
|
|
Packit Service |
50c9f2 |
element.data(DATA_FORCEDOPEN, false);
|
|
Packit Service |
50c9f2 |
if (!disableDelay) {
|
|
Packit Service |
50c9f2 |
session.delayInProgress = true;
|
|
Packit Service |
50c9f2 |
hoverTimer = setTimeout(
|
|
Packit Service |
50c9f2 |
function closeDelay() {
|
|
Packit Service |
50c9f2 |
hoverTimer = null;
|
|
Packit Service |
50c9f2 |
tipController.hideTip(element);
|
|
Packit Service |
50c9f2 |
session.delayInProgress = false;
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
options.closeDelay
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
tipController.hideTip(element);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Checks mouse position to make sure that the user intended to hover on the
|
|
Packit Service |
50c9f2 |
* specified element before showing the tooltip.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function checkForIntent() {
|
|
Packit Service |
50c9f2 |
// calculate mouse position difference
|
|
Packit Service |
50c9f2 |
var xDifference = Math.abs(session.previousX - session.currentX),
|
|
Packit Service |
50c9f2 |
yDifference = Math.abs(session.previousY - session.currentY),
|
|
Packit Service |
50c9f2 |
totalDifference = xDifference + yDifference;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// check if difference has passed the sensitivity threshold
|
|
Packit Service |
50c9f2 |
if (totalDifference < options.intentSensitivity) {
|
|
Packit Service |
50c9f2 |
tipController.showTip(element);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
// try again
|
|
Packit Service |
50c9f2 |
session.previousX = session.currentX;
|
|
Packit Service |
50c9f2 |
session.previousY = session.currentY;
|
|
Packit Service |
50c9f2 |
openTooltip();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Cancels active hover timer.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function cancelTimer() {
|
|
Packit Service |
50c9f2 |
hoverTimer = clearTimeout(hoverTimer);
|
|
Packit Service |
50c9f2 |
session.delayInProgress = false;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Repositions the tooltip on this element.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function repositionTooltip() {
|
|
Packit Service |
50c9f2 |
tipController.resetPosition(element);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// expose the methods
|
|
Packit Service |
50c9f2 |
this.show = openTooltip;
|
|
Packit Service |
50c9f2 |
this.hide = closeTooltip;
|
|
Packit Service |
50c9f2 |
this.cancel = cancelTimer;
|
|
Packit Service |
50c9f2 |
this.resetPosition = repositionTooltip;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Creates a new Placement Calculator.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @constructor
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function PlacementCalculator() {
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Compute the CSS position to display a tooltip at the specified placement
|
|
Packit Service |
50c9f2 |
* relative to the specified element.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
* @param {string} placement The placement for the tooltip.
|
|
Packit Service |
50c9f2 |
* @param {number} tipWidth Width of the tooltip element in pixels.
|
|
Packit Service |
50c9f2 |
* @param {number} tipHeight Height of the tooltip element in pixels.
|
|
Packit Service |
50c9f2 |
* @param {number} offset Distance to offset tooltips in pixels.
|
|
Packit Service |
50c9f2 |
* @return {CSSCoordinates} A CSSCoordinates object with the position.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function computePlacementCoords(element, placement, tipWidth, tipHeight, offset) {
|
|
Packit Service |
50c9f2 |
var placementBase = placement.split('-')[0], // ignore 'alt' for corners
|
|
Packit Service |
50c9f2 |
coords = new CSSCoordinates(),
|
|
Packit Service |
50c9f2 |
position;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
if (isSvgElement(element)) {
|
|
Packit Service |
50c9f2 |
position = getSvgPlacement(element, placementBase);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
position = getHtmlPlacement(element, placementBase);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// calculate the appropriate x and y position in the document
|
|
Packit Service |
50c9f2 |
switch (placement) {
|
|
Packit Service |
50c9f2 |
case 'n':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left - (tipWidth / 2));
|
|
Packit Service |
50c9f2 |
coords.set('bottom', session.windowHeight - position.top + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'e':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left + offset);
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top - (tipHeight / 2));
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 's':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left - (tipWidth / 2));
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'w':
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top - (tipHeight / 2));
|
|
Packit Service |
50c9f2 |
coords.set('right', session.windowWidth - position.left + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'nw':
|
|
Packit Service |
50c9f2 |
coords.set('bottom', session.windowHeight - position.top + offset);
|
|
Packit Service |
50c9f2 |
coords.set('right', session.windowWidth - position.left - 20);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'nw-alt':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left);
|
|
Packit Service |
50c9f2 |
coords.set('bottom', session.windowHeight - position.top + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'ne':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left - 20);
|
|
Packit Service |
50c9f2 |
coords.set('bottom', session.windowHeight - position.top + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'ne-alt':
|
|
Packit Service |
50c9f2 |
coords.set('bottom', session.windowHeight - position.top + offset);
|
|
Packit Service |
50c9f2 |
coords.set('right', session.windowWidth - position.left);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'sw':
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top + offset);
|
|
Packit Service |
50c9f2 |
coords.set('right', session.windowWidth - position.left - 20);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'sw-alt':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left);
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'se':
|
|
Packit Service |
50c9f2 |
coords.set('left', position.left - 20);
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top + offset);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'se-alt':
|
|
Packit Service |
50c9f2 |
coords.set('top', position.top + offset);
|
|
Packit Service |
50c9f2 |
coords.set('right', session.windowWidth - position.left);
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return coords;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Finds the tooltip attachment point in the document for a HTML DOM element
|
|
Packit Service |
50c9f2 |
* for the specified placement.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
* @param {string} placement The placement for the tooltip.
|
|
Packit Service |
50c9f2 |
* @return {Object} An object with the top,left position values.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function getHtmlPlacement(element, placement) {
|
|
Packit Service |
50c9f2 |
var objectOffset = element.offset(),
|
|
Packit Service |
50c9f2 |
objectWidth = element.outerWidth(),
|
|
Packit Service |
50c9f2 |
objectHeight = element.outerHeight(),
|
|
Packit Service |
50c9f2 |
left,
|
|
Packit Service |
50c9f2 |
top;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// calculate the appropriate x and y position in the document
|
|
Packit Service |
50c9f2 |
switch (placement) {
|
|
Packit Service |
50c9f2 |
case 'n':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left + objectWidth / 2;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'e':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left + objectWidth;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top + objectHeight / 2;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 's':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left + objectWidth / 2;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top + objectHeight;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'w':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top + objectHeight / 2;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'nw':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'ne':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left + objectWidth;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'sw':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top + objectHeight;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
case 'se':
|
|
Packit Service |
50c9f2 |
left = objectOffset.left + objectWidth;
|
|
Packit Service |
50c9f2 |
top = objectOffset.top + objectHeight;
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return {
|
|
Packit Service |
50c9f2 |
top: top,
|
|
Packit Service |
50c9f2 |
left: left
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Finds the tooltip attachment point in the document for a SVG element for
|
|
Packit Service |
50c9f2 |
* the specified placement.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
* @param {string} placement The placement for the tooltip.
|
|
Packit Service |
50c9f2 |
* @return {Object} An object with the top,left position values.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function getSvgPlacement(element, placement) {
|
|
Packit Service |
50c9f2 |
var svgElement = element.closest('svg')[0],
|
|
Packit Service |
50c9f2 |
domElement = element[0],
|
|
Packit Service |
50c9f2 |
point = svgElement.createSVGPoint(),
|
|
Packit Service |
50c9f2 |
boundingBox = domElement.getBBox(),
|
|
Packit Service |
50c9f2 |
matrix = domElement.getScreenCTM(),
|
|
Packit Service |
50c9f2 |
halfWidth = boundingBox.width / 2,
|
|
Packit Service |
50c9f2 |
halfHeight = boundingBox.height / 2,
|
|
Packit Service |
50c9f2 |
placements = [],
|
|
Packit Service |
50c9f2 |
placementKeys = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'],
|
|
Packit Service |
50c9f2 |
coords,
|
|
Packit Service |
50c9f2 |
rotation,
|
|
Packit Service |
50c9f2 |
steps,
|
|
Packit Service |
50c9f2 |
x;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
function pushPlacement() {
|
|
Packit Service |
50c9f2 |
placements.push(point.matrixTransform(matrix));
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// get bounding box corners and midpoints
|
|
Packit Service |
50c9f2 |
point.x = boundingBox.x;
|
|
Packit Service |
50c9f2 |
point.y = boundingBox.y;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.x += halfWidth;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.x += halfWidth;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.y += halfHeight;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.y += halfHeight;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.x -= halfWidth;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.x -= halfWidth;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
point.y -= halfHeight;
|
|
Packit Service |
50c9f2 |
pushPlacement();
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// determine rotation
|
|
Packit Service |
50c9f2 |
if (placements[0].y !== placements[1].y || placements[0].x !== placements[7].x) {
|
|
Packit Service |
50c9f2 |
rotation = Math.atan2(matrix.b, matrix.a) * RAD2DEG;
|
|
Packit Service |
50c9f2 |
steps = Math.ceil(((rotation % 360) - 22.5) / 45);
|
|
Packit Service |
50c9f2 |
if (steps < 1) {
|
|
Packit Service |
50c9f2 |
steps += 8;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
while (steps--) {
|
|
Packit Service |
50c9f2 |
placementKeys.push(placementKeys.shift());
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// find placement
|
|
Packit Service |
50c9f2 |
for (x = 0; x < placements.length; x++) {
|
|
Packit Service |
50c9f2 |
if (placementKeys[x] === placement) {
|
|
Packit Service |
50c9f2 |
coords = placements[x];
|
|
Packit Service |
50c9f2 |
break;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return {
|
|
Packit Service |
50c9f2 |
top: coords.y + session.scrollTop,
|
|
Packit Service |
50c9f2 |
left: coords.x + session.scrollLeft
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// expose methods
|
|
Packit Service |
50c9f2 |
this.compute = computePlacementCoords;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Creates a new tooltip controller.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @constructor
|
|
Packit Service |
50c9f2 |
* @param {Object} options Options object containing settings.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function TooltipController(options) {
|
|
Packit Service |
50c9f2 |
var placementCalculator = new PlacementCalculator(),
|
|
Packit Service |
50c9f2 |
tipElement = $('#' + options.popupId);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// build and append tooltip div if it does not already exist
|
|
Packit Service |
50c9f2 |
if (tipElement.length === 0) {
|
|
Packit Service |
50c9f2 |
tipElement = $('', { id: options.popupId });
|
|
Packit Service |
50c9f2 |
// grab body element if it was not populated when the script loaded
|
|
Packit Service |
50c9f2 |
// note: this hack exists solely for jsfiddle support
|
|
Packit Service |
50c9f2 |
if ($body.length === 0) {
|
|
Packit Service |
50c9f2 |
$body = $('body');
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
$body.append(tipElement);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// hook mousemove for cursor follow tooltips
|
|
Packit Service |
50c9f2 |
if (options.followMouse) {
|
|
Packit Service |
50c9f2 |
// only one positionTipOnCursor hook per tooltip element, please
|
|
Packit Service |
50c9f2 |
if (!tipElement.data(DATA_HASMOUSEMOVE)) {
|
|
Packit Service |
50c9f2 |
$document.on('mousemove', positionTipOnCursor);
|
|
Packit Service |
50c9f2 |
$window.on('scroll', positionTipOnCursor);
|
|
Packit Service |
50c9f2 |
tipElement.data(DATA_HASMOUSEMOVE, true);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// if we want to be able to mouse onto the tooltip then we need to attach
|
|
Packit Service |
50c9f2 |
// hover events to the tooltip that will cancel a close request on hover and
|
|
Packit Service |
50c9f2 |
// start a new close request on mouseleave
|
|
Packit Service |
50c9f2 |
if (options.mouseOnToPopup) {
|
|
Packit Service |
50c9f2 |
tipElement.on({
|
|
Packit Service |
50c9f2 |
mouseenter: function tipMouseEnter() {
|
|
Packit Service |
50c9f2 |
// we only let the mouse stay on the tooltip if it is set to let
|
|
Packit Service |
50c9f2 |
// users interact with it
|
|
Packit Service |
50c9f2 |
if (tipElement.data(DATA_MOUSEONTOTIP)) {
|
|
Packit Service |
50c9f2 |
// check activeHover in case the mouse cursor entered the
|
|
Packit Service |
50c9f2 |
// tooltip during the fadeOut and close cycle
|
|
Packit Service |
50c9f2 |
if (session.activeHover) {
|
|
Packit Service |
50c9f2 |
session.activeHover.data(DATA_DISPLAYCONTROLLER).cancel();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
mouseleave: function tipMouseLeave() {
|
|
Packit Service |
50c9f2 |
// check activeHover in case the mouse cursor entered the
|
|
Packit Service |
50c9f2 |
// tooltip during the fadeOut and close cycle
|
|
Packit Service |
50c9f2 |
if (session.activeHover) {
|
|
Packit Service |
50c9f2 |
session.activeHover.data(DATA_DISPLAYCONTROLLER).hide();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Gives the specified element the active-hover state and queues up the
|
|
Packit Service |
50c9f2 |
* showTip function.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function beginShowTip(element) {
|
|
Packit Service |
50c9f2 |
element.data(DATA_HASACTIVEHOVER, true);
|
|
Packit Service |
50c9f2 |
// show tooltip, asap
|
|
Packit Service |
50c9f2 |
tipElement.queue(function queueTipInit(next) {
|
|
Packit Service |
50c9f2 |
showTip(element);
|
|
Packit Service |
50c9f2 |
next();
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Shows the tooltip, as soon as possible.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function showTip(element) {
|
|
Packit Service |
50c9f2 |
var tipContent;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// it is possible, especially with keyboard navigation, to move on to
|
|
Packit Service |
50c9f2 |
// another element with a tooltip during the queue to get to this point
|
|
Packit Service |
50c9f2 |
// in the code. if that happens then we need to not proceed or we may
|
|
Packit Service |
50c9f2 |
// have the fadeout callback for the last tooltip execute immediately
|
|
Packit Service |
50c9f2 |
// after this code runs, causing bugs.
|
|
Packit Service |
50c9f2 |
if (!element.data(DATA_HASACTIVEHOVER)) {
|
|
Packit Service |
50c9f2 |
return;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// if the tooltip is open and we got asked to open another one then the
|
|
Packit Service |
50c9f2 |
// old one is still in its fadeOut cycle, so wait and try again
|
|
Packit Service |
50c9f2 |
if (session.isTipOpen) {
|
|
Packit Service |
50c9f2 |
if (!session.isClosing) {
|
|
Packit Service |
50c9f2 |
hideTip(session.activeHover);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
tipElement.delay(100).queue(function queueTipAgain(next) {
|
|
Packit Service |
50c9f2 |
showTip(element);
|
|
Packit Service |
50c9f2 |
next();
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
return;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// trigger powerTipPreRender event
|
|
Packit Service |
50c9f2 |
element.trigger('powerTipPreRender');
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// set tooltip content
|
|
Packit Service |
50c9f2 |
tipContent = getTooltipContent(element);
|
|
Packit Service |
50c9f2 |
if (tipContent) {
|
|
Packit Service |
50c9f2 |
tipElement.empty().append(tipContent);
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
// we have no content to display, give up
|
|
Packit Service |
50c9f2 |
return;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// trigger powerTipRender event
|
|
Packit Service |
50c9f2 |
element.trigger('powerTipRender');
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
session.activeHover = element;
|
|
Packit Service |
50c9f2 |
session.isTipOpen = true;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
tipElement.data(DATA_MOUSEONTOTIP, options.mouseOnToPopup);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// set tooltip position
|
|
Packit Service |
50c9f2 |
if (!options.followMouse) {
|
|
Packit Service |
50c9f2 |
positionTipOnElement(element);
|
|
Packit Service |
50c9f2 |
session.isFixedTipOpen = true;
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
positionTipOnCursor();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// fadein
|
|
Packit Service |
50c9f2 |
tipElement.fadeIn(options.fadeInTime, function fadeInCallback() {
|
|
Packit Service |
50c9f2 |
// start desync polling
|
|
Packit Service |
50c9f2 |
if (!session.desyncTimeout) {
|
|
Packit Service |
50c9f2 |
session.desyncTimeout = setInterval(closeDesyncedTip, 500);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// trigger powerTipOpen event
|
|
Packit Service |
50c9f2 |
element.trigger('powerTipOpen');
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Hides the tooltip.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function hideTip(element) {
|
|
Packit Service |
50c9f2 |
// reset session
|
|
Packit Service |
50c9f2 |
session.isClosing = true;
|
|
Packit Service |
50c9f2 |
session.activeHover = null;
|
|
Packit Service |
50c9f2 |
session.isTipOpen = false;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// stop desync polling
|
|
Packit Service |
50c9f2 |
session.desyncTimeout = clearInterval(session.desyncTimeout);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// reset element state
|
|
Packit Service |
50c9f2 |
element.data(DATA_HASACTIVEHOVER, false);
|
|
Packit Service |
50c9f2 |
element.data(DATA_FORCEDOPEN, false);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// fade out
|
|
Packit Service |
50c9f2 |
tipElement.fadeOut(options.fadeOutTime, function fadeOutCallback() {
|
|
Packit Service |
50c9f2 |
var coords = new CSSCoordinates();
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// reset session and tooltip element
|
|
Packit Service |
50c9f2 |
session.isClosing = false;
|
|
Packit Service |
50c9f2 |
session.isFixedTipOpen = false;
|
|
Packit Service |
50c9f2 |
tipElement.removeClass();
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// support mouse-follow and fixed position tips at the same time by
|
|
Packit Service |
50c9f2 |
// moving the tooltip to the last cursor location after it is hidden
|
|
Packit Service |
50c9f2 |
coords.set('top', session.currentY + options.offset);
|
|
Packit Service |
50c9f2 |
coords.set('left', session.currentX + options.offset);
|
|
Packit Service |
50c9f2 |
tipElement.css(coords);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// trigger powerTipClose event
|
|
Packit Service |
50c9f2 |
element.trigger('powerTipClose');
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Moves the tooltip to the users mouse cursor.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function positionTipOnCursor() {
|
|
Packit Service |
50c9f2 |
// to support having fixed tooltips on the same page as cursor tooltips,
|
|
Packit Service |
50c9f2 |
// where both instances are referencing the same tooltip element, we
|
|
Packit Service |
50c9f2 |
// need to keep track of the mouse position constantly, but we should
|
|
Packit Service |
50c9f2 |
// only set the tip location if a fixed tip is not currently open, a tip
|
|
Packit Service |
50c9f2 |
// open is imminent or active, and the tooltip element in question does
|
|
Packit Service |
50c9f2 |
// have a mouse-follow using it.
|
|
Packit Service |
50c9f2 |
if (!session.isFixedTipOpen && (session.isTipOpen || (session.tipOpenImminent && tipElement.data(DATA_HASMOUSEMOVE)))) {
|
|
Packit Service |
50c9f2 |
// grab measurements
|
|
Packit Service |
50c9f2 |
var tipWidth = tipElement.outerWidth(),
|
|
Packit Service |
50c9f2 |
tipHeight = tipElement.outerHeight(),
|
|
Packit Service |
50c9f2 |
coords = new CSSCoordinates(),
|
|
Packit Service |
50c9f2 |
collisions,
|
|
Packit Service |
50c9f2 |
collisionCount;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// grab collisions
|
|
Packit Service |
50c9f2 |
coords.set('top', session.currentY + options.offset);
|
|
Packit Service |
50c9f2 |
coords.set('left', session.currentX + options.offset);
|
|
Packit Service |
50c9f2 |
collisions = getViewportCollisions(
|
|
Packit Service |
50c9f2 |
coords,
|
|
Packit Service |
50c9f2 |
tipWidth,
|
|
Packit Service |
50c9f2 |
tipHeight
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// handle tooltip view port collisions
|
|
Packit Service |
50c9f2 |
if (collisions !== Collision.none) {
|
|
Packit Service |
50c9f2 |
collisionCount = countFlags(collisions);
|
|
Packit Service |
50c9f2 |
if (collisionCount === 1) {
|
|
Packit Service |
50c9f2 |
// if there is only one collision (bottom or right) then
|
|
Packit Service |
50c9f2 |
// simply constrain the tooltip to the view port
|
|
Packit Service |
50c9f2 |
if (collisions === Collision.right) {
|
|
Packit Service |
50c9f2 |
coords.set('left', session.windowWidth - tipWidth);
|
|
Packit Service |
50c9f2 |
} else if (collisions === Collision.bottom) {
|
|
Packit Service |
50c9f2 |
coords.set('top', session.scrollTop + session.windowHeight - tipHeight);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
// if the tooltip has more than one collision then it is
|
|
Packit Service |
50c9f2 |
// trapped in the corner and should be flipped to get it out
|
|
Packit Service |
50c9f2 |
// of the users way
|
|
Packit Service |
50c9f2 |
coords.set('left', session.currentX - tipWidth - options.offset);
|
|
Packit Service |
50c9f2 |
coords.set('top', session.currentY - tipHeight - options.offset);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// position the tooltip
|
|
Packit Service |
50c9f2 |
tipElement.css(coords);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Sets the tooltip to the correct position relative to the specified target
|
|
Packit Service |
50c9f2 |
* element. Based on options settings.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function positionTipOnElement(element) {
|
|
Packit Service |
50c9f2 |
var priorityList,
|
|
Packit Service |
50c9f2 |
finalPlacement;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
if (options.smartPlacement) {
|
|
Packit Service |
50c9f2 |
priorityList = $.fn.powerTip.smartPlacementLists[options.placement];
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// iterate over the priority list and use the first placement option
|
|
Packit Service |
50c9f2 |
// that does not collide with the view port. if they all collide
|
|
Packit Service |
50c9f2 |
// then the last placement in the list will be used.
|
|
Packit Service |
50c9f2 |
$.each(priorityList, function(idx, pos) {
|
|
Packit Service |
50c9f2 |
// place tooltip and find collisions
|
|
Packit Service |
50c9f2 |
var collisions = getViewportCollisions(
|
|
Packit Service |
50c9f2 |
placeTooltip(element, pos),
|
|
Packit Service |
50c9f2 |
tipElement.outerWidth(),
|
|
Packit Service |
50c9f2 |
tipElement.outerHeight()
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// update the final placement variable
|
|
Packit Service |
50c9f2 |
finalPlacement = pos;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// break if there were no collisions
|
|
Packit Service |
50c9f2 |
if (collisions === Collision.none) {
|
|
Packit Service |
50c9f2 |
return false;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
// if we're not going to use the smart placement feature then just
|
|
Packit Service |
50c9f2 |
// compute the coordinates and do it
|
|
Packit Service |
50c9f2 |
placeTooltip(element, options.placement);
|
|
Packit Service |
50c9f2 |
finalPlacement = options.placement;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// add placement as class for CSS arrows
|
|
Packit Service |
50c9f2 |
tipElement.addClass(finalPlacement);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Sets the tooltip position to the appropriate values to show the tip at
|
|
Packit Service |
50c9f2 |
* the specified placement. This function will iterate and test the tooltip
|
|
Packit Service |
50c9f2 |
* to support elastic tooltips.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element that the tooltip should target.
|
|
Packit Service |
50c9f2 |
* @param {string} placement The placement for the tooltip.
|
|
Packit Service |
50c9f2 |
* @return {CSSCoordinates} A CSSCoordinates object with the top, left, and
|
|
Packit Service |
50c9f2 |
* right position values.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function placeTooltip(element, placement) {
|
|
Packit Service |
50c9f2 |
var iterationCount = 0,
|
|
Packit Service |
50c9f2 |
tipWidth,
|
|
Packit Service |
50c9f2 |
tipHeight,
|
|
Packit Service |
50c9f2 |
coords = new CSSCoordinates();
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// set the tip to 0,0 to get the full expanded width
|
|
Packit Service |
50c9f2 |
coords.set('top', 0);
|
|
Packit Service |
50c9f2 |
coords.set('left', 0);
|
|
Packit Service |
50c9f2 |
tipElement.css(coords);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// to support elastic tooltips we need to check for a change in the
|
|
Packit Service |
50c9f2 |
// rendered dimensions after the tooltip has been positioned
|
|
Packit Service |
50c9f2 |
do {
|
|
Packit Service |
50c9f2 |
// grab the current tip dimensions
|
|
Packit Service |
50c9f2 |
tipWidth = tipElement.outerWidth();
|
|
Packit Service |
50c9f2 |
tipHeight = tipElement.outerHeight();
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// get placement coordinates
|
|
Packit Service |
50c9f2 |
coords = placementCalculator.compute(
|
|
Packit Service |
50c9f2 |
element,
|
|
Packit Service |
50c9f2 |
placement,
|
|
Packit Service |
50c9f2 |
tipWidth,
|
|
Packit Service |
50c9f2 |
tipHeight,
|
|
Packit Service |
50c9f2 |
options.offset
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// place the tooltip
|
|
Packit Service |
50c9f2 |
tipElement.css(coords);
|
|
Packit Service |
50c9f2 |
} while (
|
|
Packit Service |
50c9f2 |
// sanity check: limit to 5 iterations, and...
|
|
Packit Service |
50c9f2 |
++iterationCount <= 5 &&
|
|
Packit Service |
50c9f2 |
// try again if the dimensions changed after placement
|
|
Packit Service |
50c9f2 |
(tipWidth !== tipElement.outerWidth() || tipHeight !== tipElement.outerHeight())
|
|
Packit Service |
50c9f2 |
);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return coords;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Checks for a tooltip desync and closes the tooltip if one occurs.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function closeDesyncedTip() {
|
|
Packit Service |
50c9f2 |
var isDesynced = false;
|
|
Packit Service |
50c9f2 |
// It is possible for the mouse cursor to leave an element without
|
|
Packit Service |
50c9f2 |
// firing the mouseleave or blur event. This most commonly happens when
|
|
Packit Service |
50c9f2 |
// the element is disabled under mouse cursor. If this happens it will
|
|
Packit Service |
50c9f2 |
// result in a desynced tooltip because the tooltip was never asked to
|
|
Packit Service |
50c9f2 |
// close. So we should periodically check for a desync situation and
|
|
Packit Service |
50c9f2 |
// close the tip if such a situation arises.
|
|
Packit Service |
50c9f2 |
if (session.isTipOpen && !session.isClosing && !session.delayInProgress) {
|
|
Packit Service |
50c9f2 |
// user moused onto another tip or active hover is disabled
|
|
Packit Service |
50c9f2 |
if (session.activeHover.data(DATA_HASACTIVEHOVER) === false || session.activeHover.is(':disabled')) {
|
|
Packit Service |
50c9f2 |
isDesynced = true;
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
// hanging tip - have to test if mouse position is not over the
|
|
Packit Service |
50c9f2 |
// active hover and not over a tooltip set to let the user
|
|
Packit Service |
50c9f2 |
// interact with it.
|
|
Packit Service |
50c9f2 |
// for keyboard navigation: this only counts if the element does
|
|
Packit Service |
50c9f2 |
// not have focus.
|
|
Packit Service |
50c9f2 |
// for tooltips opened via the api: we need to check if it has
|
|
Packit Service |
50c9f2 |
// the forcedOpen flag.
|
|
Packit Service |
50c9f2 |
if (!isMouseOver(session.activeHover) && !session.activeHover.is(':focus') && !session.activeHover.data(DATA_FORCEDOPEN)) {
|
|
Packit Service |
50c9f2 |
if (tipElement.data(DATA_MOUSEONTOTIP)) {
|
|
Packit Service |
50c9f2 |
if (!isMouseOver(tipElement)) {
|
|
Packit Service |
50c9f2 |
isDesynced = true;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
} else {
|
|
Packit Service |
50c9f2 |
isDesynced = true;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
if (isDesynced) {
|
|
Packit Service |
50c9f2 |
// close the desynced tip
|
|
Packit Service |
50c9f2 |
hideTip(session.activeHover);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// expose methods
|
|
Packit Service |
50c9f2 |
this.showTip = beginShowTip;
|
|
Packit Service |
50c9f2 |
this.hideTip = hideTip;
|
|
Packit Service |
50c9f2 |
this.resetPosition = positionTipOnElement;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Determine whether a jQuery object is an SVG element
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element to check
|
|
Packit Service |
50c9f2 |
* @return {boolean} Whether this is an SVG element
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function isSvgElement(element) {
|
|
Packit Service |
50c9f2 |
return window.SVGElement && element[0] instanceof SVGElement;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Initializes the viewport dimension cache and hooks up the mouse position
|
|
Packit Service |
50c9f2 |
* tracking and viewport dimension tracking events.
|
|
Packit Service |
50c9f2 |
* Prevents attaching the events more than once.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function initTracking() {
|
|
Packit Service |
50c9f2 |
if (!session.mouseTrackingActive) {
|
|
Packit Service |
50c9f2 |
session.mouseTrackingActive = true;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// grab the current viewport dimensions on load
|
|
Packit Service |
50c9f2 |
$(function getViewportDimensions() {
|
|
Packit Service |
50c9f2 |
session.scrollLeft = $window.scrollLeft();
|
|
Packit Service |
50c9f2 |
session.scrollTop = $window.scrollTop();
|
|
Packit Service |
50c9f2 |
session.windowWidth = $window.width();
|
|
Packit Service |
50c9f2 |
session.windowHeight = $window.height();
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// hook mouse move tracking
|
|
Packit Service |
50c9f2 |
$document.on('mousemove', trackMouse);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
// hook viewport dimensions tracking
|
|
Packit Service |
50c9f2 |
$window.on({
|
|
Packit Service |
50c9f2 |
resize: function trackResize() {
|
|
Packit Service |
50c9f2 |
session.windowWidth = $window.width();
|
|
Packit Service |
50c9f2 |
session.windowHeight = $window.height();
|
|
Packit Service |
50c9f2 |
},
|
|
Packit Service |
50c9f2 |
scroll: function trackScroll() {
|
|
Packit Service |
50c9f2 |
var x = $window.scrollLeft(),
|
|
Packit Service |
50c9f2 |
y = $window.scrollTop();
|
|
Packit Service |
50c9f2 |
if (x !== session.scrollLeft) {
|
|
Packit Service |
50c9f2 |
session.currentX += x - session.scrollLeft;
|
|
Packit Service |
50c9f2 |
session.scrollLeft = x;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
if (y !== session.scrollTop) {
|
|
Packit Service |
50c9f2 |
session.currentY += y - session.scrollTop;
|
|
Packit Service |
50c9f2 |
session.scrollTop = y;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
});
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Saves the current mouse coordinates to the session object.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery.Event} event The mousemove event for the document.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function trackMouse(event) {
|
|
Packit Service |
50c9f2 |
session.currentX = event.pageX;
|
|
Packit Service |
50c9f2 |
session.currentY = event.pageY;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Tests if the mouse is currently over the specified element.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element to check for hover.
|
|
Packit Service |
50c9f2 |
* @return {boolean}
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function isMouseOver(element) {
|
|
Packit Service |
50c9f2 |
// use getBoundingClientRect() because jQuery's width() and height()
|
|
Packit Service |
50c9f2 |
// methods do not work with SVG elements
|
|
Packit Service |
50c9f2 |
// compute width/height because those properties do not exist on the object
|
|
Packit Service |
50c9f2 |
// returned by getBoundingClientRect() in older versions of IE
|
|
Packit Service |
50c9f2 |
var elementPosition = element.offset(),
|
|
Packit Service |
50c9f2 |
elementBox = element[0].getBoundingClientRect(),
|
|
Packit Service |
50c9f2 |
elementWidth = elementBox.right - elementBox.left,
|
|
Packit Service |
50c9f2 |
elementHeight = elementBox.bottom - elementBox.top;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return session.currentX >= elementPosition.left &&
|
|
Packit Service |
50c9f2 |
session.currentX <= elementPosition.left + elementWidth &&
|
|
Packit Service |
50c9f2 |
session.currentY >= elementPosition.top &&
|
|
Packit Service |
50c9f2 |
session.currentY <= elementPosition.top + elementHeight;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Fetches the tooltip content from the specified element's data attributes.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {jQuery} element The element to get the tooltip content for.
|
|
Packit Service |
50c9f2 |
* @return {(string|jQuery|undefined)} The text/HTML string, jQuery object, or
|
|
Packit Service |
50c9f2 |
* undefined if there was no tooltip content for the element.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function getTooltipContent(element) {
|
|
Packit Service |
50c9f2 |
var tipText = element.data(DATA_POWERTIP),
|
|
Packit Service |
50c9f2 |
tipObject = element.data(DATA_POWERTIPJQ),
|
|
Packit Service |
50c9f2 |
tipTarget = element.data(DATA_POWERTIPTARGET),
|
|
Packit Service |
50c9f2 |
targetElement,
|
|
Packit Service |
50c9f2 |
content;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
if (tipText) {
|
|
Packit Service |
50c9f2 |
if ($.isFunction(tipText)) {
|
|
Packit Service |
50c9f2 |
tipText = tipText.call(element[0]);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
content = tipText;
|
|
Packit Service |
50c9f2 |
} else if (tipObject) {
|
|
Packit Service |
50c9f2 |
if ($.isFunction(tipObject)) {
|
|
Packit Service |
50c9f2 |
tipObject = tipObject.call(element[0]);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
if (tipObject.length > 0) {
|
|
Packit Service |
50c9f2 |
content = tipObject.clone(true, true);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
} else if (tipTarget) {
|
|
Packit Service |
50c9f2 |
targetElement = $('#' + tipTarget);
|
|
Packit Service |
50c9f2 |
if (targetElement.length > 0) {
|
|
Packit Service |
50c9f2 |
content = targetElement.html();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return content;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Finds any viewport collisions that an element (the tooltip) would have if it
|
|
Packit Service |
50c9f2 |
* were absolutely positioned at the specified coordinates.
|
|
Packit Service |
50c9f2 |
* @private
|
|
Packit Service |
50c9f2 |
* @param {CSSCoordinates} coords Coordinates for the element.
|
|
Packit Service |
50c9f2 |
* @param {number} elementWidth Width of the element in pixels.
|
|
Packit Service |
50c9f2 |
* @param {number} elementHeight Height of the element in pixels.
|
|
Packit Service |
50c9f2 |
* @return {number} Value with the collision flags.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function getViewportCollisions(coords, elementWidth, elementHeight) {
|
|
Packit Service |
50c9f2 |
var viewportTop = session.scrollTop,
|
|
Packit Service |
50c9f2 |
viewportLeft = session.scrollLeft,
|
|
Packit Service |
50c9f2 |
viewportBottom = viewportTop + session.windowHeight,
|
|
Packit Service |
50c9f2 |
viewportRight = viewportLeft + session.windowWidth,
|
|
Packit Service |
50c9f2 |
collisions = Collision.none;
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
if (coords.top < viewportTop || Math.abs(coords.bottom - session.windowHeight) - elementHeight < viewportTop) {
|
|
Packit Service |
50c9f2 |
collisions |= Collision.top;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
if (coords.top + elementHeight > viewportBottom || Math.abs(coords.bottom - session.windowHeight) > viewportBottom) {
|
|
Packit Service |
50c9f2 |
collisions |= Collision.bottom;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
if (coords.left < viewportLeft || coords.right + elementWidth > viewportRight) {
|
|
Packit Service |
50c9f2 |
collisions |= Collision.left;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
if (coords.left + elementWidth > viewportRight || coords.right < viewportLeft) {
|
|
Packit Service |
50c9f2 |
collisions |= Collision.right;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
return collisions;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
/**
|
|
Packit Service |
50c9f2 |
* Counts the number of bits set on a flags value.
|
|
Packit Service |
50c9f2 |
* @param {number} value The flags value.
|
|
Packit Service |
50c9f2 |
* @return {number} The number of bits that have been set.
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
function countFlags(value) {
|
|
Packit Service |
50c9f2 |
var count = 0;
|
|
Packit Service |
50c9f2 |
while (value) {
|
|
Packit Service |
50c9f2 |
value &= value - 1;
|
|
Packit Service |
50c9f2 |
count++;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
return count;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
}));
|