jquery.anim.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. $.fn.bx_show_more_check_overflow = function(sClass, onFind) {
  83. if(!sClass)
  84. sClass = 'bx-overflow';
  85. return this.each(function() {
  86. var oElement = $(this);
  87. if(oElement.hasClass(sClass) || oElement.css('overflow') != 'hidden')
  88. return;
  89. if(oElement.prop('scrollHeight') <= oElement.height())
  90. return;
  91. oElement.addClass(sClass);
  92. if(typeof onFind === 'function')
  93. onFind(oElement);
  94. else
  95. oElement.after('<div class="bx-show-more bx-def-border-top"><a href="javascript:void(0)" onclick="bx_show_more(this);"><i class="sys-icon angle-double-down"></i></div>');
  96. });
  97. };
  98. function bx_show_more(oLink) {
  99. var sClass = 'bx-overflow';
  100. var oShowMore = $(oLink).parent();
  101. oShowMore.siblings('.' + sClass).css('max-height', 'none').removeClass(sClass);
  102. oShowMore.remove();
  103. };
  104. /** @} */