PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/jquery.tipsy.js

#
JavaScript | 104 lines | 79 code | 21 blank | 4 comment | 19 complexity | e82a7bca2c561de3790788a01bd2a34f MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. (function($) {
  2. $.fn.tipsy = function(options) {
  3. options = $.extend({}, $.fn.tipsy.defaults, options);
  4. return this.each(function() {
  5. var opts = $.fn.tipsy.elementOptions(this, options);
  6. $(this).hover(function() {
  7. $.data(this, 'cancel.tipsy', true);
  8. var tip = $.data(this, 'active.tipsy');
  9. if (!tip) {
  10. tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
  11. tip.css({position: 'absolute', zIndex: 100000});
  12. $.data(this, 'active.tipsy', tip);
  13. }
  14. if ($(this).attr('title') || typeof($(this).attr('original-title')) != 'string') {
  15. $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
  16. }
  17. var title;
  18. if (typeof opts.title == 'string') {
  19. title = $(this).attr(opts.title == 'title' ? 'original-title' : opts.title);
  20. } else if (typeof opts.title == 'function') {
  21. title = opts.title.call(this);
  22. }
  23. tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback);
  24. var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
  25. tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
  26. tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
  27. var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
  28. var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity;
  29. switch (gravity.charAt(0)) {
  30. case 'n':
  31. tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
  32. break;
  33. case 's':
  34. tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
  35. break;
  36. case 'e':
  37. tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');
  38. break;
  39. case 'w':
  40. tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');
  41. break;
  42. }
  43. if (opts.fade) {
  44. tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.8});
  45. } else {
  46. tip.css({visibility: 'visible'});
  47. }
  48. }, function() {
  49. $.data(this, 'cancel.tipsy', false);
  50. var self = this;
  51. setTimeout(function() {
  52. if ($.data(this, 'cancel.tipsy')) return;
  53. var tip = $.data(self, 'active.tipsy');
  54. if (opts.fade) {
  55. tip.stop().fadeOut(function() { $(this).remove(); });
  56. } else {
  57. tip.remove();
  58. }
  59. }, 100);
  60. });
  61. });
  62. };
  63. // Overwrite this method to provide options on a per-element basis.
  64. // For example, you could store the gravity in a 'tipsy-gravity' attribute:
  65. // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
  66. // (remember - do not modify 'options' in place!)
  67. $.fn.tipsy.elementOptions = function(ele, options) {
  68. return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
  69. };
  70. $.fn.tipsy.defaults = {
  71. fade: false,
  72. fallback: '',
  73. gravity: 'n',
  74. html: false,
  75. title: 'title'
  76. };
  77. $.fn.tipsy.autoNS = function() {
  78. return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
  79. };
  80. $.fn.tipsy.autoWE = function() {
  81. return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
  82. };
  83. })(jQuery);