foldBoxJqGrid.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. var callBack=options.callBack;
  42. if($(box).hasClass(options.searchBox)){ //搜索框
  43. $content=$('#searchForm',$(box));
  44. var insertHtml='<div class="title">查询条件</div><div class="drop"><a>展开</a></div>'
  45. $(insertHtml).insertBefore( $content ) ;
  46. var afterShowfn=options.afterShow;
  47. options.afterShow=function(){afterShowfn();
  48. $('.drop',$(box)).find('a').text('收起');
  49. $('.drop',$(box)).find('a').addClass('activi')}
  50. var afterHidefn=options.afterHide;
  51. options.afterHide=function(){afterHidefn();
  52. $('.drop',$(box)).find('a').text('展开');
  53. $('.drop',$(box)).find('a').removeClass('activi')}
  54. $button= $('.drop,.title',$(box));
  55. }
  56. $button.live('click',function(){
  57. if( $content.is(':hidden')){
  58. options.beforeShow($(box));
  59. $content.show();
  60. options.afterShow($(box));
  61. $.setCookie("isLocked", true);
  62. if(callBack){
  63. callBack();
  64. }
  65. }else{
  66. options.beforeHide($(box));
  67. $content.hide();
  68. options.afterHide($(box));
  69. $.setCookie("isLocked", false);
  70. if(callBack){
  71. callBack();
  72. }
  73. }
  74. });
  75. if($.getCookie("isLocked")=="true"){
  76. $('.drop',$(box)).find('a').text('收起');
  77. $('.drop',$(box)).find('a').addClass('activi');
  78. $content.show();
  79. }
  80. };
  81. $.fn.foldBox = function ( options ){
  82. options = options || {};
  83. options.searchBox = options.searchBox || 'panel-search';
  84. options.beforeShow = options.beforeShow || function($box){};
  85. options.afterShow = options.afterShow || function($box){};
  86. options.beforeHide = options.beforeHide || function($box){};
  87. options.afterHide = options.afterHide || function($box){};
  88. this.each( function()
  89. {
  90. new $.foldBox( this, options );
  91. }
  92. );
  93. return this;
  94. };
  95. })( jQuery );
  96. $(function(){
  97. $.extend({initFoldBox:function(){
  98. /**
  99. * 初始化更新页面
  100. */
  101. try{
  102. var updateHeight = function(){$("div.hide-panel").height($("div.panel-top").height());};
  103. $('.panel-search').foldBox({afterShow:updateHeight,afterHide:updateHeight,callBack:callBackFunc});
  104. $('.foldBox').foldBox();
  105. //changeScrollHeight(($('.panel-search')[0]&&$('.panel-search').attr("hasScroll")!="true"||$('.foldBox')[0]&&$('.foldBox').attr("hasScroll")!="true")?"":true);
  106. }catch(e){}
  107. }});
  108. $.initFoldBox();
  109. });