jquery.anim.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaCore UNA Core
  6. * @{
  7. */
  8. $.fn.bx_anim = function(action, effect, speed, h) {
  9. return this.each(function() {
  10. var sFunc = '';
  11. var sEval;
  12. if (speed == 0)
  13. effect = 'default';
  14. switch (action) {
  15. case 'show':
  16. switch (effect) {
  17. case 'slide': sFunc = 'slideDown'; break;
  18. case 'fade': sFunc = 'fadeIn'; break;
  19. default: sFunc = 'show';
  20. }
  21. break;
  22. case 'hide':
  23. switch (effect) {
  24. case 'slide': sFunc = 'slideUp'; break;
  25. case 'fade': sFunc = 'fadeOut'; break;
  26. default: sFunc = 'hide';
  27. }
  28. break;
  29. default:
  30. case 'toggle':
  31. switch (effect) {
  32. case 'slide': sFunc = 'slideToggle'; break;
  33. case 'fade': sFunc = ($(this).filter(':visible').length) ? 'fadeOut' : 'fadeIn'; break;
  34. default: sFunc = 'toggle';
  35. }
  36. }
  37. if ((0 == speed || undefined == speed) && undefined == h) {
  38. sEval = '$(this).' + sFunc + '();';
  39. }
  40. else if ((0 == speed || undefined == speed) && undefined != h) {
  41. sEval = '$(this).' + sFunc + '(); $(this).each(h);';
  42. }
  43. else {
  44. sEval = '$(this).' + sFunc + "('" + speed + "', h);";
  45. }
  46. eval(sEval);
  47. return this;
  48. });
  49. };
  50. $.fn.bx_loading = function(bForceIndicator) {
  51. return $.fn._bx_loading('.bx-loading-ajax', bForceIndicator);
  52. };
  53. $.fn.bx_loading_btn = function(bForceIndicator) {
  54. return $.fn._bx_loading('.bx-loading-ajax-btn', bForceIndicator);
  55. };
  56. $.fn._bx_loading = function(sLoadingSelector, bForceIndicator) {
  57. return this.each(function() {
  58. var oContainer = $(this);
  59. var oLoading = oContainer.find(sLoadingSelector);
  60. bForceIndicator = 'undefined' == typeof(bForceIndicator) ? oLoading.length && oLoading.is(':visible') : bForceIndicator;
  61. bx_loading_btn(oContainer, bForceIndicator);
  62. });
  63. };
  64. $.fn.bx_message_box = function(sMessage, iTimer, onClose) {
  65. return this.each(function() {
  66. var oParent = $(this);
  67. if(oParent.children(':first').hasClass('MsgBox'))
  68. oParent.children(':first').replaceWith(sMessage);
  69. else
  70. oParent.prepend(sMessage);
  71. if(iTimer == undefined || parseInt(iTimer) == 0)
  72. return;
  73. setTimeout(function(oParent, onClose) {
  74. oParent.children('div.MsgBox:first').bx_anim('hide', 'fade', 'slow', function(){
  75. $(this).remove();
  76. if(onClose != undefined)
  77. onClose();
  78. });
  79. }, 1000 * parseInt(iTimer), oParent, onClose);
  80. });
  81. };
  82. /** @} */