1
0

resizable.js 28 KB

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