1
- import { on , off } from 'utils/mixins'
1
+ import { bindAll } from 'underscore' ;
2
+ import { on , off } from 'utils/mixins' ;
2
3
3
4
const ToolbarView = require ( 'dom_components/view/ToolbarView' ) ;
4
5
const Toolbar = require ( 'dom_components/model/Toolbar' ) ;
@@ -10,12 +11,12 @@ const $ = Backbone.$;
10
11
module . exports = {
11
12
12
13
init ( o ) {
13
- _ . bindAll ( this , 'onHover' , 'onOut' , 'onClick' , 'onKeyPress' ) ;
14
+ bindAll ( this , 'onHover' , 'onOut' , 'onClick' , 'onKeyPress' ,
15
+ 'copyComp' , 'pasteComp' , 'onFrameScroll' ) ;
14
16
} ,
15
17
16
18
17
19
enable ( ) {
18
- _ . bindAll ( this , 'copyComp' , 'pasteComp' , 'onFrameScroll' ) ;
19
20
this . frameOff = this . canvasOff = this . adjScroll = null ;
20
21
var config = this . config . em . get ( 'Config' ) ;
21
22
this . startSelectComponent ( ) ;
@@ -25,7 +26,6 @@ module.exports = {
25
26
26
27
em . on ( 'component:update' , this . updateAttached , this ) ;
27
28
em . on ( 'change:canvasOffset' , this . updateAttached , this ) ;
28
- em . on ( 'change:selectedComponent' , this . updateToolbar , this ) ;
29
29
} ,
30
30
31
31
/**
@@ -297,6 +297,7 @@ module.exports = {
297
297
onSelect ( ) {
298
298
const editor = this . editor ;
299
299
const model = this . em . getSelected ( ) ;
300
+ this . updateToolbar ( model ) ;
300
301
301
302
if ( model ) {
302
303
const el = model . view . el ;
@@ -319,22 +320,28 @@ module.exports = {
319
320
var editor = em ? em . get ( 'Editor' ) : '' ;
320
321
var config = em ? em . get ( 'Config' ) : '' ;
321
322
var pfx = config . stylePrefix || '' ;
322
- var attrName = ' data-' + pfx + ' handler' ;
323
- var resizeClass = pfx + ' resizing' ;
323
+ var attrName = ` data-${ pfx } handler` ;
324
+ var resizeClass = ` ${ pfx } resizing` ;
324
325
var model = em . get ( 'selectedComponent' ) ;
325
326
var resizable = model . get ( 'resizable' ) ;
326
327
var options = { } ;
327
328
var modelToStyle ;
328
329
329
330
var toggleBodyClass = ( method , e , opts ) => {
330
- opts . docs && opts . docs . find ( 'body' ) [ method ] ( resizeClass ) ;
331
+ const docs = opts . docs ;
332
+ docs && docs . forEach ( doc => {
333
+ const body = doc . body ;
334
+ const cls = body . className || '' ;
335
+ body . className = ( method == 'add' ?
336
+ `${ cls } ${ resizeClass } ` : cls . replace ( resizeClass , '' ) ) . trim ( ) ;
337
+ } ) ;
331
338
} ;
332
339
333
340
334
341
if ( editor && resizable ) {
335
342
options = {
336
343
onStart ( e , opts ) {
337
- toggleBodyClass ( 'addClass ' , e , opts ) ;
344
+ toggleBodyClass ( 'add ' , e , opts ) ;
338
345
modelToStyle = em . get ( 'StyleManager' ) . getModelToStyle ( model ) ;
339
346
showOffsets = 0 ;
340
347
} ,
@@ -343,7 +350,7 @@ module.exports = {
343
350
editor . trigger ( 'change:canvasOffset' ) ;
344
351
} ,
345
352
onEnd ( e , opts ) {
346
- toggleBodyClass ( 'removeClass ' , e , opts ) ;
353
+ toggleBodyClass ( 'remove ' , e , opts ) ;
347
354
editor . trigger ( 'change:canvasOffset' ) ;
348
355
showOffsets = 1 ;
349
356
} ,
@@ -367,7 +374,8 @@ module.exports = {
367
374
}
368
375
369
376
modelToStyle . setStyle ( style , { avoidStore : 1 } ) ;
370
- em . trigger ( 'targetStyleUpdated' ) ;
377
+ const updateEvent = `update:component:style` ;
378
+ em && em . trigger ( `${ updateEvent } :height ${ updateEvent } :width` ) ;
371
379
372
380
if ( store ) {
373
381
modelToStyle . trigger ( 'change:style' , modelToStyle , style , { } ) ;
0 commit comments