Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

800 rader
25 KiB

  1. /*
  2. * jQuery UI Resizable 1.8
  3. *
  4. * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Resizables
  9. *
  10. * Depends:
  11. * jquery.ui.core.js
  12. * jquery.ui.mouse.js
  13. * jquery.ui.widget.js
  14. */
  15. (function($) {
  16. $.widget("ui.resizable", $.ui.mouse, {
  17. widgetEventPrefix: "resize",
  18. options: {
  19. alsoResize: false,
  20. animate: false,
  21. animateDuration: "slow",
  22. animateEasing: "swing",
  23. aspectRatio: false,
  24. autoHide: false,
  25. containment: false,
  26. ghost: false,
  27. grid: false,
  28. handles: "e,s,se",
  29. helper: false,
  30. maxHeight: null,
  31. maxWidth: null,
  32. minHeight: 10,
  33. minWidth: 10,
  34. zIndex: 1000
  35. },
  36. _create: function() {
  37. var self = this, o = this.options;
  38. this.element.addClass("ui-resizable");
  39. $.extend(this, {
  40. _aspectRatio: !!(o.aspectRatio),
  41. aspectRatio: o.aspectRatio,
  42. originalElement: this.element,
  43. _proportionallyResizeElements: [],
  44. _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
  45. });
  46. //Wrap the element if it cannot hold child nodes
  47. if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
  48. //Opera fix for relative positioning
  49. if (/relative/.test(this.element.css('position')) && $.browser.opera)
  50. this.element.css({ position: 'relative', top: 'auto', left: 'auto' });
  51. //Create a wrapper element and set the wrapper to the new current internal element
  52. this.element.wrap(
  53. $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
  54. position: this.element.css('position'),
  55. width: this.element.outerWidth(),
  56. height: this.element.outerHeight(),
  57. top: this.element.css('top'),
  58. left: this.element.css('left')
  59. })
  60. );
  61. //Overwrite the original this.element
  62. this.element = this.element.parent().data(
  63. "resizable", this.element.data('resizable')
  64. );
  65. this.elementIsWrapper = true;
  66. //Move margins to the wrapper
  67. this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
  68. this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
  69. //Prevent Safari textarea resize
  70. this.originalResizeStyle = this.originalElement.css('resize');
  71. this.originalElement.css('resize', 'none');
  72. //Push the actual element to our proportionallyResize internal array
  73. this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
  74. // avoid IE jump (hard set the margin)
  75. this.originalElement.css({ margin: this.originalElement.css('margin') });
  76. // fix handlers offset
  77. this._proportionallyResize();
  78. }
  79. 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' });
  80. if(this.handles.constructor == String) {
  81. if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
  82. var n = this.handles.split(","); this.handles = {};
  83. for(var i = 0; i < n.length; i++) {
  84. var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
  85. var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
  86. // increase zIndex of sw, se, ne, nw axis
  87. //TODO : this modifies original option
  88. if(/sw|se|ne|nw/.test(handle)) axis.css({ zIndex: ++o.zIndex });
  89. //TODO : What's going on here?
  90. if ('se' == handle) {
  91. axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
  92. };
  93. //Insert into internal handles object and append to element
  94. this.handles[handle] = '.ui-resizable-'+handle;
  95. this.element.append(axis);
  96. }
  97. }
  98. this._renderAxis = function(target) {
  99. target = target || this.element;
  100. for(var i in this.handles) {
  101. if(this.handles[i].constructor == String)
  102. this.handles[i] = $(this.handles[i], this.element).show();
  103. //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
  104. if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
  105. var axis = $(this.handles[i], this.element), padWrapper = 0;
  106. //Checking the correct pad and border
  107. padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
  108. //The padding type i have to apply...
  109. var padPos = [ 'padding',
  110. /ne|nw|n/.test(i) ? 'Top' :
  111. /se|sw|s/.test(i) ? 'Bottom' :
  112. /^e$/.test(i) ? 'Right' : 'Left' ].join("");
  113. target.css(padPos, padWrapper);
  114. this._proportionallyResize();
  115. }
  116. //TODO: What's that good for? There's not anything to be executed left
  117. if(!$(this.handles[i]).length)
  118. continue;
  119. }
  120. };
  121. //TODO: make renderAxis a prototype function
  122. this._renderAxis(this.element);
  123. this._handles = $('.ui-resizable-handle', this.element)
  124. .disableSelection();
  125. //Matching axis name
  126. this._handles.mouseover(function() {
  127. if (!self.resizing) {
  128. if (this.className)
  129. var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
  130. //Axis, default = se
  131. self.axis = axis && axis[1] ? axis[1] : 'se';
  132. }
  133. });
  134. //If we want to auto hide the elements
  135. if (o.autoHide) {
  136. this._handles.hide();
  137. $(this.element)
  138. .addClass("ui-resizable-autohide")
  139. .hover(function() {
  140. $(this).removeClass("ui-resizable-autohide");
  141. self._handles.show();
  142. },
  143. function(){
  144. if (!self.resizing) {
  145. $(this).addClass("ui-resizable-autohide");
  146. self._handles.hide();
  147. }
  148. });
  149. }
  150. //Initialize the mouse interaction
  151. this._mouseInit();
  152. },
  153. destroy: function() {
  154. this._mouseDestroy();
  155. var _destroy = function(exp) {
  156. $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
  157. .removeData("resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
  158. };
  159. //TODO: Unwrap at same DOM position
  160. if (this.elementIsWrapper) {
  161. _destroy(this.element);
  162. var wrapper = this.element;
  163. wrapper.after(
  164. this.originalElement.css({
  165. position: wrapper.css('position'),
  166. width: wrapper.outerWidth(),
  167. height: wrapper.outerHeight(),
  168. top: wrapper.css('top'),
  169. left: wrapper.css('left')
  170. })
  171. ).remove();
  172. }
  173. this.originalElement.css('resize', this.originalResizeStyle);
  174. _destroy(this.originalElement);
  175. return this;
  176. },
  177. _mouseCapture: function(event) {
  178. var handle = false;
  179. for (var i in this.handles) {
  180. if ($(this.handles[i])[0] == event.target) {
  181. handle = true;
  182. }
  183. }
  184. return !this.options.disabled && handle;
  185. },
  186. _mouseStart: function(event) {
  187. var o = this.options, iniPos = this.element.position(), el = this.element;
  188. this.resizing = true;
  189. this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
  190. // bugfix for http://dev.jquery.com/ticket/1749
  191. if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
  192. el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
  193. }
  194. //Opera fixing relative position
  195. if ($.browser.opera && (/relative/).test(el.css('position')))
  196. el.css({ position: 'relative', top: 'auto', left: 'auto' });
  197. this._renderProxy();
  198. var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));
  199. if (o.containment) {
  200. curleft += $(o.containment).scrollLeft() || 0;
  201. curtop += $(o.containment).scrollTop() || 0;
  202. }
  203. //Store needed variables
  204. this.offset = this.helper.offset();
  205. this.position = { left: curleft, top: curtop };
  206. this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  207. this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  208. this.originalPosition = { left: curleft, top: curtop };
  209. this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
  210. this.originalMousePosition = { left: event.pageX, top: event.pageY };
  211. //Aspect Ratio
  212. this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
  213. var cursor = $('.ui-resizable-' + this.axis).css('cursor');
  214. $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor);
  215. el.addClass("ui-resizable-resizing");
  216. this._propagate("start", event);
  217. return true;
  218. },
  219. _mouseDrag: function(event) {
  220. //Increase performance, avoid regex
  221. var el = this.helper, o = this.options, props = {},
  222. self = this, smp = this.originalMousePosition, a = this.axis;
  223. var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
  224. var trigger = this._change[a];
  225. if (!trigger) return false;
  226. // Calculate the attrs that will be change
  227. var data = trigger.apply(this, [event, dx, dy]), ie6 = $.browser.msie && $.browser.version < 7, csdif = this.sizeDiff;
  228. if (this._aspectRatio || event.shiftKey)
  229. data = this._updateRatio(data, event);
  230. data = this._respectSize(data, event);
  231. // plugins callbacks need to be called first
  232. this._propagate("resize", event);
  233. el.css({
  234. top: this.position.top + "px", left: this.position.left + "px",
  235. width: this.size.width + "px", height: this.size.height + "px"
  236. });
  237. if (!this._helper && this._proportionallyResizeElements.length)
  238. this._proportionallyResize();
  239. this._updateCache(data);
  240. // calling the user callback at the end
  241. this._trigger('resize', event, this.ui());
  242. return false;
  243. },
  244. _mouseStop: function(event) {
  245. this.resizing = false;
  246. var o = this.options, self = this;
  247. if(this._helper) {
  248. var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  249. soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
  250. soffsetw = ista ? 0 : self.sizeDiff.width;
  251. var s = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) },
  252. left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
  253. top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
  254. if (!o.animate)
  255. this.element.css($.extend(s, { top: top, left: left }));
  256. self.helper.height(self.size.height);
  257. self.helper.width(self.size.width);
  258. if (this._helper && !o.animate) this._proportionallyResize();
  259. }
  260. $('body').css('cursor', 'auto');
  261. this.element.removeClass("ui-resizable-resizing");
  262. this._propagate("stop", event);
  263. if (this._helper) this.helper.remove();
  264. return false;
  265. },
  266. _updateCache: function(data) {
  267. var o = this.options;
  268. this.offset = this.helper.offset();
  269. if (isNumber(data.left)) this.position.left = data.left;
  270. if (isNumber(data.top)) this.position.top = data.top;
  271. if (isNumber(data.height)) this.size.height = data.height;
  272. if (isNumber(data.width)) this.size.width = data.width;
  273. },
  274. _updateRatio: function(data, event) {
  275. var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
  276. if (data.height) data.width = (csize.height * this.aspectRatio);
  277. else if (data.width) data.height = (csize.width / this.aspectRatio);
  278. if (a == 'sw') {
  279. data.left = cpos.left + (csize.width - data.width);
  280. data.top = null;
  281. }
  282. if (a == 'nw') {
  283. data.top = cpos.top + (csize.height - data.height);
  284. data.left = cpos.left + (csize.width - data.width);
  285. }
  286. return data;
  287. },
  288. _respectSize: function(data, event) {
  289. var el = this.helper, o = this.options, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
  290. ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
  291. isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
  292. if (isminw) data.width = o.minWidth;
  293. if (isminh) data.height = o.minHeight;
  294. if (ismaxw) data.width = o.maxWidth;
  295. if (ismaxh) data.height = o.maxHeight;
  296. var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height;
  297. var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
  298. if (isminw && cw) data.left = dw - o.minWidth;
  299. if (ismaxw && cw) data.left = dw - o.maxWidth;
  300. if (isminh && ch) data.top = dh - o.minHeight;
  301. if (ismaxh && ch) data.top = dh - o.maxHeight;
  302. // fixing jump error on top/left - bug #2330
  303. var isNotwh = !data.width && !data.height;
  304. if (isNotwh && !data.left && data.top) data.top = null;
  305. else if (isNotwh && !data.top && data.left) data.left = null;
  306. return data;
  307. },
  308. _proportionallyResize: function() {
  309. var o = this.options;
  310. if (!this._proportionallyResizeElements.length) return;
  311. var element = this.helper || this.element;
  312. for (var i=0; i < this._proportionallyResizeElements.length; i++) {
  313. var prel = this._proportionallyResizeElements[i];
  314. if (!this.borderDif) {
  315. var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')],
  316. p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')];
  317. this.borderDif = $.map(b, function(v, i) {
  318. var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0;
  319. return border + padding;
  320. });
  321. }
  322. if ($.browser.msie && !(!($(element).is(':hidden') || $(element).parents(':hidden').length)))
  323. continue;
  324. prel.css({
  325. height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
  326. width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
  327. });
  328. };
  329. },
  330. _renderProxy: function() {
  331. var el = this.element, o = this.options;
  332. this.elementOffset = el.offset();
  333. if(this._helper) {
  334. this.helper = this.helper || $('<div style="overflow:hidden;"></div>');
  335. // fix ie6 offset TODO: This seems broken
  336. var ie6 = $.browser.msie && $.browser.version < 7, ie6offset = (ie6 ? 1 : 0),
  337. pxyoffset = ( ie6 ? 2 : -1 );
  338. this.helper.addClass(this._helper).css({
  339. width: this.element.outerWidth() + pxyoffset,
  340. height: this.element.outerHeight() + pxyoffset,
  341. position: 'absolute',
  342. left: this.elementOffset.left - ie6offset +'px',
  343. top: this.elementOffset.top - ie6offset +'px',
  344. zIndex: ++o.zIndex //TODO: Don't modify option
  345. });
  346. this.helper
  347. .appendTo("body")
  348. .disableSelection();
  349. } else {
  350. this.helper = this.element;
  351. }
  352. },
  353. _change: {
  354. e: function(event, dx, dy) {
  355. return { width: this.originalSize.width + dx };
  356. },
  357. w: function(event, dx, dy) {
  358. var o = this.options, cs = this.originalSize, sp = this.originalPosition;
  359. return { left: sp.left + dx, width: cs.width - dx };
  360. },
  361. n: function(event, dx, dy) {
  362. var o = this.options, cs = this.originalSize, sp = this.originalPosition;
  363. return { top: sp.top + dy, height: cs.height - dy };
  364. },
  365. s: function(event, dx, dy) {
  366. return { height: this.originalSize.height + dy };
  367. },
  368. se: function(event, dx, dy) {
  369. return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  370. },
  371. sw: function(event, dx, dy) {
  372. return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  373. },
  374. ne: function(event, dx, dy) {
  375. return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  376. },
  377. nw: function(event, dx, dy) {
  378. return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  379. }
  380. },
  381. _propagate: function(n, event) {
  382. $.ui.plugin.call(this, n, [event, this.ui()]);
  383. (n != "resize" && this._trigger(n, event, this.ui()));
  384. },
  385. plugins: {},
  386. ui: function() {
  387. return {
  388. originalElement: this.originalElement,
  389. element: this.element,
  390. helper: this.helper,
  391. position: this.position,
  392. size: this.size,
  393. originalSize: this.originalSize,
  394. originalPosition: this.originalPosition
  395. };
  396. }
  397. });
  398. $.extend($.ui.resizable, {
  399. version: "1.8"
  400. });
  401. /*
  402. * Resizable Extensions
  403. */
  404. $.ui.plugin.add("resizable", "alsoResize", {
  405. start: function(event, ui) {
  406. var self = $(this).data("resizable"), o = self.options;
  407. var _store = function(exp) {
  408. $(exp).each(function() {
  409. $(this).data("resizable-alsoresize", {
  410. width: parseInt($(this).width(), 10), height: parseInt($(this).height(), 10),
  411. left: parseInt($(this).css('left'), 10), top: parseInt($(this).css('top'), 10)
  412. });
  413. });
  414. };
  415. if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
  416. if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
  417. else { $.each(o.alsoResize, function(exp, c) { _store(exp); }); }
  418. }else{
  419. _store(o.alsoResize);
  420. }
  421. },
  422. resize: function(event, ui){
  423. var self = $(this).data("resizable"), o = self.options, os = self.originalSize, op = self.originalPosition;
  424. var delta = {
  425. height: (self.size.height - os.height) || 0, width: (self.size.width - os.width) || 0,
  426. top: (self.position.top - op.top) || 0, left: (self.position.left - op.left) || 0
  427. },
  428. _alsoResize = function(exp, c) {
  429. $(exp).each(function() {
  430. var el = $(this), start = $(this).data("resizable-alsoresize"), style = {}, css = c && c.length ? c : ['width', 'height', 'top', 'left'];
  431. $.each(css || ['width', 'height', 'top', 'left'], function(i, prop) {
  432. var sum = (start[prop]||0) + (delta[prop]||0);
  433. if (sum && sum >= 0)
  434. style[prop] = sum || null;
  435. });
  436. //Opera fixing relative position
  437. if (/relative/.test(el.css('position')) && $.browser.opera) {
  438. self._revertToRelativePosition = true;
  439. el.css({ position: 'absolute', top: 'auto', left: 'auto' });
  440. }
  441. el.css(style);
  442. });
  443. };
  444. if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
  445. $.each(o.alsoResize, function(exp, c) { _alsoResize(exp, c); });
  446. }else{
  447. _alsoResize(o.alsoResize);
  448. }
  449. },
  450. stop: function(event, ui){
  451. var self = $(this).data("resizable");
  452. //Opera fixing relative position
  453. if (self._revertToRelativePosition && $.browser.opera) {
  454. self._revertToRelativePosition = false;
  455. el.css({ position: 'relative' });
  456. }
  457. $(this).removeData("resizable-alsoresize-start");
  458. }
  459. });
  460. $.ui.plugin.add("resizable", "animate", {
  461. stop: function(event, ui) {
  462. var self = $(this).data("resizable"), o = self.options;
  463. var pr = self._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  464. soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : self.sizeDiff.height,
  465. soffsetw = ista ? 0 : self.sizeDiff.width;
  466. var style = { width: (self.size.width - soffsetw), height: (self.size.height - soffseth) },
  467. left = (parseInt(self.element.css('left'), 10) + (self.position.left - self.originalPosition.left)) || null,
  468. top = (parseInt(self.element.css('top'), 10) + (self.position.top - self.originalPosition.top)) || null;
  469. self.element.animate(
  470. $.extend(style, top && left ? { top: top, left: left } : {}), {
  471. duration: o.animateDuration,
  472. easing: o.animateEasing,
  473. step: function() {
  474. var data = {
  475. width: parseInt(self.element.css('width'), 10),
  476. height: parseInt(self.element.css('height'), 10),
  477. top: parseInt(self.element.css('top'), 10),
  478. left: parseInt(self.element.css('left'), 10)
  479. };
  480. if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });
  481. // propagating resize, and updating values for each animation step
  482. self._updateCache(data);
  483. self._propagate("resize", event);
  484. }
  485. }
  486. );
  487. }
  488. });
  489. $.ui.plugin.add("resizable", "containment", {
  490. start: function(event, ui) {
  491. var self = $(this).data("resizable"), o = self.options, el = self.element;
  492. var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
  493. if (!ce) return;
  494. self.containerElement = $(ce);
  495. if (/document/.test(oc) || oc == document) {
  496. self.containerOffset = { left: 0, top: 0 };
  497. self.containerPosition = { left: 0, top: 0 };
  498. self.parentData = {
  499. element: $(document), left: 0, top: 0,
  500. width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
  501. };
  502. }
  503. // i'm a node, so compute top, left, right, bottom
  504. else {
  505. var element = $(ce), p = [];
  506. $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
  507. self.containerOffset = element.offset();
  508. self.containerPosition = element.position();
  509. self.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
  510. var co = self.containerOffset, ch = self.containerSize.height, cw = self.containerSize.width,
  511. width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
  512. self.parentData = {
  513. element: ce, left: co.left, top: co.top, width: width, height: height
  514. };
  515. }
  516. },
  517. resize: function(event, ui) {
  518. var self = $(this).data("resizable"), o = self.options,
  519. ps = self.containerSize, co = self.containerOffset, cs = self.size, cp = self.position,
  520. pRatio = self._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = self.containerElement;
  521. if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
  522. if (cp.left < (self._helper ? co.left : 0)) {
  523. self.size.width = self.size.width + (self._helper ? (self.position.left - co.left) : (self.position.left - cop.left));
  524. if (pRatio) self.size.height = self.size.width / o.aspectRatio;
  525. self.position.left = o.helper ? co.left : 0;
  526. }
  527. if (cp.top < (self._helper ? co.top : 0)) {
  528. self.size.height = self.size.height + (self._helper ? (self.position.top - co.top) : self.position.top);
  529. if (pRatio) self.size.width = self.size.height * o.aspectRatio;
  530. self.position.top = self._helper ? co.top : 0;
  531. }
  532. self.offset.left = self.parentData.left+self.position.left;
  533. self.offset.top = self.parentData.top+self.position.top;
  534. var woset = Math.abs( (self._helper ? self.offset.left - cop.left : (self.offset.left - cop.left)) + self.sizeDiff.width ),
  535. hoset = Math.abs( (self._helper ? self.offset.top - cop.top : (self.offset.top - co.top)) + self.sizeDiff.height );
  536. var isParent = self.containerElement.get(0) == self.element.parent().get(0),
  537. isOffsetRelative = /relative|absolute/.test(self.containerElement.css('position'));
  538. if(isParent && isOffsetRelative) woset -= self.parentData.left;
  539. if (woset + self.size.width >= self.parentData.width) {
  540. self.size.width = self.parentData.width - woset;
  541. if (pRatio) self.size.height = self.size.width / self.aspectRatio;
  542. }
  543. if (hoset + self.size.height >= self.parentData.height) {
  544. self.size.height = self.parentData.height - hoset;
  545. if (pRatio) self.size.width = self.size.height * self.aspectRatio;
  546. }
  547. },
  548. stop: function(event, ui){
  549. var self = $(this).data("resizable"), o = self.options, cp = self.position,
  550. co = self.containerOffset, cop = self.containerPosition, ce = self.containerElement;
  551. var helper = $(self.helper), ho = helper.offset(), w = helper.outerWidth() - self.sizeDiff.width, h = helper.outerHeight() - self.sizeDiff.height;
  552. if (self._helper && !o.animate && (/relative/).test(ce.css('position')))
  553. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  554. if (self._helper && !o.animate && (/static/).test(ce.css('position')))
  555. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  556. }
  557. });
  558. $.ui.plugin.add("resizable", "ghost", {
  559. start: function(event, ui) {
  560. var self = $(this).data("resizable"), o = self.options, cs = self.size;
  561. self.ghost = self.originalElement.clone();
  562. self.ghost
  563. .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
  564. .addClass('ui-resizable-ghost')
  565. .addClass(typeof o.ghost == 'string' ? o.ghost : '');
  566. self.ghost.appendTo(self.helper);
  567. },
  568. resize: function(event, ui){
  569. var self = $(this).data("resizable"), o = self.options;
  570. if (self.ghost) self.ghost.css({ position: 'relative', height: self.size.height, width: self.size.width });
  571. },
  572. stop: function(event, ui){
  573. var self = $(this).data("resizable"), o = self.options;
  574. if (self.ghost && self.helper) self.helper.get(0).removeChild(self.ghost.get(0));
  575. }
  576. });
  577. $.ui.plugin.add("resizable", "grid", {
  578. resize: function(event, ui) {
  579. var self = $(this).data("resizable"), o = self.options, cs = self.size, os = self.originalSize, op = self.originalPosition, a = self.axis, ratio = o._aspectRatio || event.shiftKey;
  580. o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
  581. var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1);
  582. if (/^(se|s|e)$/.test(a)) {
  583. self.size.width = os.width + ox;
  584. self.size.height = os.height + oy;
  585. }
  586. else if (/^(ne)$/.test(a)) {
  587. self.size.width = os.width + ox;
  588. self.size.height = os.height + oy;
  589. self.position.top = op.top - oy;
  590. }
  591. else if (/^(sw)$/.test(a)) {
  592. self.size.width = os.width + ox;
  593. self.size.height = os.height + oy;
  594. self.position.left = op.left - ox;
  595. }
  596. else {
  597. self.size.width = os.width + ox;
  598. self.size.height = os.height + oy;
  599. self.position.top = op.top - oy;
  600. self.position.left = op.left - ox;
  601. }
  602. }
  603. });
  604. var num = function(v) {
  605. return parseInt(v, 10) || 0;
  606. };
  607. var isNumber = function(value) {
  608. return !isNaN(parseInt(value, 10));
  609. };
  610. })(jQuery);