From: Aleksander Ɓukasz Date: Mon, 19 Aug 2013 08:00:52 +0000 (+0200) Subject: editor ui: functionality of removing element while keeping its content X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/cb9c3f7643f39aaf582bf1d521622ade529f1fae editor ui: functionality of removing element while keeping its content --- diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 7ca7e59..f8806ae 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -47,7 +47,7 @@ $.extend(DocumentElement.prototype, { this.$element = $(htmlElement); }, bound: function() { - return this.canvas !== undefined; + return $.contains(document.documentElement, this.dom()[0]); }, dom: function() { return this.$element; diff --git a/modules/documentCanvas/canvas/wlxmlManagers.js b/modules/documentCanvas/canvas/wlxmlManagers.js index e70cfd2..e3addb2 100644 --- a/modules/documentCanvas/canvas/wlxmlManagers.js +++ b/modules/documentCanvas/canvas/wlxmlManagers.js @@ -35,7 +35,7 @@ var DocumentElementWrapper = function(documentElement) { documentElement._container().toggle(toggle); } - var eventBus = documentElement.bound() ? documentElement.canvas.eventBus : + var eventBus = documentElement.canvas ? documentElement.canvas.eventBus : {trigger: function() {}}; this.trigger = function() { eventBus.trigger.apply(eventBus, arguments); diff --git a/modules/documentCanvas/commands.js b/modules/documentCanvas/commands.js index 955ba48..043d6b7 100644 --- a/modules/documentCanvas/commands.js +++ b/modules/documentCanvas/commands.js @@ -132,6 +132,34 @@ commands.register('footnote', function(canvas, params) { canvas.setCurrentElement(asideElement); }); +commands.register('take-away-node', function(canvas) { + var position = canvas.getCursor().getPosition(), + element = position.element, + nodeElement = element ? element.parent() : canvas.getCurrentNodeElement(); + + if(!nodeElement || !(nodeElement.parent())) + return; + + + var range = nodeElement.unwrapContents(); + + if(element) { + var elementIsFirstChild = nodeElement.childIndex(element); + if(element.bound()) { + canvas.setCurrentElement(element, {caretTo: position.offset}); + } else { + if(elementIsFirstChild) { + canvas.setCurrentElement(range.element1, {caretTo: 'end'}); + } else { + canvas.setCurrentElement(range.element2, {caretTo: 'end'}); + } + } + } else { + canvas.setCurrentElement(range.element1, {caretTo: 'start'}); + } + +}); + return { run: function(name, params, canvas) { diff --git a/modules/documentToolbar/template.html b/modules/documentToolbar/template.html index da4f456..7ba2bc5 100644 --- a/modules/documentToolbar/template.html +++ b/modules/documentToolbar/template.html @@ -19,11 +19,12 @@
- - +
+ +