I'm using jqRnD plugin to implement a dialog application, and I found
it lacks min/max width and height, and resize callback supports, so I
hack the jqRnD.js, and here is my code, I only test it in Firefox, and
hope it'll be some useful.

/*
 * jqDnR - Minimalistic Drag'n'Resize for jQuery.
 *
 * Copyright (c) 2007 Brice Burgess <[EMAIL PROTECTED]>, http://www.iceburg.net
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * $Version: 2007.02.09 +r1
 */
(function($){
var _o={minWidth:100,minHeight:100,maxWidth:300,maxHeight:300,onresize:false};
$.fn.jqDrag=function(r, o){var opts = $.extend(_o,
o);$.jqDnR.init(this,r,'d',opts); return this;};
$.fn.jqResize=function(r, o){var opts = $.extend(_o,
o);$.jqDnR.init(this,r,'r',opts); return this;};
$.jqDnR={
init:function(w,r,t,o){ r=(r)?$(r,w):w;
r.bind('mousedown',{w:w,t:t},function(e){ var h=e.data; var w=h.w;
hash=$.extend({oX:f(w,'left'),oY:f(w,'top'),oW:f(w,'width'),oH:f(w,'height'),pX:e.pageX,pY:e.pageY,o:w.css('opacity'),opts:o||{}},h);
h.w.css('opacity',0.8); $().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
return false;});
},
drag:function(e) {var h=hash; var w=h.w[0];
if(h.t == 'd') h.w.css({left:h.oX + e.pageX - h.pX,top:h.oY + e.pageY - h.pY});
else{
var w1,h1;
w1 = Math.max(e.pageX - h.pX + h.oW, h.opts.minWidth);
w1 = Math.min(w1, h.opts.maxWidth);
h1 = Math.max(e.pageY - h.pY + h.oH, h.opts.minHeight);
h1 = Math.min(h1, h.opts.maxHeight);
h.w.css({width:w1,height:h1});
if(h.opts.onresize){h.opts.onresize(h.w,w1,h1);}
}
return false;},
stop:function(){var j=$.jqDnR; hash.w.css('opacity',hash.o);
$().unbind('mousemove',j.drag).unbind('mouseup',j.stop);},
h:false};
var hash=$.jqDnR.h;
var f=function(w,t){return parseInt(w.css(t)) || 0};
})(jQuery);


-- 
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to