PageRenderTime 81ms CodeModel.GetById 18ms app.highlight 54ms RepoModel.GetById 1ms app.codeStats 0ms

/application/static/libs/adminlte/bower_components/jquery-ui/ui/resizable.js

https://bitbucket.org/tin_gimranoff/docstar
JavaScript | 1152 lines | 916 code | 204 blank | 32 comment | 184 complexity | e0b834c44eb620df8b4332e38ee55807 MD5 | raw file
   1/*!
   2 * jQuery UI Resizable 1.11.4
   3 * http://jqueryui.com
   4 *
   5 * Copyright 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(function( factory ) {
  12	if ( typeof define === "function" && define.amd ) {
  13
  14		// AMD. Register as an anonymous module.
  15		define([
  16			"jquery",
  17			"./core",
  18			"./mouse",
  19			"./widget"
  20		], factory );
  21	} else {
  22
  23		// Browser globals
  24		factory( jQuery );
  25	}
  26}(function( $ ) {
  27
  28$.widget("ui.resizable", $.ui.mouse, {
  29	version: "1.11.4",
  30	widgetEventPrefix: "resize",
  31	options: {
  32		alsoResize: false,
  33		animate: false,
  34		animateDuration: "slow",
  35		animateEasing: "swing",
  36		aspectRatio: false,
  37		autoHide: false,
  38		containment: false,
  39		ghost: false,
  40		grid: false,
  41		handles: "e,s,se",
  42		helper: false,
  43		maxHeight: null,
  44		maxWidth: null,
  45		minHeight: 10,
  46		minWidth: 10,
  47		// See #7960
  48		zIndex: 90,
  49
  50		// callbacks
  51		resize: null,
  52		start: null,
  53		stop: null
  54	},
  55
  56	_num: function( value ) {
  57		return parseInt( value, 10 ) || 0;
  58	},
  59
  60	_isNumber: function( value ) {
  61		return !isNaN( parseInt( value, 10 ) );
  62	},
  63
  64	_hasScroll: function( el, a ) {
  65
  66		if ( $( el ).css( "overflow" ) === "hidden") {
  67			return false;
  68		}
  69
  70		var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  71			has = false;
  72
  73		if ( el[ scroll ] > 0 ) {
  74			return true;
  75		}
  76
  77		// TODO: determine which cases actually cause this to happen
  78		// if the element doesn't have the scroll set, see if it's possible to
  79		// set the scroll
  80		el[ scroll ] = 1;
  81		has = ( el[ scroll ] > 0 );
  82		el[ scroll ] = 0;
  83		return has;
  84	},
  85
  86	_create: function() {
  87
  88		var n, i, handle, axis, hname,
  89			that = this,
  90			o = this.options;
  91		this.element.addClass("ui-resizable");
  92
  93		$.extend(this, {
  94			_aspectRatio: !!(o.aspectRatio),
  95			aspectRatio: o.aspectRatio,
  96			originalElement: this.element,
  97			_proportionallyResizeElements: [],
  98			_helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
  99		});
 100
 101		// Wrap the element if it cannot hold child nodes
 102		if (this.element[0].nodeName.match(/^(canvas|textarea|input|select|button|img)$/i)) {
 103
 104			this.element.wrap(
 105				$("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
 106					position: this.element.css("position"),
 107					width: this.element.outerWidth(),
 108					height: this.element.outerHeight(),
 109					top: this.element.css("top"),
 110					left: this.element.css("left")
 111				})
 112			);
 113
 114			this.element = this.element.parent().data(
 115				"ui-resizable", this.element.resizable( "instance" )
 116			);
 117
 118			this.elementIsWrapper = true;
 119
 120			this.element.css({
 121				marginLeft: this.originalElement.css("marginLeft"),
 122				marginTop: this.originalElement.css("marginTop"),
 123				marginRight: this.originalElement.css("marginRight"),
 124				marginBottom: this.originalElement.css("marginBottom")
 125			});
 126			this.originalElement.css({
 127				marginLeft: 0,
 128				marginTop: 0,
 129				marginRight: 0,
 130				marginBottom: 0
 131			});
 132			// support: Safari
 133			// Prevent Safari textarea resize
 134			this.originalResizeStyle = this.originalElement.css("resize");
 135			this.originalElement.css("resize", "none");
 136
 137			this._proportionallyResizeElements.push( this.originalElement.css({
 138				position: "static",
 139				zoom: 1,
 140				display: "block"
 141			}) );
 142
 143			// support: IE9
 144			// avoid IE jump (hard set the margin)
 145			this.originalElement.css({ margin: this.originalElement.css("margin") });
 146
 147			this._proportionallyResize();
 148		}
 149
 150		this.handles = o.handles ||
 151			( !$(".ui-resizable-handle", this.element).length ?
 152				"e,s,se" : {
 153					n: ".ui-resizable-n",
 154					e: ".ui-resizable-e",
 155					s: ".ui-resizable-s",
 156					w: ".ui-resizable-w",
 157					se: ".ui-resizable-se",
 158					sw: ".ui-resizable-sw",
 159					ne: ".ui-resizable-ne",
 160					nw: ".ui-resizable-nw"
 161				} );
 162
 163		this._handles = $();
 164		if ( this.handles.constructor === String ) {
 165
 166			if ( this.handles === "all") {
 167				this.handles = "n,e,s,w,se,sw,ne,nw";
 168			}
 169
 170			n = this.handles.split(",");
 171			this.handles = {};
 172
 173			for (i = 0; i < n.length; i++) {
 174
 175				handle = $.trim(n[i]);
 176				hname = "ui-resizable-" + handle;
 177				axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
 178
 179				axis.css({ zIndex: o.zIndex });
 180
 181				// TODO : What's going on here?
 182				if ("se" === handle) {
 183					axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
 184				}
 185
 186				this.handles[handle] = ".ui-resizable-" + handle;
 187				this.element.append(axis);
 188			}
 189
 190		}
 191
 192		this._renderAxis = function(target) {
 193
 194			var i, axis, padPos, padWrapper;
 195
 196			target = target || this.element;
 197
 198			for (i in this.handles) {
 199
 200				if (this.handles[i].constructor === String) {
 201					this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
 202				} else if ( this.handles[ i ].jquery || this.handles[ i ].nodeType ) {
 203					this.handles[ i ] = $( this.handles[ i ] );
 204					this._on( this.handles[ i ], { "mousedown": that._mouseDown });
 205				}
 206
 207				if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)) {
 208
 209					axis = $(this.handles[i], this.element);
 210
 211					padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
 212
 213					padPos = [ "padding",
 214						/ne|nw|n/.test(i) ? "Top" :
 215						/se|sw|s/.test(i) ? "Bottom" :
 216						/^e$/.test(i) ? "Right" : "Left" ].join("");
 217
 218					target.css(padPos, padWrapper);
 219
 220					this._proportionallyResize();
 221				}
 222
 223				this._handles = this._handles.add( this.handles[ i ] );
 224			}
 225		};
 226
 227		// TODO: make renderAxis a prototype function
 228		this._renderAxis(this.element);
 229
 230		this._handles = this._handles.add( this.element.find( ".ui-resizable-handle" ) );
 231		this._handles.disableSelection();
 232
 233		this._handles.mouseover(function() {
 234			if (!that.resizing) {
 235				if (this.className) {
 236					axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
 237				}
 238				that.axis = axis && axis[1] ? axis[1] : "se";
 239			}
 240		});
 241
 242		if (o.autoHide) {
 243			this._handles.hide();
 244			$(this.element)
 245				.addClass("ui-resizable-autohide")
 246				.mouseenter(function() {
 247					if (o.disabled) {
 248						return;
 249					}
 250					$(this).removeClass("ui-resizable-autohide");
 251					that._handles.show();
 252				})
 253				.mouseleave(function() {
 254					if (o.disabled) {
 255						return;
 256					}
 257					if (!that.resizing) {
 258						$(this).addClass("ui-resizable-autohide");
 259						that._handles.hide();
 260					}
 261				});
 262		}
 263
 264		this._mouseInit();
 265	},
 266
 267	_destroy: function() {
 268
 269		this._mouseDestroy();
 270
 271		var wrapper,
 272			_destroy = function(exp) {
 273				$(exp)
 274					.removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
 275					.removeData("resizable")
 276					.removeData("ui-resizable")
 277					.unbind(".resizable")
 278					.find(".ui-resizable-handle")
 279						.remove();
 280			};
 281
 282		// TODO: Unwrap at same DOM position
 283		if (this.elementIsWrapper) {
 284			_destroy(this.element);
 285			wrapper = this.element;
 286			this.originalElement.css({
 287				position: wrapper.css("position"),
 288				width: wrapper.outerWidth(),
 289				height: wrapper.outerHeight(),
 290				top: wrapper.css("top"),
 291				left: wrapper.css("left")
 292			}).insertAfter( wrapper );
 293			wrapper.remove();
 294		}
 295
 296		this.originalElement.css("resize", this.originalResizeStyle);
 297		_destroy(this.originalElement);
 298
 299		return this;
 300	},
 301
 302	_mouseCapture: function(event) {
 303		var i, handle,
 304			capture = false;
 305
 306		for (i in this.handles) {
 307			handle = $(this.handles[i])[0];
 308			if (handle === event.target || $.contains(handle, event.target)) {
 309				capture = true;
 310			}
 311		}
 312
 313		return !this.options.disabled && capture;
 314	},
 315
 316	_mouseStart: function(event) {
 317
 318		var curleft, curtop, cursor,
 319			o = this.options,
 320			el = this.element;
 321
 322		this.resizing = true;
 323
 324		this._renderProxy();
 325
 326		curleft = this._num(this.helper.css("left"));
 327		curtop = this._num(this.helper.css("top"));
 328
 329		if (o.containment) {
 330			curleft += $(o.containment).scrollLeft() || 0;
 331			curtop += $(o.containment).scrollTop() || 0;
 332		}
 333
 334		this.offset = this.helper.offset();
 335		this.position = { left: curleft, top: curtop };
 336
 337		this.size = this._helper ? {
 338				width: this.helper.width(),
 339				height: this.helper.height()
 340			} : {
 341				width: el.width(),
 342				height: el.height()
 343			};
 344
 345		this.originalSize = this._helper ? {
 346				width: el.outerWidth(),
 347				height: el.outerHeight()
 348			} : {
 349				width: el.width(),
 350				height: el.height()
 351			};
 352
 353		this.sizeDiff = {
 354			width: el.outerWidth() - el.width(),
 355			height: el.outerHeight() - el.height()
 356		};
 357
 358		this.originalPosition = { left: curleft, top: curtop };
 359		this.originalMousePosition = { left: event.pageX, top: event.pageY };
 360
 361		this.aspectRatio = (typeof o.aspectRatio === "number") ?
 362			o.aspectRatio :
 363			((this.originalSize.width / this.originalSize.height) || 1);
 364
 365		cursor = $(".ui-resizable-" + this.axis).css("cursor");
 366		$("body").css("cursor", cursor === "auto" ? this.axis + "-resize" : cursor);
 367
 368		el.addClass("ui-resizable-resizing");
 369		this._propagate("start", event);
 370		return true;
 371	},
 372
 373	_mouseDrag: function(event) {
 374
 375		var data, props,
 376			smp = this.originalMousePosition,
 377			a = this.axis,
 378			dx = (event.pageX - smp.left) || 0,
 379			dy = (event.pageY - smp.top) || 0,
 380			trigger = this._change[a];
 381
 382		this._updatePrevProperties();
 383
 384		if (!trigger) {
 385			return false;
 386		}
 387
 388		data = trigger.apply(this, [ event, dx, dy ]);
 389
 390		this._updateVirtualBoundaries(event.shiftKey);
 391		if (this._aspectRatio || event.shiftKey) {
 392			data = this._updateRatio(data, event);
 393		}
 394
 395		data = this._respectSize(data, event);
 396
 397		this._updateCache(data);
 398
 399		this._propagate("resize", event);
 400
 401		props = this._applyChanges();
 402
 403		if ( !this._helper && this._proportionallyResizeElements.length ) {
 404			this._proportionallyResize();
 405		}
 406
 407		if ( !$.isEmptyObject( props ) ) {
 408			this._updatePrevProperties();
 409			this._trigger( "resize", event, this.ui() );
 410			this._applyChanges();
 411		}
 412
 413		return false;
 414	},
 415
 416	_mouseStop: function(event) {
 417
 418		this.resizing = false;
 419		var pr, ista, soffseth, soffsetw, s, left, top,
 420			o = this.options, that = this;
 421
 422		if (this._helper) {
 423
 424			pr = this._proportionallyResizeElements;
 425			ista = pr.length && (/textarea/i).test(pr[0].nodeName);
 426			soffseth = ista && this._hasScroll(pr[0], "left") ? 0 : that.sizeDiff.height;
 427			soffsetw = ista ? 0 : that.sizeDiff.width;
 428
 429			s = {
 430				width: (that.helper.width()  - soffsetw),
 431				height: (that.helper.height() - soffseth)
 432			};
 433			left = (parseInt(that.element.css("left"), 10) +
 434				(that.position.left - that.originalPosition.left)) || null;
 435			top = (parseInt(that.element.css("top"), 10) +
 436				(that.position.top - that.originalPosition.top)) || null;
 437
 438			if (!o.animate) {
 439				this.element.css($.extend(s, { top: top, left: left }));
 440			}
 441
 442			that.helper.height(that.size.height);
 443			that.helper.width(that.size.width);
 444
 445			if (this._helper && !o.animate) {
 446				this._proportionallyResize();
 447			}
 448		}
 449
 450		$("body").css("cursor", "auto");
 451
 452		this.element.removeClass("ui-resizable-resizing");
 453
 454		this._propagate("stop", event);
 455
 456		if (this._helper) {
 457			this.helper.remove();
 458		}
 459
 460		return false;
 461
 462	},
 463
 464	_updatePrevProperties: function() {
 465		this.prevPosition = {
 466			top: this.position.top,
 467			left: this.position.left
 468		};
 469		this.prevSize = {
 470			width: this.size.width,
 471			height: this.size.height
 472		};
 473	},
 474
 475	_applyChanges: function() {
 476		var props = {};
 477
 478		if ( this.position.top !== this.prevPosition.top ) {
 479			props.top = this.position.top + "px";
 480		}
 481		if ( this.position.left !== this.prevPosition.left ) {
 482			props.left = this.position.left + "px";
 483		}
 484		if ( this.size.width !== this.prevSize.width ) {
 485			props.width = this.size.width + "px";
 486		}
 487		if ( this.size.height !== this.prevSize.height ) {
 488			props.height = this.size.height + "px";
 489		}
 490
 491		this.helper.css( props );
 492
 493		return props;
 494	},
 495
 496	_updateVirtualBoundaries: function(forceAspectRatio) {
 497		var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
 498			o = this.options;
 499
 500		b = {
 501			minWidth: this._isNumber(o.minWidth) ? o.minWidth : 0,
 502			maxWidth: this._isNumber(o.maxWidth) ? o.maxWidth : Infinity,
 503			minHeight: this._isNumber(o.minHeight) ? o.minHeight : 0,
 504			maxHeight: this._isNumber(o.maxHeight) ? o.maxHeight : Infinity
 505		};
 506
 507		if (this._aspectRatio || forceAspectRatio) {
 508			pMinWidth = b.minHeight * this.aspectRatio;
 509			pMinHeight = b.minWidth / this.aspectRatio;
 510			pMaxWidth = b.maxHeight * this.aspectRatio;
 511			pMaxHeight = b.maxWidth / this.aspectRatio;
 512
 513			if (pMinWidth > b.minWidth) {
 514				b.minWidth = pMinWidth;
 515			}
 516			if (pMinHeight > b.minHeight) {
 517				b.minHeight = pMinHeight;
 518			}
 519			if (pMaxWidth < b.maxWidth) {
 520				b.maxWidth = pMaxWidth;
 521			}
 522			if (pMaxHeight < b.maxHeight) {
 523				b.maxHeight = pMaxHeight;
 524			}
 525		}
 526		this._vBoundaries = b;
 527	},
 528
 529	_updateCache: function(data) {
 530		this.offset = this.helper.offset();
 531		if (this._isNumber(data.left)) {
 532			this.position.left = data.left;
 533		}
 534		if (this._isNumber(data.top)) {
 535			this.position.top = data.top;
 536		}
 537		if (this._isNumber(data.height)) {
 538			this.size.height = data.height;
 539		}
 540		if (this._isNumber(data.width)) {
 541			this.size.width = data.width;
 542		}
 543	},
 544
 545	_updateRatio: function( data ) {
 546
 547		var cpos = this.position,
 548			csize = this.size,
 549			a = this.axis;
 550
 551		if (this._isNumber(data.height)) {
 552			data.width = (data.height * this.aspectRatio);
 553		} else if (this._isNumber(data.width)) {
 554			data.height = (data.width / this.aspectRatio);
 555		}
 556
 557		if (a === "sw") {
 558			data.left = cpos.left + (csize.width - data.width);
 559			data.top = null;
 560		}
 561		if (a === "nw") {
 562			data.top = cpos.top + (csize.height - data.height);
 563			data.left = cpos.left + (csize.width - data.width);
 564		}
 565
 566		return data;
 567	},
 568
 569	_respectSize: function( data ) {
 570
 571		var o = this._vBoundaries,
 572			a = this.axis,
 573			ismaxw = this._isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width),
 574			ismaxh = this._isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
 575			isminw = this._isNumber(data.width) && o.minWidth && (o.minWidth > data.width),
 576			isminh = this._isNumber(data.height) && o.minHeight && (o.minHeight > data.height),
 577			dw = this.originalPosition.left + this.originalSize.width,
 578			dh = this.position.top + this.size.height,
 579			cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
 580		if (isminw) {
 581			data.width = o.minWidth;
 582		}
 583		if (isminh) {
 584			data.height = o.minHeight;
 585		}
 586		if (ismaxw) {
 587			data.width = o.maxWidth;
 588		}
 589		if (ismaxh) {
 590			data.height = o.maxHeight;
 591		}
 592
 593		if (isminw && cw) {
 594			data.left = dw - o.minWidth;
 595		}
 596		if (ismaxw && cw) {
 597			data.left = dw - o.maxWidth;
 598		}
 599		if (isminh && ch) {
 600			data.top = dh - o.minHeight;
 601		}
 602		if (ismaxh && ch) {
 603			data.top = dh - o.maxHeight;
 604		}
 605
 606		// Fixing jump error on top/left - bug #2330
 607		if (!data.width && !data.height && !data.left && data.top) {
 608			data.top = null;
 609		} else if (!data.width && !data.height && !data.top && data.left) {
 610			data.left = null;
 611		}
 612
 613		return data;
 614	},
 615
 616	_getPaddingPlusBorderDimensions: function( element ) {
 617		var i = 0,
 618			widths = [],
 619			borders = [
 620				element.css( "borderTopWidth" ),
 621				element.css( "borderRightWidth" ),
 622				element.css( "borderBottomWidth" ),
 623				element.css( "borderLeftWidth" )
 624			],
 625			paddings = [
 626				element.css( "paddingTop" ),
 627				element.css( "paddingRight" ),
 628				element.css( "paddingBottom" ),
 629				element.css( "paddingLeft" )
 630			];
 631
 632		for ( ; i < 4; i++ ) {
 633			widths[ i ] = ( parseInt( borders[ i ], 10 ) || 0 );
 634			widths[ i ] += ( parseInt( paddings[ i ], 10 ) || 0 );
 635		}
 636
 637		return {
 638			height: widths[ 0 ] + widths[ 2 ],
 639			width: widths[ 1 ] + widths[ 3 ]
 640		};
 641	},
 642
 643	_proportionallyResize: function() {
 644
 645		if (!this._proportionallyResizeElements.length) {
 646			return;
 647		}
 648
 649		var prel,
 650			i = 0,
 651			element = this.helper || this.element;
 652
 653		for ( ; i < this._proportionallyResizeElements.length; i++) {
 654
 655			prel = this._proportionallyResizeElements[i];
 656
 657			// TODO: Seems like a bug to cache this.outerDimensions
 658			// considering that we are in a loop.
 659			if (!this.outerDimensions) {
 660				this.outerDimensions = this._getPaddingPlusBorderDimensions( prel );
 661			}
 662
 663			prel.css({
 664				height: (element.height() - this.outerDimensions.height) || 0,
 665				width: (element.width() - this.outerDimensions.width) || 0
 666			});
 667
 668		}
 669
 670	},
 671
 672	_renderProxy: function() {
 673
 674		var el = this.element, o = this.options;
 675		this.elementOffset = el.offset();
 676
 677		if (this._helper) {
 678
 679			this.helper = this.helper || $("<div style='overflow:hidden;'></div>");
 680
 681			this.helper.addClass(this._helper).css({
 682				width: this.element.outerWidth() - 1,
 683				height: this.element.outerHeight() - 1,
 684				position: "absolute",
 685				left: this.elementOffset.left + "px",
 686				top: this.elementOffset.top + "px",
 687				zIndex: ++o.zIndex //TODO: Don't modify option
 688			});
 689
 690			this.helper
 691				.appendTo("body")
 692				.disableSelection();
 693
 694		} else {
 695			this.helper = this.element;
 696		}
 697
 698	},
 699
 700	_change: {
 701		e: function(event, dx) {
 702			return { width: this.originalSize.width + dx };
 703		},
 704		w: function(event, dx) {
 705			var cs = this.originalSize, sp = this.originalPosition;
 706			return { left: sp.left + dx, width: cs.width - dx };
 707		},
 708		n: function(event, dx, dy) {
 709			var cs = this.originalSize, sp = this.originalPosition;
 710			return { top: sp.top + dy, height: cs.height - dy };
 711		},
 712		s: function(event, dx, dy) {
 713			return { height: this.originalSize.height + dy };
 714		},
 715		se: function(event, dx, dy) {
 716			return $.extend(this._change.s.apply(this, arguments),
 717				this._change.e.apply(this, [ event, dx, dy ]));
 718		},
 719		sw: function(event, dx, dy) {
 720			return $.extend(this._change.s.apply(this, arguments),
 721				this._change.w.apply(this, [ event, dx, dy ]));
 722		},
 723		ne: function(event, dx, dy) {
 724			return $.extend(this._change.n.apply(this, arguments),
 725				this._change.e.apply(this, [ event, dx, dy ]));
 726		},
 727		nw: function(event, dx, dy) {
 728			return $.extend(this._change.n.apply(this, arguments),
 729				this._change.w.apply(this, [ event, dx, dy ]));
 730		}
 731	},
 732
 733	_propagate: function(n, event) {
 734		$.ui.plugin.call(this, n, [ event, this.ui() ]);
 735		(n !== "resize" && this._trigger(n, event, this.ui()));
 736	},
 737
 738	plugins: {},
 739
 740	ui: function() {
 741		return {
 742			originalElement: this.originalElement,
 743			element: this.element,
 744			helper: this.helper,
 745			position: this.position,
 746			size: this.size,
 747			originalSize: this.originalSize,
 748			originalPosition: this.originalPosition
 749		};
 750	}
 751
 752});
 753
 754/*
 755 * Resizable Extensions
 756 */
 757
 758$.ui.plugin.add("resizable", "animate", {
 759
 760	stop: function( event ) {
 761		var that = $(this).resizable( "instance" ),
 762			o = that.options,
 763			pr = that._proportionallyResizeElements,
 764			ista = pr.length && (/textarea/i).test(pr[0].nodeName),
 765			soffseth = ista && that._hasScroll(pr[0], "left") ? 0 : that.sizeDiff.height,
 766			soffsetw = ista ? 0 : that.sizeDiff.width,
 767			style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
 768			left = (parseInt(that.element.css("left"), 10) +
 769				(that.position.left - that.originalPosition.left)) || null,
 770			top = (parseInt(that.element.css("top"), 10) +
 771				(that.position.top - that.originalPosition.top)) || null;
 772
 773		that.element.animate(
 774			$.extend(style, top && left ? { top: top, left: left } : {}), {
 775				duration: o.animateDuration,
 776				easing: o.animateEasing,
 777				step: function() {
 778
 779					var data = {
 780						width: parseInt(that.element.css("width"), 10),
 781						height: parseInt(that.element.css("height"), 10),
 782						top: parseInt(that.element.css("top"), 10),
 783						left: parseInt(that.element.css("left"), 10)
 784					};
 785
 786					if (pr && pr.length) {
 787						$(pr[0]).css({ width: data.width, height: data.height });
 788					}
 789
 790					// propagating resize, and updating values for each animation step
 791					that._updateCache(data);
 792					that._propagate("resize", event);
 793
 794				}
 795			}
 796		);
 797	}
 798
 799});
 800
 801$.ui.plugin.add( "resizable", "containment", {
 802
 803	start: function() {
 804		var element, p, co, ch, cw, width, height,
 805			that = $( this ).resizable( "instance" ),
 806			o = that.options,
 807			el = that.element,
 808			oc = o.containment,
 809			ce = ( oc instanceof $ ) ? oc.get( 0 ) : ( /parent/.test( oc ) ) ? el.parent().get( 0 ) : oc;
 810
 811		if ( !ce ) {
 812			return;
 813		}
 814
 815		that.containerElement = $( ce );
 816
 817		if ( /document/.test( oc ) || oc === document ) {
 818			that.containerOffset = {
 819				left: 0,
 820				top: 0
 821			};
 822			that.containerPosition = {
 823				left: 0,
 824				top: 0
 825			};
 826
 827			that.parentData = {
 828				element: $( document ),
 829				left: 0,
 830				top: 0,
 831				width: $( document ).width(),
 832				height: $( document ).height() || document.body.parentNode.scrollHeight
 833			};
 834		} else {
 835			element = $( ce );
 836			p = [];
 837			$([ "Top", "Right", "Left", "Bottom" ]).each(function( i, name ) {
 838				p[ i ] = that._num( element.css( "padding" + name ) );
 839			});
 840
 841			that.containerOffset = element.offset();
 842			that.containerPosition = element.position();
 843			that.containerSize = {
 844				height: ( element.innerHeight() - p[ 3 ] ),
 845				width: ( element.innerWidth() - p[ 1 ] )
 846			};
 847
 848			co = that.containerOffset;
 849			ch = that.containerSize.height;
 850			cw = that.containerSize.width;
 851			width = ( that._hasScroll ( ce, "left" ) ? ce.scrollWidth : cw );
 852			height = ( that._hasScroll ( ce ) ? ce.scrollHeight : ch ) ;
 853
 854			that.parentData = {
 855				element: ce,
 856				left: co.left,
 857				top: co.top,
 858				width: width,
 859				height: height
 860			};
 861		}
 862	},
 863
 864	resize: function( event ) {
 865		var woset, hoset, isParent, isOffsetRelative,
 866			that = $( this ).resizable( "instance" ),
 867			o = that.options,
 868			co = that.containerOffset,
 869			cp = that.position,
 870			pRatio = that._aspectRatio || event.shiftKey,
 871			cop = {
 872				top: 0,
 873				left: 0
 874			},
 875			ce = that.containerElement,
 876			continueResize = true;
 877
 878		if ( ce[ 0 ] !== document && ( /static/ ).test( ce.css( "position" ) ) ) {
 879			cop = co;
 880		}
 881
 882		if ( cp.left < ( that._helper ? co.left : 0 ) ) {
 883			that.size.width = that.size.width +
 884				( that._helper ?
 885					( that.position.left - co.left ) :
 886					( that.position.left - cop.left ) );
 887
 888			if ( pRatio ) {
 889				that.size.height = that.size.width / that.aspectRatio;
 890				continueResize = false;
 891			}
 892			that.position.left = o.helper ? co.left : 0;
 893		}
 894
 895		if ( cp.top < ( that._helper ? co.top : 0 ) ) {
 896			that.size.height = that.size.height +
 897				( that._helper ?
 898					( that.position.top - co.top ) :
 899					that.position.top );
 900
 901			if ( pRatio ) {
 902				that.size.width = that.size.height * that.aspectRatio;
 903				continueResize = false;
 904			}
 905			that.position.top = that._helper ? co.top : 0;
 906		}
 907
 908		isParent = that.containerElement.get( 0 ) === that.element.parent().get( 0 );
 909		isOffsetRelative = /relative|absolute/.test( that.containerElement.css( "position" ) );
 910
 911		if ( isParent && isOffsetRelative ) {
 912			that.offset.left = that.parentData.left + that.position.left;
 913			that.offset.top = that.parentData.top + that.position.top;
 914		} else {
 915			that.offset.left = that.element.offset().left;
 916			that.offset.top = that.element.offset().top;
 917		}
 918
 919		woset = Math.abs( that.sizeDiff.width +
 920			(that._helper ?
 921				that.offset.left - cop.left :
 922				(that.offset.left - co.left)) );
 923
 924		hoset = Math.abs( that.sizeDiff.height +
 925			(that._helper ?
 926				that.offset.top - cop.top :
 927				(that.offset.top - co.top)) );
 928
 929		if ( woset + that.size.width >= that.parentData.width ) {
 930			that.size.width = that.parentData.width - woset;
 931			if ( pRatio ) {
 932				that.size.height = that.size.width / that.aspectRatio;
 933				continueResize = false;
 934			}
 935		}
 936
 937		if ( hoset + that.size.height >= that.parentData.height ) {
 938			that.size.height = that.parentData.height - hoset;
 939			if ( pRatio ) {
 940				that.size.width = that.size.height * that.aspectRatio;
 941				continueResize = false;
 942			}
 943		}
 944
 945		if ( !continueResize ) {
 946			that.position.left = that.prevPosition.left;
 947			that.position.top = that.prevPosition.top;
 948			that.size.width = that.prevSize.width;
 949			that.size.height = that.prevSize.height;
 950		}
 951	},
 952
 953	stop: function() {
 954		var that = $( this ).resizable( "instance" ),
 955			o = that.options,
 956			co = that.containerOffset,
 957			cop = that.containerPosition,
 958			ce = that.containerElement,
 959			helper = $( that.helper ),
 960			ho = helper.offset(),
 961			w = helper.outerWidth() - that.sizeDiff.width,
 962			h = helper.outerHeight() - that.sizeDiff.height;
 963
 964		if ( that._helper && !o.animate && ( /relative/ ).test( ce.css( "position" ) ) ) {
 965			$( this ).css({
 966				left: ho.left - cop.left - co.left,
 967				width: w,
 968				height: h
 969			});
 970		}
 971
 972		if ( that._helper && !o.animate && ( /static/ ).test( ce.css( "position" ) ) ) {
 973			$( this ).css({
 974				left: ho.left - cop.left - co.left,
 975				width: w,
 976				height: h
 977			});
 978		}
 979	}
 980});
 981
 982$.ui.plugin.add("resizable", "alsoResize", {
 983
 984	start: function() {
 985		var that = $(this).resizable( "instance" ),
 986			o = that.options;
 987
 988		$(o.alsoResize).each(function() {
 989			var el = $(this);
 990			el.data("ui-resizable-alsoresize", {
 991				width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
 992				left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
 993			});
 994		});
 995	},
 996
 997	resize: function(event, ui) {
 998		var that = $(this).resizable( "instance" ),
 999			o = that.options,
1000			os = that.originalSize,
1001			op = that.originalPosition,
1002			delta = {
1003				height: (that.size.height - os.height) || 0,
1004				width: (that.size.width - os.width) || 0,
1005				top: (that.position.top - op.top) || 0,
1006				left: (that.position.left - op.left) || 0
1007			};
1008
1009			$(o.alsoResize).each(function() {
1010				var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
1011					css = el.parents(ui.originalElement[0]).length ?
1012							[ "width", "height" ] :
1013							[ "width", "height", "top", "left" ];
1014
1015				$.each(css, function(i, prop) {
1016					var sum = (start[prop] || 0) + (delta[prop] || 0);
1017					if (sum && sum >= 0) {
1018						style[prop] = sum || null;
1019					}
1020				});
1021
1022				el.css(style);
1023			});
1024	},
1025
1026	stop: function() {
1027		$(this).removeData("resizable-alsoresize");
1028	}
1029});
1030
1031$.ui.plugin.add("resizable", "ghost", {
1032
1033	start: function() {
1034
1035		var that = $(this).resizable( "instance" ), o = that.options, cs = that.size;
1036
1037		that.ghost = that.originalElement.clone();
1038		that.ghost
1039			.css({
1040				opacity: 0.25,
1041				display: "block",
1042				position: "relative",
1043				height: cs.height,
1044				width: cs.width,
1045				margin: 0,
1046				left: 0,
1047				top: 0
1048			})
1049			.addClass("ui-resizable-ghost")
1050			.addClass(typeof o.ghost === "string" ? o.ghost : "");
1051
1052		that.ghost.appendTo(that.helper);
1053
1054	},
1055
1056	resize: function() {
1057		var that = $(this).resizable( "instance" );
1058		if (that.ghost) {
1059			that.ghost.css({
1060				position: "relative",
1061				height: that.size.height,
1062				width: that.size.width
1063			});
1064		}
1065	},
1066
1067	stop: function() {
1068		var that = $(this).resizable( "instance" );
1069		if (that.ghost && that.helper) {
1070			that.helper.get(0).removeChild(that.ghost.get(0));
1071		}
1072	}
1073
1074});
1075
1076$.ui.plugin.add("resizable", "grid", {
1077
1078	resize: function() {
1079		var outerDimensions,
1080			that = $(this).resizable( "instance" ),
1081			o = that.options,
1082			cs = that.size,
1083			os = that.originalSize,
1084			op = that.originalPosition,
1085			a = that.axis,
1086			grid = typeof o.grid === "number" ? [ o.grid, o.grid ] : o.grid,
1087			gridX = (grid[0] || 1),
1088			gridY = (grid[1] || 1),
1089			ox = Math.round((cs.width - os.width) / gridX) * gridX,
1090			oy = Math.round((cs.height - os.height) / gridY) * gridY,
1091			newWidth = os.width + ox,
1092			newHeight = os.height + oy,
1093			isMaxWidth = o.maxWidth && (o.maxWidth < newWidth),
1094			isMaxHeight = o.maxHeight && (o.maxHeight < newHeight),
1095			isMinWidth = o.minWidth && (o.minWidth > newWidth),
1096			isMinHeight = o.minHeight && (o.minHeight > newHeight);
1097
1098		o.grid = grid;
1099
1100		if (isMinWidth) {
1101			newWidth += gridX;
1102		}
1103		if (isMinHeight) {
1104			newHeight += gridY;
1105		}
1106		if (isMaxWidth) {
1107			newWidth -= gridX;
1108		}
1109		if (isMaxHeight) {
1110			newHeight -= gridY;
1111		}
1112
1113		if (/^(se|s|e)$/.test(a)) {
1114			that.size.width = newWidth;
1115			that.size.height = newHeight;
1116		} else if (/^(ne)$/.test(a)) {
1117			that.size.width = newWidth;
1118			that.size.height = newHeight;
1119			that.position.top = op.top - oy;
1120		} else if (/^(sw)$/.test(a)) {
1121			that.size.width = newWidth;
1122			that.size.height = newHeight;
1123			that.position.left = op.left - ox;
1124		} else {
1125			if ( newHeight - gridY <= 0 || newWidth - gridX <= 0) {
1126				outerDimensions = that._getPaddingPlusBorderDimensions( this );
1127			}
1128
1129			if ( newHeight - gridY > 0 ) {
1130				that.size.height = newHeight;
1131				that.position.top = op.top - oy;
1132			} else {
1133				newHeight = gridY - outerDimensions.height;
1134				that.size.height = newHeight;
1135				that.position.top = op.top + os.height - newHeight;
1136			}
1137			if ( newWidth - gridX > 0 ) {
1138				that.size.width = newWidth;
1139				that.position.left = op.left - ox;
1140			} else {
1141				newWidth = gridX - outerDimensions.width;
1142				that.size.width = newWidth;
1143				that.position.left = op.left + os.width - newWidth;
1144			}
1145		}
1146	}
1147
1148});
1149
1150return $.ui.resizable;
1151
1152}));