From e1ec85db1fda9c43c162b450de452e7162d462a7 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 27 Jan 2017 15:07:13 +0100 Subject: [PATCH] Add refresh method to the editor API --- src/block_manager/view/BlockView.js | 5 +++-- src/demo.js | 6 ++++++ src/editor/main.js | 18 +++++++++++++++++- src/editor/model/Editor.js | 8 ++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/block_manager/view/BlockView.js b/src/block_manager/view/BlockView.js index ef6608c60..f60c9dc91 100644 --- a/src/block_manager/view/BlockView.js +++ b/src/block_manager/view/BlockView.js @@ -19,9 +19,10 @@ function(Backbone) { * Start block dragging * @private */ - onDrag: function(){ + onDrag: function() { if(!this.config.getSorter) return; + this.config.em.refreshCanvas(); var sorter = this.config.getSorter(); //this.config.dragHelper(this.el.cloneNode(1)); sorter.startSort(this.el); @@ -33,7 +34,7 @@ function(Backbone) { * Drop block * @private */ - onDrop: function(){ + onDrop: function() { this.doc.off('mouseup', this.onDrop); this.config.getSorter().endMove(); }, diff --git a/src/demo.js b/src/demo.js index ee03dcfca..c0b1e488c 100644 --- a/src/demo.js +++ b/src/demo.js @@ -329,6 +329,12 @@ require(['config/require-config'], function() { window.editor = editor; + $(document).ready(function(){ + console.log('doc ready4'); + }); + + $('.gjs-cv-canvas').css('padding-left', '200px'); + /* // Test toolbar commands var cmd = editor.Commands; diff --git a/src/editor/main.js b/src/editor/main.js index fd0746395..a1e9f18d4 100644 --- a/src/editor/main.js +++ b/src/editor/main.js @@ -15,6 +15,7 @@ * * [store](#store) * * [load](#load) * * [getContainer](#getcontainer) + * * [refresh](#refresh) * * [on](#on) * * [trigger](#trigger) * * [render](#render) @@ -348,13 +349,28 @@ define(function (require){ }, /** - * Returns container element. The one which was indicated as 'container' on init method + * Returns container element. The one which was indicated as 'container' + * on init method * @return {HTMLElement} */ getContainer: function(){ return c.el; }, + /** + * Update editor dimensions and refresh data useful for positioning of tools + * + * This method could be useful when you update, for example, some position + * of the editor element (eg. canvas, panels, etc.) with CSS, where without + * refresh you'll get misleading position of tools (eg. rich text editor, + * component highlighter, etc.) + * + * @private + */ + refresh: function () { + em.refreshCanvas(); + }, + /** * Attach event * @param {string} event Event name diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index fcf1b7ed5..172e450ee 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -470,5 +470,13 @@ define(['backbone', 'backboneUndo', 'keymaster', 'Utils', 'StorageManager', 'Dev this.defaultRunning = 0; }, + /** + * Update canvas dimensions and refresh data useful for tools positioning + * @private + */ + refreshCanvas: function () { + this.set('canvasOffset', this.get('Canvas').getOffset()); + }, + }); });