resizable.js 28 KB

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