/web/modules/bugs/includes/javascript/jQuery/jQuery.bt.js

https://github.com/eBiz/BMNet · JavaScript · 1227 lines · 742 code · 145 blank · 340 comment · 176 complexity · 0931d86b38b1d782e1334729a4e654bd MD5 · raw file

  1. /*
  2. * @name BeautyTips
  3. * @desc a tooltips/baloon-help plugin for jQuery
  4. *
  5. * @author Jeff Robbins - Lullabot - http://www.lullabot.com
  6. * @version 0.9.5 release candidate 1 (5/20/2009)
  7. */
  8. jQuery.bt = {version: '0.9.5-rc1'};
  9. /*
  10. * @type jQuery
  11. * @cat Plugins/bt
  12. * @requires jQuery v1.2+ (not tested on versions prior to 1.2.6)
  13. *
  14. * Dual licensed under the MIT and GPL licenses:
  15. * http://www.opensource.org/licenses/mit-license.php
  16. * http://www.gnu.org/licenses/gpl.html
  17. *
  18. * Encourage development. If you use BeautyTips for anything cool
  19. * or on a site that people have heard of, please drop me a note.
  20. * - jeff ^at lullabot > com
  21. *
  22. * No guarantees, warranties, or promises of any kind
  23. *
  24. */
  25. ;(function($) {
  26. /**
  27. * @credit Inspired by Karl Swedberg's ClueTip
  28. * (http://plugins.learningjquery.com/cluetip/), which in turn was inspired
  29. * by Cody Lindley's jTip (http://www.codylindley.com)
  30. *
  31. * @fileoverview
  32. * Beauty Tips is a jQuery tooltips plugin which uses the canvas drawing element
  33. * in the HTML5 spec in order to dynamically draw tooltip "talk bubbles" around
  34. * the descriptive help text associated with an item. This is in many ways
  35. * similar to Google Maps which both provides similar talk-bubbles and uses the
  36. * canvas element to draw them.
  37. *
  38. * The canvas element is supported in modern versions of FireFox, Safari, and
  39. * Opera. However, Internet Explorer needs a separate library called ExplorerCanvas
  40. * included on the page in order to support canvas drawing functions. ExplorerCanvas
  41. * was created by Google for use with their web apps and you can find it here:
  42. * http://excanvas.sourceforge.net/
  43. *
  44. * Beauty Tips was written to be simple to use and pretty. All of its options
  45. * are documented at the bottom of this file and defaults can be overwritten
  46. * globally for the entire page, or individually on each call.
  47. *
  48. * By default each tooltip will be positioned on the side of the target element
  49. * which has the most free space. This is affected by the scroll position and
  50. * size of the current window, so each Beauty Tip is redrawn each time it is
  51. * displayed. It may appear above an element at the bottom of the page, but when
  52. * the page is scrolled down (and the element is at the top of the page) it will
  53. * then appear below it. Additionally, positions can be forced or a preferred
  54. * order can be defined. See examples below.
  55. *
  56. * To fix z-index problems in IE6, include the bgiframe plugin on your page
  57. * http://plugins.jquery.com/project/bgiframe - BeautyTips will automatically
  58. * recognize it and use it.
  59. *
  60. * BeautyTips also works with the hoverIntent plugin
  61. * http://cherne.net/brian/resources/jquery.hoverIntent.html
  62. * see hoverIntent example below for usage
  63. *
  64. * Usage
  65. * The function can be called in a number of ways.
  66. * $(selector).bt();
  67. * $(selector).bt('Content text');
  68. * $(selector).bt('Content text', {option1: value, option2: value});
  69. * $(selector).bt({option1: value, option2: value});
  70. *
  71. * For more/better documentation and lots of examples, visit the demo page included with the distribution
  72. *
  73. */
  74. jQuery.fn.bt = function(content, options) {
  75. if (typeof content != 'string') {
  76. var contentSelect = true;
  77. options = content;
  78. content = false;
  79. }
  80. else {
  81. var contentSelect = false;
  82. }
  83. // if hoverIntent is installed, use that as default instead of hover
  84. if (jQuery.fn.hoverIntent && jQuery.bt.defaults.trigger == 'hover') {
  85. jQuery.bt.defaults.trigger = 'hoverIntent';
  86. }
  87. return this.each(function(index) {
  88. var opts = jQuery.extend(false, jQuery.bt.defaults, jQuery.bt.options, options);
  89. // clean up the options
  90. opts.spikeLength = numb(opts.spikeLength);
  91. opts.spikeGirth = numb(opts.spikeGirth);
  92. opts.overlap = numb(opts.overlap);
  93. var ajaxTimeout = false;
  94. /**
  95. * This is sort of the "starting spot" for the this.each()
  96. * These are the init functions to handle the .bt() call
  97. */
  98. if (opts.killTitle) {
  99. $(this).find('[title]').andSelf().each(function() {
  100. if (!$(this).attr('bt-xTitle')) {
  101. $(this).attr('bt-xTitle', $(this).attr('title')).attr('title', '');
  102. }
  103. });
  104. }
  105. if (typeof opts.trigger == 'string') {
  106. opts.trigger = [opts.trigger];
  107. }
  108. if (opts.trigger[0] == 'hoverIntent') {
  109. var hoverOpts = jQuery.extend(opts.hoverIntentOpts, {
  110. over: function() {
  111. this.btOn();
  112. },
  113. out: function() {
  114. this.btOff();
  115. }});
  116. $(this).hoverIntent(hoverOpts);
  117. }
  118. else if (opts.trigger[0] == 'hover') {
  119. $(this).hover(
  120. function() {
  121. this.btOn();
  122. },
  123. function() {
  124. this.btOff();
  125. }
  126. );
  127. }
  128. else if (opts.trigger[0] == 'now') {
  129. // toggle the on/off right now
  130. // note that 'none' gives more control (see below)
  131. if ($(this).hasClass('bt-active')) {
  132. this.btOff();
  133. }
  134. else {
  135. this.btOn();
  136. }
  137. }
  138. else if (opts.trigger[0] == 'none') {
  139. // initialize the tip with no event trigger
  140. // use javascript to turn on/off tip as follows:
  141. // $('#selector').btOn();
  142. // $('#selector').btOff();
  143. }
  144. else if (opts.trigger.length > 1 && opts.trigger[0] != opts.trigger[1]) {
  145. $(this)
  146. .bind(opts.trigger[0], function() {
  147. this.btOn();
  148. })
  149. .bind(opts.trigger[1], function() {
  150. this.btOff();
  151. });
  152. }
  153. else {
  154. // toggle using the same event
  155. $(this).bind(opts.trigger[0], function() {
  156. if ($(this).hasClass('bt-active')) {
  157. this.btOff();
  158. }
  159. else {
  160. this.btOn();
  161. }
  162. });
  163. }
  164. /**
  165. * The BIG TURN ON
  166. * Any element that has been initiated
  167. */
  168. this.btOn = function () {
  169. if (typeof $(this).data('bt-box') == 'object') {
  170. // if there's already a popup, remove it before creating a new one.
  171. this.btOff();
  172. }
  173. // trigger preBuild function
  174. // preBuild has no argument since the box hasn't been built yet
  175. opts.preBuild.apply(this);
  176. // turn off other tips
  177. $(jQuery.bt.vars.closeWhenOpenStack).btOff();
  178. // add the class to the target element (for hilighting, for example)
  179. // bt-active is always applied to all, but activeClass can apply another
  180. $(this).addClass('bt-active ' + opts.activeClass);
  181. if (contentSelect && opts.ajaxPath == null) {
  182. // bizarre, I know
  183. if (opts.killTitle) {
  184. // if we've killed the title attribute, it's been stored in 'bt-xTitle' so get it..
  185. $(this).attr('title', $(this).attr('bt-xTitle'));
  186. }
  187. // then evaluate the selector... title is now in place
  188. content = $.isFunction(opts.contentSelector) ? opts.contentSelector.apply(this) : eval(opts.contentSelector);
  189. if (opts.killTitle) {
  190. // now remove the title again, so we don't get double tips
  191. $(this).attr('title', '');
  192. }
  193. }
  194. // ----------------------------------------------
  195. // All the Ajax(ish) stuff is in this next bit...
  196. // ----------------------------------------------
  197. if (opts.ajaxPath != null && content == false) {
  198. if (typeof opts.ajaxPath == 'object') {
  199. var url = eval(opts.ajaxPath[0]);
  200. url += opts.ajaxPath[1] ? ' ' + opts.ajaxPath[1] : '';
  201. }
  202. else {
  203. var url = opts.ajaxPath;
  204. }
  205. var off = url.indexOf(" ");
  206. if ( off >= 0 ) {
  207. var selector = url.slice(off, url.length);
  208. url = url.slice(0, off);
  209. }
  210. // load any data cached for the given ajax path
  211. var cacheData = opts.ajaxCache ? $(document.body).data('btCache-' + url.replace(/\./g, '')) : null;
  212. if (typeof cacheData == 'string') {
  213. content = selector ? $("<div/>").append(cacheData.replace(/<script(.|\s)*?\/script>/g, "")).find(selector) : cacheData;
  214. }
  215. else {
  216. var target = this;
  217. // set up the options
  218. var ajaxOpts = jQuery.extend(false,
  219. {
  220. type: opts.ajaxType,
  221. data: opts.ajaxData,
  222. cache: opts.ajaxCache,
  223. url: url,
  224. complete: function(XMLHttpRequest, textStatus) {
  225. if (textStatus == 'success' || textStatus == 'notmodified') {
  226. if (opts.ajaxCache) {
  227. $(document.body).data('btCache-' + url.replace(/\./g, ''), XMLHttpRequest.responseText);
  228. }
  229. ajaxTimeout = false;
  230. content = selector ?
  231. // Create a dummy div to hold the results
  232. $("<div/>")
  233. // inject the contents of the document in, removing the scripts
  234. // to avoid any 'Permission Denied' errors in IE
  235. .append(XMLHttpRequest.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
  236. // Locate the specified elements
  237. .find(selector) :
  238. // If not, just inject the full result
  239. XMLHttpRequest.responseText;
  240. }
  241. else {
  242. if (textStatus == 'timeout') {
  243. // if there was a timeout, we don't cache the result
  244. ajaxTimeout = true;
  245. }
  246. content = opts.ajaxError.replace(/%error/g, XMLHttpRequest.statusText);
  247. }
  248. // if the user rolls out of the target element before the ajax request comes back, don't show it
  249. if ($(target).hasClass('bt-active')) {
  250. target.btOn();
  251. }
  252. }
  253. }, opts.ajaxOpts);
  254. // do the ajax request
  255. jQuery.ajax(ajaxOpts);
  256. // load the throbber while the magic happens
  257. content = opts.ajaxLoading;
  258. }
  259. }
  260. // </ ajax stuff >
  261. // now we start actually figuring out where to place the tip
  262. // figure out how to compensate for the shadow, if present
  263. var shadowMarginX = 0; // extra added to width to compensate for shadow
  264. var shadowMarginY = 0; // extra added to height
  265. var shadowShiftX = 0; // amount to shift the tip horizontally to allow for shadow
  266. var shadowShiftY = 0; // amount to shift vertical
  267. if (opts.shadow && !shadowSupport()) {
  268. // if browser doesn't support drop shadows, turn them off
  269. opts.shadow = false;
  270. // and bring in the noShadows options
  271. jQuery.extend(opts, opts.noShadowOpts);
  272. }
  273. if (opts.shadow) {
  274. // figure out horizontal placement
  275. if (opts.shadowBlur > Math.abs(opts.shadowOffsetX)) {
  276. shadowMarginX = opts.shadowBlur * 2;
  277. }
  278. else {
  279. shadowMarginX = opts.shadowBlur + Math.abs(opts.shadowOffsetX);
  280. }
  281. shadowShiftX = (opts.shadowBlur - opts.shadowOffsetX) > 0 ? opts.shadowBlur - opts.shadowOffsetX : 0;
  282. // now vertical
  283. if (opts.shadowBlur > Math.abs(opts.shadowOffsetY)) {
  284. shadowMarginY = opts.shadowBlur * 2;
  285. }
  286. else {
  287. shadowMarginY = opts.shadowBlur + Math.abs(opts.shadowOffsetY);
  288. }
  289. shadowShiftY = (opts.shadowBlur - opts.shadowOffsetY) > 0 ? opts.shadowBlur - opts.shadowOffsetY : 0;
  290. }
  291. if (opts.offsetParent){
  292. // if offsetParent is defined by user
  293. var offsetParent = $(opts.offsetParent);
  294. var offsetParentPos = offsetParent.offset();
  295. var pos = $(this).offset();
  296. var top = numb(pos.top) - numb(offsetParentPos.top) + numb($(this).css('margin-top')) - shadowShiftY; // IE can return 'auto' for margins
  297. var left = numb(pos.left) - numb(offsetParentPos.left) + numb($(this).css('margin-left')) - shadowShiftX;
  298. }
  299. else {
  300. // if the target element is absolutely positioned, use its parent's offsetParent instead of its own
  301. var offsetParent = ($(this).css('position') == 'absolute') ? $(this).parents().eq(0).offsetParent() : $(this).offsetParent();
  302. var pos = $(this).btPosition();
  303. var top = numb(pos.top) + numb($(this).css('margin-top')) - shadowShiftY; // IE can return 'auto' for margins
  304. var left = numb(pos.left) + numb($(this).css('margin-left')) - shadowShiftX;
  305. }
  306. var width = $(this).btOuterWidth();
  307. var height = $(this).outerHeight();
  308. if (typeof content == 'object') {
  309. // if content is a DOM object (as opposed to text)
  310. // use a clone, rather than removing the original element
  311. // and ensure that it's visible
  312. var original = content;
  313. var clone = $(original).clone(true).show();
  314. // also store a reference to the original object in the clone data
  315. // and a reference to the clone in the original
  316. var origClones = $(original).data('bt-clones') || [];
  317. origClones.push(clone);
  318. $(original).data('bt-clones', origClones);
  319. $(clone).data('bt-orig', original);
  320. $(this).data('bt-content-orig', {original: original, clone: clone});
  321. content = clone;
  322. }
  323. if (typeof content == 'null' || content == '') {
  324. // if content is empty, bail out...
  325. return;
  326. }
  327. // create the tip content div, populate it, and style it
  328. var $text = $('<div class="bt-content"></div>').append(content).css({padding: opts.padding, position: 'absolute', width: (opts.shrinkToFit ? 'auto' : opts.width), zIndex: opts.textzIndex, left: shadowShiftX, top: shadowShiftY}).css(opts.cssStyles);
  329. // create the wrapping box which contains text and canvas
  330. // put the content in it, style it, and append it to the same offset parent as the target
  331. var $box = $('<div class="bt-wrapper"></div>').append($text).addClass(opts.cssClass).css({position: 'absolute', width: opts.width, zIndex: opts.wrapperzIndex, visibility:'hidden'}).appendTo(offsetParent);
  332. // use bgiframe to get around z-index problems in IE6
  333. // http://plugins.jquery.com/project/bgiframe
  334. if (jQuery.fn.bgiframe) {
  335. $text.bgiframe();
  336. $box.bgiframe();
  337. }
  338. $(this).data('bt-box', $box);
  339. // see if the text box will fit in the various positions
  340. var scrollTop = numb($(document).scrollTop());
  341. var scrollLeft = numb($(document).scrollLeft());
  342. var docWidth = numb($(window).width());
  343. var docHeight = numb($(window).height());
  344. var winRight = scrollLeft + docWidth;
  345. var winBottom = scrollTop + docHeight;
  346. var space = new Object();
  347. var thisOffset = $(this).offset();
  348. space.top = thisOffset.top - scrollTop;
  349. space.bottom = docHeight - ((thisOffset + height) - scrollTop);
  350. space.left = thisOffset.left - scrollLeft;
  351. space.right = docWidth - ((thisOffset.left + width) - scrollLeft);
  352. var textOutHeight = numb($text.outerHeight());
  353. var textOutWidth = numb($text.btOuterWidth());
  354. if (opts.positions.constructor == String) {
  355. opts.positions = opts.positions.replace(/ /, '').split(',');
  356. }
  357. if (opts.positions[0] == 'most') {
  358. // figure out which is the largest
  359. var position = 'top'; // prime the pump
  360. for (var pig in space) { // <------- pigs in space!
  361. position = space[pig] > space[position] ? pig : position;
  362. }
  363. }
  364. else {
  365. for (var x in opts.positions) {
  366. var position = opts.positions[x];
  367. // @todo: acommodate shadow space in the following lines...
  368. if ((position == 'left' || position == 'right') && space[position] > textOutWidth + opts.spikeLength) {
  369. break;
  370. }
  371. else if ((position == 'top' || position == 'bottom') && space[position] > textOutHeight + opts.spikeLength) {
  372. break;
  373. }
  374. }
  375. }
  376. // horizontal (left) offset for the box
  377. var horiz = left + ((width - textOutWidth) * .5);
  378. // vertical (top) offset for the box
  379. var vert = top + ((height - textOutHeight) * .5);
  380. var points = new Array();
  381. var textTop, textLeft, textRight, textBottom, textTopSpace, textBottomSpace, textLeftSpace, textRightSpace, crossPoint, textCenter, spikePoint;
  382. // Yes, yes, this next bit really could use to be condensed
  383. // each switch case is basically doing the same thing in slightly different ways
  384. switch(position) {
  385. // =================== TOP =======================
  386. case 'top':
  387. // spike on bottom
  388. $text.css('margin-bottom', opts.spikeLength + 'px');
  389. $box.css({top: (top - $text.outerHeight(true)) + opts.overlap, left: horiz});
  390. // move text left/right if extends out of window
  391. textRightSpace = (winRight - opts.windowMargin) - ($text.offset().left + $text.btOuterWidth(true));
  392. var xShift = shadowShiftX;
  393. if (textRightSpace < 0) {
  394. // shift it left
  395. $box.css('left', (numb($box.css('left')) + textRightSpace) + 'px');
  396. xShift -= textRightSpace;
  397. }
  398. // we test left space second to ensure that left of box is visible
  399. textLeftSpace = ($text.offset().left + numb($text.css('margin-left'))) - (scrollLeft + opts.windowMargin);
  400. if (textLeftSpace < 0) {
  401. // shift it right
  402. $box.css('left', (numb($box.css('left')) - textLeftSpace) + 'px');
  403. xShift += textLeftSpace;
  404. }
  405. textTop = $text.btPosition().top + numb($text.css('margin-top'));
  406. textLeft = $text.btPosition().left + numb($text.css('margin-left'));
  407. textRight = textLeft + $text.btOuterWidth();
  408. textBottom = textTop + $text.outerHeight();
  409. textCenter = {x: textLeft + ($text.btOuterWidth()*opts.centerPointX), y: textTop + ($text.outerHeight()*opts.centerPointY)};
  410. // points[points.length] = {x: x, y: y};
  411. points[points.length] = spikePoint = {y: textBottom + opts.spikeLength, x: ((textRight-textLeft) * .5) + xShift, type: 'spike'};
  412. crossPoint = findIntersectX(spikePoint.x, spikePoint.y, textCenter.x, textCenter.y, textBottom);
  413. // make sure that the crossPoint is not outside of text box boundaries
  414. crossPoint.x = crossPoint.x < textLeft + opts.spikeGirth/2 + opts.cornerRadius ? textLeft + opts.spikeGirth/2 + opts.cornerRadius : crossPoint.x;
  415. crossPoint.x = crossPoint.x > (textRight - opts.spikeGirth/2) - opts.cornerRadius ? (textRight - opts.spikeGirth/2) - opts.CornerRadius : crossPoint.x;
  416. points[points.length] = {x: crossPoint.x - (opts.spikeGirth/2), y: textBottom, type: 'join'};
  417. points[points.length] = {x: textLeft, y: textBottom, type: 'corner'}; // left bottom corner
  418. points[points.length] = {x: textLeft, y: textTop, type: 'corner'}; // left top corner
  419. points[points.length] = {x: textRight, y: textTop, type: 'corner'}; // right top corner
  420. points[points.length] = {x: textRight, y: textBottom, type: 'corner'}; // right bottom corner
  421. points[points.length] = {x: crossPoint.x + (opts.spikeGirth/2), y: textBottom, type: 'join'};
  422. points[points.length] = spikePoint;
  423. break;
  424. // =================== LEFT =======================
  425. case 'left':
  426. // spike on right
  427. $text.css('margin-right', opts.spikeLength + 'px');
  428. $box.css({top: vert + 'px', left: ((left - $text.btOuterWidth(true)) + opts.overlap) + 'px'});
  429. // move text up/down if extends out of window
  430. textBottomSpace = (winBottom - opts.windowMargin) - ($text.offset().top + $text.outerHeight(true));
  431. var yShift = shadowShiftY;
  432. if (textBottomSpace < 0) {
  433. // shift it up
  434. $box.css('top', (numb($box.css('top')) + textBottomSpace) + 'px');
  435. yShift -= textBottomSpace;
  436. }
  437. // we ensure top space second to ensure that top of box is visible
  438. textTopSpace = ($text.offset().top + numb($text.css('margin-top'))) - (scrollTop + opts.windowMargin);
  439. if (textTopSpace < 0) {
  440. // shift it down
  441. $box.css('top', (numb($box.css('top')) - textTopSpace) + 'px');
  442. yShift += textTopSpace;
  443. }
  444. textTop = $text.btPosition().top + numb($text.css('margin-top'));
  445. textLeft = $text.btPosition().left + numb($text.css('margin-left'));
  446. textRight = textLeft + $text.btOuterWidth();
  447. textBottom = textTop + $text.outerHeight();
  448. textCenter = {x: textLeft + ($text.btOuterWidth()*opts.centerPointX), y: textTop + ($text.outerHeight()*opts.centerPointY)};
  449. points[points.length] = spikePoint = {x: textRight + opts.spikeLength, y: ((textBottom-textTop) * .5) + yShift, type: 'spike'};
  450. crossPoint = findIntersectY(spikePoint.x, spikePoint.y, textCenter.x, textCenter.y, textRight);
  451. // make sure that the crossPoint is not outside of text box boundaries
  452. crossPoint.y = crossPoint.y < textTop + opts.spikeGirth/2 + opts.cornerRadius ? textTop + opts.spikeGirth/2 + opts.cornerRadius : crossPoint.y;
  453. crossPoint.y = crossPoint.y > (textBottom - opts.spikeGirth/2) - opts.cornerRadius ? (textBottom - opts.spikeGirth/2) - opts.cornerRadius : crossPoint.y;
  454. points[points.length] = {x: textRight, y: crossPoint.y + opts.spikeGirth/2, type: 'join'};
  455. points[points.length] = {x: textRight, y: textBottom, type: 'corner'}; // right bottom corner
  456. points[points.length] = {x: textLeft, y: textBottom, type: 'corner'}; // left bottom corner
  457. points[points.length] = {x: textLeft, y: textTop, type: 'corner'}; // left top corner
  458. points[points.length] = {x: textRight, y: textTop, type: 'corner'}; // right top corner
  459. points[points.length] = {x: textRight, y: crossPoint.y - opts.spikeGirth/2, type: 'join'};
  460. points[points.length] = spikePoint;
  461. break;
  462. // =================== BOTTOM =======================
  463. case 'bottom':
  464. // spike on top
  465. $text.css('margin-top', opts.spikeLength + 'px');
  466. $box.css({top: (top + height) - opts.overlap, left: horiz});
  467. // move text up/down if extends out of window
  468. textRightSpace = (winRight - opts.windowMargin) - ($text.offset().left + $text.btOuterWidth(true));
  469. var xShift = shadowShiftX;
  470. if (textRightSpace < 0) {
  471. // shift it left
  472. $box.css('left', (numb($box.css('left')) + textRightSpace) + 'px');
  473. xShift -= textRightSpace;
  474. }
  475. // we ensure left space second to ensure that left of box is visible
  476. textLeftSpace = ($text.offset().left + numb($text.css('margin-left'))) - (scrollLeft + opts.windowMargin);
  477. if (textLeftSpace < 0) {
  478. // shift it right
  479. $box.css('left', (numb($box.css('left')) - textLeftSpace) + 'px');
  480. xShift += textLeftSpace;
  481. }
  482. textTop = $text.btPosition().top + numb($text.css('margin-top'));
  483. textLeft = $text.btPosition().left + numb($text.css('margin-left'));
  484. textRight = textLeft + $text.btOuterWidth();
  485. textBottom = textTop + $text.outerHeight();
  486. textCenter = {x: textLeft + ($text.btOuterWidth()*opts.centerPointX), y: textTop + ($text.outerHeight()*opts.centerPointY)};
  487. points[points.length] = spikePoint = {x: ((textRight-textLeft) * .5) + xShift, y: shadowShiftY, type: 'spike'};
  488. crossPoint = findIntersectX(spikePoint.x, spikePoint.y, textCenter.x, textCenter.y, textTop);
  489. // make sure that the crossPoint is not outside of text box boundaries
  490. crossPoint.x = crossPoint.x < textLeft + opts.spikeGirth/2 + opts.cornerRadius ? textLeft + opts.spikeGirth/2 + opts.cornerRadius : crossPoint.x;
  491. crossPoint.x = crossPoint.x > (textRight - opts.spikeGirth/2) - opts.cornerRadius ? (textRight - opts.spikeGirth/2) - opts.cornerRadius : crossPoint.x;
  492. points[points.length] = {x: crossPoint.x + opts.spikeGirth/2, y: textTop, type: 'join'};
  493. points[points.length] = {x: textRight, y: textTop, type: 'corner'}; // right top corner
  494. points[points.length] = {x: textRight, y: textBottom, type: 'corner'}; // right bottom corner
  495. points[points.length] = {x: textLeft, y: textBottom, type: 'corner'}; // left bottom corner
  496. points[points.length] = {x: textLeft, y: textTop, type: 'corner'}; // left top corner
  497. points[points.length] = {x: crossPoint.x - (opts.spikeGirth/2), y: textTop, type: 'join'};
  498. points[points.length] = spikePoint;
  499. break;
  500. // =================== RIGHT =======================
  501. case 'right':
  502. // spike on left
  503. $text.css('margin-left', (opts.spikeLength + 'px'));
  504. $box.css({top: vert + 'px', left: ((left + width) - opts.overlap) + 'px'});
  505. // move text up/down if extends out of window
  506. textBottomSpace = (winBottom - opts.windowMargin) - ($text.offset().top + $text.outerHeight(true));
  507. var yShift = shadowShiftY;
  508. if (textBottomSpace < 0) {
  509. // shift it up
  510. $box.css('top', (numb($box.css('top')) + textBottomSpace) + 'px');
  511. yShift -= textBottomSpace;
  512. }
  513. // we ensure top space second to ensure that top of box is visible
  514. textTopSpace = ($text.offset().top + numb($text.css('margin-top'))) - (scrollTop + opts.windowMargin);
  515. if (textTopSpace < 0) {
  516. // shift it down
  517. $box.css('top', (numb($box.css('top')) - textTopSpace) + 'px');
  518. yShift += textTopSpace;
  519. }
  520. textTop = $text.btPosition().top + numb($text.css('margin-top'));
  521. textLeft = $text.btPosition().left + numb($text.css('margin-left'));
  522. textRight = textLeft + $text.btOuterWidth();
  523. textBottom = textTop + $text.outerHeight();
  524. textCenter = {x: textLeft + ($text.btOuterWidth()*opts.centerPointX), y: textTop + ($text.outerHeight()*opts.centerPointY)};
  525. points[points.length] = spikePoint = {x: shadowShiftX, y: ((textBottom-textTop) * .5) + yShift, type: 'spike'};
  526. crossPoint = findIntersectY(spikePoint.x, spikePoint.y, textCenter.x, textCenter.y, textLeft);
  527. // make sure that the crossPoint is not outside of text box boundaries
  528. crossPoint.y = crossPoint.y < textTop + opts.spikeGirth/2 + opts.cornerRadius ? textTop + opts.spikeGirth/2 + opts.cornerRadius : crossPoint.y;
  529. crossPoint.y = crossPoint.y > (textBottom - opts.spikeGirth/2) - opts.cornerRadius ? (textBottom - opts.spikeGirth/2) - opts.cornerRadius : crossPoint.y;
  530. points[points.length] = {x: textLeft, y: crossPoint.y - opts.spikeGirth/2, type: 'join'};
  531. points[points.length] = {x: textLeft, y: textTop, type: 'corner'}; // left top corner
  532. points[points.length] = {x: textRight, y: textTop, type: 'corner'}; // right top corner
  533. points[points.length] = {x: textRight, y: textBottom, type: 'corner'}; // right bottom corner
  534. points[points.length] = {x: textLeft, y: textBottom, type: 'corner'}; // left bottom corner
  535. points[points.length] = {x: textLeft, y: crossPoint.y + opts.spikeGirth/2, type: 'join'};
  536. points[points.length] = spikePoint;
  537. break;
  538. } // </ switch >
  539. var canvas = document.createElement('canvas');
  540. $(canvas).attr('width', (numb($text.btOuterWidth(true)) + opts.strokeWidth*2 + shadowMarginX)).attr('height', (numb($text.outerHeight(true)) + opts.strokeWidth*2 + shadowMarginY)).appendTo($box).css({position: 'absolute', zIndex: opts.boxzIndex});
  541. // if excanvas is set up, we need to initialize the new canvas element
  542. if (typeof G_vmlCanvasManager != 'undefined') {
  543. canvas = G_vmlCanvasManager.initElement(canvas);
  544. }
  545. if (opts.cornerRadius > 0) {
  546. // round the corners!
  547. var newPoints = new Array();
  548. var newPoint;
  549. for (var i=0; i<points.length; i++) {
  550. if (points[i].type == 'corner') {
  551. // create two new arc points
  552. // find point between this and previous (using modulo in case of ending)
  553. newPoint = betweenPoint(points[i], points[(i-1)%points.length], opts.cornerRadius);
  554. newPoint.type = 'arcStart';
  555. newPoints[newPoints.length] = newPoint;
  556. // the original corner point
  557. newPoints[newPoints.length] = points[i];
  558. // find point between this and next
  559. newPoint = betweenPoint(points[i], points[(i+1)%points.length], opts.cornerRadius);
  560. newPoint.type = 'arcEnd';
  561. newPoints[newPoints.length] = newPoint;
  562. }
  563. else {
  564. newPoints[newPoints.length] = points[i];
  565. }
  566. }
  567. // overwrite points with new version
  568. points = newPoints;
  569. }
  570. var ctx = canvas.getContext("2d");
  571. if (opts.shadow && opts.shadowOverlap !== true) {
  572. var shadowOverlap = numb(opts.shadowOverlap);
  573. // keep the shadow (and canvas) from overlapping the target element
  574. switch (position) {
  575. case 'top':
  576. if (opts.shadowOffsetX + opts.shadowBlur - shadowOverlap > 0) {
  577. $box.css('top', (numb($box.css('top')) - (opts.shadowOffsetX + opts.shadowBlur - shadowOverlap)));
  578. }
  579. break;
  580. case 'right':
  581. if (shadowShiftX - shadowOverlap > 0) {
  582. $box.css('left', (numb($box.css('left')) + shadowShiftX - shadowOverlap));
  583. }
  584. break;
  585. case 'bottom':
  586. if (shadowShiftY - shadowOverlap > 0) {
  587. $box.css('top', (numb($box.css('top')) + shadowShiftY - shadowOverlap));
  588. }
  589. break;
  590. case 'left':
  591. if (opts.shadowOffsetY + opts.shadowBlur - shadowOverlap > 0) {
  592. $box.css('left', (numb($box.css('left')) - (opts.shadowOffsetY + opts.shadowBlur - shadowOverlap)));
  593. }
  594. break;
  595. }
  596. }
  597. drawIt.apply(ctx, [points], opts.strokeWidth);
  598. ctx.fillStyle = opts.fill;
  599. if (opts.shadow) {
  600. ctx.shadowOffsetX = opts.shadowOffsetX;
  601. ctx.shadowOffsetY = opts.shadowOffsetY;
  602. ctx.shadowBlur = opts.shadowBlur;
  603. ctx.shadowColor = opts.shadowColor;
  604. }
  605. ctx.closePath();
  606. ctx.fill();
  607. if (opts.strokeWidth > 0) {
  608. ctx.shadowColor = 'rgba(0, 0, 0, 0)'; //remove shadow from stroke
  609. ctx.lineWidth = opts.strokeWidth;
  610. ctx.strokeStyle = opts.strokeStyle;
  611. ctx.beginPath();
  612. drawIt.apply(ctx, [points], opts.strokeWidth);
  613. ctx.closePath();
  614. ctx.stroke();
  615. }
  616. // trigger preShow function
  617. // function receives the box element (the balloon wrapper div) as an argument
  618. opts.preShow.apply(this, [$box[0]]);
  619. // switch from visibility: hidden to display: none so we can run animations
  620. $box.css({display:'none', visibility: 'visible'});
  621. // Here's where we show the tip
  622. opts.showTip.apply(this, [$box[0]]);
  623. if (opts.overlay) {
  624. // EXPERIMENTAL AND FOR TESTING ONLY!!!!
  625. var overlay = $('<div class="bt-overlay"></div>').css({
  626. position: 'absolute',
  627. backgroundColor: 'blue',
  628. top: top,
  629. left: left,
  630. width: width,
  631. height: height,
  632. opacity: '.2'
  633. }).appendTo(offsetParent);
  634. $(this).data('overlay', overlay);
  635. }
  636. if ((opts.ajaxPath != null && opts.ajaxCache == false) || ajaxTimeout) {
  637. // if ajaxCache is not enabled or if there was a server timeout,
  638. // remove the content variable so it will be loaded again from server
  639. content = false;
  640. }
  641. // stick this element into the clickAnywhereToClose stack
  642. if (opts.clickAnywhereToClose) {
  643. jQuery.bt.vars.clickAnywhereStack.push(this);
  644. $(document).click(jQuery.bt.docClick);
  645. }
  646. // stick this element into the closeWhenOthersOpen stack
  647. if (opts.closeWhenOthersOpen) {
  648. jQuery.bt.vars.closeWhenOpenStack.push(this);
  649. }
  650. // trigger postShow function
  651. // function receives the box element (the balloon wrapper div) as an argument
  652. opts.postShow.apply(this, [$box[0]]);
  653. }; // </ turnOn() >
  654. this.btOff = function() {
  655. var box = $(this).data('bt-box');
  656. // trigger preHide function
  657. // function receives the box element (the balloon wrapper div) as an argument
  658. opts.preHide.apply(this, [box]);
  659. var i = this;
  660. // set up the stuff to happen AFTER the tip is hidden
  661. i.btCleanup = function(){
  662. var box = $(i).data('bt-box');
  663. var contentOrig = $(i).data('bt-content-orig');
  664. var overlay = $(i).data('bt-overlay');
  665. if (typeof box == 'object') {
  666. $(box).remove();
  667. $(i).removeData('bt-box');
  668. }
  669. if (typeof contentOrig == 'object') {
  670. var clones = $(contentOrig.original).data('bt-clones');
  671. $(contentOrig).data('bt-clones', arrayRemove(clones, contentOrig.clone));
  672. }
  673. if (typeof overlay == 'object') {
  674. $(overlay).remove();
  675. $(i).removeData('bt-overlay');
  676. }
  677. // remove this from the stacks
  678. jQuery.bt.vars.clickAnywhereStack = arrayRemove(jQuery.bt.vars.clickAnywhereStack, i);
  679. jQuery.bt.vars.closeWhenOpenStack = arrayRemove(jQuery.bt.vars.closeWhenOpenStack, i);
  680. // remove the 'bt-active' and activeClass classes from target
  681. $(i).removeClass('bt-active ' + opts.activeClass);
  682. // trigger postHide function
  683. // no box argument since it has been removed from the DOM
  684. opts.postHide.apply(i);
  685. }
  686. opts.hideTip.apply(this, [box, i.btCleanup]);
  687. }; // </ turnOff() >
  688. var refresh = this.btRefresh = function() {
  689. this.btOff();
  690. this.btOn();
  691. };
  692. }); // </ this.each() >
  693. function drawIt(points, strokeWidth) {
  694. this.moveTo(points[0].x, points[0].y);
  695. for (i=1;i<points.length;i++) {
  696. if (points[i-1].type == 'arcStart') {
  697. // if we're creating a rounded corner
  698. //ctx.arc(round5(points[i].x), round5(points[i].y), points[i].startAngle, points[i].endAngle, opts.cornerRadius, false);
  699. this.quadraticCurveTo(round5(points[i].x, strokeWidth), round5(points[i].y, strokeWidth), round5(points[(i+1)%points.length].x, strokeWidth), round5(points[(i+1)%points.length].y, strokeWidth));
  700. i++;
  701. //ctx.moveTo(round5(points[i].x), round5(points[i].y));
  702. }
  703. else {
  704. this.lineTo(round5(points[i].x, strokeWidth), round5(points[i].y, strokeWidth));
  705. }
  706. }
  707. }; // </ drawIt() >
  708. /**
  709. * For odd stroke widths, round to the nearest .5 pixel to avoid antialiasing
  710. * http://developer.mozilla.org/en/Canvas_tutorial/Applying_styles_and_colors
  711. */
  712. function round5(num, strokeWidth) {
  713. var ret;
  714. strokeWidth = numb(strokeWidth);
  715. if (strokeWidth%2) {
  716. ret = num;
  717. }
  718. else {
  719. ret = Math.round(num - .5) + .5;
  720. }
  721. return ret;
  722. }; // </ round5() >
  723. /**
  724. * Ensure that a number is a number... or zero
  725. */
  726. function numb(num) {
  727. return parseInt(num) || 0;
  728. }; // </ numb() >
  729. /**
  730. * Remove an element from an array
  731. */
  732. function arrayRemove(arr, elem) {
  733. var x, newArr = new Array();
  734. for (x in arr) {
  735. if (arr[x] != elem) {
  736. newArr.push(arr[x]);
  737. }
  738. }
  739. return newArr;
  740. }; // </ arrayRemove() >
  741. /**
  742. * Does the current browser support canvas?
  743. * This is a variation of http://code.google.com/p/browser-canvas-support/
  744. */
  745. function canvasSupport() {
  746. var canvas_compatible = false;
  747. try {
  748. canvas_compatible = !!(document.createElement('canvas').getContext('2d')); // S60
  749. } catch(e) {
  750. canvas_compatible = !!(document.createElement('canvas').getContext); // IE
  751. }
  752. return canvas_compatible;
  753. }
  754. /**
  755. * Does the current browser support canvas drop shadows?
  756. */
  757. function shadowSupport() {
  758. // to test for drop shadow support in the current browser, uncomment the next line
  759. // return true;
  760. // until a good feature-detect is found, we have to look at user agents
  761. try {
  762. var userAgent = navigator.userAgent.toLowerCase();
  763. if (/webkit/.test(userAgent)) {
  764. // WebKit.. let's go!
  765. return true;
  766. }
  767. else if (/gecko|mozilla/.test(userAgent) && parseFloat(userAgent.match(/firefox\/(\d+(?:\.\d+)+)/)[1]) >= 3.1){
  768. // Mozilla 3.1 or higher
  769. return true;
  770. }
  771. }
  772. catch(err) {
  773. // if there's an error, just keep going, we'll assume that drop shadows are not supported
  774. }
  775. return false;
  776. } // </ shadowSupport() >
  777. /**
  778. * Given two points, find a point which is dist pixels from point1 on a line to point2
  779. */
  780. function betweenPoint(point1, point2, dist) {
  781. // figure out if we're horizontal or vertical
  782. var y, x;
  783. if (point1.x == point2.x) {
  784. // vertical
  785. y = point1.y < point2.y ? point1.y + dist : point1.y - dist;
  786. return {x: point1.x, y: y};
  787. }
  788. else if (point1.y == point2.y) {
  789. // horizontal
  790. x = point1.x < point2.x ? point1.x + dist : point1.x - dist;
  791. return {x:x, y: point1.y};
  792. }
  793. }; // </ betweenPoint() >
  794. function centerPoint(arcStart, corner, arcEnd) {
  795. var x = corner.x == arcStart.x ? arcEnd.x : arcStart.x;
  796. var y = corner.y == arcStart.y ? arcEnd.y : arcStart.y;
  797. var startAngle, endAngle;
  798. if (arcStart.x < arcEnd.x) {
  799. if (arcStart.y > arcEnd.y) {
  800. // arc is on upper left
  801. startAngle = (Math.PI/180)*180;
  802. endAngle = (Math.PI/180)*90;
  803. }
  804. else {
  805. // arc is on upper right
  806. startAngle = (Math.PI/180)*90;
  807. endAngle = 0;
  808. }
  809. }
  810. else {
  811. if (arcStart.y > arcEnd.y) {
  812. // arc is on lower left
  813. startAngle = (Math.PI/180)*270;
  814. endAngle = (Math.PI/180)*180;
  815. }
  816. else {
  817. // arc is on lower right
  818. startAngle = 0;
  819. endAngle = (Math.PI/180)*270;
  820. }
  821. }
  822. return {x: x, y: y, type: 'center', startAngle: startAngle, endAngle: endAngle};
  823. }; // </ centerPoint() >
  824. /**
  825. * Find the intersection point of two lines, each defined by two points
  826. * arguments are x1, y1 and x2, y2 for r1 (line 1) and r2 (line 2)
  827. * It's like an algebra party!!!
  828. */
  829. function findIntersect(r1x1, r1y1, r1x2, r1y2, r2x1, r2y1, r2x2, r2y2) {
  830. if (r2x1 == r2x2) {
  831. return findIntersectY(r1x1, r1y1, r1x2, r1y2, r2x1);
  832. }
  833. if (r2y1 == r2y2) {
  834. return findIntersectX(r1x1, r1y1, r1x2, r1y2, r2y1);
  835. }
  836. // m = (y1 - y2) / (x1 - x2) // <-- how to find the slope
  837. // y = mx + b // the 'classic' linear equation
  838. // b = y - mx // how to find b (the y-intersect)
  839. // x = (y - b)/m // how to find x
  840. var r1m = (r1y1 - r1y2) / (r1x1 - r1x2);
  841. var r1b = r1y1 - (r1m * r1x1);
  842. var r2m = (r2y1 - r2y2) / (r2x1 - r2x2);
  843. var r2b = r2y1 - (r2m * r2x1);
  844. var x = (r2b - r1b) / (r1m - r2m);
  845. var y = r1m * x + r1b;
  846. return {x: x, y: y};
  847. }; // </ findIntersect() >
  848. /**
  849. * Find the y intersection point of a line and given x vertical
  850. */
  851. function findIntersectY(r1x1, r1y1, r1x2, r1y2, x) {
  852. if (r1y1 == r1y2) {
  853. return {x: x, y: r1y1};
  854. }
  855. var r1m = (r1y1 - r1y2) / (r1x1 - r1x2);
  856. var r1b = r1y1 - (r1m * r1x1);
  857. var y = r1m * x + r1b;
  858. return {x: x, y: y};
  859. }; // </ findIntersectY() >
  860. /**
  861. * Find the x intersection point of a line and given y horizontal
  862. */
  863. function findIntersectX(r1x1, r1y1, r1x2, r1y2, y) {
  864. if (r1x1 == r1x2) {
  865. return {x: r1x1, y: y};
  866. }
  867. var r1m = (r1y1 - r1y2) / (r1x1 - r1x2);
  868. var r1b = r1y1 - (r1m * r1x1);
  869. // y = mx + b // your old friend, linear equation
  870. // x = (y - b)/m // linear equation solved for x
  871. var x = (y - r1b) / r1m;
  872. return {x: x, y: y};
  873. }; // </ findIntersectX() >
  874. }; // </ jQuery.fn.bt() >
  875. /**
  876. * jQuery's compat.js (used in Drupal's jQuery upgrade module, overrides the $().position() function
  877. * this is a copy of that function to allow the plugin to work when compat.js is present
  878. * once compat.js is fixed to not override existing functions, this function can be removed
  879. * and .btPosion() can be replaced with .position() above...
  880. */
  881. jQuery.fn.btPosition = function() {
  882. function num(elem, prop) {
  883. return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
  884. };
  885. var left = 0, top = 0, results;
  886. if ( this[0] ) {
  887. // Get *real* offsetParent
  888. var offsetParent = this.offsetParent(),
  889. // Get correct offsets
  890. offset = this.offset(),
  891. parentOffset = /^body|html$/i.test(offsetParent[0].tagName) ? { top: 0, left: 0 } : offsetParent.offset();
  892. // Subtract element margins
  893. // note: when an element has margin: auto the offsetLeft and marginLeft
  894. // are the same in Safari causing offset.left to incorrectly be 0
  895. offset.top -= num( this, 'marginTop' );
  896. offset.left -= num( this, 'marginLeft' );
  897. // Add offsetParent borders
  898. parentOffset.top += num( offsetParent, 'borderTopWidth' );
  899. parentOffset.left += num( offsetParent, 'borderLeftWidth' );
  900. // Subtract the two offsets
  901. results = {
  902. top: offset.top - parentOffset.top,
  903. left: offset.left - parentOffset.left
  904. };
  905. }
  906. return results;
  907. }; // </ jQuery.fn.btPosition() >
  908. /**
  909. * jQuery's dimensions.js overrides the $().btOuterWidth() function
  910. * this is a copy of original jQuery's outerWidth() function to
  911. * allow the plugin to work when dimensions.js is present
  912. */
  913. jQuery.fn.btOuterWidth = function(margin) {
  914. function num(elem, prop) {
  915. return elem[0] && parseInt(jQuery.curCSS(elem[0], prop, true), 10) || 0;
  916. };
  917. return this["innerWidth"]()
  918. + num(this, "borderLeftWidth")
  919. + num(this, "borderRightWidth")
  920. + (margin ? num(this, "marginLeft")
  921. + num(this, "marginRight") : 0);
  922. }; // </ jQuery.fn.btOuterWidth() >
  923. /**
  924. * A convenience function to run btOn() (if available)
  925. * for each selected item
  926. */
  927. jQuery.fn.btOn = function() {
  928. return this.each(function(index){
  929. if (jQuery.isFunction(this.btOn)) {
  930. this.btOn();
  931. }
  932. });
  933. }; // </ $().btOn() >
  934. /**
  935. *
  936. * A convenience function to run btOff() (if available)
  937. * for each selected item
  938. */
  939. jQuery.fn.btOff = function() {
  940. return this.each(function(index){
  941. if (jQuery.isFunction(this.btOff)) {
  942. this.btOff();
  943. }
  944. });
  945. }; // </ $().btOff() >
  946. jQuery.bt.vars = {clickAnywhereStack: [], closeWhenOpenStack: []};
  947. /**
  948. * This function gets bound to the document's click event
  949. * It turns off all of the tips in the click-anywhere-to-close stack
  950. */
  951. jQuery.bt.docClick = function(e) {
  952. if (!e) {
  953. var e = window.event;
  954. };
  955. // if clicked element is a child of neither a tip NOR a target
  956. // and there are tips in the stack
  957. if (!$(e.target).parents().andSelf().filter('.bt-wrapper, .bt-active').length && jQuery.bt.vars.clickAnywhereStack.length) {
  958. // if clicked element isn't inside tip, close tips in stack
  959. $(jQuery.bt.vars.clickAnywhereStack).btOff();
  960. $(document).unbind('click', jQuery.bt.docClick);
  961. }
  962. }; // </ docClick() >
  963. /**
  964. * Defaults for the beauty tips
  965. *
  966. * Note this is a variable definition and not a function. So defaults can be
  967. * written for an entire page by simply redefining attributes like so:
  968. *
  969. * jQuery.bt.options.width = 400;
  970. *
  971. * Be sure to use *jQuery.bt.options* and not jQuery.bt.defaults when overriding
  972. *
  973. * This would make all Beauty Tips boxes 400px wide.
  974. *
  975. * Each of these options may also be overridden during
  976. *
  977. * Can be overriden globally or at time of call.
  978. *
  979. */
  980. jQuery.bt.defaults = {
  981. trigger: 'hover', // trigger to show/hide tip
  982. // use [on, off] to define separate on/off triggers
  983. // also use space character to allow multiple to trigger
  984. // examples:
  985. // ['focus', 'blur'] // focus displays, blur hides
  986. // 'dblclick' // dblclick toggles on/off
  987. // ['focus mouseover', 'blur mouseout'] // multiple triggers
  988. // 'now' // shows/hides tip without event
  989. // 'none' // use $('#selector').btOn(); and ...btOff();
  990. // 'hoverIntent' // hover using hoverIntent plugin (settings below)
  991. // note:
  992. // hoverIntent becomes default if available
  993. clickAnywhereToClose: true, // clicking anywhere outside of the tip will close it
  994. closeWhenOthersOpen: false, // tip will be closed before another opens - stop >= 2 tips being on
  995. shrinkToFit: false, // should short single-line content get a narrower balloon?
  996. width: '200px', // width of tooltip box
  997. padding: '10px', // padding for content (get more fine grained with cssStyles)
  998. spikeGirth: 10, // width of spike
  999. spikeLength: 15, // length of spike
  1000. overlap: 0, // spike overlap (px) onto target (can cause problems with 'hover' trigger)
  1001. overlay: false, // display overlay on target (use CSS to style) -- BUGGY!
  1002. killTitle: true, // kill title tags to avoid double tooltips
  1003. textzIndex: 9999, // z-index for the text
  1004. boxzIndex: 9998, // z-index for the "talk" box (should always be less than textzIndex)
  1005. wrapperzIndex: 9997,
  1006. offsetParent: null, // DOM node to append the tooltip into.
  1007. // Must be positioned relative or absolute. Can be selector or object
  1008. positions: ['most'], // preference of positions for tip (will use first with available space)
  1009. // possible values 'top', 'bottom', 'left', 'right' as an array in order of
  1010. // preference. Last value will be used if others don't have enough space.
  1011. // or use 'most' to use the area with the most space
  1012. fill: "rgb(255, 255, 102)", // fill color for the tooltip box, you can use any CSS-style color definition method
  1013. // http://www.w3.org/TR/css3-color/#numerical - not all methods have been tested
  1014. windowMargin: 10, // space (px) to leave between text box and browser edge
  1015. strokeWidth: 1, // width of stroke around box, **set to 0 for no stroke**
  1016. strokeStyle: "#000", // color/alpha of stroke
  1017. cornerRadius: 5, // radius of corners (px), set to 0 for square corners
  1018. // following values are on a scale of 0 to 1 with .5 being centered
  1019. centerPointX: .5, // the spike extends from center of the target edge to this point
  1020. centerPointY: .5, // defined by percentage horizontal (x) and vertical (y)
  1021. shadow: false, // use drop shadow? (only displays in Safari and FF 3.1) - experimental
  1022. shadowOffsetX: 2, // shadow offset x (px)
  1023. shadowOffsetY: 2, // shadow offset y (px)
  1024. shadowBlur: 3, // shadow blur (px)
  1025. shadowColor: "#000", // shadow color/alpha
  1026. shadowOverlap: false, // when shadows overlap the target element it can cause problem with hovering
  1027. // set this to true to overlap or set to a numeric value to define the amount of overlap
  1028. noShadowOpts: {strokeStyle: '#999'}, // use this to define 'fall-back' options for browsers which don't support drop shadows
  1029. cssClass: '', // CSS class to add to the box wrapper div (of the TIP)
  1030. cssStyles: {}, // styles to add the text box
  1031. // example: {fontFamily: 'Georgia, Times, serif', fontWeight: 'bold'}
  1032. activeClass: 'bt-active', // class added to TARGET element when its BeautyTip is active
  1033. contentSelector: "$(this).attr('title')", // if there is no content argument, use this selector to retrieve the title
  1034. // a function which returns the content may also be passed here
  1035. ajaxPath: null, // if using ajax request for content, this contains url and (opt) selector
  1036. // this will override content and contentSelector
  1037. // examples (see jQuery load() function):
  1038. // '/demo.html'
  1039. // '/help/ajax/snip'
  1040. // '/help/existing/full div#content'
  1041. // ajaxPath can also be defined as an array
  1042. // in which case, the first value will be parsed as a jQuery selector
  1043. // the result of which will be used as the ajaxPath
  1044. // the second (optional) value is the content selector as above
  1045. // examples:
  1046. // ["$(this).attr('href')", 'div#content']
  1047. // ["$(this).parents('.wrapper').find('.title').attr('href')"]
  1048. // ["$('#some-element').val()"]
  1049. ajaxError: '<strong>ERROR:</strong> <em>%error</em>',
  1050. // error text, use "%error" to insert error from server
  1051. ajaxLoading: '<blink>Loading...</blink>', // yes folks, it's the blink tag!
  1052. ajaxData: {}, // key/value pairs
  1053. ajaxType: 'GET', // 'GET' or 'POST'
  1054. ajaxCache: true, // cache ajax results and do not send request to same url multiple times
  1055. ajaxOpts: {}, // any other ajax options - timeout, passwords, processing functions, etc...
  1056. // see http://docs.jquery.com/Ajax/jQuery.ajax#options
  1057. preBuild: function(){}, // function to run before popup is built
  1058. preShow: function(box){}, // function to run before popup is displayed
  1059. showTip: function(box){
  1060. $(box).show();
  1061. },
  1062. postShow: function(box){}, // function to run after popup is built and displayed
  1063. preHide: function(box){}, // function to run before popup is removed
  1064. hideTip: function(box, callback) {
  1065. $(box).hide();
  1066. callback(); // you MUST call "callback" at the end of your animations
  1067. },
  1068. postHide: function(){}, // function to run after popup is removed
  1069. hoverIntentOpts: { // options for hoverIntent (if installed)
  1070. interval: 300, // http://cherne.net/brian/resources/jquery.hoverIntent.html
  1071. timeout: 500
  1072. }
  1073. }; // </ jQuery.bt.defaults >
  1074. jQuery.bt.options = {};
  1075. })(jQuery);
  1076. // @todo
  1077. // use larger canvas (extend to edge of page when windowMargin is active)
  1078. // add options to shift position of tip vert/horiz and position of spike tip
  1079. // create drawn (canvas) shadows
  1080. // use overlay to allow overlap with hover
  1081. // experiment with making tooltip a subelement of the target
  1082. // handle non-canvas-capable browsers elegantly