Files
Testing/js/poll.js

466 lines
12 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
$j=jQuery.noConflict();
var pollajaxurl='poll_ajax.php';
requestsInProgress=0;
maxRequestsInProgress=1;
function togglePoll(pollID, isClosed)
{
// One request at a time please
if( requestsInProgress>=maxRequestsInProgress )
{
alert(Language.Translate(2500115));
return false;
}
// Display
var pollContainer = jQuery('#sePoll_'+pollID);
if( isClosed )
{
pollContainer.find('.sePollsClose').css("display", 'none');
pollContainer.find('.sePollsOpen').css("display", "block");
}
else
{
pollContainer.find('.sePollsClose').css("display", 'block');
pollContainer.find('.sePollsOpen').css("display", "none");
}
// Ajax
var bind = this;
var request = new Request.JSON({
'method' : 'post',
'url' : pollajaxurl,
'data' : {
'task' : 'togglepoll',
'poll_id' : pollID,
'poll_closed' : (isClosed ? 1 : 0)
},
'onComplete': function(responseObject)
{
requestsInProgress--;
if( !responseObject || $type(responseObject)!="object" || responseObject.result=="failure" )
{
if( !responseObject.message )
alert(Language.Translate(2500114));
else
alert(responseObject.message);
}
else
{
}
}
});
requestsInProgress++;
request.send();
}
function deletePollConfirm(pollID)
{
// One request at a time please
if( requestsInProgress>=maxRequestsInProgress )
{
alert(bind.Base.Language.Translate(2500115));
return false;
}
// Display
jQuery('#sePoll_'+pollID).remove();
// Ajax
var bind = this;
var request = new Request.JSON({
'method' : 'post',
'url' : pollajaxurl,
'data' : {
'task' : 'deletepoll',
'poll_id' : pollID
},
'onComplete': function(responseObject)
{
bind.requestsInProgress--;
if( !responseObject || $type(responseObject)!="object" || responseObject.result=="failure" )
{
if( !responseObject.message )
alert(bind.Base.Language.Translate(2500114));
else
alert(responseObject.message);
}
}
});
this.requestsInProgress++;
request.send();
// SHOW NEW MESSAGE
if( $$('.sePollRow').length<1 )
$('pollnullmessage').style.display = 'block';
}
function sendpollvote(value, id){
// 'this' is the hidden form element holding the current value
// 'value' is the value selected
// 'element' points to the link element that received the click.
if( requestsInProgress>=maxRequestsInProgress )
{
alert("Please wait until the previous operation is complete until starting another.");
return false;
}
var request = new jQuery.ajax({
'url' : pollajaxurl,
'method' : 'post',
'secure' : false,
'data' : {
'task' : 'votepoll',
'poll_id' : id,
'vote' : value
},
dataType: 'json',
success : function(responseObject)
{
requestsInProgress--;
if( !responseObject || jQuery.type(responseObject)!="object" || responseObject.result=="failure" )
{
if( !responseObject.message )
alert("There was an error processing your request.");
else
alert(responseObject.message);
}
else
{
generatepollresults(id, responseObject);
pollViewMode(id);
}
}
});
request.send();
// To submit the form automatically:
//this.form.submit();
// To submit the form via ajax:
//$(this.form).ajaxSubmit();
}
function getpolldata(id){
// 'this' is the hidden form element holding the current value
// 'value' is the value selected
// 'element' points to the link element that received the click.
/*if( requestsInProgress>=maxRequestsInProgress )
{
alert("Please wait until the previous operation is complete until starting another.");
return false;
}*/
var request = new jQuery.ajax({
'method' : 'post',
'url' : pollajaxurl,
'data' : {
'task' : 'infopoll',
'poll_id' : id
},
dataType: 'json',
success: function(responseObject)
{
requestsInProgress--;
if( !responseObject || jQuery.type(responseObject)!="object" || responseObject.result=="failure" )
{
if( !responseObject.message )
alert("There was an error processing your request.");
else
alert(responseObject.message);
}
else
{
generatepollresults(id, responseObject);
pollViewMode(id);
}
}
});
//this.requestsInProgress++;
request.send();
// To submit the form automatically:
//this.form.submit();
// To submit the form via ajax:
//$(this.form).ajaxSubmit();
}
function generatepollresults(pollID, pollDataObject){
var pollResultsContainer = $j('poll'+pollID+'_results');
pollResultsContainer.empty();
// Options
//var bind = this;
var isFirst = true;
var pollResultIndex = 1;
showstr='<div class="pollResult'+pollID+'">';
$j.each(pollDataObject.poll_options, function(pollOptionIndex, pollOptionLabel)
{
//var pollResultTemplate = jQuery('#pollResultTemplate').getElement('.pollResult').clone();
var pollResultTemplate = jQuery('pollResultTemplate .pollResult').clone();
// Generate Stats
var pollResultID = "poll" + pollID + "_bar" + pollOptionIndex;
var pollResultClass = "poll_bar" + (pollResultIndex - (20 * Math.floor(pollResultIndex/20))).toString();
var width = 3;
var percentage = 0;
if(parseInt(function(){
return pollDataObject.poll_answers[pollOptionIndex];
})=="NaN"){thisVoteCount=0}
else{thisVoteCount=function(){
return pollDataObject.poll_answers[pollOptionIndex];
};
thisVoteCount=thisVoteCount();
}
width += Math.round((thisVoteCount / pollDataObject.poll_totalvotes) * 400);
percentage += Math.round((thisVoteCount / pollDataObject.poll_totalvotes) * 100);
// Apply to template
if(thisVoteCount!=1){
var votesString = thisVoteCount+" votes";//'('+bind.Base.Language.TranslateFormatted(2500028, [thisVoteCount || '0'])+')';
}
else{var votesString = thisVoteCount+" vote";}
//$j('.pollResultLabel').addClass(pollResultClass);
/*pollResultTemplate.getElement('.pollResultLabel').setProperty('html', pollOptionLabel);
pollResultTemplate.getElement('.pollResultBar').addClass(pollResultClass);
pollResultTemplate.getElement('.pollResultBar').setProperty('id', pollResultID);
pollResultTemplate.getElement('.pollResultPercentage').setProperty('html', percentage+'%');
pollResultTemplate.getElement('.pollResultVotes').setProperty('html', votesString);*/
// Space them
if( !isFirst )
{
//(new Element('br')).inject(pollResultTemplate, 'top');
$j(pollResultTemplate).prepend("<br>");
//(new Element('br')).inject(pollResultTemplate, 'top');
}
// Inject
//pollResultTemplate.inject(pollResultsContainer);
$j(pollResultTemplate).append(pollResultsContainer);
pollResultIndex++;
isFirst = false;
var width = 3;
var percentage = 0;
if( pollDataObject.poll_answers[pollOptionIndex] )
width += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 400);
if( pollDataObject.poll_answers[pollOptionIndex] )
percentage += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 100);
//
showstr+='<div style="display:none;">&nbsp;</div><style>.poll_bar'+pollID+(pollResultIndex-1)+'{ width:'+width+'px; -moz-animation:poll_bar'+pollID+(pollResultIndex-1)+' 2s ease-out; -webkit-animation:poll_bar'+pollID+(pollResultIndex-1)+' 2s ease-out; animation: poll_bar'+pollID+(pollResultIndex-1)+' 2s; } @keyframes poll_bar'+pollID+(pollResultIndex-1)+' { 0% { width:0px;} 100%{ width:'+percentage+'%; animation-timing-function: ease-out;} } @-webkit-keyframes poll_bar'+pollID+(pollResultIndex-1)+' { 0% { width:0px;} 100%{ width:'+percentage+'%;} } @-moz-keyframes poll_bar'+pollID+(pollResultIndex-1)+' { 0% { width:0px;} 100%{ width:'+percentage+'%;} } </style><div class="pollResult'+pollID+'"><div class="pollResultLabel">'+pollOptionLabel+'</div> <div class="barcontainer"><div class="pollResultBar poll_bar'+(pollResultIndex-1)+' poll_bar'+pollID+(pollResultIndex-1)+'" id="poll'+pollID+'_bar'+(pollResultIndex-1)+'" style="display: block;" data-percent="'+percentage+'%"></div></div> <span class="pollResultPercentage">'+percentage+'%</span> <span class="pollResultVotes">('+votesString+')</span> </div>';
/*$j('.pollResult').each(function(){
$j(this).find('poll'+pollID+'_bar'+(pollResultIndex-1)).animate({
width:$j(this).attr('data-percent')
},6000);
alert("SSS");
});
*/
//document.getElementById(pollResultID).style.width="100%";
// alert(document.getElementById('poll2130_results').innerHTML);
});
showstr+='</div>';
document.getElementById('poll'+pollID+'_results').innerHTML=showstr;
// Effects
/*$j.each(pollDataObject.poll_options,function(pollOptionIndex, pollOptionLabel)
{
var pollResultElement = $j("#poll" + pollID + "_bar" + pollOptionIndex);
//alert("fffff");
var width = 3;
var percentage = 0;
if( pollDataObject.poll_answers[pollOptionIndex] )
width += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 400);
if( pollDataObject.poll_answers[pollOptionIndex] )
percentage += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 100);
//document.getElementById("poll" + pollID + "_bar" + pollOptionIndex).style.backgroundColor="red";
alert("poll" + pollID + "_bar" + pollOptionIndex);
//jQuery("poll" + pollID + "_bar" + pollOptionIndex).style.display="block";
alert("AA");
//jQuery("#poll" + pollID + "_bar" + pollOptionIndex).style.display="block";
alert("AA");
//document.getElementById("poll" + pollID + "_bar" + pollOptionIndex).style.width="100%";
alert("AA");
//document.getElementById("poll" + pollID + "_bar" + pollOptionIndex).style.height="300px";
/*jQuery(pollResultElement).animate({
left: 500,
top: [500, 'easeOutBounce']
}, 1000);*/
//var pollEffect = new Fx.Tween(pollResultElement, {duration: 1000, transition: Fx.Transitions.Quad.easeOut});
// alert("aaa");
//pollEffect.start('width', 3, width);
// });
}
function showPollDelete(pollID)
{
var pollContainer = document.getElementById('sePoll_'+pollID);
currentConfirmDeleteID = pollID;
TB_show("Are you sure?", '#TB_inline?height=100&width=300&inlineId=confirmpolldelete', '', '../images/trans.gif');
}
function pollViewMode(pollID)
{
document.getElementById('poll'+pollID+'_results').style.display = "block";
document.getElementById('poll'+pollID+'_results_actions').style.display = "block";
document.getElementById('poll'+pollID+'_vote').style.display = "none";
document.getElementById('poll'+pollID+'_vote_actions').style.display = "none";
}
function pollVoteMode(pollID)
{
document.getElementById('poll'+pollID+'_results').style.display = "none";
document.getElementById('poll'+pollID+'_results_actions').style.display = "none";
document.getElementById('poll'+pollID+'_vote').style.display = "block";
document.getElementById('poll'+pollID+'_vote_actions').style.display = "block";
}