jquery.qtip.js 99 KB

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