@@ -62,9 +62,11 @@ define(function (require, exports, module) {
62
62
ViewUtils = require ( "utils/ViewUtils" ) ,
63
63
PreferencesManager = require ( "preferences/PreferencesManager" ) ;
64
64
65
- var $mainView ;
65
+ var $mainView ,
66
+ $sideBar ;
66
67
67
- var isResizing = false ;
68
+ var isResizing = false ,
69
+ isWindowResizing = false ;
68
70
69
71
/**
70
72
* Shows a resizable element.
@@ -133,6 +135,25 @@ define(function (require, exports, module) {
133
135
return $ ( element ) . is ( ":visible" ) ;
134
136
}
135
137
138
+ function _isPercentage ( value ) {
139
+ return ! $ . isNumeric ( value ) && value . indexOf ( '%' ) > - 1 ;
140
+ }
141
+
142
+ function _percetageToPixels ( value , total ) {
143
+ return parseFloat ( value . replace ( '%' , '' ) ) * ( total / 100 ) ;
144
+ }
145
+
146
+ function _sideBarMaxSize ( ) {
147
+ var siblingsWidth = 0 ;
148
+ $sideBar . siblings ( ) . not ( ".content" ) . each ( function ( i , elem ) {
149
+ var $elem = $ ( elem ) ;
150
+ if ( $elem . css ( "display" ) !== "none" ) {
151
+ siblingsWidth += $elem . outerWidth ( ) ;
152
+ }
153
+ } ) ;
154
+ return $ ( ".main-view" ) . width ( ) - siblingsWidth - 1 ;
155
+ }
156
+
136
157
/**
137
158
* Adds resizing and (optionally) expand/collapse capabilities to a given html element. The element's size
138
159
* & visibility are automatically saved & restored as a view-state preference.
@@ -417,6 +438,10 @@ define(function (require, exports, module) {
417
438
// respect max size if one provided (e.g. by WorkspaceManager)
418
439
var maxSize = $element . data ( "maxsize" ) ;
419
440
if ( maxSize !== undefined ) {
441
+ // if provided as percentage size convert it to a pixel size
442
+ if ( _isPercentage ( maxSize ) ) {
443
+ maxSize = _percetageToPixels ( maxSize , _sideBarMaxSize ( ) ) ;
444
+ }
420
445
newSize = Math . min ( newSize , maxSize ) ;
421
446
}
422
447
@@ -496,11 +521,52 @@ define(function (require, exports, module) {
496
521
}
497
522
}
498
523
524
+ function updateResizeLimits ( ) {
525
+ var sideBarMaxSize = _sideBarMaxSize ( ) ,
526
+ maxSize = $sideBar . data ( "maxsize" ) ,
527
+ width = false ;
528
+
529
+ if ( maxSize !== undefined && _isPercentage ( maxSize ) ) {
530
+ sideBarMaxSize = _percetageToPixels ( maxSize , sideBarMaxSize ) ;
531
+ }
532
+
533
+ if ( $sideBar . width ( ) > sideBarMaxSize ) {
534
+ // Adjust the sideBar's width in case it exceeds the window's width when resizing the window.
535
+ $sideBar . width ( sideBarMaxSize ) ;
536
+ resyncSizer ( $sideBar ) ;
537
+ $ ( ".content" ) . css ( "left" , $sideBar . width ( ) ) ;
538
+ $sideBar . trigger ( "panelResizeStart" , $sideBar . width ( ) ) ;
539
+ $sideBar . trigger ( "panelResizeUpdate" , [ $sideBar . width ( ) ] ) ;
540
+ $sideBar . trigger ( "panelResizeEnd" , [ $sideBar . width ( ) ] ) ;
541
+ }
542
+ }
543
+
544
+ function onWindowResize ( e ) {
545
+ if ( $sideBar . css ( "display" ) === "none" ) {
546
+ return ;
547
+ }
548
+
549
+ if ( ! isWindowResizing ) {
550
+ isWindowResizing = true ;
551
+
552
+ // We don't need any fancy debouncing here - we just need to react before the user can start
553
+ // resizing any panels at the new window size. So just listen for first mousemove once the
554
+ // window resize releases mouse capture.
555
+ $ ( window . document ) . one ( "mousemove" , function ( ) {
556
+ isWindowResizing = false ;
557
+ updateResizeLimits ( ) ;
558
+ } ) ;
559
+ }
560
+ }
561
+
562
+ window . addEventListener ( "resize" , onWindowResize , true ) ;
563
+
499
564
// Scan DOM for horz-resizable and vert-resizable classes and make them resizable
500
565
AppInit . htmlReady ( function ( ) {
501
566
var minSize = DEFAULT_MIN_SIZE ;
502
567
503
568
$mainView = $ ( ".main-view" ) ;
569
+ $sideBar = $ ( "#sidebar" ) ;
504
570
505
571
$ ( ".vert-resizable" ) . each ( function ( index , element ) {
506
572
0 commit comments