javascript is now mozilla-compliant
authorPierre Habouzit <madcoder@debian.org>
Mon, 18 Aug 2003 11:31:36 +0000 (11:31 +0000)
committerPierre Habouzit <madcoder@debian.org>
Mon, 18 Aug 2003 11:31:36 +0000 (11:31 +0000)
philter/philter/include/philter.js

index 29ee024..3cf2fe2 100644 (file)
@@ -21,6 +21,17 @@ function cleanChilds(Node, nbChilds) {
         Node.removeChild(Node.childNodes[nbChilds]);
 }
 
+function getElement(obj) {
+    return getNthElement(obj,0);
+}
+
+function getNthElement(obj, index) {
+    if(document.all)
+        return document.all[obj][index];
+    if(document.getElementsByName)
+        return document.getElementsByName(obj)[index];
+}
+
 /********** ORDER FORM FUNCTIONS **********/
 
 function order_up() {
@@ -127,7 +138,7 @@ function createActionRow(Node,data) {
 }
 
 function newAction() {
-    createActionRow(document.all['actions_row'], 0);
+    createActionRow(getElement('actions_row'), 0);
 }
 
 /********** RULE.MATCH FORM FUNCTIONS **********/
@@ -170,7 +181,7 @@ function createMatchRow(Node,data) {
 }
 
 function newMatch() {
-    createMatchRow(document.all['matches_row'], 0);
+    createMatchRow(getElement('matches_row'), 0);
 }
 
 /********** RULE FORM FUNCTIONS **********/
@@ -183,23 +194,23 @@ function changeRow(sel, funcs) {
 
 function createRuleForm() {
     var i;
-    var sel = document.all['order[select]'];
+    var sel = getElement('order[select]');
     var index = sel.options[sel.selectedIndex].value;
 
     actions_i = matches_i = 0;
     current_rule = filter[index];
 
-    document.all['rule[id]'].value = index;
-    document.all['rule[name]'].value = current_rule.name;
-    document.all['rule[all]'][1-current_rule.all].checked = true;
-    document.all['rule[block]'].checked = current_rule.block;
+    getElement('rule[id]').value = index;
+    getElement('rule[name]').value = current_rule.name;
+    getNthElement('rule[all]',[1-current_rule.all]).checked = true;
+    getElement('rule[block]').checked = current_rule.block;
 
-    var mr = document.all['matches_row'];
+    var mr = getElement('matches_row');
     cleanChilds(mr,0);
     for(i=0; i<current_rule.matches.length; i++)
         createMatchRow(mr, current_rule.matches[i]);
     
-    var ar = document.all['actions_row'];
+    var ar = getElement('actions_row');
     cleanChilds(ar,0);
     for(i=0; i<current_rule.actions.length; i++)
         createActionRow(ar, current_rule.actions[i]);