More changes to make mforms compatible in 1.7 with 1.8 MDL-9159

This commit is contained in:
moodler
2007-04-02 05:38:04 +00:00
parent 290b74fd49
commit f9bbb1031e
3 changed files with 107 additions and 22 deletions
+74
View File
@@ -135,6 +135,80 @@ function findParentNode(el, elName, elClass, elId) {
return el;
}
/*
findChildNode (start, elementName, elementClass, elementID)
Travels down the DOM hierarchy to find all child elements with the
specified tag name, class, and id. All conditions must be met,
but any can be ommitted.
Doesn't examine children of matches.
*/
function findChildNodes(start, tagName, elementClass, elementID, elementName) {
var children = new Array();
for (var i = 0; i < start.childNodes.length; i++) {
var classfound = false;
var child = start.childNodes[i];
if((child.nodeType == 1) &&//element node type
(elementClass && (typeof(child.className)=='string'))){
var childClasses = child.className.split(/\s+/);
for (var childClassIndex in childClasses){
if (childClasses[childClassIndex]==elementClass){
classfound = true;
break;
}
}
}
if(child.nodeType == 1) { //element node type
if ( (!tagName || child.nodeName == tagName) &&
(!elementClass || classfound)&&
(!elementID || child.id == elementID) &&
(!elementName || child.name == elementName))
{
children = children.concat(child);
} else {
children = children.concat(findChildNodes(child, tagName, elementClass, elementID, elementName));
}
}
}
return children;
}
/*
elementSetHide (elements, hide)
Adds or removes the "hide" class for the specified elements depending on boolean hide.
*/
function elementShowAdvanced(elements, show) {
for (var elementIndex in elements){
element = elements[elementIndex];
element.className = element.className.replace(new RegExp(' ?hide'), '')
if(!show) {
element.className += ' hide';
}
}
}
function showAdvancedOnClick(button, hidetext, showtext){
var toSet=findChildNodes(button.form, null, 'advanced');
var buttontext = '';
if (button.form.elements['mform_showadvanced_last'].value == '0' || button.form.elements['mform_showadvanced_last'].value == '' ) {
elementShowAdvanced(toSet, true);
buttontext = hidetext;
button.form.elements['mform_showadvanced_last'].value = '1';
} else {
elementShowAdvanced(toSet, false);
buttontext = showtext;
button.form.elements['mform_showadvanced_last'].value = '0';
}
var formelements = button.form.elements;
for (var i in formelements){
if (formelements[i] && formelements[i].name && (formelements[i].name=='mform_showadvanced')){
formelements[i].value = buttontext;
}
}
//never submit the form if js is enabled.
return false;
}
/*
elementToggleHide (element, elementFinder)