X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/bec14a088e45d21ac12f9c5e852dd0b7e559d680..5f6b12e9b2b5f3a35d22f690ba4052dd68b7f83d:/src/editor/plugins/core/switch.js diff --git a/src/editor/plugins/core/switch.js b/src/editor/plugins/core/switch.js index 57b28b9..e3ec5c4 100644 --- a/src/editor/plugins/core/switch.js +++ b/src/editor/plugins/core/switch.js @@ -14,7 +14,7 @@ var createSwitchAction = function(createParams) { }, getState: function(params) { var state = { - label: this.config.label + label: createParams.to.name }, f = params.fragment, description; @@ -32,15 +32,16 @@ var createSwitchAction = function(createParams) { var node = f instanceof f.CaretFragment ? f.node.parent() : f.getCommonParent(), alreadyInTarget = node.isInside(createParams.to), - toSwitch = node; + toSwitch = node, + textNodePath = (f.node || f.startNode).getPath(); if(!toSwitch.is(createParams.from)) { toSwitch = toSwitch.getParent(createParams.from); } - description = 'Switch to ' + createParams.to.name; + description = gettext('Switch to') + ' ' + createParams.to.name; return _.extend(state, { - allowed: !!toSwitch, + allowed: !!toSwitch || alreadyInTarget, toggled: alreadyInTarget, description: description, execute: alreadyInTarget ? function() {} : function(callback) { @@ -51,9 +52,11 @@ var createSwitchAction = function(createParams) { if(!_.isUndefined(createParams.to.klass)) { toSwitch.setClass(createParams.to.klass); } + return f.document.createFragment(f.CaretFragment, {node: f.document.getNodeByPath(textNodePath), offset: f.offset}); }, { metadata: { - description: description + description: description, + fragment: params.fragment }, success: callback }); @@ -63,12 +66,27 @@ var createSwitchAction = function(createParams) { }; }; +var headerAction = createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}), + paragraphAction = createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraph')}}), + imageAction = createSwitchAction({name: 'switchToImage', from: {tagName: 'div'}, to: {tagName: 'div', klass: 'img', name: gettext('image')}}), + videoAction = createSwitchAction({name: 'switchToVideo', from: {tagName: 'div'}, to: {tagName: 'div', klass: 'video', name: gettext('video')}}); return { - actions: [ - createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}), - createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}}) - ] + actions: [headerAction, paragraphAction, imageAction, videoAction], + canvasActionHandler: { + handles: [headerAction, paragraphAction, imageAction, videoAction] + // handle: function(canvas, action, ret) { + // var params = {}, + // f; + // if(ret && ret.node2) { + // f = ret.oldFragment; + // if(f && f instanceof f.CaretFragment) { + // params.caretTo = f.offset; + // } + // canvas.setCurrentElement(ret.node2, params); + // } + // } + } }; }); \ No newline at end of file