@@ -101,6 +101,29 @@ define(function (require, exports, module) {
101101 }
102102 }
103103
104+ /**
105+ * Removes the resizability of an element if it's resizable
106+ * @param {DOMNode } element Html element in which to remove sizing
107+ */
108+ function removeSizable ( element ) {
109+ var removeSizableFunc = $ ( element ) . data ( "removeSizable" ) ;
110+ if ( removeSizableFunc ) {
111+ removeSizableFunc . apply ( element ) ;
112+ }
113+ }
114+
115+ /**
116+ * Updates the sizing div by resyncing to the sizing edge of the element
117+ * Call this method after manually changing the size of the element
118+ * @param {DOMNode } element Html element whose sizer should be resynchronized
119+ */
120+ function resyncSizer ( element ) {
121+ var resyncSizerFunc = $ ( element ) . data ( "resyncSizer" ) ;
122+ if ( resyncSizerFunc ) {
123+ resyncSizerFunc . apply ( element ) ;
124+ }
125+ }
126+
104127 /**
105128 * Returns the visibility state of a resizable element.
106129 * @param {DOMNode } element Html element to toggle
@@ -144,9 +167,10 @@ define(function (require, exports, module) {
144167 * the resizable element's size (useful for siblings laid out to the right of
145168 * the element). Must lie in element's parent's subtree.
146169 * @param {?boolean } createdByWorkspaceManager For internal use only
170+ * @param {?boolean } usePercentages Maintain the size of the element as a percentage of its parent
171+ * the default is to maintain the size of the element in pixels
147172 */
148- function makeResizable ( element , direction , position , minSize , collapsible , forceLeft , createdByWorkspaceManager ) {
149-
173+ function makeResizable ( element , direction , position , minSize , collapsible , forceLeft , createdByWorkspaceManager , usePercentages ) {
150174 var $resizer = $ ( '<div class="' + direction + '-resizer"></div>' ) ,
151175 $element = $ ( element ) ,
152176 $parent = $element . parent ( ) ,
@@ -157,7 +181,40 @@ define(function (require, exports, module) {
157181 animationRequest = null ,
158182 directionProperty = direction === DIRECTION_HORIZONTAL ? "clientX" : "clientY" ,
159183 directionIncrement = ( position === POSITION_TOP || position === POSITION_LEFT ) ? 1 : - 1 ,
160- elementSizeFunction = direction === DIRECTION_HORIZONTAL ? $element . width : $element . height ,
184+ parentSizeFunction = direction === DIRECTION_HORIZONTAL ? $parent . innerWidth : $parent . innerHeight ,
185+
186+ elementSizeFunction = function ( newSize ) {
187+ if ( ! newSize ) {
188+ // calling the function as a getter
189+ if ( direction === DIRECTION_HORIZONTAL ) {
190+ return this . width ( ) ;
191+ } else {
192+ return this . height ( ) ;
193+ }
194+ } else if ( ! usePercentages ) {
195+ if ( direction === DIRECTION_HORIZONTAL ) {
196+ return this . width ( newSize ) ;
197+ } else {
198+ return this . height ( newSize ) ;
199+ }
200+ } else {
201+ // calling the function as a setter
202+ var parentSize = parentSizeFunction . apply ( $parent ) ,
203+ percentage ,
204+ prop ;
205+
206+ if ( direction === DIRECTION_HORIZONTAL ) {
207+ prop = "width" ;
208+ } else {
209+ prop = "height" ;
210+ }
211+ percentage = newSize / parentSize ;
212+ this . css ( prop , ( percentage * 100 ) + "%" ) ;
213+
214+ return this ; // chainable
215+ }
216+ } ,
217+
161218 resizerCSSPosition = direction === DIRECTION_HORIZONTAL ? "left" : "top" ,
162219 contentSizeFunction = direction === DIRECTION_HORIZONTAL ? $resizableElement . width : $resizableElement . height ;
163220
@@ -197,6 +254,30 @@ define(function (require, exports, module) {
197254 }
198255 }
199256
257+ // If the resizer is positioned right or bottom of the panel, we need to listen to
258+ // reposition it if the element size changes externally
259+ function repositionResizer ( elementSize ) {
260+ var resizerPosition = elementSize || 1 ;
261+ if ( position === POSITION_RIGHT || position === POSITION_BOTTOM ) {
262+ $resizer . css ( resizerCSSPosition , resizerPosition ) ;
263+ }
264+ }
265+
266+ $element . data ( "removeSizable" , function ( ) {
267+ $resizer . off ( ".resizer" ) ;
268+
269+ $element . removeData ( "show" ) ;
270+ $element . removeData ( "hide" ) ;
271+ $element . removeData ( "resyncSizer" ) ;
272+ $element . removeData ( "removeSizable" ) ;
273+
274+ $resizer . remove ( ) ;
275+ } ) ;
276+
277+ $element . data ( "resyncSizer" , function ( ) {
278+ repositionResizer ( elementSizeFunction . apply ( $element ) ) ;
279+ } ) ;
280+
200281 $element . data ( "show" , function ( ) {
201282 var elementOffset = $element . offset ( ) ,
202283 elementSize = elementSizeFunction . apply ( $element ) || elementPrefs . size ,
@@ -247,16 +328,8 @@ define(function (require, exports, module) {
247328 PreferencesManager . setViewState ( elementID , elementPrefs , null , isResizing ) ;
248329 } ) ;
249330
250- // If the resizer is positioned right or bottom of the panel, we need to listen to
251- // reposition it if the element size changes externally
252- function repositionResizer ( elementSize ) {
253- var resizerPosition = elementSize || 1 ;
254- if ( position === POSITION_RIGHT || position === POSITION_BOTTOM ) {
255- $resizer . css ( resizerCSSPosition , resizerPosition ) ;
256- }
257- }
258-
259- $resizer . on ( "mousedown" , function ( e ) {
331+
332+ $resizer . on ( "mousedown.resizer" , function ( e ) {
260333 var $resizeShield = $ ( "<div class='resizing-container " + direction + "-resizing' />" ) ,
261334 startPosition = e [ directionProperty ] ,
262335 startSize = $element . is ( ":visible" ) ? elementSizeFunction . apply ( $element ) : 0 ,
@@ -408,7 +481,7 @@ define(function (require, exports, module) {
408481 }
409482 }
410483 }
411-
484+
412485 // Scan DOM for horz-resizable and vert-resizable classes and make them resizable
413486 AppInit . htmlReady ( function ( ) {
414487 var minSize = DEFAULT_MIN_SIZE ;
@@ -465,6 +538,8 @@ define(function (require, exports, module) {
465538 PreferencesManager . convertPreferences ( module , { "panelState" : "user" } , true , _isPanelPreferences ) ;
466539
467540 exports . makeResizable = makeResizable ;
541+ exports . removeSizable = removeSizable ;
542+ exports . resyncSizer = resyncSizer ;
468543 exports . toggle = toggle ;
469544 exports . show = show ;
470545 exports . hide = hide ;
@@ -475,4 +550,6 @@ define(function (require, exports, module) {
475550 exports . DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL ;
476551 exports . POSITION_TOP = POSITION_TOP ;
477552 exports . POSITION_RIGHT = POSITION_RIGHT ;
553+ exports . POSITION_BOTTOM = POSITION_BOTTOM ;
554+ exports . POSITION_LEFT = POSITION_LEFT ;
478555} ) ;
0 commit comments