smartxml: Don't preprare for undo if it's obvious it will never come
[fnpeditor.git] / src / wlxml / extensions / list / list.js
index dd010a6..02fe08d 100644 (file)
@@ -1,13 +1,11 @@
-define(function(require) {
+define(function() {
 
 'use strict';
 
+var extension = {document: {transformations: {}}, wlxmlClass: {list: {methods: {}}}};
 
-var wlxml = require('wlxml/wlxml'),
-    extension = {documentTransformations: [], classMethods: {}};
 
-
-extension.classMethods['list'] = {
+extension.wlxmlClass.list.methods = {
     itemIndex: function(listItem) {
         var toret = -1;
         this.contents('.item').some(function(item, index) {
@@ -23,14 +21,21 @@ extension.classMethods['list'] = {
     }
 }
 
-extension.documentTransformations.push({
-    name: 'createList',
+extension.documentMethods = {
+    areItemsOfSameList: function(params) {
+        return params.node1.parent().sameNode(params.node2.parent()) && params.node2.parent().is('list');
+    }
+}
+
+
+
+extension.document.transformations.createList = {
     impl: function(params) {          
         var parent = params.node1.parent(),
             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++) {
@@ -60,15 +65,14 @@ extension.documentTransformations.push({
         });
     },
     getChangeRoot: function() {
-        return this.args.node1.parent();
+        return this.args[0].node1.parent();
     },
     isAllowed: function() {
-        return this.args.node1.parent().sameNode(this.args.node2.parent());
+        return this.args[0].node1.parent().sameNode(this.args[0].node2.parent());
     }
-});
+};
 
-extension.documentTransformations.push({
-    name: 'extractItems',
+extension.document.transformations.extractItems = {
     impl: function(params) {
         params = _.extend({}, {merge: true}, params);
         var list = params.item1.parent(),
@@ -131,37 +135,17 @@ extension.documentTransformations.push({
             reference.after(toAdd);
         }
         if(!params.merge && listIsNested) {
-            debugger;
-            return this.transform('extractItems', {item1: extractedItems[0], item2: extractedItems[extractedItems.length-1]});
+            return this.extractItems({item1: extractedItems[0], item2: extractedItems[extractedItems.length-1]});
         }
         return true;
     },
     isAllowed: function() {
-        var parent = this.args.nodel1.parent();
-        return parent.is('list') && parent.sameNode(this.args.node2.parent());
+        var parent = this.args[0].nodel1.parent();
+        return parent.is('list') && parent.sameNode(this.args[0].node2.parent());
     }
-});
-
-wlxml.registerExtension(extension);
-
-// wlxml.registerClassTransformation('list', {
-//     name: 'insertItem',
-//     impl: function(item) {
-//         if(!item.is('item')) {
-//             throw new Error ('...');
-//         }
-//         this.append(item);
-//     }
-// });
-
-// wlxml.registerClassMethod('list', {
-//     name: 'items',
-//     impl: function() {
-//         var node = this;
-//         return this.contents();    
-//     }
-// });
-
-//a atrybuty? registerClassAttrs? E... lepiej registerClassExtension({methods, attibutes})
+};
+
+return extension;
+
 
 });
\ No newline at end of file