annotate jquery-ui/development-bundle/ui/jquery.ui.resizable.js @ 0:b2e4605f20b2

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