Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / resources / lib / jquery.ui / jquery.ui.resizable.js
blobbb277e237032ed26581e937a22c317a487208a87
1 /*!
2  * jQuery UI Resizable 1.9.2
3  * http://jqueryui.com
4  *
5  * Copyright 2012 jQuery Foundation and other contributors
6  * Released under the MIT license.
7  * http://jquery.org/license
8  *
9  * http://api.jqueryui.com/resizable/
10  *
11  * Depends:
12  *      jquery.ui.core.js
13  *      jquery.ui.mouse.js
14  *      jquery.ui.widget.js
15  */
16 (function( $, undefined ) {
18 $.widget("ui.resizable", $.ui.mouse, {
19         version: "1.9.2",
20         widgetEventPrefix: "resize",
21         options: {
22                 alsoResize: false,
23                 animate: false,
24                 animateDuration: "slow",
25                 animateEasing: "swing",
26                 aspectRatio: false,
27                 autoHide: false,
28                 containment: false,
29                 ghost: false,
30                 grid: false,
31                 handles: "e,s,se",
32                 helper: false,
33                 maxHeight: null,
34                 maxWidth: null,
35                 minHeight: 10,
36                 minWidth: 10,
37                 zIndex: 1000
38         },
39         _create: function() {
41                 var that = this, o = this.options;
42                 this.element.addClass("ui-resizable");
44                 $.extend(this, {
45                         _aspectRatio: !!(o.aspectRatio),
46                         aspectRatio: o.aspectRatio,
47                         originalElement: this.element,
48                         _proportionallyResizeElements: [],
49                         _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
50                 });
52                 //Wrap the element if it cannot hold child nodes
53                 if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
55                         //Create a wrapper element and set the wrapper to the new current internal element
56                         this.element.wrap(
57                                 $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
58                                         position: this.element.css('position'),
59                                         width: this.element.outerWidth(),
60                                         height: this.element.outerHeight(),
61                                         top: this.element.css('top'),
62                                         left: this.element.css('left')
63                                 })
64                         );
66                         //Overwrite the original this.element
67                         this.element = this.element.parent().data(
68                                 "resizable", this.element.data('resizable')
69                         );
71                         this.elementIsWrapper = true;
73                         //Move margins to the wrapper
74                         this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
75                         this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
77                         //Prevent Safari textarea resize
78                         this.originalResizeStyle = this.originalElement.css('resize');
79                         this.originalElement.css('resize', 'none');
81                         //Push the actual element to our proportionallyResize internal array
82                         this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
84                         // avoid IE jump (hard set the margin)
85                         this.originalElement.css({ margin: this.originalElement.css('margin') });
87                         // fix handlers offset
88                         this._proportionallyResize();
90                 }
92                 this.handles = o.handles || (!$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' });
93                 if(this.handles.constructor == String) {
95                         if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
96                         var n = this.handles.split(","); this.handles = {};
98                         for(var i = 0; i < n.length; i++) {
100                                 var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
101                                 var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
103                                 // Apply zIndex to all handles - see #7960
104                                 axis.css({ zIndex: o.zIndex });
106                                 //TODO : What's going on here?
107                                 if ('se' == handle) {
108                                         axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
109                                 };
111                                 //Insert into internal handles object and append to element
112                                 this.handles[handle] = '.ui-resizable-'+handle;
113                                 this.element.append(axis);
114                         }
116                 }
118                 this._renderAxis = function(target) {
120                         target = target || this.element;
122                         for(var i in this.handles) {
124                                 if(this.handles[i].constructor == String)
125                                         this.handles[i] = $(this.handles[i], this.element).show();
127                                 //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
128                                 if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
130                                         var axis = $(this.handles[i], this.element), padWrapper = 0;
132                                         //Checking the correct pad and border
133                                         padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
135                                         //The padding type i have to apply...
136                                         var padPos = [ 'padding',
137                                                 /ne|nw|n/.test(i) ? 'Top' :
138                                                 /se|sw|s/.test(i) ? 'Bottom' :
139                                                 /^e$/.test(i) ? 'Right' : 'Left' ].join("");
141                                         target.css(padPos, padWrapper);
143                                         this._proportionallyResize();
145                                 }
147                                 //TODO: What's that good for? There's not anything to be executed left
148                                 if(!$(this.handles[i]).length)
149                                         continue;
151                         }
152                 };
154                 //TODO: make renderAxis a prototype function
155                 this._renderAxis(this.element);
157                 this._handles = $('.ui-resizable-handle', this.element)
158                         .disableSelection();
160                 //Matching axis name
161                 this._handles.mouseover(function() {
162                         if (!that.resizing) {
163                                 if (this.className)
164                                         var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
165                                 //Axis, default = se
166                                 that.axis = axis && axis[1] ? axis[1] : 'se';
167                         }
168                 });
170                 //If we want to auto hide the elements
171                 if (o.autoHide) {
172                         this._handles.hide();
173                         $(this.element)
174                                 .addClass("ui-resizable-autohide")
175                                 .mouseenter(function() {
176                                         if (o.disabled) return;
177                                         $(this).removeClass("ui-resizable-autohide");
178                                         that._handles.show();
179                                 })
180                                 .mouseleave(function(){
181                                         if (o.disabled) return;
182                                         if (!that.resizing) {
183                                                 $(this).addClass("ui-resizable-autohide");
184                                                 that._handles.hide();
185                                         }
186                                 });
187                 }
189                 //Initialize the mouse interaction
190                 this._mouseInit();
192         },
194         _destroy: function() {
196                 this._mouseDestroy();
198                 var _destroy = function(exp) {
199                         $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
200                                 .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
201                 };
203                 //TODO: Unwrap at same DOM position
204                 if (this.elementIsWrapper) {
205                         _destroy(this.element);
206                         var wrapper = this.element;
207                         this.originalElement.css({
208                                 position: wrapper.css('position'),
209                                 width: wrapper.outerWidth(),
210                                 height: wrapper.outerHeight(),
211                                 top: wrapper.css('top'),
212                                 left: wrapper.css('left')
213                         }).insertAfter( wrapper );
214                         wrapper.remove();
215                 }
217                 this.originalElement.css('resize', this.originalResizeStyle);
218                 _destroy(this.originalElement);
220                 return this;
221         },
223         _mouseCapture: function(event) {
224                 var handle = false;
225                 for (var i in this.handles) {
226                         if ($(this.handles[i])[0] == event.target) {
227                                 handle = true;
228                         }
229                 }
231                 return !this.options.disabled && handle;
232         },
234         _mouseStart: function(event) {
236                 var o = this.options, iniPos = this.element.position(), el = this.element;
238                 this.resizing = true;
239                 this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
241                 // bugfix for http://dev.jquery.com/ticket/1749
242                 if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
243                         el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
244                 }
246                 this._renderProxy();
248                 var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));
250                 if (o.containment) {
251                         curleft += $(o.containment).scrollLeft() || 0;
252                         curtop += $(o.containment).scrollTop() || 0;
253                 }
255                 //Store needed variables
256                 this.offset = this.helper.offset();
257                 this.position = { left: curleft, top: curtop };
258                 this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
259                 this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
260                 this.originalPosition = { left: curleft, top: curtop };
261                 this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
262                 this.originalMousePosition = { left: event.pageX, top: event.pageY };
264                 //Aspect Ratio
265                 this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
267                 var cursor = $('.ui-resizable-' + this.axis).css('cursor');
268                 $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor);
270                 el.addClass("ui-resizable-resizing");
271                 this._propagate("start", event);
272                 return true;
273         },
275         _mouseDrag: function(event) {
277                 //Increase performance, avoid regex
278                 var el = this.helper, o = this.options, props = {},
279                         that = this, smp = this.originalMousePosition, a = this.axis;
281                 var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
282                 var trigger = this._change[a];
283                 if (!trigger) return false;
285                 // Calculate the attrs that will be change
286                 var data = trigger.apply(this, [event, dx, dy]);
288                 // Put this in the mouseDrag handler since the user can start pressing shift while resizing
289                 this._updateVirtualBoundaries(event.shiftKey);
290                 if (this._aspectRatio || event.shiftKey)
291                         data = this._updateRatio(data, event);
293                 data = this._respectSize(data, event);
295                 // plugins callbacks need to be called first
296                 this._propagate("resize", event);
298                 el.css({
299                         top: this.position.top + "px", left: this.position.left + "px",
300                         width: this.size.width + "px", height: this.size.height + "px"
301                 });
303                 if (!this._helper && this._proportionallyResizeElements.length)
304                         this._proportionallyResize();
306                 this._updateCache(data);
308                 // calling the user callback at the end
309                 this._trigger('resize', event, this.ui());
311                 return false;
312         },
314         _mouseStop: function(event) {
316                 this.resizing = false;
317                 var o = this.options, that = this;
319                 if(this._helper) {
320                         var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
321                                 soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
322                                 soffsetw = ista ? 0 : that.sizeDiff.width;
324                         var s = { width: (that.helper.width()  - soffsetw), height: (that.helper.height() - soffseth) },
325                                 left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
326                                 top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
328                         if (!o.animate)
329                                 this.element.css($.extend(s, { top: top, left: left }));
331                         that.helper.height(that.size.height);
332                         that.helper.width(that.size.width);
334                         if (this._helper && !o.animate) this._proportionallyResize();
335                 }
337                 $('body').css('cursor', 'auto');
339                 this.element.removeClass("ui-resizable-resizing");
341                 this._propagate("stop", event);
343                 if (this._helper) this.helper.remove();
344                 return false;
346         },
348         _updateVirtualBoundaries: function(forceAspectRatio) {
349                 var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b;
351                 b = {
352                         minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
353                         maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
354                         minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
355                         maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
356                 };
358                 if(this._aspectRatio || forceAspectRatio) {
359                         // We want to create an enclosing box whose aspect ration is the requested one
360                         // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
361                         pMinWidth = b.minHeight * this.aspectRatio;
362                         pMinHeight = b.minWidth / this.aspectRatio;
363                         pMaxWidth = b.maxHeight * this.aspectRatio;
364                         pMaxHeight = b.maxWidth / this.aspectRatio;
366                         if(pMinWidth > b.minWidth) b.minWidth = pMinWidth;
367                         if(pMinHeight > b.minHeight) b.minHeight = pMinHeight;
368                         if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth;
369                         if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight;
370                 }
371                 this._vBoundaries = b;
372         },
374         _updateCache: function(data) {
375                 var o = this.options;
376                 this.offset = this.helper.offset();
377                 if (isNumber(data.left)) this.position.left = data.left;
378                 if (isNumber(data.top)) this.position.top = data.top;
379                 if (isNumber(data.height)) this.size.height = data.height;
380                 if (isNumber(data.width)) this.size.width = data.width;
381         },
383         _updateRatio: function(data, event) {
385                 var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
387                 if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
388                 else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
390                 if (a == 'sw') {
391                         data.left = cpos.left + (csize.width - data.width);
392                         data.top = null;
393                 }
394                 if (a == 'nw') {
395                         data.top = cpos.top + (csize.height - data.height);
396                         data.left = cpos.left + (csize.width - data.width);
397                 }
399                 return data;
400         },
402         _respectSize: function(data, event) {
404                 var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
405                                 ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
406                                         isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
408                 if (isminw) data.width = o.minWidth;
409                 if (isminh) data.height = o.minHeight;
410                 if (ismaxw) data.width = o.maxWidth;
411                 if (ismaxh) data.height = o.maxHeight;
413                 var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height;
414                 var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
416                 if (isminw && cw) data.left = dw - o.minWidth;
417                 if (ismaxw && cw) data.left = dw - o.maxWidth;
418                 if (isminh && ch)       data.top = dh - o.minHeight;
419                 if (ismaxh && ch)       data.top = dh - o.maxHeight;
421                 // fixing jump error on top/left - bug #2330
422                 var isNotwh = !data.width && !data.height;
423                 if (isNotwh && !data.left && data.top) data.top = null;
424                 else if (isNotwh && !data.top && data.left) data.left = null;
426                 return data;
427         },
429         _proportionallyResize: function() {
431                 var o = this.options;
432                 if (!this._proportionallyResizeElements.length) return;
433                 var element = this.helper || this.element;
435                 for (var i=0; i < this._proportionallyResizeElements.length; i++) {
437                         var prel = this._proportionallyResizeElements[i];
439                         if (!this.borderDif) {
440                                 var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')],
441                                         p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')];
443                                 this.borderDif = $.map(b, function(v, i) {
444                                         var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0;
445                                         return border + padding;
446                                 });
447                         }
449                         prel.css({
450                                 height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
451                                 width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
452                         });
454                 };
456         },
458         _renderProxy: function() {
460                 var el = this.element, o = this.options;
461                 this.elementOffset = el.offset();
463                 if(this._helper) {
465                         this.helper = this.helper || $('<div style="overflow:hidden;"></div>');
467                         // fix ie6 offset TODO: This seems broken
468                         var ie6offset = ($.ui.ie6 ? 1 : 0),
469                         pxyoffset = ( $.ui.ie6 ? 2 : -1 );
471                         this.helper.addClass(this._helper).css({
472                                 width: this.element.outerWidth() + pxyoffset,
473                                 height: this.element.outerHeight() + pxyoffset,
474                                 position: 'absolute',
475                                 left: this.elementOffset.left - ie6offset +'px',
476                                 top: this.elementOffset.top - ie6offset +'px',
477                                 zIndex: ++o.zIndex //TODO: Don't modify option
478                         });
480                         this.helper
481                                 .appendTo("body")
482                                 .disableSelection();
484                 } else {
485                         this.helper = this.element;
486                 }
488         },
490         _change: {
491                 e: function(event, dx, dy) {
492                         return { width: this.originalSize.width + dx };
493                 },
494                 w: function(event, dx, dy) {
495                         var o = this.options, cs = this.originalSize, sp = this.originalPosition;
496                         return { left: sp.left + dx, width: cs.width - dx };
497                 },
498                 n: function(event, dx, dy) {
499                         var o = this.options, cs = this.originalSize, sp = this.originalPosition;
500                         return { top: sp.top + dy, height: cs.height - dy };
501                 },
502                 s: function(event, dx, dy) {
503                         return { height: this.originalSize.height + dy };
504                 },
505                 se: function(event, dx, dy) {
506                         return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
507                 },
508                 sw: function(event, dx, dy) {
509                         return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
510                 },
511                 ne: function(event, dx, dy) {
512                         return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
513                 },
514                 nw: function(event, dx, dy) {
515                         return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
516                 }
517         },
519         _propagate: function(n, event) {
520                 $.ui.plugin.call(this, n, [event, this.ui()]);
521                 (n != "resize" && this._trigger(n, event, this.ui()));
522         },
524         plugins: {},
526         ui: function() {
527                 return {
528                         originalElement: this.originalElement,
529                         element: this.element,
530                         helper: this.helper,
531                         position: this.position,
532                         size: this.size,
533                         originalSize: this.originalSize,
534                         originalPosition: this.originalPosition
535                 };
536         }
541  * Resizable Extensions
542  */
544 $.ui.plugin.add("resizable", "alsoResize", {
546         start: function (event, ui) {
547                 var that = $(this).data("resizable"), o = that.options;
549                 var _store = function (exp) {
550                         $(exp).each(function() {
551                                 var el = $(this);
552                                 el.data("resizable-alsoresize", {
553                                         width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
554                                         left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10)
555                                 });
556                         });
557                 };
559                 if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
560                         if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
561                         else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
562                 }else{
563                         _store(o.alsoResize);
564                 }
565         },
567         resize: function (event, ui) {
568                 var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition;
570                 var delta = {
571                         height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
572                         top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
573                 },
575                 _alsoResize = function (exp, c) {
576                         $(exp).each(function() {
577                                 var el = $(this), start = $(this).data("resizable-alsoresize"), style = {},
578                                         css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left'];
580                                 $.each(css, function (i, prop) {
581                                         var sum = (start[prop]||0) + (delta[prop]||0);
582                                         if (sum && sum >= 0)
583                                                 style[prop] = sum || null;
584                                 });
586                                 el.css(style);
587                         });
588                 };
590                 if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
591                         $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
592                 }else{
593                         _alsoResize(o.alsoResize);
594                 }
595         },
597         stop: function (event, ui) {
598                 $(this).removeData("resizable-alsoresize");
599         }
602 $.ui.plugin.add("resizable", "animate", {
604         stop: function(event, ui) {
605                 var that = $(this).data("resizable"), o = that.options;
607                 var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
608                                         soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
609                                                 soffsetw = ista ? 0 : that.sizeDiff.width;
611                 var style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
612                                         left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
613                                                 top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
615                 that.element.animate(
616                         $.extend(style, top && left ? { top: top, left: left } : {}), {
617                                 duration: o.animateDuration,
618                                 easing: o.animateEasing,
619                                 step: function() {
621                                         var data = {
622                                                 width: parseInt(that.element.css('width'), 10),
623                                                 height: parseInt(that.element.css('height'), 10),
624                                                 top: parseInt(that.element.css('top'), 10),
625                                                 left: parseInt(that.element.css('left'), 10)
626                                         };
628                                         if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });
630                                         // propagating resize, and updating values for each animation step
631                                         that._updateCache(data);
632                                         that._propagate("resize", event);
634                                 }
635                         }
636                 );
637         }
641 $.ui.plugin.add("resizable", "containment", {
643         start: function(event, ui) {
644                 var that = $(this).data("resizable"), o = that.options, el = that.element;
645                 var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
646                 if (!ce) return;
648                 that.containerElement = $(ce);
650                 if (/document/.test(oc) || oc == document) {
651                         that.containerOffset = { left: 0, top: 0 };
652                         that.containerPosition = { left: 0, top: 0 };
654                         that.parentData = {
655                                 element: $(document), left: 0, top: 0,
656                                 width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
657                         };
658                 }
660                 // i'm a node, so compute top, left, right, bottom
661                 else {
662                         var element = $(ce), p = [];
663                         $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
665                         that.containerOffset = element.offset();
666                         that.containerPosition = element.position();
667                         that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
669                         var co = that.containerOffset, ch = that.containerSize.height,  cw = that.containerSize.width,
670                                                 width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
672                         that.parentData = {
673                                 element: ce, left: co.left, top: co.top, width: width, height: height
674                         };
675                 }
676         },
678         resize: function(event, ui) {
679                 var that = $(this).data("resizable"), o = that.options,
680                                 ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position,
681                                 pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement;
683                 if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
685                 if (cp.left < (that._helper ? co.left : 0)) {
686                         that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
687                         if (pRatio) that.size.height = that.size.width / that.aspectRatio;
688                         that.position.left = o.helper ? co.left : 0;
689                 }
691                 if (cp.top < (that._helper ? co.top : 0)) {
692                         that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
693                         if (pRatio) that.size.width = that.size.height * that.aspectRatio;
694                         that.position.top = that._helper ? co.top : 0;
695                 }
697                 that.offset.left = that.parentData.left+that.position.left;
698                 that.offset.top = that.parentData.top+that.position.top;
700                 var woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width ),
701                                         hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
703                 var isParent = that.containerElement.get(0) == that.element.parent().get(0),
704                         isOffsetRelative = /relative|absolute/.test(that.containerElement.css('position'));
706                 if(isParent && isOffsetRelative) woset -= that.parentData.left;
708                 if (woset + that.size.width >= that.parentData.width) {
709                         that.size.width = that.parentData.width - woset;
710                         if (pRatio) that.size.height = that.size.width / that.aspectRatio;
711                 }
713                 if (hoset + that.size.height >= that.parentData.height) {
714                         that.size.height = that.parentData.height - hoset;
715                         if (pRatio) that.size.width = that.size.height * that.aspectRatio;
716                 }
717         },
719         stop: function(event, ui){
720                 var that = $(this).data("resizable"), o = that.options, cp = that.position,
721                                 co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement;
723                 var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height;
725                 if (that._helper && !o.animate && (/relative/).test(ce.css('position')))
726                         $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
728                 if (that._helper && !o.animate && (/static/).test(ce.css('position')))
729                         $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
731         }
734 $.ui.plugin.add("resizable", "ghost", {
736         start: function(event, ui) {
738                 var that = $(this).data("resizable"), o = that.options, cs = that.size;
740                 that.ghost = that.originalElement.clone();
741                 that.ghost
742                         .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
743                         .addClass('ui-resizable-ghost')
744                         .addClass(typeof o.ghost == 'string' ? o.ghost : '');
746                 that.ghost.appendTo(that.helper);
748         },
750         resize: function(event, ui){
751                 var that = $(this).data("resizable"), o = that.options;
752                 if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width });
753         },
755         stop: function(event, ui){
756                 var that = $(this).data("resizable"), o = that.options;
757                 if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0));
758         }
762 $.ui.plugin.add("resizable", "grid", {
764         resize: function(event, ui) {
765                 var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis, ratio = o._aspectRatio || event.shiftKey;
766                 o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
767                 var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1);
769                 if (/^(se|s|e)$/.test(a)) {
770                         that.size.width = os.width + ox;
771                         that.size.height = os.height + oy;
772                 }
773                 else if (/^(ne)$/.test(a)) {
774                         that.size.width = os.width + ox;
775                         that.size.height = os.height + oy;
776                         that.position.top = op.top - oy;
777                 }
778                 else if (/^(sw)$/.test(a)) {
779                         that.size.width = os.width + ox;
780                         that.size.height = os.height + oy;
781                         that.position.left = op.left - ox;
782                 }
783                 else {
784                         that.size.width = os.width + ox;
785                         that.size.height = os.height + oy;
786                         that.position.top = op.top - oy;
787                         that.position.left = op.left - ox;
788                 }
789         }
793 var num = function(v) {
794         return parseInt(v, 10) || 0;
797 var isNumber = function(value) {
798         return !isNaN(parseInt(value, 10));
801 })(jQuery);