Merge "Typo fix"
[mediawiki.git] / resources / jquery.ui / jquery.ui.resizable.js
blob6cc6f41fb65f63c53f1f7e9b4370542d88e4ef08
1 /*!
2  * jQuery UI Resizable 1.8.24
3  *
4  * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
5  * Dual licensed under the MIT or GPL Version 2 licenses.
6  * http://jquery.org/license
7  *
8  * http://docs.jquery.com/UI/Resizables
9  *
10  * Depends:
11  *      jquery.ui.core.js
12  *      jquery.ui.mouse.js
13  *      jquery.ui.widget.js
14  */
15 (function( $, undefined ) {
17 $.widget("ui.resizable", $.ui.mouse, {
18         widgetEventPrefix: "resize",
19         options: {
20                 alsoResize: false,
21                 animate: false,
22                 animateDuration: "slow",
23                 animateEasing: "swing",
24                 aspectRatio: false,
25                 autoHide: false,
26                 containment: false,
27                 ghost: false,
28                 grid: false,
29                 handles: "e,s,se",
30                 helper: false,
31                 maxHeight: null,
32                 maxWidth: null,
33                 minHeight: 10,
34                 minWidth: 10,
35                 zIndex: 1000
36         },
37         _create: function() {
39                 var self = this, o = this.options;
40                 this.element.addClass("ui-resizable");
42                 $.extend(this, {
43                         _aspectRatio: !!(o.aspectRatio),
44                         aspectRatio: o.aspectRatio,
45                         originalElement: this.element,
46                         _proportionallyResizeElements: [],
47                         _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
48                 });
50                 //Wrap the element if it cannot hold child nodes
51                 if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
53                         //Create a wrapper element and set the wrapper to the new current internal element
54                         this.element.wrap(
55                                 $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
56                                         position: this.element.css('position'),
57                                         width: this.element.outerWidth(),
58                                         height: this.element.outerHeight(),
59                                         top: this.element.css('top'),
60                                         left: this.element.css('left')
61                                 })
62                         );
64                         //Overwrite the original this.element
65                         this.element = this.element.parent().data(
66                                 "resizable", this.element.data('resizable')
67                         );
69                         this.elementIsWrapper = true;
71                         //Move margins to the wrapper
72                         this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
73                         this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
75                         //Prevent Safari textarea resize
76                         this.originalResizeStyle = this.originalElement.css('resize');
77                         this.originalElement.css('resize', 'none');
79                         //Push the actual element to our proportionallyResize internal array
80                         this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
82                         // avoid IE jump (hard set the margin)
83                         this.originalElement.css({ margin: this.originalElement.css('margin') });
85                         // fix handlers offset
86                         this._proportionallyResize();
88                 }
90                 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' });
91                 if(this.handles.constructor == String) {
93                         if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
94                         var n = this.handles.split(","); this.handles = {};
96                         for(var i = 0; i < n.length; i++) {
98                                 var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
99                                 var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
101                                 // Apply zIndex to all handles - see #7960
102                                 axis.css({ zIndex: o.zIndex });
104                                 //TODO : What's going on here?
105                                 if ('se' == handle) {
106                                         axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
107                                 };
109                                 //Insert into internal handles object and append to element
110                                 this.handles[handle] = '.ui-resizable-'+handle;
111                                 this.element.append(axis);
112                         }
114                 }
116                 this._renderAxis = function(target) {
118                         target = target || this.element;
120                         for(var i in this.handles) {
122                                 if(this.handles[i].constructor == String)
123                                         this.handles[i] = $(this.handles[i], this.element).show();
125                                 //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
126                                 if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
128                                         var axis = $(this.handles[i], this.element), padWrapper = 0;
130                                         //Checking the correct pad and border
131                                         padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
133                                         //The padding type i have to apply...
134                                         var padPos = [ 'padding',
135                                                 /ne|nw|n/.test(i) ? 'Top' :
136                                                 /se|sw|s/.test(i) ? 'Bottom' :
137                                                 /^e$/.test(i) ? 'Right' : 'Left' ].join("");
139                                         target.css(padPos, padWrapper);
141                                         this._proportionallyResize();
143                                 }
145                                 //TODO: What's that good for? There's not anything to be executed left
146                                 if(!$(this.handles[i]).length)
147                                         continue;
149                         }
150                 };
152                 //TODO: make renderAxis a prototype function
153                 this._renderAxis(this.element);
155                 this._handles = $('.ui-resizable-handle', this.element)
156                         .disableSelection();
158                 //Matching axis name
159                 this._handles.mouseover(function() {
160                         if (!self.resizing) {
161                                 if (this.className)
162                                         var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
163                                 //Axis, default = se
164                                 self.axis = axis && axis[1] ? axis[1] : 'se';
165                         }
166                 });
168                 //If we want to auto hide the elements
169                 if (o.autoHide) {
170                         this._handles.hide();
171                         $(this.element)
172                                 .addClass("ui-resizable-autohide")
173                                 .hover(function() {
174                                         if (o.disabled) return;
175                                         $(this).removeClass("ui-resizable-autohide");
176                                         self._handles.show();
177                                 },
178                                 function(){
179                                         if (o.disabled) return;
180                                         if (!self.resizing) {
181                                                 $(this).addClass("ui-resizable-autohide");
182                                                 self._handles.hide();
183                                         }
184                                 });
185                 }
187                 //Initialize the mouse interaction
188                 this._mouseInit();
190         },
192         destroy: function() {
194                 this._mouseDestroy();
196                 var _destroy = function(exp) {
197                         $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
198                                 .removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
199                 };
201                 //TODO: Unwrap at same DOM position
202                 if (this.elementIsWrapper) {
203                         _destroy(this.element);
204                         var wrapper = this.element;
205                         wrapper.after(
206                                 this.originalElement.css({
207                                         position: wrapper.css('position'),
208                                         width: wrapper.outerWidth(),
209                                         height: wrapper.outerHeight(),
210                                         top: wrapper.css('top'),
211                                         left: wrapper.css('left')
212                                 })
213                         ).remove();
214                 }
216                 this.originalElement.css('resize', this.originalResizeStyle);
217                 _destroy(this.originalElement);
219                 return this;
220         },
222         _mouseCapture: function(event) {
223                 var handle = false;
224                 for (var i in this.handles) {
225                         if ($(this.handles[i])[0] == event.target) {
226                                 handle = true;
227                         }
228                 }
230                 return !this.options.disabled && handle;
231         },
233         _mouseStart: function(event) {
235                 var o = this.options, iniPos = this.element.position(), el = this.element;
237                 this.resizing = true;
238                 this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
240                 // bugfix for http://dev.jquery.com/ticket/1749
241                 if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
242                         el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
243                 }
245                 this._renderProxy();
247                 var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));
249                 if (o.containment) {
250                         curleft += $(o.containment).scrollLeft() || 0;
251                         curtop += $(o.containment).scrollTop() || 0;
252                 }
254                 //Store needed variables
255                 this.offset = this.helper.offset();
256                 this.position = { left: curleft, top: curtop };
257                 this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
258                 this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
259                 this.originalPosition = { left: curleft, top: curtop };
260                 this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
261                 this.originalMousePosition = { left: event.pageX, top: event.pageY };
263                 //Aspect Ratio
264                 this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
266             var cursor = $('.ui-resizable-' + this.axis).css('cursor');
267             $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor);
269                 el.addClass("ui-resizable-resizing");
270                 this._propagate("start", event);
271                 return true;
272         },
274         _mouseDrag: function(event) {
276                 //Increase performance, avoid regex
277                 var el = this.helper, o = this.options, props = {},
278                         self = this, smp = this.originalMousePosition, a = this.axis;
280                 var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
281                 var trigger = this._change[a];
282                 if (!trigger) return false;
284                 // Calculate the attrs that will be change
285                 var data = trigger.apply(this, [event, dx, dy]), ie6 = $.browser.msie && $.browser.version < 7, csdif = this.sizeDiff;
287                 // Put this in the mouseDrag handler since the user can start pressing shift while resizing
288                 this._updateVirtualBoundaries(event.shiftKey);
289                 if (this._aspectRatio || event.shiftKey)
290                         data = this._updateRatio(data, event);
292                 data = this._respectSize(data, event);
294                 // plugins callbacks need to be called first
295                 this._propagate("resize", event);
297                 el.css({
298                         top: this.position.top + "px", left: this.position.left + "px",
299                         width: this.size.width + "px", height: this.size.height + "px"
300                 });
302                 if (!this._helper && this._proportionallyResizeElements.length)
303                         this._proportionallyResize();
305                 this._updateCache(data);
307                 // calling the user callback at the end
308                 this._trigger('resize', event, this.ui());
310                 return false;
311         },
313         _mouseStop: function(event) {
315                 this.resizing = false;
316                 var o = this.options, self = this;
318                 if(this._helper) {
319                         var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
320                                 soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
321                                 soffsetw = ista ? 0 : self.sizeDiff.width;
323                         var s = { width: (self.helper.width()  - soffsetw), height: (self.helper.height() - soffseth) },
324                                 left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
325                                 top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
327                         if (!o.animate)
328                                 this.element.css($.extend(s, { top: top, left: left }));
330                         self.helper.height(self.size.height);
331                         self.helper.width(self.size.width);
333                         if (this._helper && !o.animate) this._proportionallyResize();
334                 }
336                 $('body').css('cursor', 'auto');
338                 this.element.removeClass("ui-resizable-resizing");
340                 this._propagate("stop", event);
342                 if (this._helper) this.helper.remove();
343                 return false;
345         },
347     _updateVirtualBoundaries: function(forceAspectRatio) {
348         var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b;
350         b = {
351             minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
352             maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
353             minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
354             maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
355         };
357         if(this._aspectRatio || forceAspectRatio) {
358             // We want to create an enclosing box whose aspect ration is the requested one
359             // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
360             pMinWidth = b.minHeight * this.aspectRatio;
361             pMinHeight = b.minWidth / this.aspectRatio;
362             pMaxWidth = b.maxHeight * this.aspectRatio;
363             pMaxHeight = b.maxWidth / this.aspectRatio;
365             if(pMinWidth > b.minWidth) b.minWidth = pMinWidth;
366             if(pMinHeight > b.minHeight) b.minHeight = pMinHeight;
367             if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth;
368             if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight;
369         }
370         this._vBoundaries = b;
371     },
373         _updateCache: function(data) {
374                 var o = this.options;
375                 this.offset = this.helper.offset();
376                 if (isNumber(data.left)) this.position.left = data.left;
377                 if (isNumber(data.top)) this.position.top = data.top;
378                 if (isNumber(data.height)) this.size.height = data.height;
379                 if (isNumber(data.width)) this.size.width = data.width;
380         },
382         _updateRatio: function(data, event) {
384                 var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
386                 if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
387                 else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
389                 if (a == 'sw') {
390                         data.left = cpos.left + (csize.width - data.width);
391                         data.top = null;
392                 }
393                 if (a == 'nw') {
394                         data.top = cpos.top + (csize.height - data.height);
395                         data.left = cpos.left + (csize.width - data.width);
396                 }
398                 return data;
399         },
401         _respectSize: function(data, event) {
403                 var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
404                                 ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
405                                         isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
407                 if (isminw) data.width = o.minWidth;
408                 if (isminh) data.height = o.minHeight;
409                 if (ismaxw) data.width = o.maxWidth;
410                 if (ismaxh) data.height = o.maxHeight;
412                 var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height;
413                 var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
415                 if (isminw && cw) data.left = dw - o.minWidth;
416                 if (ismaxw && cw) data.left = dw - o.maxWidth;
417                 if (isminh && ch)       data.top = dh - o.minHeight;
418                 if (ismaxh && ch)       data.top = dh - o.maxHeight;
420                 // fixing jump error on top/left - bug #2330
421                 var isNotwh = !data.width && !data.height;
422                 if (isNotwh && !data.left && data.top) data.top = null;
423                 else if (isNotwh && !data.top && data.left) data.left = null;
425                 return data;
426         },
428         _proportionallyResize: function() {
430                 var o = this.options;
431                 if (!this._proportionallyResizeElements.length) return;
432                 var element = this.helper || this.element;
434                 for (var i=0; i < this._proportionallyResizeElements.length; i++) {
436                         var prel = this._proportionallyResizeElements[i];
438                         if (!this.borderDif) {
439                                 var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')],
440                                         p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')];
442                                 this.borderDif = $.map(b, function(v, i) {
443                                         var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0;
444                                         return border + padding;
445                                 });
446                         }
448                         if ($.browser.msie && !(!($(element).is(':hidden') || $(element).parents(':hidden').length)))
449                                 continue;
451                         prel.css({
452                                 height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
453                                 width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
454                         });
456                 };
458         },
460         _renderProxy: function() {
462                 var el = this.element, o = this.options;
463                 this.elementOffset = el.offset();
465                 if(this._helper) {
467                         this.helper = this.helper || $('<div style="overflow:hidden;"></div>');
469                         // fix ie6 offset TODO: This seems broken
470                         var ie6 = $.browser.msie && $.browser.version < 7, ie6offset = (ie6 ? 1 : 0),
471                         pxyoffset = ( ie6 ? 2 : -1 );
473                         this.helper.addClass(this._helper).css({
474                                 width: this.element.outerWidth() + pxyoffset,
475                                 height: this.element.outerHeight() + pxyoffset,
476                                 position: 'absolute',
477                                 left: this.elementOffset.left - ie6offset +'px',
478                                 top: this.elementOffset.top - ie6offset +'px',
479                                 zIndex: ++o.zIndex //TODO: Don't modify option
480                         });
482                         this.helper
483                                 .appendTo("body")
484                                 .disableSelection();
486                 } else {
487                         this.helper = this.element;
488                 }
490         },
492         _change: {
493                 e: function(event, dx, dy) {
494                         return { width: this.originalSize.width + dx };
495                 },
496                 w: function(event, dx, dy) {
497                         var o = this.options, cs = this.originalSize, sp = this.originalPosition;
498                         return { left: sp.left + dx, width: cs.width - dx };
499                 },
500                 n: function(event, dx, dy) {
501                         var o = this.options, cs = this.originalSize, sp = this.originalPosition;
502                         return { top: sp.top + dy, height: cs.height - dy };
503                 },
504                 s: function(event, dx, dy) {
505                         return { height: this.originalSize.height + dy };
506                 },
507                 se: function(event, dx, dy) {
508                         return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
509                 },
510                 sw: function(event, dx, dy) {
511                         return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
512                 },
513                 ne: function(event, dx, dy) {
514                         return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
515                 },
516                 nw: function(event, dx, dy) {
517                         return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
518                 }
519         },
521         _propagate: function(n, event) {
522                 $.ui.plugin.call(this, n, [event, this.ui()]);
523                 (n != "resize" && this._trigger(n, event, this.ui()));
524         },
526         plugins: {},
528         ui: function() {
529                 return {
530                         originalElement: this.originalElement,
531                         element: this.element,
532                         helper: this.helper,
533                         position: this.position,
534                         size: this.size,
535                         originalSize: this.originalSize,
536                         originalPosition: this.originalPosition
537                 };
538         }
542 $.extend($.ui.resizable, {
543         version: "1.8.24"
547  * Resizable Extensions
548  */
550 $.ui.plugin.add("resizable", "alsoResize", {
552         start: function (event, ui) {
553                 var self = $(this).data("resizable"), o = self.options;
555                 var _store = function (exp) {
556                         $(exp).each(function() {
557                                 var el = $(this);
558                                 el.data("resizable-alsoresize", {
559                                         width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
560                                         left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10)
561                                 });
562                         });
563                 };
565                 if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
566                         if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
567                         else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
568                 }else{
569                         _store(o.alsoResize);
570                 }
571         },
573         resize: function (event, ui) {
574                 var self = $(this).data("resizable"), o = self.options, os = self.originalSize, op = self.originalPosition;
576                 var delta = {
577                         height: (self.size.height - os.height) || 0, width: (self.size.width - os.width) || 0,
578                         top: (self.position.top - op.top) || 0, left: (self.position.left - op.left) || 0
579                 },
581                 _alsoResize = function (exp, c) {
582                         $(exp).each(function() {
583                                 var el = $(this), start = $(this).data("resizable-alsoresize"), style = {}, 
584                                         css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left'];
586                                 $.each(css, function (i, prop) {
587                                         var sum = (start[prop]||0) + (delta[prop]||0);
588                                         if (sum && sum >= 0)
589                                                 style[prop] = sum || null;
590                                 });
592                                 el.css(style);
593                         });
594                 };
596                 if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
597                         $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
598                 }else{
599                         _alsoResize(o.alsoResize);
600                 }
601         },
603         stop: function (event, ui) {
604                 $(this).removeData("resizable-alsoresize");
605         }
608 $.ui.plugin.add("resizable", "animate", {
610         stop: function(event, ui) {
611                 var self = $(this).data("resizable"), o = self.options;
613                 var pr = self._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
614                                         soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
615                                                 soffsetw = ista ? 0 : self.sizeDiff.width;
617                 var style = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) },
618                                         left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
619                                                 top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
621                 self.element.animate(
622                         $.extend(style, top && left ? { top: top, left: left } : {}), {
623                                 duration: o.animateDuration,
624                                 easing: o.animateEasing,
625                                 step: function() {
627                                         var data = {
628                                                 width: parseInt(self.element.css('width'), 10),
629                                                 height: parseInt(self.element.css('height'), 10),
630                                                 top: parseInt(self.element.css('top'), 10),
631                                                 left: parseInt(self.element.css('left'), 10)
632                                         };
634                                         if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });
636                                         // propagating resize, and updating values for each animation step
637                                         self._updateCache(data);
638                                         self._propagate("resize", event);
640                                 }
641                         }
642                 );
643         }
647 $.ui.plugin.add("resizable", "containment", {
649         start: function(event, ui) {
650                 var self = $(this).data("resizable"), o = self.options, el = self.element;
651                 var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
652                 if (!ce) return;
654                 self.containerElement = $(ce);
656                 if (/document/.test(oc) || oc == document) {
657                         self.containerOffset = { left: 0, top: 0 };
658                         self.containerPosition = { left: 0, top: 0 };
660                         self.parentData = {
661                                 element: $(document), left: 0, top: 0,
662                                 width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
663                         };
664                 }
666                 // i'm a node, so compute top, left, right, bottom
667                 else {
668                         var element = $(ce), p = [];
669                         $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
671                         self.containerOffset = element.offset();
672                         self.containerPosition = element.position();
673                         self.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
675                         var co = self.containerOffset, ch = self.containerSize.height,  cw = self.containerSize.width,
676                                                 width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
678                         self.parentData = {
679                                 element: ce, left: co.left, top: co.top, width: width, height: height
680                         };
681                 }
682         },
684         resize: function(event, ui) {
685                 var self = $(this).data("resizable"), o = self.options,
686                                 ps = self.containerSize, co = self.containerOffset, cs = self.size, cp = self.position,
687                                 pRatio = self._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = self.containerElement;
689                 if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
691                 if (cp.left < (self._helper ? co.left : 0)) {
692                         self.size.width = self.size.width + (self._helper ? (self.position.left - co.left) : (self.position.left - cop.left));
693                         if (pRatio) self.size.height = self.size.width / self.aspectRatio;
694                         self.position.left = o.helper ? co.left : 0;
695                 }
697                 if (cp.top < (self._helper ? co.top : 0)) {
698                         self.size.height = self.size.height + (self._helper ? (self.position.top - co.top) : self.position.top);
699                         if (pRatio) self.size.width = self.size.height * self.aspectRatio;
700                         self.position.top = self._helper ? co.top : 0;
701                 }
703                 self.offset.left = self.parentData.left+self.position.left;
704                 self.offset.top = self.parentData.top+self.position.top;
706                 var woset = Math.abs( (self._helper ? self.offset.left - cop.left : (self.offset.left - cop.left)) + self.sizeDiff.width ),
707                                         hoset = Math.abs( (self._helper ? self.offset.top - cop.top : (self.offset.top - co.top)) + self.sizeDiff.height );
709                 var isParent = self.containerElement.get(0) == self.element.parent().get(0),
710                     isOffsetRelative = /relative|absolute/.test(self.containerElement.css('position'));
712                 if(isParent && isOffsetRelative) woset -= self.parentData.left;
714                 if (woset + self.size.width >= self.parentData.width) {
715                         self.size.width = self.parentData.width - woset;
716                         if (pRatio) self.size.height = self.size.width / self.aspectRatio;
717                 }
719                 if (hoset + self.size.height >= self.parentData.height) {
720                         self.size.height = self.parentData.height - hoset;
721                         if (pRatio) self.size.width = self.size.height * self.aspectRatio;
722                 }
723         },
725         stop: function(event, ui){
726                 var self = $(this).data("resizable"), o = self.options, cp = self.position,
727                                 co = self.containerOffset, cop = self.containerPosition, ce = self.containerElement;
729                 var helper = $(self.helper), ho = helper.offset(), w = helper.outerWidth() - self.sizeDiff.width, h = helper.outerHeight() - self.sizeDiff.height;
731                 if (self._helper && !o.animate && (/relative/).test(ce.css('position')))
732                         $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
734                 if (self._helper && !o.animate && (/static/).test(ce.css('position')))
735                         $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
737         }
740 $.ui.plugin.add("resizable", "ghost", {
742         start: function(event, ui) {
744                 var self = $(this).data("resizable"), o = self.options, cs = self.size;
746                 self.ghost = self.originalElement.clone();
747                 self.ghost
748                         .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
749                         .addClass('ui-resizable-ghost')
750                         .addClass(typeof o.ghost == 'string' ? o.ghost : '');
752                 self.ghost.appendTo(self.helper);
754         },
756         resize: function(event, ui){
757                 var self = $(this).data("resizable"), o = self.options;
758                 if (self.ghost) self.ghost.css({ position: 'relative', height: self.size.height, width: self.size.width });
759         },
761         stop: function(event, ui){
762                 var self = $(this).data("resizable"), o = self.options;
763                 if (self.ghost && self.helper) self.helper.get(0).removeChild(self.ghost.get(0));
764         }
768 $.ui.plugin.add("resizable", "grid", {
770         resize: function(event, ui) {
771                 var self = $(this).data("resizable"), o = self.options, cs = self.size, os = self.originalSize, op = self.originalPosition, a = self.axis, ratio = o._aspectRatio || event.shiftKey;
772                 o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
773                 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);
775                 if (/^(se|s|e)$/.test(a)) {
776                         self.size.width = os.width + ox;
777                         self.size.height = os.height + oy;
778                 }
779                 else if (/^(ne)$/.test(a)) {
780                         self.size.width = os.width + ox;
781                         self.size.height = os.height + oy;
782                         self.position.top = op.top - oy;
783                 }
784                 else if (/^(sw)$/.test(a)) {
785                         self.size.width = os.width + ox;
786                         self.size.height = os.height + oy;
787                         self.position.left = op.left - ox;
788                 }
789                 else {
790                         self.size.width = os.width + ox;
791                         self.size.height = os.height + oy;
792                         self.position.top = op.top - oy;
793                         self.position.left = op.left - ox;
794                 }
795         }
799 var num = function(v) {
800         return parseInt(v, 10) || 0;
803 var isNumber = function(value) {
804         return !isNaN(parseInt(value, 10));
807 })(jQuery);