Skip to content

Commit

Permalink
Dev: #05514: Remove prepareCellAdapters and cellAdapter for jquery
Browse files Browse the repository at this point in the history
Dev: updated addClassEmpty too
Dev: use $.delegate function and stopPropagation
  • Loading branch information
Shnoulle committed Feb 7, 2013
1 parent 90fc75d commit 114baa1
Showing 1 changed file with 13 additions and 72 deletions.
85 changes: 13 additions & 72 deletions scripts/survey_runtime.js
Expand Up @@ -134,15 +134,7 @@ function addClassEmpty(){
$(this).addClass('empty');
}
});

$(".answer-item input.text,.text-item input[type=text]").live("blur", function(){
if ($(this).val() == ""){
$(this).addClass('empty');
}else{
$(this).removeClass('empty');
}
});
$(".answer-item textarea").live("blur", function(){
$("body").delegate(".answer-item input.text,.text-item input[type=text],.answer-item textarea","blur focusout",function(){
if ($(this).val() == ""){
$(this).addClass('empty');
}else{
Expand Down Expand Up @@ -326,71 +318,20 @@ 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 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;
}
}
}
$('table.question').delegate('tbody td input:checkbox,tbody td input:radio,tbody td label',"click", function(e) {
e.stopPropagation();
});
$('table.question').delegate('tbody td',"click", function() {
if($(this).find("input:radio,input:checkbox").length==1)
{
$(this).find("input:radio").click();
$(this).find("input:radio").triggerHandler("click");
$(this).find("input:checkbox").click();
$(this).find("input:checkbox").triggerHandler("click");
}
});
}

function addHiddenField(theform,thename,thevalue)
Expand Down

0 comments on commit 114baa1

Please sign in to comment.