better_messages.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. (function($) {
  2. Drupal.behaviors.betterMessages = {
  3. attach: function (context) {
  4. var betterMessages = Drupal.settings.betterMessages;
  5. var message_box = $('#better-messages-wrapper');
  6. /* jQuery UI Enhancements */
  7. if (betterMessages.jquery_ui != null) {
  8. if (betterMessages.jquery_ui.draggable == '1') { message_box.draggable(); }
  9. }
  10. /* Popup Message handling */
  11. if (!message_box.hasClass("better-messeges-processed")) {
  12. /* Functions to determine the popin/popout animation */
  13. betterMessages.open = function() {
  14. switch (betterMessages.popin.effect) {
  15. case 'fadeIn': message_box.fadeIn(betterMessages.popin.duration);
  16. break;
  17. case 'slideDown': message_box.slideDown(betterMessages.popin.duration);
  18. break;
  19. default: message_box.fadeIn(betterMessages.popin.duration);
  20. break;
  21. }
  22. }
  23. betterMessages.close = function() {
  24. switch (betterMessages.popout.effect) {
  25. case 'fadeOut': message_box.fadeOut(betterMessages.popout.duration);
  26. break;
  27. case 'slideUp': message_box.slideUp(betterMessages.popout.duration);
  28. break;
  29. default: message_box.fadeOut(betterMessages.popout.duration);
  30. break;
  31. }
  32. message_box.addClass("better-messeges-processed");
  33. }
  34. /* Function to determine closing count */
  35. betterMessages.countDownClose = function(seconds) {
  36. if(seconds > 0) {
  37. seconds--;
  38. if (betterMessages.show_countdown == '1') {
  39. $('.message-timer').text(Drupal.t('Closing in !seconds seconds', {'!seconds': seconds}));
  40. }
  41. if(seconds > 0) {
  42. betterMessages.countDown = setTimeout( function() {betterMessages.countDownClose(seconds);}, 1000 );
  43. }
  44. else {
  45. betterMessages.close();
  46. }
  47. }
  48. }
  49. /* Determine Popup Message position */
  50. message_box.css('width', betterMessages.width);
  51. var vertical = betterMessages.vertical; var horizontal = betterMessages.horizontal;
  52. switch (betterMessages.position) {
  53. case 'center':
  54. vertical = ( $(window).height() - message_box.height() ) / 2;
  55. horizontal = ( $(window).width() - message_box.width() ) / 2;
  56. message_box.css({"top":vertical + 'px', "left":horizontal + 'px'});
  57. break;
  58. case 'tl':
  59. message_box.css({"top":vertical + 'px', "left":horizontal + 'px'});
  60. break;
  61. case 'tr':
  62. message_box.css({"top":vertical + 'px', "right":horizontal + 'px'});
  63. break;
  64. case 'bl':
  65. message_box.css({"bottom":vertical + 'px', "left":horizontal + 'px'});
  66. break;
  67. case 'br':
  68. message_box.css({"bottom":vertical + 'px', "right":horizontal + 'px'});
  69. break;
  70. }
  71. /* Here we control closing and opeing effects and controls */
  72. if (betterMessages.opendelay != 0) {
  73. setTimeout( function() {betterMessages.open()}, betterMessages.opendelay * 1000 );
  74. } else { betterMessages.open(); }
  75. if (betterMessages.autoclose != 0) {
  76. betterMessages.countDownClose(betterMessages.autoclose);
  77. }
  78. if (betterMessages.hover_autoclose == '1') {
  79. message_box.hover(function() {
  80. clearTimeout(betterMessages.countDown);
  81. $('.message-timer').fadeOut('slow');
  82. }, function() {
  83. /* Suggest something to do here! */
  84. }
  85. );
  86. }
  87. $('a.message-close').click(function() { betterMessages.close(); return false; });
  88. /* Esc key handler for closing the message. This doesn't work on Safari or Chrome
  89. See the issue here: http://code.google.com/p/chromium/issues/detail?id=14635
  90. */
  91. $(document).keypress(function(e){
  92. if(e.keyCode==27){
  93. betterMessages.close();
  94. return false;
  95. }
  96. });
  97. /* Determine Popup Message position for IE6 bug with fixed display */
  98. if (betterMessages.fixed == '1' && !($.browser.msie && $.browser.version == '6.0')) {
  99. message_box.css({"position":"fixed"});
  100. }
  101. else { /* IE6 handing */
  102. message_box.css({"position":"absolute"});
  103. $(window).scroll(function() { message_box.stop().css({top:($(window).scrollTop() + vertical) + 'px'});});
  104. }
  105. }
  106. }
  107. }
  108. })(jQuery);