11angular . module ( 'angularResizable' , [ ] )
2- . directive ( 'resizable' , function ( ) {
2+ . directive ( 'resizable' , function ( $parse ) {
33 var toCall ;
44 function throttle ( fun ) {
55 if ( toCall === undefined ) {
@@ -14,42 +14,47 @@ angular.module('angularResizable', [])
1414 }
1515 return {
1616 restrict : 'AE' ,
17- scope : {
18- rDirections : '=' ,
19- rCenteredX : '=' ,
20- rCenteredY : '=' ,
21- rWidth : '=' ,
22- rHeight : '=' ,
23- rFlex : '=' ,
24- rGrabber : '@' ,
25- rDisabled : '@' ,
26- rNoThrottle : '=' ,
27- resizable : '@' ,
28- } ,
17+ /*
18+ Do not use isolated scope. Use attr instead. Attr should behave like the following isolated scope:
19+ rDirections: '=',
20+ rCenteredX: '=',
21+ rCenteredY: '=',
22+ rWidth: '=',
23+ rHeight: '=',
24+ rFlex: '=',
25+ rGrabber: '@',
26+ rDisabled: '@',
27+ rNoThrottle: '=',
28+ resizable: '@',
29+ */
30+ scope : false ,
2931 link : function ( scope , element , attr ) {
30- if ( scope . resizable === 'false' ) return ;
32+ if ( attr . resizable === 'false' ) return ;
3133
3234 var flexBasis = 'flexBasis' in document . documentElement . style ? 'flexBasis' :
3335 'webkitFlexBasis' in document . documentElement . style ? 'webkitFlexBasis' :
3436 'msFlexPreferredSize' in document . documentElement . style ? 'msFlexPreferredSize' : 'flexBasis' ;
3537
38+ var rFlex = $parse ( attr . rFlex ) ( ) ;
39+ var rNoThrottle = $parse ( attr . rNoThrottle ) ;
40+
3641 // register watchers on width and height attributes if they are set
37- scope . $watch ( ' rWidth' , function ( value ) {
38- element [ 0 ] . style [ scope . rFlex ? flexBasis : 'width' ] = scope . rWidth + 'px' ;
42+ scope . $watch ( attr . rWidth , function ( value ) {
43+ element [ 0 ] . style [ rFlex ? flexBasis : 'width' ] = value + 'px' ;
3944 } ) ;
4045 scope . $watch ( 'rHeight' , function ( value ) {
41- element [ 0 ] . style [ scope . rFlex ? flexBasis : 'height' ] = scope . rHeight + 'px' ;
46+ element [ 0 ] . style [ rFlex ? flexBasis : 'height' ] = value + 'px' ;
4247 } ) ;
4348
4449 element . addClass ( 'resizable' ) ;
4550
4651 var style = window . getComputedStyle ( element [ 0 ] , null ) ,
4752 w ,
4853 h ,
49- dir = scope . rDirections || [ 'right' ] ,
50- vx = scope . rCenteredX ? 2 : 1 , // if centered double velocity
51- vy = scope . rCenteredY ? 2 : 1 , // if centered double velocity
52- inner = scope . rGrabber ? scope . rGrabber : '<span></span>' ,
54+ dir = $parse ( attr . rDirections ) ( ) || [ 'right' ] ,
55+ vx = $parse ( attr . rCenteredX ) ( ) ? 2 : 1 , // if centered double velocity
56+ vy = $parse ( attr . rCenteredY ) ( ) ? 2 : 1 , // if centered double velocity
57+ inner = attr . rGrabber ? attr . rGrabber : '<span></span>' ,
5358 start ,
5459 dragDir ,
5560 axis ,
@@ -58,9 +63,9 @@ angular.module('angularResizable', [])
5863 var updateInfo = function ( e ) {
5964 info . width = false ; info . height = false ;
6065 if ( axis === 'x' )
61- info . width = parseInt ( element [ 0 ] . style [ scope . rFlex ? flexBasis : 'width' ] ) ;
66+ info . width = parseInt ( element [ 0 ] . style [ rFlex ? flexBasis : 'width' ] ) ;
6267 else
63- info . height = parseInt ( element [ 0 ] . style [ scope . rFlex ? flexBasis : 'height' ] ) ;
68+ info . height = parseInt ( element [ 0 ] . style [ rFlex ? flexBasis : 'height' ] ) ;
6469 info . id = element [ 0 ] . id ;
6570 info . evt = e ;
6671 } ;
@@ -77,27 +82,27 @@ angular.module('angularResizable', [])
7782 var prop , offset = axis === 'x' ? start - getClientX ( e ) : start - getClientY ( e ) ;
7883 switch ( dragDir ) {
7984 case 'top' :
80- prop = scope . rFlex ? flexBasis : 'height' ;
85+ prop = rFlex ? flexBasis : 'height' ;
8186 element [ 0 ] . style [ prop ] = h + ( offset * vy ) + 'px' ;
8287 break ;
8388 case 'bottom' :
84- prop = scope . rFlex ? flexBasis : 'height' ;
89+ prop = rFlex ? flexBasis : 'height' ;
8590 element [ 0 ] . style [ prop ] = h - ( offset * vy ) + 'px' ;
8691 break ;
8792 case 'right' :
88- prop = scope . rFlex ? flexBasis : 'width' ;
93+ prop = rFlex ? flexBasis : 'width' ;
8994 element [ 0 ] . style [ prop ] = w - ( offset * vx ) + 'px' ;
9095 break ;
9196 case 'left' :
92- prop = scope . rFlex ? flexBasis : 'width' ;
97+ prop = rFlex ? flexBasis : 'width' ;
9398 element [ 0 ] . style [ prop ] = w + ( offset * vx ) + 'px' ;
9499 break ;
95100 }
96101 updateInfo ( e ) ;
97102 function resizingEmit ( ) {
98103 scope . $emit ( 'angular-resizable.resizing' , info ) ;
99104 }
100- if ( scope . rNoThrottle ) {
105+ if ( rNoThrottle ( ) ) {
101106 resizingEmit ( ) ;
102107 } else {
103108 throttle ( resizingEmit ) ;
@@ -149,7 +154,7 @@ angular.module('angularResizable', [])
149154 grabber . ondragstart = function ( ) { return false ; } ;
150155
151156 var down = function ( e ) {
152- var disabled = ( scope . rDisabled === 'true' ) ;
157+ var disabled = ( attr . rDisabled === 'true' ) ;
153158 if ( ! disabled && ( e . which === 1 || e . touches ) ) {
154159 // left mouse click or touch screen
155160 dragStart ( e , direction ) ;
0 commit comments