X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/981e87b8a8d4dfca0c816d8bcedcd7c4dbdab9f4..d0e1e19934b1c67a46a9b9c271b5054455edc5ad:/src/editor/plugins/core/core.js diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index bbc27ac..509d743 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -10,7 +10,8 @@ var _ = require('libs/underscore'), lists = require('plugins/core/lists'), plugin = {name: 'core', actions: [], canvas: {}, documentExtension: {textNode: {}}}, Dialog = require('views/dialog/dialog'), - canvasElements = require('plugins/core/canvasElements'); + canvasElements = require('plugins/core/canvasElements'), + metadataEditor = require('plugins/core/metadataEditor/metadataEditor'); @@ -18,14 +19,27 @@ plugin.documentExtension.textNode.transformations = { breakContent: { impl: function(args) { var node = this, + parentDescribingNodes = [], newNodes, emptyText; newNodes = node.split({offset: args.offset}); + newNodes.second.contents() + .filter(function(child) { + return child.object.describesParent; + }) + .forEach(function(child) { + //child.detach(); + parentDescribingNodes.push(child); + child.detach(); + }); [newNodes.first, newNodes.second].some(function(newNode) { if(!(newNode.contents().length)) { emptyText = newNode.append({text: ''}); return true; // break } }); + parentDescribingNodes.forEach(function(node) { + newNodes.first.append(node); + }); return _.extend(newNodes, {emptyText: emptyText}); }, getChangeRoot: function() { @@ -376,6 +390,7 @@ var linkAction = { } }; +var metadataParams = {}; plugin.actions = [ undoRedoAction('undo'), @@ -383,7 +398,8 @@ plugin.actions = [ commentAction, createWrapTextAction({name: 'emphasis', klass: 'emp', wrapDescription: gettext('Mark as emphasized'), unwrapDescription: gettext('Remove emphasis')}), createWrapTextAction({name: 'cite', klass: 'cite', wrapDescription: gettext('Mark as citation'), unwrapDescription: gettext('Remove citation')}), - linkAction + linkAction, + metadataEditor.action(metadataParams) ].concat(plugin.actions, templates.actions, footnote.actions, switchTo.actions, lists.actions); @@ -391,6 +407,15 @@ plugin.actions = [ plugin.config = function(config) { // templates.actions[0].config(config.templates); templates.actions[0].params.template.options = config.templates; + metadataParams.config = (config.metadata || []).sort(function(configRow1, configRow2) { + if(configRow1.key < configRow2.key) { + return -1; + } + if(configRow1.key > configRow2.key) { + return 1; + } + return 0; + }); }; plugin.canvasElements = canvasElements;