From bec14a088e45d21ac12f9c5e852dd0b7e559d680 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 22 Apr 2014 12:35:16 +0200 Subject: [PATCH] editor: actions returns via callback --- .../modules/documentToolbar/actionView.js | 5 ++-- src/editor/plugins/core/core.js | 23 +++++++++++-------- src/editor/plugins/core/lists.js | 15 +++++++----- src/editor/plugins/core/switch.js | 5 ++-- src/editor/plugins/core/templates.js | 5 ++-- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/editor/modules/documentToolbar/actionView.js b/src/editor/modules/documentToolbar/actionView.js index 114eb32..74db332 100644 --- a/src/editor/modules/documentToolbar/actionView.js +++ b/src/editor/modules/documentToolbar/actionView.js @@ -108,8 +108,9 @@ var ActionView = Backbone.View.extend({ this.trigger('mousedown'); }, onExecute: function() { - var ret = this.action.execute(); - this.trigger('actionExecuted', this.action, ret); + this.action.execute(function(ret) { + this.trigger('actionExecuted', this.action, ret); + }.bind(this)); }, onSelectionChange: function(e) { var select = $(e.target), diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index 3465046..4c2f4c0 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -54,8 +54,9 @@ var undoRedoAction = function(dir) { label: dir === 'undo' ? '<-' : '->', icon: 'share-alt', iconStyle: dir === 'undo' ? '-webkit-transform: scale(-1,1); transform: scale(-1, 1)' : '', - execute: function(params) { + execute: function(callback, params) { params.document[dir](); + callback(); }, }, getState: function(params) { @@ -90,7 +91,7 @@ var commentAction = { }, stateDefaults: { icon: 'comment', - execute: function(params, editor) { + execute: function(callback, params, editor) { /* globals Node */ var node = params.fragment.node, action = this; @@ -124,7 +125,8 @@ var commentAction = { }, { metadata: { description: action.getState().description - } + }, + success: callback }); }, }, @@ -168,7 +170,7 @@ var createWrapTextAction = function(createParams) { return _.extend(state, { allowed: true, description: createParams.description, - execute: function(params) { + execute: function(callback, params) { params.fragment.document.transaction(function() { var parent = params.fragment.startNode.parent(); return parent.wrapText({ @@ -180,7 +182,8 @@ var createWrapTextAction = function(createParams) { }, { metadata: { description: createParams.description - } + }, + success: callback }); } }); @@ -189,7 +192,7 @@ var createWrapTextAction = function(createParams) { }; -var createLinkFromSelection = function(params) { +var createLinkFromSelection = function(callback, params) { var doc = params.fragment.document, dialog = Dialog.create({ title: gettext('Create link'), @@ -215,13 +218,14 @@ var createLinkFromSelection = function(params) { }, { metadata: { description: action.getState().description - } + }, + success: callback }); }); dialog.show(); }; -var editLink = function(params) { +var editLink = function(callback, params) { var doc = params.fragment.document, link = params.fragment.node.getParent('link'), dialog = Dialog.create({ @@ -241,7 +245,8 @@ var editLink = function(params) { }, { metadata: { description: action.getState().description - } + }, + success: callback }); }); dialog.show(); diff --git a/src/editor/plugins/core/lists.js b/src/editor/plugins/core/lists.js index a8dc802..911a1f2 100644 --- a/src/editor/plugins/core/lists.js +++ b/src/editor/plugins/core/lists.js @@ -32,7 +32,7 @@ var countItems = function(boundries) { var toggleListAction = function(type) { var execute = { - add: function(params) { + add: function(callback, params) { var boundries = getBoundriesForAList(params.fragment), listParams = {klass: type === 'Bullet' ? 'list' : 'list.enum'}, action = this; @@ -45,13 +45,14 @@ var toggleListAction = function(type) { }, { metadata: { description: action.getState().description - } + }, + success: callback }); } else { throw new Error('Invalid boundries'); } }, - remove: function(params) { + remove: function(callback, params) { /* globals Node */ var current = params.fragment.node, action = this; @@ -65,14 +66,15 @@ var toggleListAction = function(type) { }, { metadata: { description: action.getState().description - } + }, + success: callback }); return true; // break } }.bind(this)); }, - changeType: function(params) { + changeType: function(callback, params) { var node = params.fragment.node, action = this; node.document.transaction(function() { @@ -80,7 +82,8 @@ var toggleListAction = function(type) { }, { metadata: { description: action.getState().description - } + }, + success: callback }); } }; diff --git a/src/editor/plugins/core/switch.js b/src/editor/plugins/core/switch.js index 2730761..57b28b9 100644 --- a/src/editor/plugins/core/switch.js +++ b/src/editor/plugins/core/switch.js @@ -43,7 +43,7 @@ var createSwitchAction = function(createParams) { allowed: !!toSwitch, toggled: alreadyInTarget, description: description, - execute: alreadyInTarget ? function() {} : function() { + execute: alreadyInTarget ? function() {} : function(callback) { f.document.transaction(function() { if(createParams.to.tagName) { toSwitch = toSwitch.setTag(createParams.to.tagName); @@ -54,7 +54,8 @@ var createSwitchAction = function(createParams) { }, { metadata: { description: description - } + }, + success: callback }); } }); diff --git a/src/editor/plugins/core/templates.js b/src/editor/plugins/core/templates.js index 69e30f9..7d6d74f 100644 --- a/src/editor/plugins/core/templates.js +++ b/src/editor/plugins/core/templates.js @@ -38,7 +38,7 @@ var insertTemplateAction = { return { allowed: true, description: description, - execute: function(params) { + execute: function(callback, params) { var node = params.fragment.node.getNearestElementNode(); node.document.transaction(function() { var toAdd = node.document.createDocumentNode(params.template.content); @@ -46,7 +46,8 @@ var insertTemplateAction = { }, { metadata: { description: description - } + }, + success: callback }); } }; -- 2.20.1