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