X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f90725bd2dd63943756915116b9a5f743ab94616..d0e1e19934b1c67a46a9b9c271b5054455edc5ad:/src/editor/plugins/core/core.js diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index ba6229f..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() { @@ -220,7 +234,8 @@ var createWrapTextAction = function(createParams) { return newFragment; }, { metadata: { - description: createParams.unwrapDescription + description: createParams.unwrapDescription, + fragment: params.fragment }, success: callback }); @@ -256,7 +271,8 @@ var createWrapTextAction = function(createParams) { } }, { metadata: { - description: createParams.wrapDescription + description: createParams.wrapDescription, + fragment: params.fragment }, success: callback }); @@ -298,7 +314,8 @@ var createLinkFromSelection = function(callback, params) { return doc.createFragment(doc.CaretFragment, {node: span.contents()[0], offset:0}); }, { metadata: { - description: action.getState().description + description: action.getState().description, + fragment: params.fragment }, success: callback }); @@ -326,7 +343,8 @@ var editLink = function(callback, params) { return params.fragment; }, { metadata: { - description: action.getState().description + description: action.getState().description, + fragment: params.fragment }, success: callback }); @@ -372,6 +390,7 @@ var linkAction = { } }; +var metadataParams = {}; plugin.actions = [ undoRedoAction('undo'), @@ -379,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); @@ -387,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;