From 68c9d615c3b5f4d6fefcd721f0315fde89fc3328 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 17 Apr 2014 12:36:13 +0200 Subject: [PATCH 1/1] template get state fix --- src/editor/plugins/core/templates.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/editor/plugins/core/templates.js b/src/editor/plugins/core/templates.js index 2b1f730..1114258 100644 --- a/src/editor/plugins/core/templates.js +++ b/src/editor/plugins/core/templates.js @@ -13,12 +13,7 @@ var insertTemplateAction = { }, stateDefaults: { label: '+', - icon: 'core.plus', - execute: function(params) { - var node = params.fragment.node.getNearestElementNode(); - var toAdd = node.document.createDocumentNode(params.template.content); - node.after(toAdd); - } + icon: 'core.plus' }, getState: function(params) { if(!(params.template && params.template.id)) { @@ -26,15 +21,24 @@ var insertTemplateAction = { allowed: false, description: gettext('No template selected') }; - } else if(!params.fragment || !params.fragment.isValid() || !(params.fragment instanceof params.fragment.NodeFragment)) { - return { - allowed: false, - description: gettext('Wrong node selected') + } else if( + !params.fragment || !params.fragment.isValid() || + !(params.fragment instanceof params.fragment.NodeFragment) || + params.fragment.node.getNearestElementNode().isRoot() + ) { + return { + allowed: false, + description: gettext('Wrong node selected') }; } return { allowed: true, - description: interpolate(gettext('Insert template %s after %s'), [params.template.name, params.fragment.node.getNearestElementNode().getTagName()]) + description: interpolate(gettext('Insert template %s after %s'), [params.template.name, params.fragment.node.getNearestElementNode().getTagName()]), + execute: function(params) { + var node = params.fragment.node.getNearestElementNode(); + var toAdd = node.document.createDocumentNode(params.template.content); + node.after(toAdd); + } }; } }; -- 2.20.1