Simplifying toolbar list button
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 8 Aug 2013 08:01:15 +0000 (10:01 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 8 Aug 2013 08:01:15 +0000 (10:01 +0200)
Now it doesn't have a state and works in out of list context only

modules/documentCanvas/canvas/documentElement.js
modules/documentCanvas/commands.js
modules/documentToolbar/template.html

index 4d74722..1a2ef91 100644 (file)
@@ -103,6 +103,12 @@ $.extend(DocumentElement.prototype, {
 
     isVisible: function() {
         return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata';
+    },
+
+    isInsideList: function() {
+        return this.parents().some(function(parent) {
+            return parent.is('list');
+        });
     }
 });
 
index 8152ccd..738ab76 100644 (file)
@@ -48,7 +48,7 @@ commands.register('wrap-node', function(canvas) {
     }
 });
 
-commands.register('toggle-list', function(canvas, params) {
+commands.register('list', function(canvas, params) {
     var cursor = canvas.getCursor(),
         selectionStart = cursor.getSelectionStart(),
         selectionEnd = cursor.getSelectionEnd(),
@@ -56,13 +56,13 @@ commands.register('toggle-list', function(canvas, params) {
         parent2 = selectionEnd.element.parent() || undefined;
 
     var selectionFocus = cursor.getSelectionFocus();
-    if(params.toggle) {
-        canvas.list.create({element1: parent1, element2: parent2});
-    } else {
-        if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
-            canvas.list.extractItems({element1: parent1, element2: parent2, merge: false});
-        } 
+
+    if(selectionStart.element.isInsideList() || selectionEnd.element.isInsideList()) {
+        return;
     }
+
+    canvas.list.create({element1: parent1, element2: parent2});
+
     canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset});
 });
 
index 86357bc..7701e5f 100644 (file)
@@ -23,7 +23,7 @@
         <button data-name="wrap-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-arrow-down"></i></button>
     </div>    
     <div class="rng-module-documentToolbar-toolbarGroup">
-        <button data-name="list" data-btn-type="toggle" data-meta="bullets" class="btn btn-mini"><i class="icon-list"></i></button>
+        <button data-name="list" data-btn-type="cmd" data-meta="bullets" class="btn btn-mini"><i class="icon-list"></i></button>
         <button data-name="createList" data-btn-type="cmd" data-meta="enum" class="btn btn-mini"><i class="icon-th-list"></i></button>
     </div>
     <div class="rng-module-documentToolbar-toolbarGroup">