X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a29236f6a3f5166a3cace703dd5f89cf17405617..7dc3d4d5e031615e4dd5393fe126daa7248ce184:/modules/documentCanvas/canvasManager.js?ds=sidebyside diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index 26bc4fa..235c97b 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -228,26 +228,37 @@ Manager.prototype.onBackspaceKey = function(e) { } }; +Manager.prototype.toggleList = function(toggle) { + var selection = window.getSelection(), + node1 = $(selection.anchorNode).parent()[0], + node2 = $(selection.focusNode).parent()[0], + element1 = this.canvas.getDocumentElement(node1), + element2 = this.canvas.getDocumentElement(node2); + if(toggle) { + this.canvas.list.create({element1: element1, element2: element2}); + } else { + if(this.canvas.list.areItemsOfTheSameList({element1: element1, element2: element2})) { + this.canvas.list.extractItems({element1: element1, element2: element2, merge: false}); + } + } +}; + Manager.prototype.command = function(command, meta) { - var pos = getCursorPosition(); - - if(command === 'createList') { - var node = canvasNode.create(pos.parentNode); - if(window.getSelection().getRangeAt(0).collapsed && this.canvas.nodeInsideList({node: node})) { - this.canvas.listRemove({pointer: node}); - this.selectNode(node, {movecaret: 'end'}); - this.sandbox.publish('contentChanged'); + var selection = window.getSelection(), + node1 = $(selection.anchorNode).parent()[0], + node2 = $(selection.focusNode).parent()[0], + element1 = this.canvas.getDocumentElement(node1), + element2 = this.canvas.getDocumentElement(node2); + if(command === 'unwrap-node') { + // this.canvas.nodeUnwrap({node: canvasNode.create(pos.parentNode)}); + // this.sandbox.publish('contentChanged'); + if(this.canvas.list.areItemsOfTheSameList({element1: element1, element2: element2})) { + this.canvas.list.extractItems({element1: element1, element2: element2}); } - else { - //if(!this.canvas.nodeInsideList({node: node})) { - this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode), type: meta}); - this.selectNode(node, {movecaret: 'end'}); - this.sandbox.publish('contentChanged'); - //} + } else if(command === 'wrap-node') { + if(this.canvas.list.areItemsOfTheSameList({element1: element1, element2: element2})) { + this.canvas.list.create({element1: element1, element2: element2}); } - } else if(command === 'unwrap-node') { - this.canvas.nodeUnwrap({node: canvasNode.create(pos.parentNode)}); - this.sandbox.publish('contentChanged'); } };