PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.5
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.5
6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 All 152 releases
poll-maker / public / js / poll-maker-ays-public.js

poll-maker-ays-public.js in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.5, at public/js/poll-maker-ays-public.js

561 lines 23.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 window.FontAwesomeConfig = {
3 autoReplaceSvg: false
4 }
5
6 $(document).ready(function() {
7 var active = false;
8 var emailValivatePattern = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/;
9 $(document).on('mouseleave', '.rating-poll .apm-answers', function() {
10 if ($(this).find('label:not(.emoji)').length > 0) {
11 var allRateLabels = $(this).find('label');
12 if (active) {
13 var index = -1;
14 allRateLabels.each(function() {
15 if ($(this).hasClass('active-answer')) {
16 index = allRateLabels.index(this);
17 }
18 })
19 for (var i = 0; i < allRateLabels.length; i++) {
20 if (i > index) {
21 allRateLabels.eq(i).find('i').removeClass('fas').addClass('far');
22 } else {
23 allRateLabels.eq(i).find('i').removeClass('far').addClass('fas');
24 }
25 }
26 } else {
27 allRateLabels.each(function() {
28 $(this).find('i').removeClass('fas').addClass('far');
29 })
30 }
31 }
32 })
33
34 $(document).on('click', '.rating-poll label:not(.emoji)', function(){
35 $(this).parent().parent().find('label').each(function() {
36 $(this).removeClass('active-answer');
37 })
38 $(this).addClass('active-answer');
39 active = true;
40 });
41
42 $(document).on('mouseover', '.rating-poll label:not(.emoji)', function(){
43 var allRateLabels = $(this).parent().parent().find('label');
44 var index = allRateLabels.index(this);
45 allRateLabels.each(function() {
46 $(this).find('i').removeClass('fas').addClass('far');
47 });
48 for (var i = 0; i <= index; i++) {
49 allRateLabels.eq(i).find('i').removeClass('far').addClass('fas');
50 }
51 });
52
53 $(document).on('mouseleave', '.rating-poll .apm-answers', function() {
54 if ($(this).find('label.emoji').length > 0) {
55 var $this = $(this);
56 if (active) {
57 var index = -1;
58 $this.find('label.emoji').each(function() {
59 if ($(this).hasClass('active-answer')) {
60 index = $this.find('label.emoji').index(this);
61 }
62 });
63 for (var i = 0; i < $this.find('label.emoji').length; i++) {
64 if (i != index) {
65 $this.find('label.emoji').eq(i).find('i').removeClass('fas').addClass('far');
66 } else {
67 $this.find('label.emoji').eq(i).find('i').removeClass('far').addClass('fas');
68 }
69 }
70 } else {
71 $this.find('label.emoji').each(function() {
72 $(this).find('i').removeClass('fas').addClass('far');
73 });
74 }
75 }
76 });
77
78 $(document).on('mouseover', '.rating-poll label.emoji', function() {
79 var $this = $(this);
80 var thisLabels = $this.parent().parent().find('label.emoji');
81 var index = thisLabels.index(this);
82
83 thisLabels.each(function() {
84 $(this).find('i').removeClass('fas').addClass('far');
85 });
86 thisLabels.eq(index).find('i').removeClass('far').addClass('fas');
87 });
88
89 $(document).on('click', '.rating-poll label.emoji', function() {
90 var thisLabels = $(this).parent().parent().find('label.emoji');
91 thisLabels.each(function() {
92 $(this).removeClass('active-answer');
93 })
94 $(this).addClass('active-answer');
95 active = true;
96 });
97
98 $(document).on('mouseleave', '.voting-poll .apm-answers', function() {
99 var index = -1;
100 var labels = $(this).find('label');
101 if (active) {
102 labels.each(function() {
103 if ($(this).hasClass('active-answer')) {
104 index = labels.index(this);
105 }
106 });
107 for (var i = 0; i < labels.length; i++) {
108 if (i != index) {
109 labels.eq(i).find('i').removeClass('fas').addClass('far');
110 } else {
111 labels.eq(i).find('i').removeClass('far').addClass('fas');
112 }
113 }
114 } else {
115 labels.each(function() {
116 $(this).find('i').removeClass('fas').addClass('far');
117 });
118 }
119 });
120
121 $(document).on('mouseover', '.voting-poll label', function() {
122 var $this = $(this);
123 var index = $this.parent().parent().find('label').index(this);
124 $this.parent().parent().find('label').each(function() {
125 $(this).find('i').removeClass('fas').addClass('far');
126 });
127 $this.parent().parent().find('label').eq(index).find('i').removeClass('far').addClass('fas');
128 });
129
130 $(document).on('click', '.voting-poll label', function() {
131 var $this = $(this);
132 $this.parent().parent().find('label').each(function() {
133 $(this).removeClass('active-answer');
134 });
135 $(this).addClass('active-answer');
136 active = true;
137 });
138
139 $('.redirect-after-vote-url').on('click', function(e) {
140 var x = $(this).attr('data-answers-url');
141 var multivoteActivated = $(document).find('#ays_poll_multivote_min_count').length;
142 var finalUrl = "";
143
144 if (multivoteActivated > 0) {
145 var checkedBoxes = $(this).parents(".apm-answers").find("input:checkbox:checked");
146
147 for(var i = 0; i <= checkedBoxes.length; i ++) {
148 var answersUrl = checkedBoxes.eq(i).next().attr('data-answers-url');
149
150 if(typeof answersUrl !== 'undefined' && answersUrl !== false) {
151 finalUrl = answersUrl;
152 break;
153 }
154 else {
155 finalUrl = $(this).attr('data-answers-url');
156 }
157 }
158 var url = $(this).parents(".box-apm").attr('data-url-href', finalUrl);
159 }
160 else if(multivoteActivated == 0) {
161 var url = $(this).parents(".box-apm").attr('data-url-href', x);
162 }
163 });
164
165 $('.poll_answers_sound').on('click', function(e) {
166 var answers_sound = $(this).parents('.ays-poll-main').find('.ays_poll_ans_sound').get(0);
167 if(answers_sound){
168 resetPlaying(answers_sound);
169 setTimeout(function(){
170 answers_sound.play();
171 }, 10);
172 }
173 });
174
175 $(document).on('click','.ays-poll-view-more-button', function(e) {
176 var $this = $(this);
177 var parent = $this.parents('.ays-poll-main ');
178 var pollAnswers = parent.find('.apm-answers .apm-choosing');
179
180 pollAnswers.each(function(e) {
181 if ($(this).hasClass('ays_poll_display_none')) {
182 $(this).removeClass('ays_poll_display_none');
183 }
184 });
185
186 $this.parents('.ays-poll-view-more-button-box').addClass('ays_poll_display_none');
187 });
188
189 $(document).on('mouseover', '.ays-poll-logo-image-url-link', function () {
190 if($(this).attr("href") == "javascript:void(0)") {
191 $(this).css('cursor', 'auto');
192 }
193 })
194
195 //Users limitations
196 if ($('.apm-redirection').length > 0) {
197 $('.apm-redirection').each(function(e) {
198 var url = $(this).find('p').attr('data-href');
199 var delay = +$(this).find('p').attr('data-delay');
200 var formId = $(this).find('p').attr('data-id');
201 setTimeout(function() {
202 var interval = setInterval(function() {
203 if (delay > 0) {
204 delay--;
205 $(this).find('p b').text(secsToText(delay));
206 } else {
207 clearInterval(interval);
208 location.href = url;
209 }
210 }, 1000);
211 }, 1500);
212 })
213 }
214
215 function secsToText(sec) {
216 /*** get the hours ***/
217 var hours = ((sec / 3600) % 24).toFixed(0);
218 if (hours > 0) hours = hours < 10 ? '0'+hours : hours;
219 else hours = '00';
220 /*** get the minutes ***/
221 var minutes = ((sec / 60) % 60).toFixed(0);
222 if (minutes > 0) minutes = minutes < 10 ? '0'+minutes : minutes;
223 else minutes = '00';
224 /*** get the seconds ***/
225 var seconds = (sec % 60).toFixed(0);
226 if (seconds > 0) seconds = seconds < 10 ? '0'+seconds : seconds;
227 else seconds = '00';
228
229 return hours+':'+minutes+':'+seconds;
230 }
231
232 $(document).on('input', '.ays_animated_xms', function(){
233 $(document).find('.apm-info-form input[name]').each(function () {
234 $(this).removeClass('ays_poll_shake');
235 });
236 $(this).removeClass('ays_red_border');
237 $(this).removeClass('ays_green_border');
238 if ($(this).attr('type') !== 'hidden' && $(this).attr('name') != 'apm_email') {
239 if($(this).val() == '' && $(this).data('required')){
240 $(this).addClass('ays_red_border');
241 }else{
242 $(this).addClass('ays_green_border');
243 }
244 }else if($(this).attr('type') !== 'hidden'){
245 if($(this).val() != ''){
246 if (!(emailValivatePattern.test($(this).val()))) {
247 $(this).addClass('ays_red_border');
248 }else{
249 $(this).addClass('ays_green_border');
250 }
251 }
252 }
253 });
254
255 $(document).on('input', '.amp-info-form-input-box input[name="apm_phone"]', function(){
256 if ($(this).attr('type') !== 'hidden') {
257 $(this).removeClass('ays_red_border');
258 $(this).removeClass('ays_green_border');
259 if($(this).val() != ''){
260 if (!(/^[+ 0-9-]+$/.test($(this).val()))) {
261 $(this).addClass('ays_red_border');
262 }else{
263 $(this).addClass('ays_green_border');
264 }
265 }
266 }
267 });
268
269 function resetPlaying(audelems) {
270 audelems.pause();
271 audelems.currentTime = 0;
272 }
273 //AV Countdown date
274 var poll_id = $(document).find('.box-apm').data('id');
275
276 $(document).find('.show_timer_countdown').each(function(e){
277 // Countdown date
278 var countDownEndDate = $(this).data('timer_countdown');
279 var this_poll_id = $(this).parents(".ays-poll-main").attr("id");
280 var refreshButton = "<input type='button' id='ays_refresh_btn_"+this_poll_id+"' class='btn ays-poll-btn btn-restart' style='text-align:center;' value='Refresh'>";
281 if (countDownEndDate != '' && countDownEndDate != undefined) {
282 ays_countdown_datetime(countDownEndDate, this_poll_id);
283 }
284 });
285
286 function ays_countdown_datetime(sec, poll_id) {
287 var distance = sec*1000;
288 var x_int;
289
290 // Update the count down every 1 second
291 x_int = setInterval(function() {
292 // Time calculations for days, hours, minutes and seconds
293 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
294 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
295 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
296 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
297
298 // Output the result in an element with id="demo"
299 var text = "";
300
301 if(days > 0){
302 text += days + " ";
303 if(days == 1){
304 text += poll_maker_ajax_public.day + " ";
305 }else{
306 text += poll_maker_ajax_public.days + " ";
307 }
308 }
309
310 if(hours > 0){
311 text += hours + " ";
312 if(hours == 1){
313 text += poll_maker_ajax_public.hour + " ";
314 }else{
315 text += poll_maker_ajax_public.hours + " ";
316 }
317 }
318
319 if(minutes > 0){
320 text += minutes + " ";
321 if(minutes == 1){
322 text += poll_maker_ajax_public.minute + " ";
323 }else{
324 text += poll_maker_ajax_public.minutes + " ";
325 }
326 }
327
328 text += seconds + " " + poll_maker_ajax_public.seconds;
329
330 jQuery(document).find( "#"+ poll_id +" .show_timer_countdown" ).html(text);
331
332 // If the count down is over, write some text
333 if (distance > 0) {
334 distance -= 1000;
335 }
336 if (distance <= 0) {
337 clearInterval(x_int);
338 jQuery(document).find( "#"+ poll_id +" .show_timer_countdown" ).html('');
339 }
340 if(distance == 0){
341 location.reload();
342 }
343 }, 1000);
344 }
345
346 $(document).on('click', '#ays_refresh_btn_'+poll_id, function(){
347 location.reload();
348 });
349
350 // Answer Sound Muter
351 $(document).on('click', '.ays_music_sound', function() {
352 var $this = $(this);
353 var pollCoutainer = $this.parents('.ays-poll-main');
354 var audioEl = pollCoutainer.find('.ays_poll_ans_sound').get(0);
355 if($this.hasClass('ays_sound_active')){
356 audioEl.volume = 0;
357 $this.find('.ays_poll_far').addClass('ays_poll_fa-volume_off').removeClass('ays_poll_fa-volume_up');
358 $this.removeClass('ays_sound_active');
359 } else {
360 audioEl.volume = 1;
361 $this.find('.ays_poll_far').addClass('ays_poll_fa-volume_up').removeClass('ays_poll_fa-volume_off');
362 $this.addClass('ays_sound_active');
363 }
364 });
365
366 // Allow Multivote
367 $(document).on('change', '.apm-choosing' , function(){
368 var numberOfChecked = $(this).parent().find("input:checkbox:checked").length;
369 var multivote_answer_count = $(this).parent().find("#multivot_answer_count").val();
370 var pollMultivoteMinCount = $(this).parent().find("#ays_poll_multivote_min_count").val();
371 var numberNotChecked = $(this).parent().find('input:checkbox:not(":checked")');
372 var numberAllAnswers = $(this).parents("form").find('input:checkbox').length;
373 var voteButton = $(this).parents("form").find("input[name='ays_finish_poll']");
374 var otherAnswer = $(this).parent().find('input.ays-poll-new-answer-apply-text');
375 otherAnswer.attr("data-votes" , numberOfChecked);
376 if(otherAnswer.length > 0){
377 var otherAnswerVotes = otherAnswer.data("votes");
378 var otherAnswerVal = otherAnswer.val();
379 if(otherAnswerVal != ""){
380 otherAnswer.attr("data-votes" , numberOfChecked+1);
381 otherAnswerVotes = numberOfChecked+1;
382 }
383 if (numberOfChecked >= multivote_answer_count && otherAnswerVal == ""){
384 otherAnswer.attr("data-votes" , numberOfChecked);
385 numberNotChecked.prop( "disabled", true );
386 otherAnswer.prop( "disabled", true );
387 otherAnswer.css( "opacity", "0.5" );
388 } else if (otherAnswerVotes >= multivote_answer_count) {
389 numberNotChecked.prop( "disabled", true );
390 } else{
391 numberNotChecked.prop( "disabled", false );
392 otherAnswer.prop( "disabled", false );
393 otherAnswer.css( "opacity", "1" );
394 }
395
396 if (numberAllAnswers < pollMultivoteMinCount) {
397 pollMultivoteMinCount = numberAllAnswers;
398 }
399
400 if (otherAnswerVal == "") {
401 if(pollMultivoteMinCount > numberOfChecked){
402 voteButton.css("opacity" , "0.5");
403 } else {
404 voteButton.css("opacity" , "1");
405 }
406 } else {
407 if (pollMultivoteMinCount > otherAnswerVotes) {
408 voteButton.css("opacity" , "0.5");
409 } else {
410 voteButton.css("opacity" , "1");
411 }
412 }
413 }
414 else{
415 if(numberOfChecked >= multivote_answer_count){
416 numberNotChecked.prop( "disabled", true );
417 } else {
418 numberNotChecked.prop( "disabled", false );
419 }
420
421 if (numberAllAnswers < pollMultivoteMinCount){
422 pollMultivoteMinCount = numberAllAnswers;
423 }
424
425 if (pollMultivoteMinCount > numberOfChecked){
426 voteButton.css("opacity" , "0.5");
427 } else {
428 voteButton.css("opacity" , "1");
429 }
430 }
431 });
432
433 $(document).find(".ays-poll-new-answer-apply-text").on("input" , function(){
434 var _this = $(this);
435 var voteButton = _this.parents("form").find("input[name='ays_finish_poll']");
436 var allowMultivoteCheck = _this.parents("form").find('input#ays_poll_multivote_min_count').data("allow");
437 var pollMultivoteMinCount = _this.parents(".apm-answers").find("#ays_poll_multivote_min_count").val();
438 var CheckedBoxes = _this.parents(".apm-answers").find("input:checkbox:checked");
439 var numberOfChecked = CheckedBoxes.length;
440 if(_this.val() != ""){
441 numberOfChecked++;
442 }
443 var noteBox = _this.parents(".apm-add-answer").next();
444 if(noteBox.hasClass('ays-poll-add-answer-note-enable')){
445 noteBox.slideDown(200);
446 noteBox.removeClass("ays-poll-add-answer-note-enable");
447 }
448 else if(_this.val() == ''){
449 noteBox.addClass("ays-poll-add-answer-note-enable");
450 noteBox.slideUp(200);
451 }
452 if(allowMultivoteCheck){
453 if(pollMultivoteMinCount > numberOfChecked){
454 voteButton.css("opacity" , "0.5");
455 }
456 else{
457 voteButton.css("opacity" , "1");
458 }
459 }
460 });
461
462 var questionTypeText = $(document).find('textarea.ays-poll-text-types-inputs-only-textarea');
463 autosize(questionTypeText);
464
465 $(document).find('textarea.ays_poll_question_limit_length, input.ays_poll_question_limit_length').on('keyup keypress', function(e) {
466 var $this = $(this);
467 var limitType = $this.data("limitType");
468 var limitMaxLength = $this.data("maxLength");
469 var limitTextMessage = $this.parents(".ays-poll-maker-text-answer-main").find('.ays_poll_question_text_message_span');
470
471 var remainder = '';
472 if(limitMaxLength != '' && limitMaxLength != 0){
473 switch ( limitType ) {
474 case 'characters':
475 var tval = $this.val();
476 var tlength = tval.length;
477 var set = limitMaxLength;
478 var remain = parseInt(set - tlength);
479 if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
480 $this.val((tval).substring(0, tlength - 1));
481 }
482 if (e.type=="keyup") {
483 var tval = $this.val().trim();
484 if(tval.length > 0 && tval != null){
485 var wordsLength = this.value.split('').length;
486 if (wordsLength > limitMaxLength) {
487 var trimmed = tval.split('', limitMaxLength).join("");
488 $this.val(trimmed);
489 }
490 }
491 }
492 remainder = remain;
493 break;
494 case 'words':
495 if (e.type=="keyup") {
496 var tval = $this.val().trim();
497 if(tval.length > 0 && tval != null){
498 var wordsLength = this.value.match(/\S+/g).length;
499 if (wordsLength > limitMaxLength) {
500 var trimmed = tval.split(/\s+/, limitMaxLength).join(" ");
501 $this.val(trimmed + " ");
502 }
503 remainder = limitMaxLength - wordsLength;
504 }
505 }
506 break;
507 default:
508 break;
509 }
510 if (e.type=="keyup") {
511 if ( limitTextMessage ) {
512 if(limitMaxLength != '' && limitMaxLength != 0){
513 if (remainder <= 0) {
514 remainder = 0;
515 }
516 if (tval.length == 0 || tval == null) {
517 remainder = limitMaxLength;
518 }
519 }
520 limitTextMessage.html( remainder );
521 }
522 }
523 }
524 });
525
526 $(document).on('click', '.ays-poll-password-toggle', function(e){
527 var $this = $(this);
528
529 var parent = $this.parents('.ays-poll-password-input-box-visibility');
530 var passwordInput = parent.find('.ays-poll-password-input');
531
532 var visibilityOn = parent.find('.ays-poll-password-toggle-visibility');
533 var visibilityOff = parent.find('.ays-poll-password-toggle-visibility-off');
534
535 if( $this.hasClass('ays-poll-password-toggle-visibility-off') ) {
536 passwordInput.attr('type', 'text');
537
538 if ( visibilityOn.hasClass('ays_poll_display_none') ) {
539 visibilityOn.removeClass('ays_poll_display_none');
540 }
541
542 if ( ! visibilityOff.hasClass('ays_poll_display_none') ) {
543 visibilityOff.addClass('ays_poll_display_none');
544 }
545
546 } else if( $this.hasClass('ays-poll-password-toggle-visibility') ) {
547 passwordInput.attr('type', 'password');
548
549 if ( ! visibilityOn.hasClass('ays_poll_display_none') ) {
550 visibilityOn.addClass('ays_poll_display_none');
551 }
552
553 if ( visibilityOff.hasClass('ays_poll_display_none') ) {
554 visibilityOff.removeClass('ays_poll_display_none');
555 }
556 }
557 });
558
559
560 })
561 })(jQuery);