Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Variables
- var poll_id = 0;
- var poll_answer_id = '';
- var is_being_voted = false;
- pollsL10n.show_loading = parseInt(pollsL10n.show_loading);
- pollsL10n.show_fading = parseInt(pollsL10n.show_fading);
- // When User Vote For Poll
- function poll_vote(current_poll_id) {
- jQuery(document).ready(function($) {
- if(!is_being_voted) {
- set_is_being_voted(true);
- poll_id = current_poll_id;
- poll_answer_id = '';
- poll_multiple_ans = 0;
- poll_multiple_ans_count = 0;
- if($('#poll_multiple_ans_' + poll_id).length) {
- poll_multiple_ans = parseInt($('#poll_multiple_ans_' + poll_id).val());
- }
- $('#polls_form_' + poll_id + ' input.m_poll_answer:checkbox, #polls_form_' + poll_id + ' input.m_poll_answer:radio, #polls_form_' + poll_id + ' option').each(function(i){
- if ($(this).is(':checked') || $(this).is(':selected')) {
- if(poll_multiple_ans > 0) {
- poll_answer_id = $(this).val() + ',' + poll_answer_id;
- poll_multiple_ans_count++;
- } else {
- poll_answer_id = parseInt($(this).val());
- }
- }
- });
- if(poll_multiple_ans > 0) {
- if(poll_multiple_ans_count > 0 && poll_multiple_ans_count <= poll_multiple_ans) {
- poll_answer_id = poll_answer_id.substring(0, (poll_answer_id.length-1));
- poll_process();
- } else if(poll_multiple_ans_count == 0) {
- set_is_being_voted(false);
- alert(pollsL10n.text_valid);
- } else {
- set_is_being_voted(false);
- alert(pollsL10n.text_multiple + ' ' + poll_multiple_ans);
- }
- } else {
- //alert(poll_answer_id);
- if( poll_answer_id == '' ){
- set_is_being_voted(false);
- alert(pollsL10n.text_valid);
- }else if(!$('#checkbox1').is(':checked') ){
- set_is_being_voted(false);
- alert('Please agree to the terms and conditions.');
- }
- else if(poll_answer_id > 0 ){
- //display_comment();
- poll_process();
- }
- /*if(poll_answer_id > 0) {
- //poll_process();
- } else {
- set_is_being_voted(false);
- alert(pollsL10n.text_valid);
- }*/
- }
- } else {
- alert(pollsL10n.text_wait);
- }
- });
- }
- //Comment function
- // Process Poll (User Click "Vote" Button)
- function poll_process() {
- jQuery(document).ready(function($) {
- poll_nonce = $('#poll_' + poll_id + '_nonce').val();
- if(pollsL10n.show_fading) {
- $('#polls-' + poll_id).fadeTo('def', 0);
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').show();
- }
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=process&poll_id=' + poll_id + '&poll_' + poll_id + '=' + poll_answer_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
- } else {
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').show();
- }
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=process&poll_id=' + poll_id + '&poll_' + poll_id + '=' + poll_answer_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
- }
- });
- }
- // Poll's Result (User Click "View Results" Link)
- function poll_result(current_poll_id) {
- jQuery(document).ready(function($) {
- if(!is_being_voted) {
- set_is_being_voted(true);
- poll_id = current_poll_id;
- poll_nonce = $('#poll_' + poll_id + '_nonce').val();
- if(pollsL10n.show_fading) {
- $('#polls-' + poll_id).fadeTo('def', 0);
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').show();
- }
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=result&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
- } else {
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').show();
- }
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=result&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
- }
- } else {
- alert(pollsL10n.text_wait);
- }
- });
- }
- // Poll's Voting Booth (User Click "Vote" Link)
- function poll_booth(current_poll_id) {
- jQuery(document).ready(function($) {
- if(!is_being_voted) {
- set_is_being_voted(true);
- poll_id = current_poll_id;
- poll_nonce = $('#poll_' + poll_id + '_nonce').val();
- if(pollsL10n.show_fading) {
- $('#polls-' + poll_id).fadeTo('def', 0);
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').show();
- }
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=booth&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
- } else {
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').show();
- }
- $.ajax({type: 'POST', xhrFields: {withCredentials: true}, url: pollsL10n.ajax_url, data: 'action=polls&view=booth&poll_id=' + poll_id + '&poll_' + poll_id + '_nonce=' + poll_nonce, cache: false, success: poll_process_success});
- }
- } else {
- alert(pollsL10n.text_wait);
- }
- });
- }
- // Poll Process Successfully
- function poll_process_success(data) {
- jQuery(document).ready(function($) {
- //$('#polls-' + poll_id).replaceWith(data);
- var html ='<div class="first-block vote-submitted"><h2>Thanks for your vote!</h2><p>Come back next Monday to listen to the winning beat!</p><p>Do you have any questions or feedback for Kina and Ken as they work on the remix? Submit it here for the chance to have them respond to it in the near future!</p></div><form id="poll_qst_form" class="second-block comment-block">';
- html = html+'<input type="text" name="name" id="poll_name" placeholder="Your name" required>' ;
- <!--html = html+'<input type="email" name="email" id="poll_email" placeholder="Your email" required>' ;-->
- html = html+'<textarea name="comment" id="poll_comment" class="text poll_comment" placeholder="Let Kina and Ken know your feedback and questions!" required></textarea>' ;
- html = html+'<input type="button" class="Buttons" onclick="send_comment()" id="com_bnt" value="send">';
- html = html+'</form>' ;
- $('#polls-' + poll_id).replaceWith(html);
- if(pollsL10n.show_loading) {
- $('#polls-' + poll_id + '-loading').hide();
- }
- if(pollsL10n.show_fading) {
- $('#polls-' + poll_id).fadeTo('def', 1);
- set_is_being_voted(false);
- } else {
- set_is_being_voted(false);
- }
- });
- }
- /*function send_comment(){
- jQuery(document).ready(function($) {
- var comment = $('#poll_comment').val();
- var html = 'Thanks for Voting';
- //alert(comment);
- if(comment ==''){
- alert('Please fill Your question');
- return false;
- }else{
- //alert('Thanks for Voting');
- $('#poll_qst_form').replaceWith(html);
- //document.write("Thankyou for Voting");
- //is_being_voted();
- }
- });
- }*/
- function send_comment(){
- jQuery(document).ready(function($) {
- var html = '<div class="second-block comment-success"><span class="green">Thank you!</span> Your message has been submitted.</span></div>';
- var comment = $('#poll_comment').val();
- var name = $('#poll_name').val();
- var email = $('#poll_email').val();
- //alert(comment);
- if(comment ==''){
- alert('Please fill out your message.');
- return false;
- }else if(name ==''){
- alert('Please fill out your name.');
- return false;
- }
- else if(email ==''){
- alert('Please fill out your email.');
- return false;
- }else{
- var data = {
- 'action': 'sending_mail',
- 'whatever': 1234
- };
- $('.wp-polls-loading').show();
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
- $.post(pollsL10n.ajax_url+'/?comment='+comment+'&name='+name, data, function(response) {
- if($.trim(response) == 'true'){
- $('.wp-polls-loading').hide();
- $('#poll_qst_form').replaceWith(html);
- /* $.getJSON("http://jsonip.appspot.com?callback=?",
- function(data){
- var ipaddress = data.ip;
- alert( "Your ip: " + ipaddress);
- });
- if(ipaddress == ipaddress)
- {
- alert( "Your ip is equal to " + ipaddress);
- }
- */
- }else{
- //alert(response);
- }
- });
- }
- });
- }
- // Set is_being_voted Status
- function set_is_being_voted(voted_status) {
- is_being_voted = voted_status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement