[kupu-checkins] r32807 - in kupu/trunk/kupu: common tests

duncan at codespeak.net duncan at codespeak.net
Mon Oct 2 10:59:59 CEST 2006


Author: duncan
Date: Mon Oct  2 10:59:53 2006
New Revision: 32807

Modified:
   kupu/trunk/kupu/common/kupubasetools.js
   kupu/trunk/kupu/tests/test_kupubasetools.js
   kupu/trunk/kupu/tests/test_kupuhelpers.js
Log:
Table selections covering more than one row and setting a row style changed the TD tags to TR (in Firefox, IE just gave obscure errors). Added a suitable test and fixed _cleanCell so the test passes.
Modified _setSelection so that it allows separate fudge factors for IE on the start and end of the selection: one day it should be rewritten to not require the fudge factors at all.


Modified: kupu/trunk/kupu/common/kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/common/kupubasetools.js	(original)
+++ kupu/trunk/kupu/common/kupubasetools.js	Mon Oct  2 10:59:53 2006
@@ -570,11 +570,13 @@
     }
 
     this._cleanCell = function(eltype, classname, strip) {
+        var alttype=eltype=='TD'?'TH':eltype=='TH'?'TD':null;
+        
         var selNode = this.editor.getSelectedNode(true);
         var el = this.editor.getNearestParentOfType(selNode, eltype);
-        if (!el) {
-                // Maybe changing type
-            el = this.editor.getNearestParentOfType(selNode, eltype=='TD'?'TH':'TD');
+        if (!el && alttype) {
+            // Maybe changing type
+            el = this.editor.getNearestParentOfType(selNode, alttype);
         }
 
         //either the selection is inside a cell, spans cells, or includes
@@ -612,15 +614,17 @@
         } else {
             //otherwise, find all cells that intersect the selection
             var selection = this.editor.getSelection();
-            var tdNodes = selNode.getElementsByTagName('TD');
-            var thNodes = selNode.getElementsByTagName('TH');
+            var nodes = selNode.getElementsByTagName(eltype);
 
             var cellNodes = Array();
-            for (var i = 0; i < tdNodes.length; i++) {
-                cellNodes.push(tdNodes.item(i));
+            for (var i = 0; i < nodes.length; i++) {
+                cellNodes.push(nodes.item(i));
             };
-            for (var i = 0; i < thNodes.length; i++) {
-                cellNodes.push(thNodes.item(i));
+            if (alttype) {
+                nodes = selNode.getElementsByTagName(alttype);
+                for (var i = 0; i < nodes.length; i++) {
+                    cellNodes.push(nodes.item(i));
+                };
             };
             
             for (var i = 0; i < cellNodes.length; i++) {

Modified: kupu/trunk/kupu/tests/test_kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/tests/test_kupubasetools.js	(original)
+++ kupu/trunk/kupu/tests/test_kupubasetools.js	Mon Oct  2 10:59:53 2006
@@ -152,6 +152,26 @@
 //         this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
 //     };
 
+    this.test_setTextStyle_TableRow = function() {
+        //Apply a table row style inside a table cell 
+        var data = '<table><tbody><tr><td>foo</td><td>bar</td></tr></tbody></table>';
+        var expected =  '<table><tbody><tr class="te st"><td>foo</td><td>bar</td></tr></tbody></table>';
+        this.body.innerHTML = data;
+        this._setSelection(1, null, 5, null, 'ooba', 1, 2);
+        this.ui.setTextStyle('tr|te st');
+        this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
+    };
+    
+    this.test_setTextStyle_TableRow2 = function() {
+        //Apply a table row style across 2 rows 
+        var data = '<table><tbody><tr><td>foo</td></tr><tr><td>bar</td></tr></tbody></table>';
+        var expected =  '<table><tbody><tr class="te st"><td>foo</td></tr><tr class="te st"><td>bar</td></tr></tbody></table>';
+        this.body.innerHTML = data;
+        this._setSelection(1, null, 5, null, 'ooba', 1, 2);
+        this.ui.setTextStyle('tr|te st');
+        this.assertEquals(this._cleanHtml(this.body.innerHTML), expected);
+    };
+
     this.test_setTextStyle_ParaStyleThenCellStyle_SingleTableCell = function() {
         //Change the paragraph style inside a table cell, then change the cell
         //style to a td with a class

Modified: kupu/trunk/kupu/tests/test_kupuhelpers.js
==============================================================================
--- kupu/trunk/kupu/tests/test_kupuhelpers.js	(original)
+++ kupu/trunk/kupu/tests/test_kupuhelpers.js	Mon Oct  2 10:59:53 2006
@@ -62,13 +62,17 @@
     };
 
     this._setSelection = function(startOffset, startNextNode, endOffset,
-        endNextNode, verificationString, ieskew) {
+        endNextNode, verificationString, ieskew, endskew) {
         var element = this.body;
         var innerSelection = this.selection.selection;
         if (_SARISSA_IS_IE) {
             if (ieskew) {
                 startOffset += ieskew;
-                endOffset += ieskew;
+                if (endskew) {
+                    endOffset += endskew;
+                } else {
+                    endOffset += ieskew;
+                }
             };
             var range = innerSelection.createRange();
             var endrange = innerSelection.createRange();
@@ -88,7 +92,7 @@
                 innerSelection.extend(position[0], position[1]);
             };
         };
-        this.assertEquals('"'+this.selection.toString().replace(/\r|\n/g, '')+'"',
+        this.assertEquals('"'+this.selection.toString().replace(/(\r|\n|\t)+/g, '')+'"',
                           '"'+verificationString+'"');
     };
 


More information about the kupu-checkins mailing list