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

duncan at codespeak.net duncan at codespeak.net
Tue Oct 3 13:31:15 CEST 2006


Author: duncan
Date: Tue Oct  3 13:31:13 2006
New Revision: 32839

Modified:
   kupu/trunk/kupu/common/kupubasetools.js
   kupu/trunk/kupu/common/kupuhelpers.js
   kupu/trunk/kupu/tests/test_kupubasetools.js
Log:
Fix unit tests and style pulldown for IE. Move mixed/other style entry to top of list (because IE is braindead if you mix select.options.add and select.appendChild and there is no way to add an option at the end outside an optgroup without using appendChild). Stopped the list reloading all the styles every time you switch in and out of table mode (reduces flicker on IE).


Modified: kupu/trunk/kupu/common/kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/common/kupubasetools.js	(original)
+++ kupu/trunk/kupu/common/kupubasetools.js	Tue Oct  3 13:31:13 2006
@@ -250,6 +250,7 @@
     var styleoptions = [];
     var tableoffset = 0;
     var styleoffset = 0;
+    var tablegrp = null;
     this.optionstate = -1;
     this.otherstyle = null;
     this.tablestyles = {};
@@ -397,39 +398,43 @@
         var select = this.tsselect;
         var options = select.options;
         if (this.otherstyle) {
-            options[options.length-1] = null;
+            options[0] = null;
             this.otherstyle = null;
         }
         if (this.optionstate == inTable) return; /* No change */
 
-        while (select.firstChild) select.removeChild(select.firstChild);
-        this.otherstyle = null;
+        // while (select.firstChild) select.removeChild(select.firstChild);
 
         function option(info) {
-            var opt = document.createElement('option');
-            opt.text = info[0];
-            var v = info[1];
-            opt.value = v;
-            return opt;
-        }
-        for (var i = 0; i < paraoptions.length; i++) {
-            options.add(option(paraoptions[i]));
-        }
-        var grp = document.createElement('optgroup');
-        grp.label = 'Character styles';
-        for (var i = 0; i < styleoptions.length; i++) {
-            grp.appendChild(option(styleoptions[i]));
+            return newElement('option', {'value': info[1]}, [info[0]]);
         }
-        select.appendChild(grp);
-        if (inTable) {
+        if (this.optionstate==-1) {
+            for (var i = 0; i < paraoptions.length; i++) {
+                select.appendChild(option(paraoptions[i]));
+            }
             var grp = document.createElement('optgroup');
+            grp.label = 'Character styles';
+            for (var i = 0; i < styleoptions.length; i++) {
+                grp.appendChild(option(styleoptions[i]));
+            }
+            select.appendChild(grp);
+        }
+        if (inTable) {
+            var grp = tablegrp = document.createElement('optgroup');
             grp.label = 'Table elements';
             for (var i = 0; i < tableoptions.length; i++) {
                 grp.appendChild(option(tableoptions[i]));
             }
             select.appendChild(grp);
-        }
-        select.selectedIndex = 0;
+        } else {
+            while (select.options[tableoffset]) {
+                select.options[tableoffset] = null;
+            };
+            if (tablegrp) {
+                select.removeChild(tablegrp);
+                tablegrp = null;
+            };
+        };
         this.optionstate = inTable;
     }
     
@@ -450,7 +455,6 @@
     this.nodeStyle = function(node) {
         var currnode = node;
         var index = -1;
-        var options = this.tsselect.options;
         this.styletag = undefined;
         this.classname = '';
 
@@ -538,12 +542,11 @@
                 var caption = '<no style>';
             }
 
-            var opt = document.createElement('option');
+            var opt = newElement('option');
             opt.text = caption;
             this.otherstyle = opt;
-            this.tsselect.options.add(opt);
-
-            index = this.tsselect.length-1;
+            this.tsselect.options.add(opt,0);
+            index = 0;
         }
         this.tsselect.selectedIndex = Math.max(index,0);
     };

Modified: kupu/trunk/kupu/common/kupuhelpers.js
==============================================================================
--- kupu/trunk/kupu/common/kupuhelpers.js	(original)
+++ kupu/trunk/kupu/common/kupuhelpers.js	Tue Oct  3 13:31:13 2006
@@ -102,7 +102,11 @@
             };
         } else {
             for (var i = 0; i < arg.length; i++) {
-                node.appendChild(arg[i]);
+                if(typeof(arg[i])=='string') {
+                    node.appendChild(doc.createTextNode(arg[i]));
+                } else {
+                    node.appendChild(arg[i]);
+                }
             }
         }
     }

Modified: kupu/trunk/kupu/tests/test_kupubasetools.js
==============================================================================
--- kupu/trunk/kupu/tests/test_kupubasetools.js	(original)
+++ kupu/trunk/kupu/tests/test_kupubasetools.js	Tue Oct  3 13:31:13 2006
@@ -121,6 +121,16 @@
             4, 6, 'az', 2, "Caption");
     }
 
+    this.test_updateState6 = function() {
+        this.updateStateTest('<p>foo</p><div class="other">baz</div>',
+            5, 7, 'az', 0, "Other: div other");
+    }
+
+    this.test_updateState7 = function() {
+        this.updateStateTest('<p>foo</p><div class="other">baz</div>',
+            1, 7, 'oobaz', 0, "Mixed styles");
+    }
+
     this.test_setTextStyle = function() {
         this.body.innerHTML = '<p>foo</p><p>bar</p><p>baz</p>';
         // select                          |bar|


More information about the kupu-checkins mailing list