]> git.mjollnir.org Git - moodle.git/commitdiff
Fix whitespace, and a minor problem, in javascript-static.
authortjhunt <tjhunt>
Fri, 12 Jun 2009 12:01:16 +0000 (12:01 +0000)
committertjhunt <tjhunt>
Fri, 12 Jun 2009 12:01:16 +0000 (12:01 +0000)
Also, new, more efficient, variant of the select all checkboxes function,
for when they are all in a container with an id.

lib/javascript-static.js

index ce8940bcbbe615bd19e8bfdeda424a26748fc6d2..6dd02ff9582408f04d9ba99e169ce25a6ee9e14a 100644 (file)
@@ -219,6 +219,24 @@ function submitFormById(id) {
     }
 }
 
+/**
+ * Either check, or uncheck, all checkboxes inside the element with id is
+ * @param id the id of the container
+ * @param checked the new state, either '' or 'checked'.
+ */
+function select_all_in_element_with_id(id, checked) {
+    var container = document.getElementById(id);
+    if (!container) {
+        return;
+    }
+    var inputs = container.getElementsByTagName('input');
+    for (var i = 0; i < inputs.length; ++i) {
+        if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
+            inputs[i].checked = checked;
+        }
+    }
+}
+
 function select_all_in(elTagName, elClass, elId) {
     var inputs = document.getElementsByTagName('input');
     inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elClass, elId);});
@@ -256,12 +274,10 @@ function confirm_if(expr, message) {
     found.
 */
 function findParentNode(el, elName, elClass, elId) {
-    while(el.nodeName.toUpperCase() != 'BODY') {
-        if(
-            (!elName || el.nodeName.toUpperCase() == elName) &&
+    while (el.nodeName.toUpperCase() != 'BODY') {
+        if ((!elName || el.nodeName.toUpperCase() == elName) &&
             (!elClass || el.className.indexOf(elClass) != -1) &&
-            (!elId || el.id == elId))
-        {
+            (!elId || el.id == elId)) {
             break;
         }
         el = el.parentNode;
@@ -653,9 +669,9 @@ function elementCookieHide(id, strShow, strHide) {
 
 function filterByParent(elCollection, parentFinder) {
     var filteredCollection = [];
-    for(var i = 0; i < elCollection.length; ++i) {
+    for (var i = 0; i < elCollection.length; ++i) {
         var findParent = parentFinder(elCollection[i]);
-        if(findParent.nodeName != 'BODY') {
+        if (findParent.nodeName.toUpperCase != 'BODY') {
             filteredCollection.push(elCollection[i]);
         }
     }