From 0e100dced6c5982e02aaa0bda87238418976adde Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 29 May 2014 09:33:03 +0200 Subject: [PATCH 01/16] editor: remove code supporting main editing area sidebar as it's not used anymore This also hides metadata editor from the ui for now - it must be moved somewhere else. --- src/editor/modules/rng/editingLayout.less | 61 +---------------------- src/editor/modules/rng/rng.js | 19 +------ 2 files changed, 3 insertions(+), 77 deletions(-) diff --git a/src/editor/modules/rng/editingLayout.less b/src/editor/modules/rng/editingLayout.less index 40082a6..eefd222 100644 --- a/src/editor/modules/rng/editingLayout.less +++ b/src/editor/modules/rng/editingLayout.less @@ -3,54 +3,6 @@ width: 600px;*/ } -.rng-module-rng2-right { - /*float: right; - position: relative; - width: 258px; - margin-left: 50px;*/ - - border-width: 1px 1px 1px 1px; - border-style: solid; - border-color: #ddd; - padding: 5px 15px; - - p, td, label, input, select { - font-size: 11px; - line-height:13px; - } - - select { - -webkit-appearance: button; - -moz-appearance: button; - appearance: button; - height: auto; - line-height: 14px; - } - - legend { - font-size:11px; - height:30px; - } - - - .rng-view-tabs-tabBar { - position:absolute; - top:-1px; - right:-50px; - border-width: 1px 1px 1px 0px; - border-style: solid; - border-color: #ddd; - padding: 5px; - background: #ededed; - } - - label + select { - position:relative; - top: 5px; - } - -} - .rng-module-rng2-statusBar { margin: 10px 5px; font-size:0.9em; @@ -67,22 +19,11 @@ } - [fnpjs-place="leftColumn"], [fnpjs-place="rightColumn"] { + [fnpjs-place="leftColumn"] { position: absolute; top: 30px; // bottom: 50px; // - } - - [fnpjs-place="leftColumn"] { left:0; right: 0; } - - [fnpjs-place="rightColumn"] { - right: 0px; - width: 290px; - - } - - } \ No newline at end of file diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 8fb27ed..459dcc1 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -2,13 +2,12 @@ define([ './documentSummary', 'libs/underscore', 'fnpjs/layout', -'fnpjs/vbox', 'fnpjs/logging/logging', 'views/tabs/tabs', 'libs/text!./mainLayout.html', 'libs/text!./editingLayout.html', 'libs/text!./diffLayout.html', -], function(documentSummary, _, layout, vbox, logging, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) { +], function(documentSummary, _, layout, logging, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) { 'use strict'; @@ -35,10 +34,8 @@ return function(sandbox) { if(fragment && fragment.node) { elementParent = fragment.node.getNearestElementNode(); sandbox.getModule('nodeBreadCrumbs').setNodeElement(elementParent); - sandbox.getModule('metadataEditor').setNodeElement(elementParent); } else { sandbox.getModule('nodeBreadCrumbs').setNodeElement(null); - sandbox.getModule('metadataEditor').setNodeElement(null); } }, }; @@ -48,20 +45,15 @@ return function(sandbox) { mainLayout: new layout.Layout(mainLayoutTemplate), mainTabs: (new tabs.View()).render(), visualEditing: new layout.Layout(visualEditingLayoutTemplate), - visualEditingSidebar: (new tabs.View({stacked: true})).render(), - currentNodePaneLayout: new vbox.VBox(), diffLayout: new layout.Layout(diffLayoutTemplate) }; - views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView()); addMainTab(gettext('Editor'), 'editor', views.visualEditing.getAsView()); addMainTab(gettext('Source'), 'sourceEditor', ''); addMainTab(gettext('History'), 'history', views.diffLayout.getAsView()); sandbox.getDOM().append(views.mainLayout.getAsView()); - views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView()); - var wlxmlDocument, documentIsDirty; /* Events handling */ @@ -89,7 +81,7 @@ return function(sandbox) { sandbox.getModule('mainBar').setCommandEnabled('drop-draft', usingDraft); sandbox.getModule('mainBar').setCommandEnabled('save', usingDraft); - _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'metadataEditor', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer', 'statusBar'], function(moduleName) { + _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer', 'statusBar'], function(moduleName) { sandbox.getModule(moduleName).start(); }); @@ -195,13 +187,6 @@ return function(sandbox) { } }; - eventHandlers.metadataEditor = { - ready: function() { - sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument()); - views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView()); - } - }; - eventHandlers.documentToolbar = { ready: function() { views.visualEditing.setView('toolbar', sandbox.getModule('documentToolbar').getView()); -- 2.20.1 From ab8679cf48d2edc82f2b7a882a87bff24be9f745 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 29 May 2014 09:11:37 +0200 Subject: [PATCH 02/16] editor: tweaking visual appearance --- .../modules/documentCanvas/canvas/canvas.less | 5 +-- .../modules/documentCanvas/canvas/gutter.less | 4 +-- .../documentCanvas/documentCanvas.less | 36 +++++++++++++++---- src/editor/modules/rng/editingLayout.html | 1 - src/editor/modules/rng/editingLayout.less | 4 ++- src/editor/modules/rng/mainLayout.less | 6 ++-- src/editor/modules/rng/rng.js | 2 +- src/editor/styles/mixins.less | 2 +- 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.less b/src/editor/modules/documentCanvas/canvas/canvas.less index b594247..2c6edc2 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.less +++ b/src/editor/modules/documentCanvas/canvas/canvas.less @@ -1,7 +1,8 @@ .view-table { display: table; - width: 100%; - + width: calc(~'100% - 100px'); + margin: 10px 0 20px 100px; + .view-row { display: table-row; } diff --git a/src/editor/modules/documentCanvas/canvas/gutter.less b/src/editor/modules/documentCanvas/canvas/gutter.less index b41179b..17178c7 100644 --- a/src/editor/modules/documentCanvas/canvas/gutter.less +++ b/src/editor/modules/documentCanvas/canvas/gutter.less @@ -2,11 +2,11 @@ display: table-cell; width: calc(~'100% - 800px'); min-width: 250px; - padding-left: 45px; + padding: 0 25px; } .gutter-box { - border: 1px solid #ddd; + border: 1px solid darken(#ddd, 10%); padding: 5px 10px; position: relative; background-color: darken(#FFFCB7, 15%); diff --git a/src/editor/modules/documentCanvas/documentCanvas.less b/src/editor/modules/documentCanvas/documentCanvas.less index 541eca2..879d78d 100644 --- a/src/editor/modules/documentCanvas/documentCanvas.less +++ b/src/editor/modules/documentCanvas/documentCanvas.less @@ -10,15 +10,36 @@ } #rng-module-documentCanvas-contentWrapper { - border-color: #ddd; - border-style: solid; - border-width: 1px; + background-color: #ddd; float:left; - width: calc(~'100% - 20px'); + width: 100%; height: 100%; overflow-y: scroll; - padding: 0 10px; + &:before { + content: ""; + position: absolute; + top: 0; + bottom: 0; + left: -15px; + right: -15px; + box-shadow: inset 0 20px 12px -20px rgba(0,0,0,0.6); + pointer-events:none; + z-index: 1; + } + + &:after { + content: ""; + position: absolute; + top: 0; + bottom: 0; + left: -15px; + right: -15px; + box-shadow: inset 0px -20px 12px -20px rgba(0,0,0,0.6); + pointer-events:none; + z-index: 1; + } + &::-webkit-scrollbar { .rng-mixin-scrollbar; } @@ -35,8 +56,11 @@ .root-wrapper { display: table-cell; vertical-align: top; - width:800px; + width: 600px; outline: 0px solid transparent; + padding: 0 100px; + background-color: white; + box-shadow: 0 0 20px rgba(0, 0, 0, 0.2), inset 0 0 10px rgba(0, 0, 0, 0.1); } .current-text-element { diff --git a/src/editor/modules/rng/editingLayout.html b/src/editor/modules/rng/editingLayout.html index 259f0f4..9fb37e6 100644 --- a/src/editor/modules/rng/editingLayout.html +++ b/src/editor/modules/rng/editingLayout.html @@ -1,5 +1,4 @@
-
\ No newline at end of file diff --git a/src/editor/modules/rng/editingLayout.less b/src/editor/modules/rng/editingLayout.less index eefd222..fe46e6d 100644 --- a/src/editor/modules/rng/editingLayout.less +++ b/src/editor/modules/rng/editingLayout.less @@ -10,6 +10,8 @@ .fnp-module-rng-editingLayout { + margin-left: 60px; + [fnpjs-place="statusBar"] { position: absolute; bottom: 0; @@ -22,7 +24,7 @@ [fnpjs-place="leftColumn"] { position: absolute; top: 30px; // - bottom: 50px; // + bottom: 0px; // left:0; right: 0; } diff --git a/src/editor/modules/rng/mainLayout.less b/src/editor/modules/rng/mainLayout.less index c1a7e8e..859b581 100644 --- a/src/editor/modules/rng/mainLayout.less +++ b/src/editor/modules/rng/mainLayout.less @@ -2,8 +2,8 @@ position: fixed; top: 5px; bottom: 5px; - left: 80px; - right: 80px; + left: 0px; + right: 0px; [fnpjs-place="messages"] { position: absolute; @@ -16,6 +16,7 @@ float: right; position: relative; z-index: 2; + margin-right: 60px; } [fnpjs-place="mainView"] { @@ -29,6 +30,7 @@ > .rng-view-tabs { position: relative; height: 100%; + padding-left: 60px; > .rng-view-tabs-content { position: absolute; diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 459dcc1..032fea4 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -81,7 +81,7 @@ return function(sandbox) { sandbox.getModule('mainBar').setCommandEnabled('drop-draft', usingDraft); sandbox.getModule('mainBar').setCommandEnabled('save', usingDraft); - _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer', 'statusBar'], function(moduleName) { + _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'mainBar', 'indicator', 'documentHistory', 'diffViewer', 'statusBar'], function(moduleName) { sandbox.getModule(moduleName).start(); }); diff --git a/src/editor/styles/mixins.less b/src/editor/styles/mixins.less index 3a14f31..28effc8 100644 --- a/src/editor/styles/mixins.less +++ b/src/editor/styles/mixins.less @@ -1,5 +1,5 @@ .rng-mixin-scrollbar { - width: 9px; + width: 12px; } .rng-mixin-scrollbar-track { -- 2.20.1 From 6003b8824fdcba0d59db6681282c7d2d7f2bae1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 29 May 2014 14:32:23 +0200 Subject: [PATCH 03/16] editor: Hide comment header if there is nothing to show in it --- .../documentCanvas/canvas/comments/comment.html | 10 ++++++---- .../modules/documentCanvas/canvas/comments/comments.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/comments/comment.html b/src/editor/modules/documentCanvas/canvas/comments/comment.html index 3e9fb28..ca15b77 100644 --- a/src/editor/modules/documentCanvas/canvas/comments/comment.html +++ b/src/editor/modules/documentCanvas/canvas/comments/comment.html @@ -1,8 +1,10 @@
-
- <%= author %> - <%= date %> -
+ <% if(author || date) { %> +
+ <%= author %> + <%= date %> +
+ <% } %>
<%= content %> diff --git a/src/editor/modules/documentCanvas/canvas/comments/comments.js b/src/editor/modules/documentCanvas/canvas/comments/comments.js index 3076f52..65c80f2 100644 --- a/src/editor/modules/documentCanvas/canvas/comments/comments.js +++ b/src/editor/modules/documentCanvas/canvas/comments/comments.js @@ -142,8 +142,8 @@ var CommentView = function(commentNode) { }, 'date'); this.dom = $(_.template(commentTemplate)({ - author: author ||'?', - date: date || '?', + author: author || '', + date: date || '', content: this.node.object.getText() || '?' })); -- 2.20.1 From c6526aebeee1d516b8bd7c793fecda2fcb80bbdf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 4 Jun 2014 14:03:31 +0200 Subject: [PATCH 04/16] editor: canvas fix - fix selecting node without direct text node child Without this fix, clicking element without direct text child element but with children containing text nodes resulted in selecting this child text element (while visual indication for the user was that the requested element was selected). --- src/editor/modules/documentCanvas/canvas/canvas.js | 2 +- .../modules/documentCanvas/canvas/genericElement.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 05c109c..b234dd8 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -349,7 +349,7 @@ $.extend(Canvas.prototype, Backbone.Events, { if(byBrowser && byBrowser.parent().sameNode(nodeToLand)) { return byBrowser; } - return e.getVerticallyFirstTextElement(); + return e.getVerticallyFirstTextElement({considerChildren: false}); }.bind(this); var _markAsCurrent = function(element) { if(element instanceof documentElement.DocumentTextElement) { diff --git a/src/editor/modules/documentCanvas/canvas/genericElement.js b/src/editor/modules/documentCanvas/canvas/genericElement.js index 878e140..4dfbe59 100644 --- a/src/editor/modules/documentCanvas/canvas/genericElement.js +++ b/src/editor/modules/documentCanvas/canvas/genericElement.js @@ -80,13 +80,18 @@ $.extend(generic, { return toret; }, - getVerticallyFirstTextElement: function() { + getVerticallyFirstTextElement: function(params) { var toret; + + params = _.extend({ + considerChildren: true + }, params); + this.children().some(function(child) { if(child instanceof documentElement.DocumentTextElement) { toret = child; return true; // break - } else { + } else if(params.considerChildren) { toret = child.getVerticallyFirstTextElement(); if(toret) { return true; // break -- 2.20.1 From 123b453a3cf4195c7a7b0133f740ea568af859a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 9 Jun 2014 16:08:24 +0200 Subject: [PATCH 05/16] editor: small fix --- src/editor/plugins/core/lists.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/editor/plugins/core/lists.js b/src/editor/plugins/core/lists.js index 662dc53..7a9d321 100644 --- a/src/editor/plugins/core/lists.js +++ b/src/editor/plugins/core/lists.js @@ -45,8 +45,9 @@ var toggleListAction = function(type) { item1 = list.object.getItem(0), text = item1 ? item1.contents()[0] : undefined, // doc = boundries.node1.document; - - return doc.createFragment(doc.CaretFragment, {node: text, offset:0}); + if(text) { + return doc.createFragment(doc.CaretFragment, {node: text, offset:0}); + } }, { metadata: { description: action.getState().description, -- 2.20.1 From 160268708973c7ba08f277a9d2e7cf8b9aeed1c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 4 Jun 2014 12:44:04 +0200 Subject: [PATCH 06/16] editor: handle situation when element doesn't implement getVerticallyFirstTextElement --- src/editor/modules/documentCanvas/canvas/canvas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index b234dd8..5bd5e85 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -349,7 +349,7 @@ $.extend(Canvas.prototype, Backbone.Events, { if(byBrowser && byBrowser.parent().sameNode(nodeToLand)) { return byBrowser; } - return e.getVerticallyFirstTextElement({considerChildren: false}); + return _.isFunction(e.getVerticallyFirstTextElement) ? e.getVerticallyFirstTextElement({considerChildren: false}) : null; }.bind(this); var _markAsCurrent = function(element) { if(element instanceof documentElement.DocumentTextElement) { -- 2.20.1 From 1038a12a841bbacec60cd8a73a93ecf1658ea8a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 23 Jun 2014 11:40:21 +0200 Subject: [PATCH 07/16] smartxml: fix - handle invalid params.node value --- src/smartxml/fragments.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/smartxml/fragments.js b/src/smartxml/fragments.js index 62a7a4c..b1befdf 100644 --- a/src/smartxml/fragments.js +++ b/src/smartxml/fragments.js @@ -19,7 +19,7 @@ $.extend(Fragment.prototype, { var NodeFragment = function(document, params) { Fragment.call(this, document); this.node = params.node; - this.nodePath = params.node.getPath(); + this.nodePath = this.isValid() ? params.node.getPath() : null; }; NodeFragment.prototype = Object.create(Fragment.prototype); $.extend(NodeFragment.prototype, { @@ -27,14 +27,16 @@ $.extend(NodeFragment.prototype, { return this.document.containsNode(this.node); }, restoreFromPaths: function() { - this.node = this.document.getNodeByPath(this.nodePath); + if(this.nodePath) { + this.node = this.document.getNodeByPath(this.nodePath); + } } }); var CaretFragment = function(document, params) { - NodeFragment.call(this, document, params); this.offset = params.offset; + NodeFragment.call(this, document, params); }; CaretFragment.prototype = Object.create(NodeFragment.prototype); -- 2.20.1 From f053afa06b122dc6d6a2a0ff1dd3ac2691d79a5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 23 Jun 2014 15:04:26 +0200 Subject: [PATCH 08/16] smartxml: fixing tests --- src/smartxml/smartxml.test.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index b7676e2..6b2f91d 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -650,14 +650,16 @@ describe('smartxml', function() { }); it('keeps parent-describing nodes in place', function() { - var doc = getDocumentFromXML('Alice has a cat'), + var doc = getDocumentFromXML('Alice probably has a cat'), root = doc.root, - x = root.contents()[1]; + x = root.contents()[1], + y = root.contents()[3]; doc.registerExtension({documentNode: {methods: { object: { describesParent: function() { - return this.getTagName() === 'x'; + /* globals Node */ + return this.nodeType === Node.ELEMENT_NODE && this.getTagName() === 'x'; } } }}}); @@ -666,9 +668,11 @@ describe('smartxml', function() { _with: {tagName: 'span', attrs: {'attr1': 'value1'}}, offsetStart: 1, offsetEnd: 4, - textNodeIdx: [0,2] + textNodeIdx: [0,4] }); + expect(x.parent().sameNode(root)).to.be.true; + expect(y.parent().getTagName()).to.equal('span'); }); }); @@ -728,7 +732,7 @@ describe('smartxml', function() { section.document.registerExtension({documentNode: {methods: { object: { describesParent: function() { - return this.getTagName() === 'x'; + return this.nodeType === Node.ELEMENT_NODE && this.getTagName() === 'x'; } } }}}); @@ -740,6 +744,8 @@ describe('smartxml', function() { }); expect(x.parent().sameNode(section)).to.be.true; + expect(aliceText.parent().getTagName()).to.equal('header'); + expect(lastDiv.parent().getTagName()).to.equal('header'); }); }); -- 2.20.1 From a920c78116d0177f440c98fb4a067437fea5f27c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 11 Jun 2014 11:03:18 +0200 Subject: [PATCH 09/16] editor: removing unsued code (canvas grid) --- src/editor/modules/documentCanvas/canvas/canvas.js | 8 -------- src/editor/modules/documentCanvas/nodes.less | 6 ------ 2 files changed, 14 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 5bd5e85..d4e16ad 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -418,14 +418,6 @@ $.extend(Canvas.prototype, Backbone.Events, { if(position.element) { this._moveCaretToTextElement(position.element, position.offset); } - }, - - toggleGrid: function() { - this.rootWrapper.toggleClass('grid-on'); - this.trigger('changed'); - }, - isGridToggled: function() { - return this.rootWrapper.hasClass('grid-on'); } }); diff --git a/src/editor/modules/documentCanvas/nodes.less b/src/editor/modules/documentCanvas/nodes.less index 3b47209..7938911 100644 --- a/src/editor/modules/documentCanvas/nodes.less +++ b/src/editor/modules/documentCanvas/nodes.less @@ -20,12 +20,6 @@ border: none; } -.grid-on { - [wlxml-tag] { - .rng-common-hoveredNode; - } -} - [wlxml-tag=span] { min-width: 10px; } -- 2.20.1 From e3d081dda1fe6502f0809ddf602d2c0bdf1f24ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 11 Jun 2014 11:06:16 +0200 Subject: [PATCH 10/16] editor: removing unused code (breadcrumbs) --- src/editor/modules.js | 1 - .../nodeBreadCrumbs/nodeBreadCrumbs.js | 69 ------------------- .../modules/nodeBreadCrumbs/template.html | 10 --- src/editor/modules/rng/rng.js | 20 +----- src/editor/styles/common.less | 5 -- 5 files changed, 1 insertion(+), 104 deletions(-) delete mode 100644 src/editor/modules/nodeBreadCrumbs/nodeBreadCrumbs.js delete mode 100644 src/editor/modules/nodeBreadCrumbs/template.html diff --git a/src/editor/modules.js b/src/editor/modules.js index 312ac0b..83ed141 100644 --- a/src/editor/modules.js +++ b/src/editor/modules.js @@ -18,7 +18,6 @@ define(function(require) { documentCanvas: require('modules/documentCanvas/documentCanvas'), documentToolbar: require('modules/documentToolbar/documentToolbar'), metadataEditor: require('modules/metadataEditor/metadataEditor'), - nodeBreadCrumbs: require('modules/nodeBreadCrumbs/nodeBreadCrumbs'), documentHistory: require('modules/documentHistory/documentHistory'), diffViewer: require('modules/diffViewer/diffViewer') diff --git a/src/editor/modules/nodeBreadCrumbs/nodeBreadCrumbs.js b/src/editor/modules/nodeBreadCrumbs/nodeBreadCrumbs.js deleted file mode 100644 index 24a61de..0000000 --- a/src/editor/modules/nodeBreadCrumbs/nodeBreadCrumbs.js +++ /dev/null @@ -1,69 +0,0 @@ -define([ -'libs/jquery', -'libs/underscore', -'utils/wlxml', -'libs/text!./template.html'], function($, _, wlxmlUtils, templateSrc) { - -'use strict'; - -return function(sandbox) { - - var template = _.template(templateSrc), - listens = false; - - var view = { - dom: $('
' + template({node:null, parents: null}) + '
'), - setup: function() { - this.dom.on('click', 'a', function(e) { - e.preventDefault(); - var target = $(e.target); - sandbox.publish('elementClicked', target.data('element')); - }); - }, - - setNodeElement: function(nodeElement) { - this.dom.empty(); - this.currentNodeElement = nodeElement; - var parents; - if(nodeElement) { - parents = nodeElement.parents(); - } - - this.dom.html(template({node: nodeElement, parents: parents, utils: wlxmlUtils})); - - this.dom.find('li > a[href="#"]').each(function(idx, a) { - $(a).data('element', parents[parents.length - 1 - idx]); - }); - this.dom.find('a.active').data('element', nodeElement); - }, - - highlightNode: function(node) { - this.dom.find('a[data-id="'+node.id+'"]').addClass('rng-common-hoveredNode'); - }, - dimNode: function(node) { - this.dom.find('a[data-id="'+node.id+'"]').removeClass('rng-common-hoveredNode'); - } - }; - - view.setup(); - - return { - start: function() { sandbox.publish('ready'); }, - getView: function() { return view.dom; }, - setNodeElement: function(nodeElement) { - if(!listens && nodeElement) { - nodeElement.document.on('change', function() { - if(view.currentNodeElement && !view.currentNodeElement.isInDocument()) { - view.setNodeElement(null); - } - }); - listens = true; - } - view.setNodeElement(nodeElement); - }, - highlightNode: function(id) { view.highlightNode(id); }, - dimNode: function(id) { view.dimNode(id); } - }; -}; - -}); \ No newline at end of file diff --git a/src/editor/modules/nodeBreadCrumbs/template.html b/src/editor/modules/nodeBreadCrumbs/template.html deleted file mode 100644 index 062fb1e..0000000 --- a/src/editor/modules/nodeBreadCrumbs/template.html +++ /dev/null @@ -1,10 +0,0 @@ -
- -
\ No newline at end of file diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 032fea4..4160ad9 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -26,17 +26,8 @@ return function(sandbox) { sandbox.getModule('documentCanvas').jumpToElement(element); }, refreshCanvasSelection: function(selection) { - var fragment = selection.toDocumentFragment(), - elementParent; - + var fragment = selection.toDocumentFragment(); sandbox.getModule('documentToolbar').setDocumentFragment(fragment); - - if(fragment && fragment.node) { - elementParent = fragment.node.getNearestElementNode(); - sandbox.getModule('nodeBreadCrumbs').setNodeElement(elementParent); - } else { - sandbox.getModule('nodeBreadCrumbs').setNodeElement(null); - } }, }; @@ -197,15 +188,6 @@ return function(sandbox) { } }; - eventHandlers.nodeBreadCrumbs = { - ready: function() { - views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView()); - }, - elementClicked: function(element) { - commands.jumpToDocumentElement(element); - } - }; - eventHandlers.documentHistory = { ready: function() { sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory()); diff --git a/src/editor/styles/common.less b/src/editor/styles/common.less index 00e1525..84af877 100644 --- a/src/editor/styles/common.less +++ b/src/editor/styles/common.less @@ -2,9 +2,4 @@ body { padding-top: 5px; } -.rng-common-hoveredNode { - border-color: red !important; - border-style:solid; - border-width:1px; -} -- 2.20.1 From dea68129ff763bf38f632ad7373072faf1fda1ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 25 Jun 2014 09:59:05 +0200 Subject: [PATCH 11/16] editor: canvas fix - check for the case when mutation concerns already detached text node --- src/editor/modules/documentCanvas/canvas/canvas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index d4e16ad..50c0ae4 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -200,7 +200,7 @@ $.extend(Canvas.prototype, Backbone.Events, { /* globals MutationObserver */ var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { - if(documentElement.DocumentTextElement.isContentContainer(mutation.target)) { + if(canvas.dom[0].contains(mutation.target) && documentElement.DocumentTextElement.isContentContainer(mutation.target)) { observer.disconnect(); if(mutation.target.data === '') { mutation.target.data = utils.unicode.ZWS; -- 2.20.1 From 824b4e2265ab7fe8e30dc72feb5f299c28778da2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 25 Jun 2014 10:22:46 +0200 Subject: [PATCH 12/16] editor: fix --- src/editor/modules/documentCanvas/canvas/canvas.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 50c0ae4..29edbe5 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -457,6 +457,9 @@ $.extend(Selection.prototype, { return doc.createFragment(doc.CaretFragment, {node: anchorNode, offset: this.nativeSelection.anchorOffset}); } if(this.type === 'textSelection') { + if(!anchorNode || !focusNode) { + return; + } if(anchorNode.isSiblingOf(focusNode)) { return doc.createFragment(doc.TextRangeFragment, { node1: anchorNode, -- 2.20.1 From aba92db36cedd657b0c8c0637aa4aae7b573f023 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 26 Jun 2014 11:40:44 +0200 Subject: [PATCH 13/16] editor: fix splitting text when its parent contains comments --- src/editor/plugins/core/core.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index c12405b..450f147 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -18,22 +18,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() { -- 2.20.1 From 643d726b32f530502411247a087274284e3f9c3a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 26 Jun 2014 14:26:44 +0200 Subject: [PATCH 14/16] smartxml: fix - adding nodes before/after root node is not allowed --- src/smartxml/core.js | 9 ++++++++- src/smartxml/smartxml.test.js | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/smartxml/core.js b/src/smartxml/core.js index fdce751..7118584 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -23,7 +23,7 @@ var INSERTION = function(implementation) { next.detach(); } returned = implementation.call(this, insertion.ofNode); - if(!options.silent && returned.sameNode(insertion.ofNode)) { + if(!options.silent && returned && returned.sameNode(insertion.ofNode)) { if(!insertion.insertsNew) { this.triggerChangeEvent('nodeDetached', {node: insertion.ofNode, parent: nodeParent, move: true}); } @@ -63,7 +63,11 @@ var documentNodeTransformations = { }, after: INSERTION(function(node) { + if(this.isRoot()) { + return; + } var next = this.next(); + if(next && next.nodeType === Node.TEXT_NODE && node.nodeType === Node.TEXT_NODE) { next.setText(node.getText() + next.getText()); node.detach(); @@ -74,6 +78,9 @@ var documentNodeTransformations = { }), before: INSERTION(function(node) { + if(this.isRoot()) { + return; + } var prev = this.prev(); if(prev && prev.nodeType === Node.TEXT_NODE && node.nodeType === Node.TEXT_NODE) { prev.setText(prev.getText() + node.getText()); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 6b2f91d..b50da7f 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -240,6 +240,29 @@ describe('smartxml', function() { }); }); }); + + describe('Putting nodes around', function() { + it('will not allow to put node before or after root node', function() { + var doc = getDocumentFromXML(''), + spy = sinon.spy(), + root = doc.root, + result; + + doc.on('change', spy); + + result = doc.root.before({tagName: 'test'}); + + expect(spy.callCount).to.equal(0); + expect(result).to.undefined; + + result = doc.root.after({tagName: 'test'}); + + expect(spy.callCount).to.equal(0); + expect(result).to.undefined; + + expect(doc.root.sameNode(root)); + }); + }); }); describe('Basic TextNode properties', function() { -- 2.20.1 From 84a0c8eeefe4f8ea5da616a0527f1f958cad893c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 26 Jun 2014 14:33:41 +0200 Subject: [PATCH 15/16] editor: canvas fix --- src/editor/modules/documentCanvas/canvas/keyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index b739cf8..71a50b0 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -48,7 +48,7 @@ handlers.push({key: KEYS.ENTER, if(Object.keys(cursor.getPosition()).length === 0) { var currentElement = canvas.getCurrentNodeElement(); - if(currentElement) { + if(currentElement && !currentElement.wlxmlNode.isRoot()) { canvas.wlxmlDocument.transaction(function() { var added = currentElement.wlxmlNode.after({ tagName: currentElement.wlxmlNode.getTagName() || 'div', -- 2.20.1 From cef69fff5322bdc7766d7063809694f6ee0e9e47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 30 Jun 2014 14:47:57 +0200 Subject: [PATCH 16/16] smartxml: additional text nodes merge strategies for ElementNode.detach --- src/smartxml/core.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/smartxml/core.js b/src/smartxml/core.js index 7118584..b40e9c3 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -120,12 +120,24 @@ var documentNodeTransformations = { var elementNodeTransformations = { - detach: function() { + detach: function(params) { var next; + params = _.extend({ + normalizeStrategy: 'merge' + }, params); + if(this.parent() && this.isSurroundedByTextNodes()) { - next = this.next(); - this.prev().appendText(next.getText()); - next.detach(); + if(params.normalizeStrategy === 'detach-left') { + this.prev().detach(); + } else if(params.normalizeStrategy === 'detach-right') { + this.next().detach(); + } else if(params.normalizeStrategy === 'merge') { + next = this.next(); + this.prev().appendText(next.getText()); + next.detach(); + } else { + throw new Error('unknown normalize strategy for detach'); + } } return this.__super__.detach(); }, -- 2.20.1