Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. // Variables
  2. var poll_id = 0;
  3. var poll_answer_id = '';
  4. var is_being_voted = false;
  5. pollsL10n.show_loading = parseInt(pollsL10n.show_loading);
  6. pollsL10n.show_fading = parseInt(pollsL10n.show_fading);
  7.  
  8. // When User Vote For Poll
  9. function poll_vote(current_poll_id) {
  10. jQuery(document).ready(function($) {
  11. if(!is_being_voted) {
  12. set_is_being_voted(true);
  13. poll_id = current_poll_id;
  14. poll_answer_id = '';
  15. poll_multiple_ans = 0;
  16. poll_multiple_ans_count = 0;
  17. if($('#poll_multiple_ans_' + poll_id).length) {
  18. poll_multiple_ans = parseInt($('#poll_multiple_ans_' + poll_id).val());
  19. }
  20. $('#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){
  21. if ($(this).is(':checked') || $(this).is(':selected')) {
  22. if(poll_multiple_ans > 0) {
  23. poll_answer_id = $(this).val() + ',' + poll_answer_id;
  24. poll_multiple_ans_count++;
  25. } else {
  26. poll_answer_id = parseInt($(this).val());
  27. }
  28. }
  29. });
  30. if(poll_multiple_ans > 0) {
  31. if(poll_multiple_ans_count > 0 && poll_multiple_ans_count <= poll_multiple_ans) {
  32. poll_answer_id = poll_answer_id.substring(0, (poll_answer_id.length-1));
  33. poll_process();
  34. } else if(poll_multiple_ans_count == 0) {
  35. set_is_being_voted(false);
  36. alert(pollsL10n.text_valid);
  37. } else {
  38. set_is_being_voted(false);
  39. alert(pollsL10n.text_multiple + ' ' + poll_multiple_ans);
  40. }
  41. } else {
  42. //alert(poll_answer_id);
  43. if( poll_answer_id == '' ){
  44. set_is_being_voted(false);
  45. alert(pollsL10n.text_valid);
  46. }else if(!$('#checkbox1').is(':checked') ){
  47. set_is_being_voted(false);
  48. alert('Please agree to the terms and conditions.');
  49. }
  50. else if(poll_answer_id > 0 ){
  51. //display_comment();
  52. poll_process();
  53. }
  54.  
  55.  
  56. /*if(poll_answer_id > 0) {
  57. //poll_process();
  58. } else {
  59. set_is_being_voted(false);
  60. alert(pollsL10n.text_valid);
  61. }*/
  62. }
  63. } else {
  64. alert(pollsL10n.text_wait);
  65. }
  66.  
  67.  
  68. });
  69. }
  70.  
  71. //Comment function
  72.  
  73.  
  74.  
  75. // Process Poll (User Click "Vote" Button)
  76. function poll_process() {
  77. jQuery(document).ready(function($) {
  78. poll_nonce = $('#poll_' + poll_id + '_nonce').val();
  79. if(pollsL10n.show_fading) {
  80. $('#polls-' + poll_id).fadeTo('def', 0);
  81. if(pollsL10n.show_loading) {
  82. $('#polls-' + poll_id + '-loading').show();
  83. }
  84. $.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});
  85. } else {
  86. if(pollsL10n.show_loading) {
  87. $('#polls-' + poll_id + '-loading').show();
  88. }
  89. $.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});
  90. }
  91. });
  92. }
  93.  
  94. // Poll's Result (User Click "View Results" Link)
  95. function poll_result(current_poll_id) {
  96. jQuery(document).ready(function($) {
  97. if(!is_being_voted) {
  98. set_is_being_voted(true);
  99. poll_id = current_poll_id;
  100. poll_nonce = $('#poll_' + poll_id + '_nonce').val();
  101. if(pollsL10n.show_fading) {
  102. $('#polls-' + poll_id).fadeTo('def', 0);
  103. if(pollsL10n.show_loading) {
  104. $('#polls-' + poll_id + '-loading').show();
  105. }
  106. $.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});
  107. } else {
  108. if(pollsL10n.show_loading) {
  109. $('#polls-' + poll_id + '-loading').show();
  110. }
  111. $.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});
  112. }
  113. } else {
  114. alert(pollsL10n.text_wait);
  115. }
  116. });
  117. }
  118.  
  119. // Poll's Voting Booth (User Click "Vote" Link)
  120. function poll_booth(current_poll_id) {
  121. jQuery(document).ready(function($) {
  122. if(!is_being_voted) {
  123. set_is_being_voted(true);
  124. poll_id = current_poll_id;
  125. poll_nonce = $('#poll_' + poll_id + '_nonce').val();
  126. if(pollsL10n.show_fading) {
  127. $('#polls-' + poll_id).fadeTo('def', 0);
  128. if(pollsL10n.show_loading) {
  129. $('#polls-' + poll_id + '-loading').show();
  130. }
  131. $.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});
  132. } else {
  133. if(pollsL10n.show_loading) {
  134. $('#polls-' + poll_id + '-loading').show();
  135. }
  136. $.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});
  137. }
  138. } else {
  139. alert(pollsL10n.text_wait);
  140. }
  141. });
  142. }
  143.  
  144. // Poll Process Successfully
  145. function poll_process_success(data) {
  146. jQuery(document).ready(function($) {
  147. //$('#polls-' + poll_id).replaceWith(data);
  148.  
  149. 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">';
  150. html = html+'<input type="text" name="name" id="poll_name" placeholder="Your name" required>' ;
  151. <!--html = html+'<input type="email" name="email" id="poll_email" placeholder="Your email" required>' ;-->
  152. html = html+'<textarea name="comment" id="poll_comment" class="text poll_comment" placeholder="Let Kina and Ken know your feedback and questions!" required></textarea>' ;
  153. html = html+'<input type="button" class="Buttons" onclick="send_comment()" id="com_bnt" value="send">';
  154. html = html+'</form>' ;
  155. $('#polls-' + poll_id).replaceWith(html);
  156.  
  157.  
  158. if(pollsL10n.show_loading) {
  159. $('#polls-' + poll_id + '-loading').hide();
  160. }
  161. if(pollsL10n.show_fading) {
  162. $('#polls-' + poll_id).fadeTo('def', 1);
  163. set_is_being_voted(false);
  164. } else {
  165. set_is_being_voted(false);
  166. }
  167. });
  168. }
  169.  
  170. /*function send_comment(){
  171.  
  172. jQuery(document).ready(function($) {
  173. var comment = $('#poll_comment').val();
  174. var html = 'Thanks for Voting';
  175.  
  176. //alert(comment);
  177. if(comment ==''){
  178. alert('Please fill Your question');
  179. return false;
  180. }else{
  181.  
  182. //alert('Thanks for Voting');
  183. $('#poll_qst_form').replaceWith(html);
  184. //document.write("Thankyou for Voting");
  185. //is_being_voted();
  186.  
  187. }
  188.  
  189. });
  190.  
  191. }*/
  192.  
  193.  
  194.  
  195.  
  196. function send_comment(){
  197.  
  198. jQuery(document).ready(function($) {
  199. var html = '<div class="second-block comment-success"><span class="green">Thank you!</span> Your message has been submitted.</span></div>';
  200. var comment = $('#poll_comment').val();
  201. var name = $('#poll_name').val();
  202. var email = $('#poll_email').val();
  203. //alert(comment);
  204. if(comment ==''){
  205. alert('Please fill out your message.');
  206. return false;
  207. }else if(name ==''){
  208. alert('Please fill out your name.');
  209. return false;
  210. }
  211. else if(email ==''){
  212. alert('Please fill out your email.');
  213. return false;
  214. }else{
  215.  
  216. var data = {
  217. 'action': 'sending_mail',
  218. 'whatever': 1234
  219. };
  220.  
  221. $('.wp-polls-loading').show();
  222. // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
  223. $.post(pollsL10n.ajax_url+'/?comment='+comment+'&name='+name, data, function(response) {
  224.  
  225.  
  226. if($.trim(response) == 'true'){
  227.  
  228. $('.wp-polls-loading').hide();
  229.  
  230. $('#poll_qst_form').replaceWith(html);
  231.  
  232. /* $.getJSON("http://jsonip.appspot.com?callback=?",
  233. function(data){
  234.  
  235. var ipaddress = data.ip;
  236. alert( "Your ip: " + ipaddress);
  237.  
  238. });
  239.  
  240. if(ipaddress == ipaddress)
  241. {
  242. alert( "Your ip is equal to " + ipaddress);
  243.  
  244. }
  245. */
  246.  
  247. }else{
  248. //alert(response);
  249. }
  250. });
  251.  
  252. }
  253.  
  254. });
  255.  
  256. }
  257.  
  258.  
  259.  
  260. // Set is_being_voted Status
  261. function set_is_being_voted(voted_status) {
  262. is_being_voted = voted_status;
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement