jquery.qtip.js 100 KB

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