jquery.qtip.js 95 KB

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