dwz.barDrag.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @author Roger Wu
  3. * @version 1.0
  4. */
  5. (function($){
  6. $.fn.cssv = function(pre){
  7. var cssPre = $(this).css(pre);
  8. return cssPre.substring(0, cssPre.indexOf("px")) * 1;
  9. };
  10. $.fn.jBar = function(options){
  11. var op = $.extend({container:"#container", collapse:".collapse", toggleBut:".toggleCollapse div", sideBar:"#sidebar", sideBar2:"#sidebar_s", splitBar:"#splitBar", splitBar2:"#splitBarProxy"}, options);
  12. return this.each(function(){
  13. var jbar = this;
  14. var sbar = $(op.sideBar2, jbar);
  15. var bar = $(op.sideBar, jbar);
  16. $(op.toggleBut, bar).click(function(){
  17. DWZ.ui.sbar = false;
  18. $(op.splitBar).hide();
  19. var sbarwidth = sbar.cssv("left") + sbar.outerWidth();
  20. var barleft = sbarwidth - bar.outerWidth();
  21. var cleft = $(op.container).cssv("left") - (bar.outerWidth() - sbar.outerWidth());
  22. var cwidth = bar.outerWidth() - sbar.outerWidth() + $(op.container).outerWidth();
  23. $(op.container).animate({left: cleft,width: cwidth},50,function(){
  24. bar.animate({left: barleft}, 500, function(){
  25. bar.hide();
  26. sbar.show().css("left", -50).animate({left: 5}, 200);
  27. $(window).trigger(DWZ.eventType.resizeGrid);
  28. });
  29. });
  30. $(op.collapse,sbar).click(function(){
  31. var sbarwidth = sbar.cssv("left") + sbar.outerWidth();
  32. if(bar.is(":hidden")) {
  33. $(op.toggleBut, bar).hide();
  34. bar.show().animate({left: sbarwidth}, 500);
  35. $(op.container).click(_hideBar);
  36. } else {
  37. bar.animate({left: barleft}, 500, function(){
  38. bar.hide();
  39. });
  40. }
  41. function _hideBar() {
  42. $(op.container).unbind("click", _hideBar);
  43. if (!DWZ.ui.sbar) {
  44. bar.animate({left: barleft}, 500, function(){
  45. bar.hide();
  46. });
  47. }
  48. }
  49. return false;
  50. });
  51. return false;
  52. });
  53. $(op.toggleBut, sbar).click(function(){
  54. DWZ.ui.sbar = true;
  55. sbar.animate({left: -25}, 200, function(){
  56. bar.show();
  57. });
  58. bar.animate({left: 5}, 800, function(){
  59. $(op.splitBar).show();
  60. $(op.toggleBut, bar).show();
  61. var cleft = 5 + bar.outerWidth() + $(op.splitBar).outerWidth();
  62. var cwidth = $(op.container).outerWidth() - (cleft - $(op.container).cssv("left"));
  63. $(op.container).css({left: cleft,width: cwidth});
  64. $(op.collapse, sbar).unbind('click');
  65. $(window).trigger(DWZ.eventType.resizeGrid);
  66. });
  67. return false;
  68. });
  69. $(op.splitBar).mousedown(function(event){
  70. $(op.splitBar2).each(function(){
  71. var spbar2 = $(this);
  72. setTimeout(function(){spbar2.show();}, 100);
  73. spbar2.css({visibility: "visible",left: $(op.splitBar).css("left")});
  74. spbar2.jDrag($.extend(options, {obj:$("#sidebar"), move:"horizontal", event:event,stop: function(){
  75. $(this).css("visibility", "hidden");
  76. var move = $(this).cssv("left") - $(op.splitBar).cssv("left");
  77. var sbarwidth = bar.outerWidth() + move;
  78. var cleft = $(op.container).cssv("left") + move;
  79. var cwidth = $(op.container).outerWidth() - move;
  80. bar.css("width", sbarwidth);
  81. $(op.splitBar).css("left", $(this).css("left"));
  82. $(op.container).css({left: cleft,width: cwidth});
  83. }}));
  84. return false;
  85. });
  86. });
  87. });
  88. }
  89. })(jQuery);