From 45caa363f0fb94f3954656166fcb2b78116aeeb7 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 12 Jun 2009 12:01:16 +0000 Subject: [PATCH] Fix whitespace, and a minor problem, in javascript-static. 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 | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/javascript-static.js b/lib/javascript-static.js index ce8940bcbb..6dd02ff958 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -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]); } } -- 2.39.5