wip: integrating lists, first extensions api approach
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 3 Dec 2013 13:49:29 +0000 (14:49 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 21:32:47 +0000 (22:32 +0100)
src/editor/modules/data/data.js
src/editor/modules/documentCanvas/commands.js
src/editor/modules/documentCanvas/nodes.less
src/wlxml/extensions/list/list.js
src/wlxml/extensions/list/list.test.js
src/wlxml/wlxml.js

index 7c9077f..556d9b5 100644 (file)
@@ -1,7 +1,8 @@
 define([
     'libs/jquery',
     './saveDialog',
 define([
     'libs/jquery',
     './saveDialog',
-    'wlxml/wlxml'
+    'wlxml/wlxml',
+    'wlxml/extensions/list/list'
 
 ], function($, saveDialog, wlxml) {
 
 
 ], function($, saveDialog, wlxml) {
 
index 8793b9c..df21cff 100644 (file)
@@ -50,12 +50,17 @@ commands.register('unwrap-node', function(canvas) {
         parent1 = selectionStart.element.parent() || undefined,
         parent2 = selectionEnd.element.parent() || undefined;
 
         parent1 = selectionStart.element.parent() || undefined,
         parent2 = selectionEnd.element.parent() || undefined;
 
-    if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
-        return;
-        // TODO
-        // var selectionAnchor = cursor.getSelectionAnchor();
-        // canvas.list.extractItems({element1: parent1, element2: parent2});
-        // canvas.setCurrentElement(selectionAnchor.element, {caretTo: selectionAnchor.offset});
+    var selectionAnchor = cursor.getSelectionAnchor(),
+        node1 = parent1.data('wlxmlNode'),
+        node2 = parent2.data('wlxmlNode'),
+        doc = node1.document;
+    if(doc.areItemsOfSameList({node1: node1, node2: node2})) {
+
+
+        doc.transform('extractItems', {item1: node1, item2: node2});
+
+        //canvas.list.extractItems({element1: parent1, element2: parent2});
+        canvas.setCurrentElement(selectionAnchor.element, {caretTo: selectionAnchor.offset});
     } else if(!cursor.isSelecting()) {
         var nodeToUnwrap = cursor.getPosition().element.data('wlxmlNode'),
             parentNode = nodeToUnwrap.unwrap();
     } else if(!cursor.isSelecting()) {
         var nodeToUnwrap = cursor.getPosition().element.data('wlxmlNode'),
             parentNode = nodeToUnwrap.unwrap();
@@ -65,17 +70,22 @@ commands.register('unwrap-node', function(canvas) {
     }
 });
 
     }
 });
 
-// commands.register('wrap-node', function(canvas) {
-//     var cursor = canvas.getCursor(),
-//         selectionStart = cursor.getSelectionStart(),
-//         selectionEnd = cursor.getSelectionEnd(),
-//         parent1 = selectionStart.element.parent() || undefined,
-//         parent2 = selectionEnd.element.parent() || undefined;
+commands.register('wrap-node', function(canvas) {
+    var cursor = canvas.getCursor(),
+        selectionStart = cursor.getSelectionStart(),
+        selectionEnd = cursor.getSelectionEnd(),
+        parent1 = selectionStart.element.parent() || undefined,
+        parent2 = selectionEnd.element.parent() || undefined;
 
 
-//     if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
-//         canvas.list.create({element1: parent1, element2: parent2});
-//     }
-// });
+    var node1 = parent1.data('wlxmlNode'),
+        node2 = parent2.data('wlxmlNode'),
+        doc = node1.document;
+
+    if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
+        //canvas.list.create({element1: parent1, element2: parent2});
+        doc.transform('createList', {node1: node1, node2: node2});
+    }
+});
 
 commands.register('list', function(canvas, params) {
     var cursor = canvas.getCursor(),
 
 commands.register('list', function(canvas, params) {
     var cursor = canvas.getCursor(),
@@ -90,7 +100,11 @@ commands.register('list', function(canvas, params) {
         return;
     }
 
         return;
     }
 
-    canvas.list.create({element1: parent1, element2: parent2});
+    var node1 = parent1.data('wlxmlNode'),
+        node2 = parent2.data('wlxmlNode'),
+        doc = node1.document;
+    
+    doc.transform('createList', {node1: node1, node2: node2});
 
     canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset});
 });
 
     canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset});
 });
index d02e872..ab26442 100644 (file)
@@ -73,7 +73,7 @@
     display:none;
 }
 
     display:none;
 }
 
-[wlxml-class="list-items"] {
+[wlxml-class="list"] {
 
      [wlxml-class="item"] {
         display: list-item;
 
      [wlxml-class="item"] {
         display: list-item;
 }
 
 [wlxml-class="item"] {
 }
 
 [wlxml-class="item"] {
-    [wlxml-class="list-items"] {
+    [wlxml-class="list"] {
         display: block;
     }
 }
 
 
         display: block;
     }
 }
 
 
-[wlxml-class="list-items-enum"] {
+[wlxml-class="list-enum"] {
 
     counter-reset: myitem;
 
 
     counter-reset: myitem;
 
index 6cf875f..4291957 100644 (file)
@@ -23,6 +23,12 @@ extension.classMethods['list'] = {
     }
 }
 
     }
 }
 
+extension.documentMethods = {
+    areItemsOfSameList: function(params) {
+        return params.node1.parent().sameNode(params.node2.parent()) && params.node2.parent().is('list');
+    }
+}
+
 extension.documentTransformations.push({
     name: 'createList',
     impl: function(params) {          
 extension.documentTransformations.push({
     name: 'createList',
     impl: function(params) {          
@@ -30,7 +36,7 @@ extension.documentTransformations.push({
             parentContents = parent.contents(),
             nodeIndexes = [params.node1.getIndex(), params.node2.getIndex()].sort(),
             nodesToWrap = [],
             parentContents = parent.contents(),
             nodeIndexes = [params.node1.getIndex(), params.node2.getIndex()].sort(),
             nodesToWrap = [],
-            listNode = params.node1.document.createDocumentNode({tagName: 'div', attrs: {'class': 'list.items'}}),
+            listNode = params.node1.document.createDocumentNode({tagName: 'div', attrs: {'class': 'list'}}),
             node, i;
 
         for(i = nodeIndexes[0]; i <= nodeIndexes[1]; i++) {
             node, i;
 
         for(i = nodeIndexes[0]; i <= nodeIndexes[1]; i++) {
@@ -131,7 +137,6 @@ extension.documentTransformations.push({
             reference.after(toAdd);
         }
         if(!params.merge && listIsNested) {
             reference.after(toAdd);
         }
         if(!params.merge && listIsNested) {
-            debugger;
             return this.transform('extractItems', {item1: extractedItems[0], item2: extractedItems[extractedItems.length-1]});
         }
         return true;
             return this.transform('extractItems', {item1: extractedItems[0], item2: extractedItems[extractedItems.length-1]});
         }
         return true;
index f15d75b..1efa795 100644 (file)
@@ -28,7 +28,7 @@ var removeEmptyTextNodes = function(xml) {
 };
 
 
 };
 
 
-describe.only('Lists extension', function() {
+describe('Lists extension', function() {
 
     describe('creating lists', function() {
         it('allows creation of a list from existing sibling DocumentElements', function() {
 
     describe('creating lists', function() {
         it('allows creation of a list from existing sibling DocumentElements', function() {
index d2dbd30..dbc0cf0 100644 (file)
@@ -274,6 +274,8 @@ return {
             
         });
 
             
         });
 
+        _.extend(WLXMLDocument.prototype, extension.documentMethods);
+
     }
 
 };
     }
 
 };