X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/cd087df95dce695f044472b6f017fbb697e90b7f..189a6efb18ccc8275be3c2ff7ce40f0330465142:/src/editor/modules/documentCanvas/commands.js diff --git a/src/editor/modules/documentCanvas/commands.js b/src/editor/modules/documentCanvas/commands.js index e0fc3f8..7302df3 100644 --- a/src/editor/modules/documentCanvas/commands.js +++ b/src/editor/modules/documentCanvas/commands.js @@ -1,7 +1,7 @@ define([ -'modules/documentCanvas/canvas/documentElement', -'./canvas/utils' -], function(documentElement, utils) { +'./canvas/utils', +'fnpjs/datetime' +], function(utils, datetime) { 'use strict'; @@ -109,14 +109,7 @@ commands.register('newNodeRequested', function(canvas, params, user) { var insertNode = function(insertion) { var doc = canvas.wlxmlDocument, - node, metadata, creator, currentDate, dt; - - var pad = function(number) { - if(number < 10) { - number = '0' + number; - } - return number; - }; + node, metadata, creator; doc.startTransaction(); node = insertion(); @@ -130,17 +123,9 @@ commands.register('newNodeRequested', function(canvas, params, user) { creator = 'anonymous'; } - currentDate = new Date(); - dt = pad(currentDate.getDate()) + '-' + - pad((currentDate.getMonth() + 1)) + '-' + - pad(currentDate.getFullYear()) + ' ' + - pad(currentDate.getHours()) + ':' + - pad(currentDate.getMinutes()) + ':' + - pad(currentDate.getSeconds()); - metadata = node.getMetadata(); metadata.add({key: 'creator', value: creator}); - metadata.add({key: 'date', value: dt}); + metadata.add({key: 'date', value: datetime.currentStrfmt()}); } doc.endTransaction(); return node; @@ -212,14 +197,17 @@ commands.register('footnote', function(canvas, params) { void(params); var cursor = canvas.getCursor(), position = cursor.getPosition(), - asideNode, asideElement; + asideNode, asideElement, node; if(cursor.isSelectingWithinElement()) { asideNode = position.element.data('wlxmlNode').wrapWith({tagName: 'aside', attrs:{'class': 'footnote'}, start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset}); } else { - asideNode = position.element.data('wlxmlNode').divideWithElementNode({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: position.offset}); - asideNode.append({text: ''}); + node = position.element.data('wlxmlNode'); + node.document.transaction(function() { + asideNode = node.divideWithElementNode({tagName: 'aside', attrs:{'class': 'footnote'}}, {offset: position.offset}); + asideNode.append({text: ''}); + }); } asideElement = utils.findCanvasElement(asideNode);