@@ -184,18 +184,44 @@ astroidFramework.directive("astroidspacing", ["$http", function ($http) {
184184 [ 'top' , 'right' , 'bottom' , 'left' , 'unit' ] . forEach ( function ( _prop ) {
185185 $element . find ( '[data-device=' + _device + '][data-attr=' + _prop + ']' ) . val ( _value [ _device ] [ _prop ] ) ;
186186 } ) ;
187+ if ( _value [ _device ] . lock ) {
188+ $element . find ( 'button[data-device=' + _device + ']' ) . removeClass ( 'btn-light' ) . addClass ( 'btn-purple' ) . addClass ( 'active' ) ;
189+ } else {
190+ $element . find ( 'button[data-device=' + _device + ']' ) . removeClass ( 'btn-purple' ) . removeClass ( 'active' ) . addClass ( 'btn-light' ) ;
191+ }
192+
193+ if ( _value [ _device ] . lock ) {
194+ [ 'right' , 'bottom' , 'left' ] . forEach ( function ( _prop ) {
195+ $element . find ( 'input[data-device=' + _device + '][data-attr=' + _prop + ']' ) . prop ( 'disabled' , true ) ;
196+ } ) ;
197+ } else {
198+ [ 'right' , 'bottom' , 'left' ] . forEach ( function ( _prop ) {
199+ $element . find ( 'input[data-device=' + _device + '][data-attr=' + _prop + ']' ) . prop ( 'disabled' , false ) ;
200+ } ) ;
201+ }
202+
187203 } ) ;
188204
189205 } , 100 ) ;
190206
207+ $scope . setDevice = function ( _device ) {
208+ $element . find ( 'a' ) . removeClass ( 'active' ) ;
209+ $element . find ( 'a[data-device=' + _device + ']' ) . addClass ( 'active' ) ;
210+ $element . find ( '.astroid-spacing-field' ) . addClass ( 'd-none' ) ;
211+ $element . find ( '.astroid-spacing-field[data-device=' + _device + ']' ) . removeClass ( 'd-none' ) ;
212+ }
213+
214+ $scope . setDevice ( 'desktop' ) ;
215+
191216 $scope . updateInput = function ( _input ) {
192217 var _device = _input . data ( 'device' ) ;
193218 var _attr = _input . data ( 'attr' ) ;
194219 _value [ _device ] [ _attr ] = _input . val ( ) ;
195220 if ( _attr == 'top' && _value [ _device ] . lock ) {
196221 var _topVal = _value [ _device ] [ _attr ] ;
197- [ 'right' , 'bottom' , 'left' , 'unit' ] . forEach ( function ( _prop ) {
222+ [ 'right' , 'bottom' , 'left' ] . forEach ( function ( _prop ) {
198223 $element . find ( 'input[data-device=' + _device + '][data-attr=' + _prop + ']' ) . val ( _topVal ) ;
224+ _value [ _device ] [ _prop ] = _topVal ;
199225 } ) ;
200226 }
201227 $element . find ( 'textarea' ) . val ( JSON . stringify ( _value ) ) ;
@@ -215,23 +241,29 @@ astroidFramework.directive("astroidspacing", ["$http", function ($http) {
215241
216242 $scope . switchLock = function ( _device ) {
217243 _value [ _device ] . lock = ! _value [ _device ] . lock ;
218- $element . find ( 'textarea' ) . val ( JSON . stringify ( _value ) ) ;
219244 $scope . updateLock ( _device ) ;
220245 }
221246
222247 $scope . updateLock = function ( _device ) {
223248 if ( _value [ _device ] . lock ) {
224249 var _topVal = $element . find ( 'input[data-device=' + _device + '][data-attr=top]' ) . val ( ) ;
225- [ 'right' , 'bottom' , 'left' , 'unit' ] . forEach ( function ( _prop ) {
250+ [ 'right' , 'bottom' , 'left' ] . forEach ( function ( _prop ) {
226251 $element . find ( 'input[data-device=' + _device + '][data-attr=' + _prop + ']' ) . val ( _topVal ) ;
227252 $element . find ( 'input[data-device=' + _device + '][data-attr=' + _prop + ']' ) . prop ( 'disabled' , true ) ;
253+ _value [ _device ] [ _prop ] = _topVal ;
228254 } ) ;
229255 $element . find ( 'input[data-device=' + _device + '][data-attr=top]' ) . focus ( ) ;
230256 } else {
231- [ 'right' , 'bottom' , 'left' , 'unit' ] . forEach ( function ( _prop ) {
257+ [ 'right' , 'bottom' , 'left' ] . forEach ( function ( _prop ) {
232258 $element . find ( 'input[data-device=' + _device + '][data-attr=' + _prop + ']' ) . prop ( 'disabled' , false ) ;
233259 } ) ;
234260 }
261+ if ( _value [ _device ] . lock ) {
262+ $element . find ( 'button[data-device=' + _device + ']' ) . removeClass ( 'btn-light' ) . addClass ( 'btn-purple' ) . addClass ( 'active' ) ;
263+ } else {
264+ $element . find ( 'button[data-device=' + _device + ']' ) . removeClass ( 'btn-purple' ) . removeClass ( 'active' ) . addClass ( 'btn-light' ) ;
265+ }
266+ $element . find ( 'textarea' ) . val ( JSON . stringify ( _value ) ) ;
235267 }
236268 }
237269 }
0 commit comments