jqDnR.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  3. *
  4. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  5. * Licensed under the MIT License:
  6. * http://www.opensource.org/licenses/mit-license.php
  7. *
  8. * $Version: 2007.08.19 +r2
  9. */
  10. (function($){
  11. $.fn.jqDrag=function(h){return i(this,h,'d');};
  12. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  13. $.jqDnR={
  14. dnr:{},
  15. e:0,
  16. drag:function(v){
  17. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  18. else {
  19. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  20. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  21. }
  22. return false;
  23. },
  24. stop:function(){
  25. //E.css('opacity',M.o);
  26. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  27. }
  28. };
  29. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  30. i=function(e,h,k,aR){
  31. return e.each(function(){
  32. h=(h)?$(h,e):e;
  33. h.bind('mousedown',{e:e,k:k},function(v){
  34. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  35. // attempt utilization of dimensions plugin to fix IE issues
  36. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  37. M={
  38. X:p.left||f('left')||0,
  39. Y:p.top||f('top')||0,
  40. W:f('width')||E[0].scrollWidth||0,
  41. H:f('height')||E[0].scrollHeight||0,
  42. pX:v.pageX,
  43. pY:v.pageY,
  44. k:d.k
  45. //o:E.css('opacity')
  46. };
  47. // also resize
  48. if(E1 && d.k != 'd'){
  49. M1={
  50. X:p.left||f1('left')||0,
  51. Y:p.top||f1('top')||0,
  52. W:E1[0].offsetWidth||f1('width')||0,
  53. H:E1[0].offsetHeight||f1('height')||0,
  54. pX:v.pageX,
  55. pY:v.pageY,
  56. k:d.k
  57. };
  58. } else {M1 = false;}
  59. //E.css({opacity:0.8});
  60. if($("input.hasDatepicker",E[0])[0]) {
  61. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  62. }
  63. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  64. return false;
  65. });
  66. });
  67. },
  68. f=function(k){return parseInt(E.css(k),10)||false;},
  69. f1=function(k){return parseInt(E1.css(k),10)||false;};
  70. })(jQuery);