foldBoxLg.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * jquery.scrollFollow.js
  3. * Copyright (c) 2008 Net Perspective (http://kitchen.net-perspective.com/)
  4. * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
  5. *
  6. * @author R.A. Ray
  7. *
  8. * @projectDescription jQuery plugin for allowing an element to animate down as the user scrolls the page.
  9. *
  10. * @version 0.4.0
  11. *
  12. * @requires jquery.js (tested with 1.2.6)
  13. * @requires ui.core.js (tested with 1.5.2)
  14. *
  15. * @optional jquery.cookie.js (http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/)
  16. * @optional jquery.easing.js (http://gsgd.co.uk/sandbox/jquery/easing/ - tested with 1.3)
  17. *
  18. * @param speed int - Duration of animation (in milliseconds)
  19. * default: 500
  20. * @param offset int - Number of pixels box should remain from top of viewport
  21. * default: 0
  22. * @param easing string - Any one of the easing options from the easing plugin - Requires jQuery Easing Plugin < http://gsgd.co.uk/sandbox/jquery/easing/ >
  23. * default: 'linear'
  24. * @param container string - ID of the containing div
  25. * default: box's immediate parent
  26. * @param killSwitch string - ID of the On/Off toggle element
  27. * default: 'killSwitch'
  28. * @param onText string - killSwitch text to be displayed if sliding is enabled
  29. * default: 'Turn Slide Off'
  30. * @param offText string - killSwitch text to be displayed if sliding is disabled
  31. * default: 'Turn Slide On'
  32. * @param relativeTo string - Scroll animation can be relative to either the 'top' or 'bottom' of the viewport
  33. * default: 'top'
  34. * @param delay int - Time between the end of the scroll and the beginning of the animation in milliseconds
  35. * default: 0
  36. */
  37. ( function( $ ) {
  38. $.foldBox = function ( box, options ){
  39. var $content=$('.content',$(box));
  40. var $button= $('.drop',$(box));
  41. if($(box).hasClass(options.searchBox)){ //搜索框
  42. $content=$('#searchForm',$(box));
  43. var insertHtml='<div class="title">查询条件</div><div class="drop"><a>展开</a></div>'
  44. $(insertHtml).insertBefore( $content ) ;
  45. var afterShowfn=options.afterShow;
  46. options.afterShow=function(){afterShowfn();
  47. $('.drop',$(box)).find('a').text('收起');
  48. $('.drop',$(box)).find('a').addClass('activi')}
  49. var afterHidefn=options.afterHide;
  50. options.afterHide=function(){afterHidefn();
  51. $('.drop',$(box)).find('a').text('展开');
  52. $('.drop',$(box)).find('a').removeClass('activi')}
  53. $button= $('.drop,.title',$(box));
  54. }
  55. $button.live('click',function(){
  56. if( $content.is(':hidden')){
  57. options.beforeShow($(box));
  58. $content.show();
  59. options.afterShow($(box));
  60. $.setCookie("isLocked", true);
  61. }else{
  62. options.beforeHide($(box));
  63. $content.hide();
  64. options.afterHide($(box));
  65. $.setCookie("isLocked", false);
  66. }
  67. });
  68. if($.getCookie("isLocked")=="true"){
  69. $('.drop',$(box)).find('a').text('收起');
  70. $('.drop',$(box)).find('a').addClass('activi');
  71. $content.show();
  72. }
  73. };
  74. $.fn.foldBox = function ( options ){
  75. options = options || {};
  76. options.searchBox = options.searchBox || 'panel-search';
  77. options.beforeShow = options.beforeShow || function($box){};
  78. options.afterShow = options.afterShow || function($box){};
  79. options.beforeHide = options.beforeHide || function($box){};
  80. options.afterHide = options.afterHide || function($box){};
  81. this.each( function()
  82. {
  83. new $.foldBox( this, options );
  84. }
  85. );
  86. return this;
  87. };
  88. })( jQuery );
  89. $(function(){
  90. $.extend({initFoldBox:function(){
  91. /**
  92. * 初始化更新页面
  93. */
  94. try{
  95. var updateHeight = function() {
  96. $("div.hide-panel").height($("div.panel-top").height());
  97. try {grid._setHeight({isFoldBox:true});} catch (e) {}
  98. };
  99. $('.panel-search').foldBox({afterShow:updateHeight,afterHide:updateHeight});
  100. $('.foldBox').foldBox();
  101. }catch(e){}
  102. }});
  103. $.initFoldBox();
  104. });