Adding/removing lists - first approach
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 24 Jun 2013 10:42:00 +0000 (12:42 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 24 Jun 2013 10:42:00 +0000 (12:42 +0200)
modules/documentCanvas/canvas.js
modules/documentCanvas/canvasManager.js
modules/documentCanvas/documentCanvas.js
modules/documentCanvas/transformations.js
modules/documentToolbar/documentToolbar.js
modules/documentToolbar/template.html
modules/rng/rng.js

index 5db5e78..80d3915 100644 (file)
@@ -175,6 +175,16 @@ Canvas.prototype.removeList = function(options) {
     \r
 }\r
 \r
+Canvas.prototype.insideList = function(options) {\r
+    if(options.pointer) {\r
+        if(options.pointer.klass === 'list-items' || options.pointer.klass === 'item')\r
+            return true;\r
+        var pointerElement = $(this.content.find('#' + options.pointer.id));\r
+        return pointerElement.parents('list-items').length > 0;\r
+    }\r
+    return false;\r
+}\r
+\r
 \r
 return {Canvas: Canvas, Node: Node};\r
 \r
index 6a0fc5c..3ced49a 100644 (file)
@@ -14,6 +14,7 @@ var getCursorPosition = function() {
         textNodeOffset: selection.anchorOffset,\r
         textNodeIndex: parent.contents().index(anchorNode),\r
         parentNode: parent,\r
+        focusNode: $(selection.focusNode).parent(),\r
         isAtEnd: selection.anchorOffset === anchorNode.text().length\r
     }\r
 };\r
@@ -181,6 +182,26 @@ Manager.prototype.onBackspaceKey = function(e) {
     }\r
 }\r
 \r
+Manager.prototype.command = function(command, meta) {\r
+    var pos = getCursorPosition();\r
+    \r
+    if(command === 'createList') {\r
+        var node = new wlxmlNode.Node(pos.parentNode);\r
+        if(window.getSelection().getRangeAt().collapsed && this.canvas.insideList({pointer: node})) {\r
+            this.canvas.removeList({pointer: node});\r
+            this.selectNode(node, {movecaret: 'end'});\r
+            this.sandbox.publish('contentChanged');\r
+        }\r
+        else {\r
+            if(!this.canvas.insideList({pointer: node})) {\r
+                this.canvas.createList({start: new wlxmlNode.Node(pos.parentNode), end: new wlxmlNode.Node(pos.focusNode)});\r
+                this.selectNode(new wlxmlNode.Node(pos.parentNode), {movecaret: 'end'});\r
+                this.sandbox.publish('contentChanged');\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
 \r
 \r
 return Manager;\r
index fb67c0d..cc4964b 100644 (file)
@@ -52,6 +52,9 @@ return function(sandbox) {
         },\r
         wrapSelectionWithNewNode: function(wlxmlTag, wlxmlClass) {\r
             manager.wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);\r
+        },\r
+        command: function(command, meta) {\r
+            manager.command(command, meta);\r
         }\r
     }\r
     \r
index d245818..4824849 100644 (file)
@@ -37,6 +37,20 @@ define(['libs/jquery-1.9.1.min'], function($) {
             transform(toBlock, 'div');\r
             transform(toInline, 'span');\r
 \r
+            toret.find(":not(iframe)").addBack().contents().filter(function() {\r
+                return this.nodeType == 3} ).each(function() {\r
+                    var n = $(this); \r
+                    var hasText = /\S/g.test(n.text());\r
+                    if(!hasText) {\r
+                        n.remove();\r
+                        return;\r
+                    }\r
+                    var startSpace = /\s/g.test(n.text().substr(0,1));\r
+                    var endSpace = /\s/g.test(n.text().substr(-1)) && n.text().length > 1;\r
+                    var trimmed = $.trim(n.text());\r
+                    n.get(0).data = (startSpace ? ' ' : '') + trimmed + (endSpace ? ' ' : '');\r
+            });\r
+            \r
             return toret.children();\r
         },\r
         getMetaData: function(xml) {\r
index a2a1567..c459428 100644 (file)
@@ -40,8 +40,9 @@ return function(sandbox) {
                             //this.wrapWithNodeRequest(wlxmlTag, wlxmlClass);\r
                         }\r
                         sandbox.publish('newNodeRequested', wlxmlTag, wlxmlClass);\r
+                    } else {\r
+                        sandbox.publish('command', btn.attr('data-btn'), btn.attr('data-meta'));\r
                     }\r
-                    //sandbox.publish('command', btn.attr('data-btn'), btn.attr('data-meta'));\r
                 }\r
             });\r
         },\r
index 104f00a..112d93b 100644 (file)
@@ -22,5 +22,8 @@
         <button data-btn="grid" data-btn-type="toggle" class="btn btn-mini"><i class="icon-th-large"></i></button>\r
         <button data-btn="tags" data-btn-type="toggle" class="btn btn-mini"><i class="icon-tag"></i></button>\r
     </div>\r
+    <div class="rng-module-documentToolbar-toolbarGroup">\r
+        <button data-btn="createList" data-btn-type="cmd" class="btn btn-mini"><i class="icon-list"></i></button>\r
+    </div>\r
     <div style="clear: both;"></div>\r
 </div>
\ No newline at end of file
index 643b683..7c39d0f 100644 (file)
@@ -259,6 +259,9 @@ return function(sandbox) {
             } else {\r
                 sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);\r
             }\r
+        },\r
+        command: function(cmd, meta) {\r
+            sandbox.getModule('documentCanvas').command(cmd, meta);\r
         }\r
     };\r
     \r