sonata_jqueryui_js_jquery.ui.resizable_6.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /*!
  2. * jQuery UI Resizable 1.10.4
  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. * Depends:
  12. * jquery.ui.core.js
  13. * jquery.ui.mouse.js
  14. * jquery.ui.widget.js
  15. */
  16. (function( $, undefined ) {
  17. function num(v) {
  18. return parseInt(v, 10) || 0;
  19. }
  20. function isNumber(value) {
  21. return !isNaN(parseInt(value, 10));
  22. }
  23. $.widget("ui.resizable", $.ui.mouse, {
  24. version: "1.10.4",
  25. widgetEventPrefix: "resize",
  26. options: {
  27. alsoResize: false,
  28. animate: false,
  29. animateDuration: "slow",
  30. animateEasing: "swing",
  31. aspectRatio: false,
  32. autoHide: false,
  33. containment: false,
  34. ghost: false,
  35. grid: false,
  36. handles: "e,s,se",
  37. helper: false,
  38. maxHeight: null,
  39. maxWidth: null,
  40. minHeight: 10,
  41. minWidth: 10,
  42. // See #7960
  43. zIndex: 90,
  44. // callbacks
  45. resize: null,
  46. start: null,
  47. stop: null
  48. },
  49. _create: function() {
  50. var n, i, handle, axis, hname,
  51. that = this,
  52. o = this.options;
  53. this.element.addClass("ui-resizable");
  54. $.extend(this, {
  55. _aspectRatio: !!(o.aspectRatio),
  56. aspectRatio: o.aspectRatio,
  57. originalElement: this.element,
  58. _proportionallyResizeElements: [],
  59. _helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
  60. });
  61. //Wrap the element if it cannot hold child nodes
  62. if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
  63. //Create a wrapper element and set the wrapper to the new current internal element
  64. this.element.wrap(
  65. $("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
  66. position: this.element.css("position"),
  67. width: this.element.outerWidth(),
  68. height: this.element.outerHeight(),
  69. top: this.element.css("top"),
  70. left: this.element.css("left")
  71. })
  72. );
  73. //Overwrite the original this.element
  74. this.element = this.element.parent().data(
  75. "ui-resizable", this.element.data("ui-resizable")
  76. );
  77. this.elementIsWrapper = true;
  78. //Move margins to the wrapper
  79. this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
  80. this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
  81. //Prevent Safari textarea resize
  82. this.originalResizeStyle = this.originalElement.css("resize");
  83. this.originalElement.css("resize", "none");
  84. //Push the actual element to our proportionallyResize internal array
  85. this._proportionallyResizeElements.push(this.originalElement.css({ position: "static", zoom: 1, display: "block" }));
  86. // avoid IE jump (hard set the margin)
  87. this.originalElement.css({ margin: this.originalElement.css("margin") });
  88. // fix handlers offset
  89. this._proportionallyResize();
  90. }
  91. this.handles = o.handles || (!$(".ui-resizable-handle", this.element).length ? "e,s,se" : { n: ".ui-resizable-n", e: ".ui-resizable-e", s: ".ui-resizable-s", w: ".ui-resizable-w", se: ".ui-resizable-se", sw: ".ui-resizable-sw", ne: ".ui-resizable-ne", nw: ".ui-resizable-nw" });
  92. if(this.handles.constructor === String) {
  93. if ( this.handles === "all") {
  94. this.handles = "n,e,s,w,se,sw,ne,nw";
  95. }
  96. n = this.handles.split(",");
  97. this.handles = {};
  98. for(i = 0; i < n.length; i++) {
  99. handle = $.trim(n[i]);
  100. hname = "ui-resizable-"+handle;
  101. axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
  102. // Apply zIndex to all handles - see #7960
  103. axis.css({ zIndex: o.zIndex });
  104. //TODO : What's going on here?
  105. if ("se" === handle) {
  106. axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
  107. }
  108. //Insert into internal handles object and append to element
  109. this.handles[handle] = ".ui-resizable-"+handle;
  110. this.element.append(axis);
  111. }
  112. }
  113. this._renderAxis = function(target) {
  114. var i, axis, padPos, padWrapper;
  115. target = target || this.element;
  116. for(i in this.handles) {
  117. if(this.handles[i].constructor === String) {
  118. this.handles[i] = $(this.handles[i], this.element).show();
  119. }
  120. //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
  121. if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
  122. axis = $(this.handles[i], this.element);
  123. //Checking the correct pad and border
  124. padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
  125. //The padding type i have to apply...
  126. padPos = [ "padding",
  127. /ne|nw|n/.test(i) ? "Top" :
  128. /se|sw|s/.test(i) ? "Bottom" :
  129. /^e$/.test(i) ? "Right" : "Left" ].join("");
  130. target.css(padPos, padWrapper);
  131. this._proportionallyResize();
  132. }
  133. //TODO: What's that good for? There's not anything to be executed left
  134. if(!$(this.handles[i]).length) {
  135. continue;
  136. }
  137. }
  138. };
  139. //TODO: make renderAxis a prototype function
  140. this._renderAxis(this.element);
  141. this._handles = $(".ui-resizable-handle", this.element)
  142. .disableSelection();
  143. //Matching axis name
  144. this._handles.mouseover(function() {
  145. if (!that.resizing) {
  146. if (this.className) {
  147. axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
  148. }
  149. //Axis, default = se
  150. that.axis = axis && axis[1] ? axis[1] : "se";
  151. }
  152. });
  153. //If we want to auto hide the elements
  154. if (o.autoHide) {
  155. this._handles.hide();
  156. $(this.element)
  157. .addClass("ui-resizable-autohide")
  158. .mouseenter(function() {
  159. if (o.disabled) {
  160. return;
  161. }
  162. $(this).removeClass("ui-resizable-autohide");
  163. that._handles.show();
  164. })
  165. .mouseleave(function(){
  166. if (o.disabled) {
  167. return;
  168. }
  169. if (!that.resizing) {
  170. $(this).addClass("ui-resizable-autohide");
  171. that._handles.hide();
  172. }
  173. });
  174. }
  175. //Initialize the mouse interaction
  176. this._mouseInit();
  177. },
  178. _destroy: function() {
  179. this._mouseDestroy();
  180. var wrapper,
  181. _destroy = function(exp) {
  182. $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
  183. .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove();
  184. };
  185. //TODO: Unwrap at same DOM position
  186. if (this.elementIsWrapper) {
  187. _destroy(this.element);
  188. wrapper = this.element;
  189. this.originalElement.css({
  190. position: wrapper.css("position"),
  191. width: wrapper.outerWidth(),
  192. height: wrapper.outerHeight(),
  193. top: wrapper.css("top"),
  194. left: wrapper.css("left")
  195. }).insertAfter( wrapper );
  196. wrapper.remove();
  197. }
  198. this.originalElement.css("resize", this.originalResizeStyle);
  199. _destroy(this.originalElement);
  200. return this;
  201. },
  202. _mouseCapture: function(event) {
  203. var i, handle,
  204. capture = false;
  205. for (i in this.handles) {
  206. handle = $(this.handles[i])[0];
  207. if (handle === event.target || $.contains(handle, event.target)) {
  208. capture = true;
  209. }
  210. }
  211. return !this.options.disabled && capture;
  212. },
  213. _mouseStart: function(event) {
  214. var curleft, curtop, cursor,
  215. o = this.options,
  216. iniPos = this.element.position(),
  217. el = this.element;
  218. this.resizing = true;
  219. // bugfix for http://dev.jquery.com/ticket/1749
  220. if ( (/absolute/).test( el.css("position") ) ) {
  221. el.css({ position: "absolute", top: el.css("top"), left: el.css("left") });
  222. } else if (el.is(".ui-draggable")) {
  223. el.css({ position: "absolute", top: iniPos.top, left: iniPos.left });
  224. }
  225. this._renderProxy();
  226. curleft = num(this.helper.css("left"));
  227. curtop = num(this.helper.css("top"));
  228. if (o.containment) {
  229. curleft += $(o.containment).scrollLeft() || 0;
  230. curtop += $(o.containment).scrollTop() || 0;
  231. }
  232. //Store needed variables
  233. this.offset = this.helper.offset();
  234. this.position = { left: curleft, top: curtop };
  235. this.size = this._helper ? { width: this.helper.width(), height: this.helper.height() } : { width: el.width(), height: el.height() };
  236. this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  237. this.originalPosition = { left: curleft, top: curtop };
  238. this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
  239. this.originalMousePosition = { left: event.pageX, top: event.pageY };
  240. //Aspect Ratio
  241. this.aspectRatio = (typeof o.aspectRatio === "number") ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
  242. cursor = $(".ui-resizable-" + this.axis).css("cursor");
  243. $("body").css("cursor", cursor === "auto" ? this.axis + "-resize" : cursor);
  244. el.addClass("ui-resizable-resizing");
  245. this._propagate("start", event);
  246. return true;
  247. },
  248. _mouseDrag: function(event) {
  249. //Increase performance, avoid regex
  250. var data,
  251. el = this.helper, props = {},
  252. smp = this.originalMousePosition,
  253. a = this.axis,
  254. prevTop = this.position.top,
  255. prevLeft = this.position.left,
  256. prevWidth = this.size.width,
  257. prevHeight = this.size.height,
  258. dx = (event.pageX-smp.left)||0,
  259. dy = (event.pageY-smp.top)||0,
  260. trigger = this._change[a];
  261. if (!trigger) {
  262. return false;
  263. }
  264. // Calculate the attrs that will be change
  265. data = trigger.apply(this, [event, dx, dy]);
  266. // Put this in the mouseDrag handler since the user can start pressing shift while resizing
  267. this._updateVirtualBoundaries(event.shiftKey);
  268. if (this._aspectRatio || event.shiftKey) {
  269. data = this._updateRatio(data, event);
  270. }
  271. data = this._respectSize(data, event);
  272. this._updateCache(data);
  273. // plugins callbacks need to be called first
  274. this._propagate("resize", event);
  275. if (this.position.top !== prevTop) {
  276. props.top = this.position.top + "px";
  277. }
  278. if (this.position.left !== prevLeft) {
  279. props.left = this.position.left + "px";
  280. }
  281. if (this.size.width !== prevWidth) {
  282. props.width = this.size.width + "px";
  283. }
  284. if (this.size.height !== prevHeight) {
  285. props.height = this.size.height + "px";
  286. }
  287. el.css(props);
  288. if (!this._helper && this._proportionallyResizeElements.length) {
  289. this._proportionallyResize();
  290. }
  291. // Call the user callback if the element was resized
  292. if ( ! $.isEmptyObject(props) ) {
  293. this._trigger("resize", event, this.ui());
  294. }
  295. return false;
  296. },
  297. _mouseStop: function(event) {
  298. this.resizing = false;
  299. var pr, ista, soffseth, soffsetw, s, left, top,
  300. o = this.options, that = this;
  301. if(this._helper) {
  302. pr = this._proportionallyResizeElements;
  303. ista = pr.length && (/textarea/i).test(pr[0].nodeName);
  304. soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height;
  305. soffsetw = ista ? 0 : that.sizeDiff.width;
  306. s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) };
  307. left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null;
  308. top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
  309. if (!o.animate) {
  310. this.element.css($.extend(s, { top: top, left: left }));
  311. }
  312. that.helper.height(that.size.height);
  313. that.helper.width(that.size.width);
  314. if (this._helper && !o.animate) {
  315. this._proportionallyResize();
  316. }
  317. }
  318. $("body").css("cursor", "auto");
  319. this.element.removeClass("ui-resizable-resizing");
  320. this._propagate("stop", event);
  321. if (this._helper) {
  322. this.helper.remove();
  323. }
  324. return false;
  325. },
  326. _updateVirtualBoundaries: function(forceAspectRatio) {
  327. var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
  328. o = this.options;
  329. b = {
  330. minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
  331. maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
  332. minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
  333. maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
  334. };
  335. if(this._aspectRatio || forceAspectRatio) {
  336. // We want to create an enclosing box whose aspect ration is the requested one
  337. // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
  338. pMinWidth = b.minHeight * this.aspectRatio;
  339. pMinHeight = b.minWidth / this.aspectRatio;
  340. pMaxWidth = b.maxHeight * this.aspectRatio;
  341. pMaxHeight = b.maxWidth / this.aspectRatio;
  342. if(pMinWidth > b.minWidth) {
  343. b.minWidth = pMinWidth;
  344. }
  345. if(pMinHeight > b.minHeight) {
  346. b.minHeight = pMinHeight;
  347. }
  348. if(pMaxWidth < b.maxWidth) {
  349. b.maxWidth = pMaxWidth;
  350. }
  351. if(pMaxHeight < b.maxHeight) {
  352. b.maxHeight = pMaxHeight;
  353. }
  354. }
  355. this._vBoundaries = b;
  356. },
  357. _updateCache: function(data) {
  358. this.offset = this.helper.offset();
  359. if (isNumber(data.left)) {
  360. this.position.left = data.left;
  361. }
  362. if (isNumber(data.top)) {
  363. this.position.top = data.top;
  364. }
  365. if (isNumber(data.height)) {
  366. this.size.height = data.height;
  367. }
  368. if (isNumber(data.width)) {
  369. this.size.width = data.width;
  370. }
  371. },
  372. _updateRatio: function( data ) {
  373. var cpos = this.position,
  374. csize = this.size,
  375. a = this.axis;
  376. if (isNumber(data.height)) {
  377. data.width = (data.height * this.aspectRatio);
  378. } else if (isNumber(data.width)) {
  379. data.height = (data.width / this.aspectRatio);
  380. }
  381. if (a === "sw") {
  382. data.left = cpos.left + (csize.width - data.width);
  383. data.top = null;
  384. }
  385. if (a === "nw") {
  386. data.top = cpos.top + (csize.height - data.height);
  387. data.left = cpos.left + (csize.width - data.width);
  388. }
  389. return data;
  390. },
  391. _respectSize: function( data ) {
  392. var o = this._vBoundaries,
  393. a = this.axis,
  394. ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
  395. isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height),
  396. dw = this.originalPosition.left + this.originalSize.width,
  397. dh = this.position.top + this.size.height,
  398. cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
  399. if (isminw) {
  400. data.width = o.minWidth;
  401. }
  402. if (isminh) {
  403. data.height = o.minHeight;
  404. }
  405. if (ismaxw) {
  406. data.width = o.maxWidth;
  407. }
  408. if (ismaxh) {
  409. data.height = o.maxHeight;
  410. }
  411. if (isminw && cw) {
  412. data.left = dw - o.minWidth;
  413. }
  414. if (ismaxw && cw) {
  415. data.left = dw - o.maxWidth;
  416. }
  417. if (isminh && ch) {
  418. data.top = dh - o.minHeight;
  419. }
  420. if (ismaxh && ch) {
  421. data.top = dh - o.maxHeight;
  422. }
  423. // fixing jump error on top/left - bug #2330
  424. if (!data.width && !data.height && !data.left && data.top) {
  425. data.top = null;
  426. } else if (!data.width && !data.height && !data.top && data.left) {
  427. data.left = null;
  428. }
  429. return data;
  430. },
  431. _proportionallyResize: function() {
  432. if (!this._proportionallyResizeElements.length) {
  433. return;
  434. }
  435. var i, j, borders, paddings, prel,
  436. element = this.helper || this.element;
  437. for ( i=0; i < this._proportionallyResizeElements.length; i++) {
  438. prel = this._proportionallyResizeElements[i];
  439. if (!this.borderDif) {
  440. this.borderDif = [];
  441. borders = [prel.css("borderTopWidth"), prel.css("borderRightWidth"), prel.css("borderBottomWidth"), prel.css("borderLeftWidth")];
  442. paddings = [prel.css("paddingTop"), prel.css("paddingRight"), prel.css("paddingBottom"), prel.css("paddingLeft")];
  443. for ( j = 0; j < borders.length; j++ ) {
  444. this.borderDif[ j ] = ( parseInt( borders[ j ], 10 ) || 0 ) + ( parseInt( paddings[ j ], 10 ) || 0 );
  445. }
  446. }
  447. prel.css({
  448. height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
  449. width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
  450. });
  451. }
  452. },
  453. _renderProxy: function() {
  454. var el = this.element, o = this.options;
  455. this.elementOffset = el.offset();
  456. if(this._helper) {
  457. this.helper = this.helper || $("<div style='overflow:hidden;'></div>");
  458. this.helper.addClass(this._helper).css({
  459. width: this.element.outerWidth() - 1,
  460. height: this.element.outerHeight() - 1,
  461. position: "absolute",
  462. left: this.elementOffset.left +"px",
  463. top: this.elementOffset.top +"px",
  464. zIndex: ++o.zIndex //TODO: Don't modify option
  465. });
  466. this.helper
  467. .appendTo("body")
  468. .disableSelection();
  469. } else {
  470. this.helper = this.element;
  471. }
  472. },
  473. _change: {
  474. e: function(event, dx) {
  475. return { width: this.originalSize.width + dx };
  476. },
  477. w: function(event, dx) {
  478. var cs = this.originalSize, sp = this.originalPosition;
  479. return { left: sp.left + dx, width: cs.width - dx };
  480. },
  481. n: function(event, dx, dy) {
  482. var cs = this.originalSize, sp = this.originalPosition;
  483. return { top: sp.top + dy, height: cs.height - dy };
  484. },
  485. s: function(event, dx, dy) {
  486. return { height: this.originalSize.height + dy };
  487. },
  488. se: function(event, dx, dy) {
  489. return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  490. },
  491. sw: function(event, dx, dy) {
  492. return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  493. },
  494. ne: function(event, dx, dy) {
  495. return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  496. },
  497. nw: function(event, dx, dy) {
  498. return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  499. }
  500. },
  501. _propagate: function(n, event) {
  502. $.ui.plugin.call(this, n, [event, this.ui()]);
  503. (n !== "resize" && this._trigger(n, event, this.ui()));
  504. },
  505. plugins: {},
  506. ui: function() {
  507. return {
  508. originalElement: this.originalElement,
  509. element: this.element,
  510. helper: this.helper,
  511. position: this.position,
  512. size: this.size,
  513. originalSize: this.originalSize,
  514. originalPosition: this.originalPosition
  515. };
  516. }
  517. });
  518. /*
  519. * Resizable Extensions
  520. */
  521. $.ui.plugin.add("resizable", "animate", {
  522. stop: function( event ) {
  523. var that = $(this).data("ui-resizable"),
  524. o = that.options,
  525. pr = that._proportionallyResizeElements,
  526. ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  527. soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  528. soffsetw = ista ? 0 : that.sizeDiff.width,
  529. style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
  530. left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null,
  531. top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
  532. that.element.animate(
  533. $.extend(style, top && left ? { top: top, left: left } : {}), {
  534. duration: o.animateDuration,
  535. easing: o.animateEasing,
  536. step: function() {
  537. var data = {
  538. width: parseInt(that.element.css("width"), 10),
  539. height: parseInt(that.element.css("height"), 10),
  540. top: parseInt(that.element.css("top"), 10),
  541. left: parseInt(that.element.css("left"), 10)
  542. };
  543. if (pr && pr.length) {
  544. $(pr[0]).css({ width: data.width, height: data.height });
  545. }
  546. // propagating resize, and updating values for each animation step
  547. that._updateCache(data);
  548. that._propagate("resize", event);
  549. }
  550. }
  551. );
  552. }
  553. });
  554. $.ui.plugin.add("resizable", "containment", {
  555. start: function() {
  556. var element, p, co, ch, cw, width, height,
  557. that = $(this).data("ui-resizable"),
  558. o = that.options,
  559. el = that.element,
  560. oc = o.containment,
  561. ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
  562. if (!ce) {
  563. return;
  564. }
  565. that.containerElement = $(ce);
  566. if (/document/.test(oc) || oc === document) {
  567. that.containerOffset = { left: 0, top: 0 };
  568. that.containerPosition = { left: 0, top: 0 };
  569. that.parentData = {
  570. element: $(document), left: 0, top: 0,
  571. width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
  572. };
  573. }
  574. // i'm a node, so compute top, left, right, bottom
  575. else {
  576. element = $(ce);
  577. p = [];
  578. $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
  579. that.containerOffset = element.offset();
  580. that.containerPosition = element.position();
  581. that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
  582. co = that.containerOffset;
  583. ch = that.containerSize.height;
  584. cw = that.containerSize.width;
  585. width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw );
  586. height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
  587. that.parentData = {
  588. element: ce, left: co.left, top: co.top, width: width, height: height
  589. };
  590. }
  591. },
  592. resize: function( event ) {
  593. var woset, hoset, isParent, isOffsetRelative,
  594. that = $(this).data("ui-resizable"),
  595. o = that.options,
  596. co = that.containerOffset, cp = that.position,
  597. pRatio = that._aspectRatio || event.shiftKey,
  598. cop = { top:0, left:0 }, ce = that.containerElement;
  599. if (ce[0] !== document && (/static/).test(ce.css("position"))) {
  600. cop = co;
  601. }
  602. if (cp.left < (that._helper ? co.left : 0)) {
  603. that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
  604. if (pRatio) {
  605. that.size.height = that.size.width / that.aspectRatio;
  606. }
  607. that.position.left = o.helper ? co.left : 0;
  608. }
  609. if (cp.top < (that._helper ? co.top : 0)) {
  610. that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
  611. if (pRatio) {
  612. that.size.width = that.size.height * that.aspectRatio;
  613. }
  614. that.position.top = that._helper ? co.top : 0;
  615. }
  616. that.offset.left = that.parentData.left+that.position.left;
  617. that.offset.top = that.parentData.top+that.position.top;
  618. woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width );
  619. hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
  620. isParent = that.containerElement.get(0) === that.element.parent().get(0);
  621. isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position"));
  622. if ( isParent && isOffsetRelative ) {
  623. woset -= Math.abs( that.parentData.left );
  624. }
  625. if (woset + that.size.width >= that.parentData.width) {
  626. that.size.width = that.parentData.width - woset;
  627. if (pRatio) {
  628. that.size.height = that.size.width / that.aspectRatio;
  629. }
  630. }
  631. if (hoset + that.size.height >= that.parentData.height) {
  632. that.size.height = that.parentData.height - hoset;
  633. if (pRatio) {
  634. that.size.width = that.size.height * that.aspectRatio;
  635. }
  636. }
  637. },
  638. stop: function(){
  639. var that = $(this).data("ui-resizable"),
  640. o = that.options,
  641. co = that.containerOffset,
  642. cop = that.containerPosition,
  643. ce = that.containerElement,
  644. helper = $(that.helper),
  645. ho = helper.offset(),
  646. w = helper.outerWidth() - that.sizeDiff.width,
  647. h = helper.outerHeight() - that.sizeDiff.height;
  648. if (that._helper && !o.animate && (/relative/).test(ce.css("position"))) {
  649. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  650. }
  651. if (that._helper && !o.animate && (/static/).test(ce.css("position"))) {
  652. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  653. }
  654. }
  655. });
  656. $.ui.plugin.add("resizable", "alsoResize", {
  657. start: function () {
  658. var that = $(this).data("ui-resizable"),
  659. o = that.options,
  660. _store = function (exp) {
  661. $(exp).each(function() {
  662. var el = $(this);
  663. el.data("ui-resizable-alsoresize", {
  664. width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
  665. left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
  666. });
  667. });
  668. };
  669. if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
  670. if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
  671. else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
  672. }else{
  673. _store(o.alsoResize);
  674. }
  675. },
  676. resize: function (event, ui) {
  677. var that = $(this).data("ui-resizable"),
  678. o = that.options,
  679. os = that.originalSize,
  680. op = that.originalPosition,
  681. delta = {
  682. height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
  683. top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
  684. },
  685. _alsoResize = function (exp, c) {
  686. $(exp).each(function() {
  687. var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
  688. css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ["width", "height"] : ["width", "height", "top", "left"];
  689. $.each(css, function (i, prop) {
  690. var sum = (start[prop]||0) + (delta[prop]||0);
  691. if (sum && sum >= 0) {
  692. style[prop] = sum || null;
  693. }
  694. });
  695. el.css(style);
  696. });
  697. };
  698. if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
  699. $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
  700. }else{
  701. _alsoResize(o.alsoResize);
  702. }
  703. },
  704. stop: function () {
  705. $(this).removeData("resizable-alsoresize");
  706. }
  707. });
  708. $.ui.plugin.add("resizable", "ghost", {
  709. start: function() {
  710. var that = $(this).data("ui-resizable"), o = that.options, cs = that.size;
  711. that.ghost = that.originalElement.clone();
  712. that.ghost
  713. .css({ opacity: 0.25, display: "block", position: "relative", height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
  714. .addClass("ui-resizable-ghost")
  715. .addClass(typeof o.ghost === "string" ? o.ghost : "");
  716. that.ghost.appendTo(that.helper);
  717. },
  718. resize: function(){
  719. var that = $(this).data("ui-resizable");
  720. if (that.ghost) {
  721. that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
  722. }
  723. },
  724. stop: function() {
  725. var that = $(this).data("ui-resizable");
  726. if (that.ghost && that.helper) {
  727. that.helper.get(0).removeChild(that.ghost.get(0));
  728. }
  729. }
  730. });
  731. $.ui.plugin.add("resizable", "grid", {
  732. resize: function() {
  733. var that = $(this).data("ui-resizable"),
  734. o = that.options,
  735. cs = that.size,
  736. os = that.originalSize,
  737. op = that.originalPosition,
  738. a = that.axis,
  739. grid = typeof o.grid === "number" ? [o.grid, o.grid] : o.grid,
  740. gridX = (grid[0]||1),
  741. gridY = (grid[1]||1),
  742. ox = Math.round((cs.width - os.width) / gridX) * gridX,
  743. oy = Math.round((cs.height - os.height) / gridY) * gridY,
  744. newWidth = os.width + ox,
  745. newHeight = os.height + oy,
  746. isMaxWidth = o.maxWidth && (o.maxWidth < newWidth),
  747. isMaxHeight = o.maxHeight && (o.maxHeight < newHeight),
  748. isMinWidth = o.minWidth && (o.minWidth > newWidth),
  749. isMinHeight = o.minHeight && (o.minHeight > newHeight);
  750. o.grid = grid;
  751. if (isMinWidth) {
  752. newWidth = newWidth + gridX;
  753. }
  754. if (isMinHeight) {
  755. newHeight = newHeight + gridY;
  756. }
  757. if (isMaxWidth) {
  758. newWidth = newWidth - gridX;
  759. }
  760. if (isMaxHeight) {
  761. newHeight = newHeight - gridY;
  762. }
  763. if (/^(se|s|e)$/.test(a)) {
  764. that.size.width = newWidth;
  765. that.size.height = newHeight;
  766. } else if (/^(ne)$/.test(a)) {
  767. that.size.width = newWidth;
  768. that.size.height = newHeight;
  769. that.position.top = op.top - oy;
  770. } else if (/^(sw)$/.test(a)) {
  771. that.size.width = newWidth;
  772. that.size.height = newHeight;
  773. that.position.left = op.left - ox;
  774. } else {
  775. if ( newHeight - gridY > 0 ) {
  776. that.size.height = newHeight;
  777. that.position.top = op.top - oy;
  778. } else {
  779. that.size.height = gridY;
  780. that.position.top = op.top + os.height - gridY;
  781. }
  782. if ( newWidth - gridX > 0 ) {
  783. that.size.width = newWidth;
  784. that.position.left = op.left - ox;
  785. } else {
  786. that.size.width = gridX;
  787. that.position.left = op.left + os.width - gridX;
  788. }
  789. }
  790. }
  791. });
  792. })(jQuery);