Skip to content

Commit

Permalink
Dev Rewrote the table cell click script in jQuery
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8816 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jun 8, 2010
1 parent caa3ef8 commit f89bddc
Showing 1 changed file with 20 additions and 63 deletions.
83 changes: 20 additions & 63 deletions scripts/survey_runtime.js
Expand Up @@ -4,7 +4,7 @@ $(document).ready(function()
DOM1 = (typeof document.getElementsByTagName!='undefined');
if (typeof checkconditions!='undefined') checkconditions();
if (typeof template_onload!='undefined') template_onload();
prepCellAdapters();
prepareCellAdapters();
if (typeof(focus_element) != 'undefined')
{
$(focus_element).focus();
Expand Down Expand Up @@ -59,71 +59,28 @@ function match_regex(testedstring,str_regexp)
return pattern.test(testedstring)
}

function cellAdapter(evt,src)
{
var eChild = null, eChildren = src.getElementsByTagName('INPUT');
var curCount = eChildren.length;
//This cell contains multiple controls, don't know which to set.
if (eChildren.length > 1)
{
//Some cells contain hidden fields
for (i = 0; i < eChildren.length; i++)
{
if ( ( eChildren[i].type == 'radio' || eChildren[i].type == 'checkbox' ) && eChild == null)
eChild = eChildren[i];
else if ( ( eChildren[i].type == 'radio' || eChildren[i].type == 'checkbox' ) && eChild != null)
{
//A cell with multiple radio buttons -- unhandled
return;
}

}
}
else eChild = eChildren[0];

if (eChild && eChild.type == 'radio')
{
eChild.checked = true;
//Make sure the change propagates to the conditions handling mechanism
if(eChild.onclick) eChild.onclick(evt);
if(eChild.onchange) eChild.onchange(evt);
}
else if (eChild && eChild.type == 'checkbox')
{
eChild.checked = !eChild.checked;
//Make sure the change propagates to the conditions handling mechanism
if(eChild.onclick) eChild.onclick(evt);
if(eChild.onchange) eChild.onchange(evt);
}
}

function prepCellAdapters()
function prepareCellAdapters()
{
if (!DOM1) return;
var formCtls = document.getElementsByTagName('INPUT');
var ptr = null;
var foundTD = false;
for (var i = 0; i < formCtls.length; i++)
{
ptr = formCtls[i];
if (ptr.type == 'radio' || ptr.type == 'checkbox')
{
foundTD = false;
while (ptr && !foundTD)
{
if(ptr.nodeName == 'TD')
{
foundTD = true;
ptr.onclick =
function(evt){
return cellAdapter(evt,this);
};
continue;
}
ptr = ptr.parentNode;
}
}
}
$('TD INPUT[type=radio]:first-child,TD INPUT[type=checkbox]:first-child').each( function(){
$(this).parents('TD').click(function(){
if($('INPUT[type=radio],INPUT[type=checkbox]',this).length==1)
{
$('INPUT[type=radio],INPUT[type=checkbox]',this).each( function()
{
if (this.type == 'radio')
{
this.checked = true;
}
else if (this.type == 'checkbox')
{
this.checked = !this.checked;
};
});
}
});
});
}

function addHiddenField(theform,thename,thevalue)
Expand Down

0 comments on commit f89bddc

Please sign in to comment.