X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0c57fd826a58a217f499b5084c837fb8ef3f6d4f..6515d67111202f746a1a58c66dcf2261636f2a26:/src/editor/plugins/core/core.js diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index c12405b..9445682 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('./metadataEditor/metadataEditor'); @@ -18,22 +19,27 @@ plugin.documentExtension.textNode.transformations = { breakContent: { impl: function(args) { var node = this, + parentDescribingNodes = [], newNodes, emptyText; newNodes = node.split({offset: args.offset}); - [newNodes.first, newNodes.second].some(function(newNode) { - if(!(newNode.contents().length)) { - emptyText = newNode.append({text: ''}); - return true; // break - } - }); newNodes.second.contents() .filter(function(child) { return child.object.describesParent; }) .forEach(function(child) { //child.detach(); - newNodes.first.append(child); + 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() { @@ -384,6 +390,7 @@ var linkAction = { } }; +var metadataParams = {}; plugin.actions = [ undoRedoAction('undo'), @@ -391,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); @@ -399,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;