From ce55d201affde343b815f80c21fc6a3858c8fa60 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 2 Aug 2016 14:37:25 +0200 Subject: [PATCH] Update blocks --- src/block_manager/view/BlocksView.js | 6 +++++- src/dom_components/view/ComponentImageView.js | 6 ++++-- src/dom_components/view/ComponentTextView.js | 2 +- src/editor/config/config.js | 19 ++++++++++++++++++- src/utils/Sorter.js | 8 +++++--- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/block_manager/view/BlocksView.js b/src/block_manager/view/BlocksView.js index f3b1dbeec..52a3d432c 100644 --- a/src/block_manager/view/BlocksView.js +++ b/src/block_manager/view/BlocksView.js @@ -80,10 +80,14 @@ function(Backbone, BlockView) { * Callback when block is dropped * @private */ - onDrop: function(){ + onDrop: function(model){ this.em.runDefault(); this.em.get('Canvas').getBody().style.cursor = ''; document.body.style.cursor = ''; + if(model && model.get('activeOnRender')){ + model.trigger('active'); + model.set('activeOnRender', 0); + } }, /** diff --git a/src/dom_components/view/ComponentImageView.js b/src/dom_components/view/ComponentImageView.js index 34d471a88..94e236db3 100644 --- a/src/dom_components/view/ComponentImageView.js +++ b/src/dom_components/view/ComponentImageView.js @@ -11,8 +11,8 @@ define(['backbone', './ComponentView'], initialize: function(o){ ComponentView.prototype.initialize.apply(this, arguments); - this.listenTo( this.model, 'change:src', this.updateSrc); - this.listenTo( this.model, 'dblclick', this.openModal); + this.listenTo( this.model, 'change:src', this.updateSrc); + this.listenTo( this.model, 'dblclick active', this.openModal); this.classEmpty = this.ppfx + 'plh-image'; if(this.config.modal) @@ -61,6 +61,8 @@ define(['backbone', './ComponentView'], if(!this.model.get('src')) this.$el.attr('class', this.classEmpty); + // Avoid strange behaviours while try to drag + this.$el.attr('onmousedown', 'return false'); return this; }, }); diff --git a/src/dom_components/view/ComponentTextView.js b/src/dom_components/view/ComponentTextView.js index 782225f99..929e1b70f 100644 --- a/src/dom_components/view/ComponentTextView.js +++ b/src/dom_components/view/ComponentTextView.js @@ -10,7 +10,7 @@ define(['backbone', './ComponentView'], initialize: function(o){ ComponentView.prototype.initialize.apply(this, arguments); _.bindAll(this,'disableEditing'); - this.listenTo(this.model, 'focus', this.enableEditing); + this.listenTo(this.model, 'focus active', this.enableEditing); this.rte = this.config.rte || ''; }, diff --git a/src/editor/config/config.js b/src/editor/config/config.js index c8fbf3fef..351e978e3 100644 --- a/src/editor/config/config.js +++ b/src/editor/config/config.js @@ -110,7 +110,24 @@ define(function () { },{ id: 'b3', label: 'Block3', - content: '

Block 3

', + content: '
Block 3
', + },{ + id: 'text', + label: 'Text', + content: '
Insert your text here
', + },{ + id: 'text2', + label: 'Text2', + content: { + type:'text', + content:'Insert your text here', + style: { padding: '10px' }, + activeOnRender: 1 + }, + },{ + id: 'image', + label: 'Image', + content: {type:'image', activeOnRender: 1}, }], }, diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 49535c819..4e98798a4 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -476,6 +476,7 @@ define(['backbone'], * @return void * */ endMove: function(e){ + var created; this.$el.off('mousemove', this.onMove); $(this.document).off('mouseup', this.endMove); $(this.document).off('keypress', this.rollback); @@ -484,14 +485,14 @@ define(['backbone'], if(this.eV) this.eV.className = this.eV.className.replace(clsReg, ''); if(this.moved) - this.move(this.target, this.eV, this.lastPos); + created = this.move(this.target, this.eV, this.lastPos); if(this.plh) this.plh.style.display = 'none'; this.helperEl = ''; if(this.helper) this.helper.parentNode.removeChild(this.helper); if(typeof this.onEndMove === 'function') - this.onEndMove(); + this.onEndMove(created); }, /** @@ -521,7 +522,7 @@ define(['backbone'], modelToDrop = this.dropContent; opts.silent = false; } - targetCollection.add(modelToDrop, opts); + var created = targetCollection.add(modelToDrop, opts); if(!this.dropContent){ targetCollection.remove(modelTemp); }else{ @@ -529,6 +530,7 @@ define(['backbone'], } // This will cause to recalculate children dimensions this.prevTarget = null; + return created; }else console.warn("Invalid target position"); },