| 1 |
(function ($) { |
| 2 |
// String.prototype.stripSlashes = function () { |
| 3 |
// return this.replace(/\\(.)/mg, "$1"); |
| 4 |
// } |
| 5 |
function stripSlashes(str) { |
| 6 |
return str.replace(/\\(.)/mg, "$1"); |
| 7 |
} |
| 8 |
$.fn.serializeFormJSON = function () { |
| 9 |
var o = {}, |
| 10 |
a = this.serializeArray(); |
| 11 |
$.each(a, function () { |
| 12 |
if (o[this.name]) { |
| 13 |
if (!o[this.name].push) { |
| 14 |
o[this.name] = [o[this.name]]; |
| 15 |
} |
| 16 |
o[this.name].push(this.value || ''); |
| 17 |
} else { |
| 18 |
o[this.name] = this.value || ''; |
| 19 |
} |
| 20 |
}); |
| 21 |
return o; |
| 22 |
}; |
| 23 |
|
| 24 |
$.fn.goToPoll = function(enabelAnimation, scroll) { |
| 25 |
var pollAnimationTop = (scroll && scroll != 0) ? parseInt(scroll) : 100; |
| 26 |
|
| 27 |
if( enabelAnimation ){ |
| 28 |
$('html, body').animate({ |
| 29 |
scrollTop: $(this).offset().top - scroll + 'px' |
| 30 |
}, 'slow'); |
| 31 |
} |
| 32 |
return this; // for chaining... |
| 33 |
} |
| 34 |
|
| 35 |
$.fn.aysModal = function(action){ |
| 36 |
var $this = $(this); |
| 37 |
switch(action){ |
| 38 |
case 'hide': |
| 39 |
$(this).find('.ays-poll-avatars-modal-content').css('animation-name', 'zoomOut'); |
| 40 |
setTimeout(function(){ |
| 41 |
$(document.body).removeClass('modal-open'); |
| 42 |
$(document).find('.ays-modal-backdrop').remove(); |
| 43 |
$this.hide(); |
| 44 |
}, 250); |
| 45 |
break; |
| 46 |
case 'show': |
| 47 |
default: |
| 48 |
$this.show(); |
| 49 |
$(this).find('.ays-poll-avatars-modal-content').css('animation-name', 'zoomIn'); |
| 50 |
$(document).find('.modal-backdrop').remove(); |
| 51 |
$(document.body).append('<div class="ays-modal-backdrop"></div>'); |
| 52 |
$(document.body).addClass('modal-open'); |
| 53 |
break; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
$(document).find(".ays-poll-main .apm-info-form").each(function(e){ |
| 58 |
var infoForm = $(this); |
| 59 |
var mainContainer = infoForm.parents('.ays-poll-main'); |
| 60 |
var id = mainContainer.attr('id').match(/\d+$/)[0]; |
| 61 |
var pollBox = mainContainer.find('div[data-id="' + id + '"]'); |
| 62 |
var uniqueId = pollBox.attr('id'); |
| 63 |
var pollOptions = JSON.parse(window.atob(window.aysPollOptions[uniqueId])); |
| 64 |
|
| 65 |
if (pollOptions.autofill_user_data && pollOptions.autofill_user_data == "on") { |
| 66 |
var userData = {}; |
| 67 |
userData.action = 'ays_poll_get_user_information'; |
| 68 |
$.ajax({ |
| 69 |
url: poll_maker_ajax_public.ajax_url, |
| 70 |
method: 'post', |
| 71 |
dataType: 'json', |
| 72 |
data: userData, |
| 73 |
success: function (response) { |
| 74 |
if(response !== null){ |
| 75 |
infoForm.find("input[name='apm_name']").val(response.data.display_name); |
| 76 |
infoForm.find("input[name='apm_email']").val(response.data.user_email); |
| 77 |
} |
| 78 |
} |
| 79 |
}); |
| 80 |
} |
| 81 |
}) |
| 82 |
|
| 83 |
function socialBtnAdd(formId, buttons) { |
| 84 |
var socialDiv = $("<div class='apm-social-btn'></div>"); |
| 85 |
if(buttons.heading != ""){ |
| 86 |
socialDiv.append("<div class='ays-survey-social-shares-heading'>"+ |
| 87 |
buttons.heading |
| 88 |
+"</div>"); |
| 89 |
} |
| 90 |
if(buttons.faceBook){ |
| 91 |
socialDiv.append("<a class='fb-share-button ays-share-btn ays-share-btn-branded ays-share-btn-facebook'"+ |
| 92 |
"title='Share on Facebook'>"+ |
| 93 |
"<span class='ays-share-btn-text'>Facebook</span>"+ |
| 94 |
"</a>"); |
| 95 |
} |
| 96 |
if(buttons.twitter){ |
| 97 |
socialDiv.append("<a class='twt-share-button ays-share-btn ays-share-btn-branded ays-share-btn-twitter'"+ |
| 98 |
"title='Share on Twitter'>"+ |
| 99 |
"<span class='ays-share-btn-text'>Twitter</span>"+ |
| 100 |
"</a>"); |
| 101 |
} |
| 102 |
if(buttons.linkedIn){ |
| 103 |
socialDiv.append("<a class='linkedin-share-button ays-share-btn ays-share-btn-branded ays-share-btn-linkedin'"+ |
| 104 |
"title='Share on LinkedIn'>"+ |
| 105 |
"<span class='ays-share-btn-text'>LinkedIn</span>"+ |
| 106 |
"</a>"); |
| 107 |
} |
| 108 |
if(buttons.vkontakte){ |
| 109 |
socialDiv.append("<a class='vkontakte-share-button ays-share-btn ays-share-btn-branded ays-share-btn-vkontakte'"+ |
| 110 |
"title='Share on VKontakte'>"+ |
| 111 |
"<span class='ays-survey-share-btn-icon'></span>"+ |
| 112 |
"<span class='ays-share-btn-text'>VKontakte</span>"+ |
| 113 |
"</a>"); |
| 114 |
} |
| 115 |
$("#"+formId).append(socialDiv); |
| 116 |
$(document).on('click', '.fb-share-button', function (e) { |
| 117 |
window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location.href, |
| 118 |
'facebook-share-dialog', |
| 119 |
'width=650,height=450' |
| 120 |
); |
| 121 |
return false; |
| 122 |
}) |
| 123 |
$(document).on('click', '.twt-share-button', function (e) { |
| 124 |
window.open('https://twitter.com/intent/tweet?url=' + window.location.href, |
| 125 |
'twitter-share-dialog', |
| 126 |
'width=650,height=450' |
| 127 |
); |
| 128 |
return false; |
| 129 |
}) |
| 130 |
$(document).on('click', '.linkedin-share-button', function (e) { |
| 131 |
window.open('https://www.linkedin.com/shareArticle?mini=true&url=' + window.location.href, |
| 132 |
'linkedin-share-dialog', |
| 133 |
'width=650,height=450' |
| 134 |
); |
| 135 |
return false; |
| 136 |
}) |
| 137 |
$(document).on('click', '.vkontakte-share-button', function (e) { |
| 138 |
window.open('https://vk.com/share.php?url=' + window.location.href, |
| 139 |
'vkontakte-share-dialog', |
| 140 |
'width=650,height=450' |
| 141 |
); |
| 142 |
return false; |
| 143 |
}) |
| 144 |
setTimeout(function() { |
| 145 |
$("#"+formId+" .apm-social-btn").css('opacity', '1'); |
| 146 |
}, 1000); |
| 147 |
} |
| 148 |
|
| 149 |
function socialLinksAdd(formId, buttons) { |
| 150 |
var socialLinksDiv = $("<div class='apm-social-btn'></div>"); |
| 151 |
if(buttons.heading != ""){ |
| 152 |
socialLinksDiv.append("<div class='ays-survey-social-shares-heading'>"+ |
| 153 |
buttons.heading |
| 154 |
+"</div>"); |
| 155 |
} |
| 156 |
if(buttons.faceBookLink != ''){ |
| 157 |
socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-facebook'"+ |
| 158 |
"title='Facebook Link' target='_blank' href=" + buttons.faceBookLink + ">"+ |
| 159 |
"<div class='ays-poll-link-icon'><?xml version='1.0'?><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='48px' height='48px'><path d='M19,3H5C3.895,3,3,3.895,3,5v14c0,1.105,0.895,2,2,2h7.621v-6.961h-2.343v-2.725h2.343V9.309 c0-2.324,1.421-3.591,3.495-3.591c0.699-0.002,1.397,0.034,2.092,0.105v2.43h-1.428c-1.13,0-1.35,0.534-1.35,1.322v1.735h2.7 l-0.351,2.725h-2.365V21H19c1.105,0,2-0.895,2-2V5C21,3.895,20.105,3,19,3z'/></svg></div>"+ |
| 160 |
"</a>"); |
| 161 |
} |
| 162 |
if(buttons.twitterLink != ''){ |
| 163 |
socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-twitter'"+ |
| 164 |
"title='Twitter Link' target='_blank' href=" + buttons.twitterLink + ">"+ |
| 165 |
"<div class='ays-poll-link-icon'><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' width='16px' height='16px'><path d='M44.719,10.305C44.424,10,43.97,9.913,43.583,10.091l-0.164,0.075c-0.139,0.064-0.278,0.128-0.418,0.191 c0.407-0.649,0.73-1.343,0.953-2.061c0.124-0.396-0.011-0.829-0.339-1.085c-0.328-0.256-0.78-0.283-1.135-0.066 c-1.141,0.693-2.237,1.192-3.37,1.54C37.4,7.026,35.071,6,32.5,6c-5.247,0-9.5,4.253-9.5,9.5c0,0.005,0,0.203,0,0.5l-0.999-0.08 c-9.723-1.15-12.491-7.69-12.606-7.972c-0.186-0.47-0.596-0.813-1.091-0.916C7.81,6.927,7.297,7.082,6.939,7.439 C6.741,7.638,5,9.48,5,13c0,2.508,1.118,4.542,2.565,6.124c-0.674-0.411-1.067-0.744-1.077-0.753 c-0.461-0.402-1.121-0.486-1.669-0.208c-0.546,0.279-0.868,0.862-0.813,1.473c0.019,0.211,0.445,4.213,5.068,7.235l-0.843,0.153 c-0.511,0.093-0.938,0.444-1.128,0.928C6.914,28.437,6.988,28.984,7.3,29.4c0.105,0.141,2.058,2.68,6.299,4.14 C11.334,34.295,8.222,35,4.5,35c-0.588,0-1.123,0.344-1.366,0.88c-0.244,0.536-0.151,1.165,0.237,1.607 C3.532,37.672,7.435,42,17.5,42C34.213,42,42,26.485,42,16v-0.5c0-0.148-0.016-0.293-0.022-0.439 c2.092-2.022,2.879-3.539,2.917-3.614C45.084,11.067,45.014,10.609,44.719,10.305z'/></svg></div>"+ |
| 166 |
"</a>"); |
| 167 |
} |
| 168 |
if(buttons.linkedInLink != ''){ |
| 169 |
socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-linkedin'"+ |
| 170 |
"title='LinkedIn Link' target='_blank' href=" + buttons.linkedInLink + ">"+ |
| 171 |
"<div class='ays-poll-link-icon'><?xml version='1.0'?><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='48px' height='48px'> <path d='M21,3H3v18h18V3z M9,17H6.477v-7H9V17z M7.694,8.717c-0.771,0-1.286-0.514-1.286-1.2s0.514-1.2,1.371-1.2 c0.771,0,1.286,0.514,1.286,1.2S8.551,8.717,7.694,8.717z M18,17h-2.442v-3.826c0-1.058-0.651-1.302-0.895-1.302 s-1.058,0.163-1.058,1.302c0,0.163,0,3.826,0,3.826h-2.523v-7h2.523v0.977C13.93,10.407,14.581,10,15.802,10 C17.023,10,18,10.977,18,13.174V17z'/></svg></div>"+ |
| 172 |
"</a>"); |
| 173 |
} |
| 174 |
if(buttons.vkontakteLink != ''){ |
| 175 |
socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-vkontakte'"+ |
| 176 |
"title='VKontakte Link' target='_blank' href=" + buttons.vkontakteLink + ">"+ |
| 177 |
"<div class='ays-poll-link-icon'><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' width='48px' height='48px'><path d='M45.763,35.202c-1.797-3.234-6.426-7.12-8.337-8.811c-0.523-0.463-0.579-1.264-0.103-1.776 c3.647-3.919,6.564-8.422,7.568-11.143C45.334,12.27,44.417,11,43.125,11l-3.753,0c-1.237,0-1.961,0.444-2.306,1.151 c-3.031,6.211-5.631,8.899-7.451,10.47c-1.019,0.88-2.608,0.151-2.608-1.188c0-2.58,0-5.915,0-8.28 c0-1.147-0.938-2.075-2.095-2.075L18.056,11c-0.863,0-1.356,0.977-0.838,1.662l1.132,1.625c0.426,0.563,0.656,1.248,0.656,1.951 L19,23.556c0,1.273-1.543,1.895-2.459,1.003c-3.099-3.018-5.788-9.181-6.756-12.128C9.505,11.578,8.706,11.002,7.8,11l-3.697-0.009 c-1.387,0-2.401,1.315-2.024,2.639c3.378,11.857,10.309,23.137,22.661,24.36c1.217,0.12,2.267-0.86,2.267-2.073l0-3.846 c0-1.103,0.865-2.051,1.977-2.079c0.039-0.001,0.078-0.001,0.117-0.001c3.267,0,6.926,4.755,8.206,6.979 c0.368,0.64,1.056,1.03,1.8,1.03l4.973,0C45.531,38,46.462,36.461,45.763,35.202z'/></svg></div>"+ |
| 178 |
"</a>"); |
| 179 |
} |
| 180 |
if(buttons.youtubeLink != ''){ |
| 181 |
socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-poll-share-btn-youtube'"+ |
| 182 |
"title='Youtube Link' target='_blank' href=" + buttons.youtubeLink + ">"+ |
| 183 |
"<div class='ays-poll-link-icon'><svg xmlns='http://www.w3.org/2000/svg' fill='#FF0000' viewBox='0 0 28 28' width='48px' height='48px'> <path d='M 15 4 C 10.814 4 5.3808594 5.0488281 5.3808594 5.0488281 L 5.3671875 5.0644531 C 3.4606632 5.3693645 2 7.0076245 2 9 L 2 15 L 2 15.001953 L 2 21 L 2 21.001953 A 4 4 0 0 0 5.3769531 24.945312 L 5.3808594 24.951172 C 5.3808594 24.951172 10.814 26.001953 15 26.001953 C 19.186 26.001953 24.619141 24.951172 24.619141 24.951172 L 24.621094 24.949219 A 4 4 0 0 0 28 21.001953 L 28 21 L 28 15.001953 L 28 15 L 28 9 A 4 4 0 0 0 24.623047 5.0546875 L 24.619141 5.0488281 C 24.619141 5.0488281 19.186 4 15 4 z M 12 10.398438 L 20 15 L 12 19.601562 L 12 10.398438 z'/></svg></div>"+ |
| 184 |
"</a>"); |
| 185 |
} |
| 186 |
$("#"+formId).append(socialLinksDiv); |
| 187 |
|
| 188 |
setTimeout(function() { |
| 189 |
$("#"+formId+" .apm-social-btn").css('opacity', '1'); |
| 190 |
}, 1000); |
| 191 |
} |
| 192 |
|
| 193 |
function loadEffect(formId, onOff , fontSize,message) { |
| 194 |
var loadFontSize = fontSize.length > 0 ? fontSize+"px" : '100%'; |
| 195 |
var form = $("#"+formId), |
| 196 |
effect = form.attr('data-loading'); |
| 197 |
switch (effect) { |
| 198 |
case 'blur': |
| 199 |
form.css({ |
| 200 |
WebkitFilter: onOff ? 'blur(5px)' : 'unset', |
| 201 |
filter: onOff ? 'blur(5px)' : 'unset', |
| 202 |
}) |
| 203 |
break; |
| 204 |
case 'load_gif': |
| 205 |
if (onOff) { |
| 206 |
var loadSvg = ''; |
| 207 |
switch (form.attr('data-load-gif')) { |
| 208 |
case 'plg_1': |
| 209 |
loadSvg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+ |
| 210 |
'<rect x="0" y="0" width="4" height="10" fill="#333">'+ |
| 211 |
'<animateTransform attributeType="xml"'+ |
| 212 |
'attributeName="transform" type="translate"'+ |
| 213 |
'values="0 0; 0 20; 0 0"'+ |
| 214 |
'begin="0" dur="0.8s" repeatCount="indefinite" />'+ |
| 215 |
'</rect>'+ |
| 216 |
'<rect x="10" y="0" width="4" height="10" fill="#333">'+ |
| 217 |
'<animateTransform attributeType="xml"'+ |
| 218 |
'attributeName="transform" type="translate"'+ |
| 219 |
'values="0 0; 0 20; 0 0"'+ |
| 220 |
'begin="0.2s" dur="0.8s" repeatCount="indefinite" />'+ |
| 221 |
'</rect>'+ |
| 222 |
'<rect x="20" y="0" width="4" height="10" fill="#333">'+ |
| 223 |
'<animateTransform attributeType="xml"'+ |
| 224 |
'attributeName="transform" type="translate"'+ |
| 225 |
'values="0 0; 0 20; 0 0"'+ |
| 226 |
'begin="0.4s" dur="0.8s" repeatCount="indefinite" />'+ |
| 227 |
'</rect>'+ |
| 228 |
'</svg>'; |
| 229 |
break; |
| 230 |
case 'plg_2': |
| 231 |
loadSvg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+ |
| 232 |
'<rect x="0" y="10" width="4" height="10" fill="#333" opacity="0.2">'+ |
| 233 |
'<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0s" dur="0.7s" repeatCount="indefinite" />'+ |
| 234 |
'<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0s" dur="0.7s" repeatCount="indefinite" />'+ |
| 235 |
'<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0s" dur="0.7s" repeatCount="indefinite" />'+ |
| 236 |
'</rect>'+ |
| 237 |
'<rect x="8" y="10" width="4" height="10" fill="#333" opacity="0.2">'+ |
| 238 |
'<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+ |
| 239 |
'<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+ |
| 240 |
'<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+ |
| 241 |
'</rect>'+ |
| 242 |
'<rect x="16" y="10" width="4" height="10" fill="#333" opacity="0.2">'+ |
| 243 |
'<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+ |
| 244 |
'<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+ |
| 245 |
'<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+ |
| 246 |
'</rect>'+ |
| 247 |
'</svg>'; |
| 248 |
break; |
| 249 |
case 'plg_3': |
| 250 |
loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 105 105" xmlns="http://www.w3.org/2000/svg" fill="#000">'+ |
| 251 |
'<circle cx="12.5" cy="12.5" r="12.5">'+ |
| 252 |
'<animate attributeName="fill-opacity"'+ |
| 253 |
'begin="0s" dur="0.9s"'+ |
| 254 |
'values="1;.2;1" calcMode="linear"'+ |
| 255 |
'repeatCount="indefinite" />'+ |
| 256 |
'</circle>'+ |
| 257 |
'<circle cx="12.5" cy="52.5" r="12.5" fill-opacity=".5">'+ |
| 258 |
'<animate attributeName="fill-opacity"'+ |
| 259 |
'begin="100ms" dur="0.9s"'+ |
| 260 |
'values="1;.2;1" calcMode="linear"'+ |
| 261 |
'repeatCount="indefinite" />'+ |
| 262 |
'</circle>'+ |
| 263 |
'<circle cx="52.5" cy="12.5" r="12.5">'+ |
| 264 |
'<animate attributeName="fill-opacity"'+ |
| 265 |
'begin="300ms" dur="0.9s"'+ |
| 266 |
'values="1;.2;1" calcMode="linear"'+ |
| 267 |
'repeatCount="indefinite" />'+ |
| 268 |
'</circle>'+ |
| 269 |
'<circle cx="52.5" cy="52.5" r="12.5">'+ |
| 270 |
'<animate attributeName="fill-opacity"'+ |
| 271 |
'begin="600ms" dur="0.9s"'+ |
| 272 |
'values="1;.2;1" calcMode="linear"'+ |
| 273 |
'repeatCount="indefinite" />'+ |
| 274 |
'</circle>'+ |
| 275 |
'<circle cx="92.5" cy="12.5" r="12.5">'+ |
| 276 |
'<animate attributeName="fill-opacity"'+ |
| 277 |
'begin="800ms" dur="0.9s"'+ |
| 278 |
'values="1;.2;1" calcMode="linear"'+ |
| 279 |
'repeatCount="indefinite" />'+ |
| 280 |
'</circle>'+ |
| 281 |
'<circle cx="92.5" cy="52.5" r="12.5">'+ |
| 282 |
'<animate attributeName="fill-opacity"'+ |
| 283 |
'begin="400ms" dur="0.9s"'+ |
| 284 |
'values="1;.2;1" calcMode="linear"'+ |
| 285 |
'repeatCount="indefinite" />'+ |
| 286 |
'</circle>'+ |
| 287 |
'<circle cx="12.5" cy="92.5" r="12.5">'+ |
| 288 |
'<animate attributeName="fill-opacity"'+ |
| 289 |
'begin="700ms" dur="0.9s"'+ |
| 290 |
'values="1;.2;1" calcMode="linear"'+ |
| 291 |
'repeatCount="indefinite" />'+ |
| 292 |
'</circle>'+ |
| 293 |
'<circle cx="52.5" cy="92.5" r="12.5">'+ |
| 294 |
'<animate attributeName="fill-opacity"'+ |
| 295 |
'begin="500ms" dur="0.9s"'+ |
| 296 |
'values="1;.2;1" calcMode="linear"'+ |
| 297 |
'repeatCount="indefinite" />'+ |
| 298 |
'</circle>'+ |
| 299 |
'<circle cx="92.5" cy="92.5" r="12.5">'+ |
| 300 |
'<animate attributeName="fill-opacity"'+ |
| 301 |
'begin="200ms" dur="0.9s"'+ |
| 302 |
'values="1;.2;1" calcMode="linear"'+ |
| 303 |
'repeatCount="indefinite" />'+ |
| 304 |
'</circle>'+ |
| 305 |
'</svg>'; |
| 306 |
break; |
| 307 |
case 'plg_4': |
| 308 |
loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 57 57" xmlns="http://www.w3.org/2000/svg" stroke="#000">'+ |
| 309 |
'<g fill="none" fill-rule="evenodd">'+ |
| 310 |
'<g transform="translate(1 1)" stroke-width="2">'+ |
| 311 |
'<circle cx="5" cy="50" r="5">'+ |
| 312 |
'<animate attributeName="cy"'+ |
| 313 |
'begin="0s" dur="2.2s"'+ |
| 314 |
'values="50;5;50;50"'+ |
| 315 |
'calcMode="linear"'+ |
| 316 |
'repeatCount="indefinite" />'+ |
| 317 |
'<animate attributeName="cx"'+ |
| 318 |
'begin="0s" dur="2.2s"'+ |
| 319 |
'values="5;27;49;5"'+ |
| 320 |
'calcMode="linear"'+ |
| 321 |
'repeatCount="indefinite" />'+ |
| 322 |
'</circle>'+ |
| 323 |
'<circle cx="27" cy="5" r="5">'+ |
| 324 |
'<animate attributeName="cy"'+ |
| 325 |
'begin="0s" dur="2.2s"'+ |
| 326 |
'from="5" to="5"'+ |
| 327 |
'values="5;50;50;5"'+ |
| 328 |
'calcMode="linear"'+ |
| 329 |
'repeatCount="indefinite" />'+ |
| 330 |
'<animate attributeName="cx"'+ |
| 331 |
'begin="0s" dur="2.2s"'+ |
| 332 |
'from="27" to="27"'+ |
| 333 |
'values="27;49;5;27"'+ |
| 334 |
'calcMode="linear"'+ |
| 335 |
'repeatCount="indefinite" />'+ |
| 336 |
'</circle>'+ |
| 337 |
'<circle cx="49" cy="50" r="5">'+ |
| 338 |
'<animate attributeName="cy"'+ |
| 339 |
'begin="0s" dur="2.2s"'+ |
| 340 |
'values="50;50;5;50"'+ |
| 341 |
'calcMode="linear"'+ |
| 342 |
'repeatCount="indefinite" />'+ |
| 343 |
'<animate attributeName="cx"'+ |
| 344 |
'from="49" to="49"'+ |
| 345 |
'begin="0s" dur="2.2s"'+ |
| 346 |
'values="49;5;27;49"'+ |
| 347 |
'calcMode="linear"'+ |
| 348 |
'repeatCount="indefinite" />'+ |
| 349 |
'</circle>'+ |
| 350 |
'</g>'+ |
| 351 |
'</g>'+ |
| 352 |
'</svg>'; |
| 353 |
break; |
| 354 |
case 'plg_5': |
| 355 |
loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 135 140" xmlns="http://www.w3.org/2000/svg" stroke="#000">'+ |
| 356 |
'<rect y="10" width="15" height="120" rx="6">'+ |
| 357 |
'<animate attributeName="height" begin="0.5s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite" />'+ |
| 358 |
'<animate attributeName="y" begin="0.5s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite" />'+ |
| 359 |
'</rect>'+ |
| 360 |
'<rect x="30" y="10" width="15" height="120" rx="6">'+ |
| 361 |
'<animate attributeName="height" begin="0.25s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+ |
| 362 |
'<animate attributeName="y" begin="0.25s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+ |
| 363 |
'</rect>'+ |
| 364 |
' <rect x="60" width="15" height="140" rx="6">'+ |
| 365 |
'<animate attributeName="height" begin="0s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+ |
| 366 |
'<animate attributeName="y" begin="0s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+ |
| 367 |
'</rect>'+ |
| 368 |
'<rect x="90" y="10" width="15" height="120" rx="6">'+ |
| 369 |
'<animate attributeName="height" begin="0.25s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+ |
| 370 |
'<animate attributeName="y" begin="0.25s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+ |
| 371 |
'</rect>'+ |
| 372 |
'<rect x="120" y="10" width="15" height="120" rx="6">'+ |
| 373 |
'<animate attributeName="height" begin="0.5s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+ |
| 374 |
'<animate attributeName="y" begin="0.5s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+ |
| 375 |
'</rect>'+ |
| 376 |
'</svg>'; |
| 377 |
break; |
| 378 |
default: |
| 379 |
loadSvg = '<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"'+ |
| 380 |
'width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+ |
| 381 |
'<path fill="#000" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318, 0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0, 14.615, 6.543,14.615,14.615H43.935z">'+ |
| 382 |
'<animateTransform attributeType="xml"'+ |
| 383 |
'attributeName="transform"'+ |
| 384 |
'type="rotate"'+ |
| 385 |
'from="0 25 25"'+ |
| 386 |
'to="360 25 25"'+ |
| 387 |
'dur="0.6s"'+ |
| 388 |
'repeatCount="indefinite"/>'+ |
| 389 |
'</path>'+ |
| 390 |
'</svg>'; |
| 391 |
} |
| 392 |
var layer = $('<div class="apm-opacity-layer-light" style="margin-top: 0">'+ |
| 393 |
'<div class="apm-loading-gif">'+ |
| 394 |
'<div class="apm-loader loader--style3">'+ |
| 395 |
loadSvg+ |
| 396 |
'</div>'+ |
| 397 |
'</div>'+ |
| 398 |
'</div>'); |
| 399 |
form.css({ |
| 400 |
position: 'relative' |
| 401 |
}); |
| 402 |
form.append(layer); |
| 403 |
layer.css('opacity', 1); |
| 404 |
} else { |
| 405 |
$('.apm-opacity-layer-light').css('opacity', 0).empty(); |
| 406 |
setTimeout(function() { |
| 407 |
$('.apm-opacity-layer-light').remove(); |
| 408 |
}, 500); |
| 409 |
} |
| 410 |
break; |
| 411 |
case 'message': |
| 412 |
if (onOff) { |
| 413 |
var layer = $('<div class="apm-opacity-layer-light apm-load-message-container"><span>'+message+'</span></div>'); |
| 414 |
form.css({ |
| 415 |
position: 'relative' |
| 416 |
}); |
| 417 |
form.append(layer); |
| 418 |
layer.css('opacity', 1); |
| 419 |
setTimeout(function() { |
| 420 |
$('.apm-load-message-container').remove(); |
| 421 |
}, 500); |
| 422 |
} |
| 423 |
else{ |
| 424 |
$('.apm-opacity-layer-light').css('opacity', 0).empty(); |
| 425 |
setTimeout(function() { |
| 426 |
$('.apm-opacity-layer-dark').remove(); |
| 427 |
}, 500); |
| 428 |
} |
| 429 |
break; |
| 430 |
default: |
| 431 |
if (onOff) { |
| 432 |
var layer = $('<div class="apm-opacity-layer-dark"></div>'); |
| 433 |
form.css({ |
| 434 |
position: 'relative' |
| 435 |
}); |
| 436 |
form.append(layer); |
| 437 |
layer.css('opacity', 1); |
| 438 |
} else { |
| 439 |
$('.apm-opacity-layer-dark').css('opacity', 0); |
| 440 |
setTimeout(function() { |
| 441 |
$('.apm-opacity-layer-dark').remove(); |
| 442 |
}, 500); |
| 443 |
} |
| 444 |
break; |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
function sortDate(rateCount, votesSum, answers, formId) { |
| 449 |
var form = $("#"+formId), |
| 450 |
sortable = form.attr('data-res-sort'), |
| 451 |
widths = []; |
| 452 |
for (var i = 0; i < rateCount; i++) { |
| 453 |
var answer = answers[i]; |
| 454 |
widths[i] = {}; |
| 455 |
var width = (answer.votes * 100 / votesSum).toFixed(0); |
| 456 |
widths[i].width = width; |
| 457 |
widths[i].index = i; |
| 458 |
} |
| 459 |
if (sortable === "ASC") { |
| 460 |
for (var i = 0; i < rateCount; i++) { |
| 461 |
for (var j = (i + 1); j < rateCount; j++) { |
| 462 |
if (Number(widths[i].width) > Number(widths[j].width)) { |
| 463 |
var temp = widths[i].width; |
| 464 |
widths[i].width = widths[j].width; |
| 465 |
widths[j].width = temp; |
| 466 |
temp = widths[i].index; |
| 467 |
widths[i].index = widths[j].index; |
| 468 |
widths[j].index = temp; |
| 469 |
} |
| 470 |
} |
| 471 |
} |
| 472 |
} else if (sortable === "DESC") { |
| 473 |
for (var i = 0; i < rateCount; i++) { |
| 474 |
for (var j = (i + 1); j < rateCount; j++) { |
| 475 |
if (Number(widths[i].width) < Number(widths[j].width)) { |
| 476 |
var temp = widths[i].width; |
| 477 |
widths[i].width = widths[j].width; |
| 478 |
widths[j].width = temp; |
| 479 |
temp = widths[i].index; |
| 480 |
widths[i].index = widths[j].index; |
| 481 |
widths[j].index = temp; |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
} |
| 486 |
return widths; |
| 487 |
} |
| 488 |
|
| 489 |
var apmIcons = { |
| 490 |
star: "<i class='ays_poll_far ays_poll_fa-star'></i>", |
| 491 |
star1: "<i class='ays_poll_fas ays_poll_fa-star'></i>", |
| 492 |
emoji: [ |
| 493 |
"<i class='ays_poll_far ays_poll_fa-dizzy'></i>", |
| 494 |
"<i class='ays_poll_far ays_poll_fa-smile'></i>", |
| 495 |
"<i class='ays_poll_far ays_poll_fa-meh'></i>", |
| 496 |
"<i class='ays_poll_far ays_poll_fa-frown'></i>", |
| 497 |
"<i class='ays_poll_far ays_poll_fa-tired'></i>", |
| 498 |
], |
| 499 |
emoji1: [ |
| 500 |
"<i class='ays_poll_fas ays_poll_fa-dizzy'></i>", |
| 501 |
"<i class='ays_poll_fas ays_poll_fa-smile'></i>", |
| 502 |
"<i class='ays_poll_fas ays_poll_fa-meh'></i>", |
| 503 |
"<i class='ays_poll_fas ays_poll_fa-frown'></i>", |
| 504 |
"<i class='ays_poll_fas ays_poll_fa-tired'></i>", |
| 505 |
], |
| 506 |
hand: [ |
| 507 |
"<i class='ays_poll_far ays_poll_fa-thumbs-up'></i>", |
| 508 |
"<i class='ays_poll_far ays_poll_fa-thumbs-down'></i>" |
| 509 |
], |
| 510 |
hand1: [ |
| 511 |
"<i class='ays_poll_fas ays_poll_fa-thumbs-up'></i>", |
| 512 |
"<i class='ays_poll_fas ays_poll_fa-thumbs-down'></i>" |
| 513 |
], |
| 514 |
}; |
| 515 |
|
| 516 |
function showInfoForm($form) { |
| 517 |
$form.find('.ays_question, .apm-answers').fadeOut(0); |
| 518 |
$infoForm = $form.find('.apm-info-form'); |
| 519 |
$infoForm.fadeIn(); |
| 520 |
$form.find('.ays_finish_poll').val($infoForm.attr('data-text')); |
| 521 |
$form.find('.ays_finish_poll').attr('style', 'display:initial !important'); |
| 522 |
$form.find('.ays-see-res-button-show').attr('style', 'display:none'); |
| 523 |
$form.attr('data-info-form', ''); |
| 524 |
} |
| 525 |
|
| 526 |
var emailValivatePattern = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/; |
| 527 |
|
| 528 |
function voting(btnId , type) { |
| 529 |
if (typeof btnId == "undefined"){ |
| 530 |
btnId = 0; |
| 531 |
} |
| 532 |
var btn; |
| 533 |
if( btnId === 0 ){ |
| 534 |
btn = $(this); |
| 535 |
}else{ |
| 536 |
btn = btnId; |
| 537 |
} |
| 538 |
var seeRes = btn.attr('data-seeRes'), |
| 539 |
isLimitation = btn.attr('data-limitation') == 'true'; |
| 540 |
formId = btn.attr('data-form'), |
| 541 |
form = $("#"+formId), |
| 542 |
pollId = form.attr('data-id'), |
| 543 |
isRestart = form.attr('data-restart'), |
| 544 |
voteURLRedirection = form.attr('data-redirect-check'), |
| 545 |
voteRedirection = form.attr('data-redirection'), |
| 546 |
infoForm = form.attr('data-info-form'), |
| 547 |
resultColorsRgba = form.attr('data-res-rgba'), |
| 548 |
hideBgImage = form.attr('data-hide-bg-image'), |
| 549 |
hideBgImageDefColor = form.data('hide-bg-image-def-color'), |
| 550 |
backgroundGradientCheck = form.data('gradient-check'), |
| 551 |
backgroundGradientC1 = form.data('gradient-c1'), |
| 552 |
backgroundGradientC2 = form.data('gradient-c2'), |
| 553 |
backgroundGradientDir = form.data('gradient-dir'), |
| 554 |
loadEffectFontSize = form.attr('data-load-gif-font-size'); |
| 555 |
enableTopAnimation = form.attr('data-enable-top-animation'); |
| 556 |
topAnimationScroll = form.attr('data-top-animation-scroll'); |
| 557 |
loadEffectMessage = typeof form.data('loadMessage') != "undefined" ? form.data('loadMessage') : ""; |
| 558 |
|
| 559 |
var pollOptions = JSON.parse(window.atob(window.aysPollOptions[formId])); |
| 560 |
var pollEnableLn = typeof pollOptions.poll_show_social_ln != "undefined" && pollOptions.poll_show_social_ln.length > 0 && pollOptions.poll_show_social_ln == "on" ? true : false; |
| 561 |
var pollEnableFb = typeof pollOptions.poll_show_social_fb != "undefined" && pollOptions.poll_show_social_fb.length > 0 && pollOptions.poll_show_social_fb == "on" ? true : false; |
| 562 |
var pollEnableTr = typeof pollOptions.poll_show_social_tr != "undefined" && pollOptions.poll_show_social_tr.length > 0 && pollOptions.poll_show_social_tr == "on" ? true : false; |
| 563 |
var pollEnableVk = typeof pollOptions.poll_show_social_vk != "undefined" && pollOptions.poll_show_social_vk.length > 0 && pollOptions.poll_show_social_vk == "on" ? true : false; |
| 564 |
var pollSocialButtons = { |
| 565 |
linkedIn : pollEnableLn, |
| 566 |
faceBook : pollEnableFb, |
| 567 |
twitter : pollEnableTr, |
| 568 |
vkontakte : pollEnableVk, |
| 569 |
}; |
| 570 |
|
| 571 |
if( typeof pollOptions.social_links != "undefined" ) { |
| 572 |
var pollLinkedInLink = pollOptions.social_links.linkedin_link != "" ? pollOptions.social_links.linkedin_link : ""; |
| 573 |
var pollFacebookInLink = pollOptions.social_links.facebook_link != "" ? pollOptions.social_links.facebook_link : ""; |
| 574 |
var pollTwitterLink = pollOptions.social_links.twitter_link != "" ? pollOptions.social_links.twitter_link : ""; |
| 575 |
var pollVkontakteLink = pollOptions.social_links.vkontakte_link != "" ? pollOptions.social_links.vkontakte_link : ""; |
| 576 |
var pollYoutubeLink = pollOptions.social_links.youtube_link != "" ? pollOptions.social_links.youtube_link : ""; |
| 577 |
} |
| 578 |
var pollSocialLinks = { |
| 579 |
linkedInLink : pollLinkedInLink, |
| 580 |
faceBookLink : pollFacebookInLink, |
| 581 |
twitterLink : pollTwitterLink, |
| 582 |
vkontakteLink : pollVkontakteLink, |
| 583 |
youtubeLink : pollYoutubeLink, |
| 584 |
} |
| 585 |
|
| 586 |
var data = form.parent().serializeFormJSON(); |
| 587 |
|
| 588 |
if(form.hasClass('choosing-poll') && !seeRes){ |
| 589 |
var allowMultivoteCheck = $('#'+formId).find('input#ays_poll_multivote_min_count').data("allow"); |
| 590 |
if(allowMultivoteCheck){ |
| 591 |
var numberCheckedAnswers = $('#'+formId).find('input:checkbox:checked').length; |
| 592 |
var numberAllAnswers = $('#'+formId).find('input:checkbox').length; |
| 593 |
var minimumVotesCount = $('#'+formId).find('input#ays_poll_multivote_min_count').val(); |
| 594 |
var otherAnswer = $('#'+formId).find('input.ays-poll-new-answer-apply-text'); |
| 595 |
var otherAnswerVal = otherAnswer.val(); |
| 596 |
if(otherAnswer.length > 0 && otherAnswerVal != ""){ |
| 597 |
numberCheckedAnswers++; |
| 598 |
} |
| 599 |
if( numberAllAnswers < minimumVotesCount){ |
| 600 |
minimumVotesCount = numberAllAnswers; |
| 601 |
form.find('.ays-poll-multivote-message').html("Minimum votes count shoulde be "+minimumVotesCount); |
| 602 |
} |
| 603 |
if(minimumVotesCount > numberCheckedAnswers){ |
| 604 |
form.find('.ays-poll-multivote-message').show(); |
| 605 |
return false; |
| 606 |
} |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
if (infoForm) { |
| 611 |
if (type == "text" && data.answer == ""){ |
| 612 |
return; |
| 613 |
} |
| 614 |
|
| 615 |
if ('answer' in data && !seeRes || (('ays_poll_new_answer' in data) && data.ays_poll_new_answer != '')) { |
| 616 |
return showInfoForm(form); |
| 617 |
} else if(!seeRes) { |
| 618 |
return false; |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
var valid = true; |
| 623 |
form.find('.apm-info-form input[name]').each(function () { |
| 624 |
$(this).removeClass('ays_poll_shake'); |
| 625 |
if ($(this).attr('data-required') == 'true' && $(this).val() == "" && !seeRes) { |
| 626 |
$(this).addClass('apm-invalid'); |
| 627 |
$(this).addClass('ays_red_border'); |
| 628 |
$(this).addClass('ays_poll_shake'); |
| 629 |
valid = false; |
| 630 |
} |
| 631 |
}); |
| 632 |
|
| 633 |
var email_val = $('[check_id="'+formId+'"]'); |
| 634 |
if (email_val.attr('type') !== 'hidden' && email_val.attr('check_id') == formId) { |
| 635 |
if(email_val.val() != ''){ |
| 636 |
if (!(emailValivatePattern.test(email_val.val())) && !seeRes) { |
| 637 |
email_val.addClass('ays_red_border'); |
| 638 |
email_val.addClass('ays_poll_shake'); |
| 639 |
valid = false; |
| 640 |
}else{ |
| 641 |
email_val.addClass('ays_green_border'); |
| 642 |
} |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
var phoneInput = $(document).find("#"+formId).find('input[name="apm_phone"]'); |
| 647 |
var phoneInputVal = phoneInput.val(); |
| 648 |
if(phoneInputVal != '' && typeof phoneInputVal !== 'undefined'){ |
| 649 |
phoneInput.removeClass('ays_red_border'); |
| 650 |
phoneInput.removeClass('ays_green_border'); |
| 651 |
if (!validatePhoneNumber(phoneInput.get(0))) { |
| 652 |
if (phoneInput.attr('type') !== 'hidden') { |
| 653 |
phoneInput.addClass('ays_red_border'); |
| 654 |
phoneInput.addClass('ays_poll_shake'); |
| 655 |
valid = false; |
| 656 |
} |
| 657 |
}else{ |
| 658 |
phoneInput.addClass('ays_green_border'); |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
if (!valid && !seeRes) { |
| 663 |
return false; |
| 664 |
} |
| 665 |
|
| 666 |
if ((!('answer' in data) && !seeRes) && (!('ays_poll_new_answer' in data) || (('ays_poll_new_answer' in data) && data.ays_poll_new_answer == ''))) return; |
| 667 |
var userAnswerValue; |
| 668 |
if (data.answer) { |
| 669 |
var userAnswerId = data.answer; |
| 670 |
|
| 671 |
if ($.isArray(userAnswerId)) { |
| 672 |
var userEachAnswerValue = []; |
| 673 |
|
| 674 |
for (var i = 0; i < userAnswerId.length; i++) { |
| 675 |
var userEachAnswer = form.find('input[name="answer"][value="'+userAnswerId[i]+'"]'); |
| 676 |
var userEachAnswerBox = userEachAnswer.parent(); |
| 677 |
userEachAnswerValue.push(userEachAnswerBox.find('span.ays-poll-each-answer-grid').text()); |
| 678 |
} |
| 679 |
|
| 680 |
userAnswerValue = userEachAnswerValue; |
| 681 |
|
| 682 |
if (data.ays_poll_new_answer) { |
| 683 |
userAnswerValue.push(data.ays_poll_new_answer); |
| 684 |
} |
| 685 |
} else { |
| 686 |
var userAnsweInput = form.find('input[name="answer"][value="'+userAnswerId+'"]'); |
| 687 |
var userAnswerBox = userAnsweInput.parent(); |
| 688 |
userAnswerValue = userAnswerBox.find('span.ays-poll-each-answer-grid').text(); |
| 689 |
} |
| 690 |
} else if(data.ays_poll_new_answer) { |
| 691 |
userAnswerValue = data.ays_poll_new_answer; |
| 692 |
} |
| 693 |
if (seeRes && ('answer' in data)) delete data['answer']; |
| 694 |
loadEffect(formId, true , loadEffectFontSize,loadEffectMessage); |
| 695 |
btn.off(); |
| 696 |
data.action = 'ays_finish_poll'; |
| 697 |
data.poll_id = pollId; |
| 698 |
|
| 699 |
var endDate = GetFullDateTime(); |
| 700 |
data.end_date = endDate; |
| 701 |
|
| 702 |
// Mute answer sound button |
| 703 |
var $this = $(document).find('.ays_finish_poll').data("form"); |
| 704 |
var currentContainer = $(document).find("#"+$this); |
| 705 |
var soundEls = currentContainer.find('.ays_music_sound'); |
| 706 |
if(soundEls.hasClass("ays_music_sound")){ |
| 707 |
soundEls.removeClass("ays_sound_active"); |
| 708 |
soundEls.addClass("ays_poll_display_none"); |
| 709 |
} |
| 710 |
if($(document).scrollTop() >= form.offset().top){ |
| 711 |
form.goToPoll(enableTopAnimation,topAnimationScroll); |
| 712 |
} |
| 713 |
|
| 714 |
$.ajax({ |
| 715 |
url: poll_maker_ajax_public.ajax_url, |
| 716 |
dataType: 'json', |
| 717 |
method:'post', |
| 718 |
data: data, |
| 719 |
success: function(res) { |
| 720 |
form.find(".ays-poll-vote-reason").hide(); |
| 721 |
var answers_sounds = $("#"+formId).parent().find('.ays_poll_ans_sound').get(0); |
| 722 |
if(answers_sounds){ |
| 723 |
setTimeout(function() { |
| 724 |
resetPlaying(answers_sounds); |
| 725 |
}, 1000); |
| 726 |
} |
| 727 |
if(hideBgImage == 'true'){ |
| 728 |
if(!backgroundGradientCheck){ |
| 729 |
$(document).find("#"+formId).css("background-image", "none"); |
| 730 |
$(document).find("#"+formId).css("background-color", hideBgImageDefColor); |
| 731 |
} |
| 732 |
else{ |
| 733 |
$(document).find("#"+formId).css("background-image", "linear-gradient("+backgroundGradientDir+", "+backgroundGradientC1+", "+backgroundGradientC2+")"); |
| 734 |
} |
| 735 |
} |
| 736 |
$("#"+formId+" .ays_poll_cb_and_a").hide(); |
| 737 |
$("#"+formId+" .ays_poll_show_timer").hide(); |
| 738 |
var delay = $('.ays-poll-main').find('div.box-apm[data-delay]').attr('data-delay'); |
| 739 |
delayCountDown(delay); |
| 740 |
loadEffect(formId, false , loadEffectFontSize,loadEffectMessage); |
| 741 |
form.parent().next().prop('disabled', false); |
| 742 |
$('.answer-' + formId).parent().remove(); //for removing apm-answer |
| 743 |
form.find('.ays_poll_passed_count').remove(); |
| 744 |
form.find('.apm-info-form').remove(); |
| 745 |
var redirectMessage = voteRedirection ? form.find('.redirectionAfterVote').clone(true) : ''; |
| 746 |
$("#"+formId+" .apm-button-box").remove(); |
| 747 |
var hideRes = form.attr('data-res'); |
| 748 |
var resultContainer = $("#"+formId).parent().find('.box-apm'); |
| 749 |
|
| 750 |
var hideResOption = false; |
| 751 |
var pollSocialLinksHeading = ""; |
| 752 |
var pollSocialButtonsHeading = ""; |
| 753 |
if(typeof res.styles != "undefined"){ |
| 754 |
|
| 755 |
if(typeof res.styles['hide_results'] != "undefined"){ |
| 756 |
hideResOption = res.styles['hide_results'].length > 0 && res.styles['hide_results'] != 1 ? true : false; |
| 757 |
} |
| 758 |
|
| 759 |
if(typeof res.styles['poll_social_links_heading'] != "undefined"){ |
| 760 |
pollSocialLinksHeading = typeof res.styles['poll_social_links_heading'] != "undefined" && res.styles['poll_social_links_heading'].length > 0 && res.styles['poll_social_links_heading'] != "" ? res.styles['poll_social_links_heading'] : ""; |
| 761 |
} |
| 762 |
|
| 763 |
if(typeof res.styles['poll_social_buttons_heading'] != "undefined"){ |
| 764 |
pollSocialButtonsHeading = typeof res.styles['poll_social_buttons_heading'] != "undefined" && res.styles['poll_social_buttons_heading'].length > 0 && res.styles['poll_social_buttons_heading'] != "" ? res.styles['poll_social_buttons_heading'] : ""; |
| 765 |
} |
| 766 |
|
| 767 |
var result_message = typeof res.styles['result_message'] != "undefined" && res.styles['result_message'] != "" ? res.styles['result_message'] : ""; |
| 768 |
|
| 769 |
if (!isLimitation) { |
| 770 |
form.find('.apm-title-box.ays_res_mess').html(result_message); |
| 771 |
} |
| 772 |
|
| 773 |
var hide_results_text = typeof res.styles['hide_results_text'] != "undefined" && res.styles['hide_results_text'] != "" ? res.styles['hide_results_text'] : ""; |
| 774 |
form.find('.ays-poll-hide-result-box').html(hide_results_text); |
| 775 |
|
| 776 |
} |
| 777 |
pollSocialLinks.heading = pollSocialLinksHeading; |
| 778 |
pollSocialButtons.heading = pollSocialButtonsHeading; |
| 779 |
|
| 780 |
if( !res.voted_status && !seeRes && hideResOption){ |
| 781 |
var content = ''; |
| 782 |
var limitation_message = (res.styles['limitation_message'] && res.styles['limitation_message'] != '') ? res.styles['limitation_message'] : poll_maker_ajax_public.alreadyVoted; |
| 783 |
limitation_message = limitation_message.replace(/\\/g, ''); |
| 784 |
|
| 785 |
content += '<div class="ays-poll-vote-message">'; |
| 786 |
content += '<p>'+ limitation_message +'</p>'; |
| 787 |
content += '</div>'; |
| 788 |
|
| 789 |
resultContainer.append(content); |
| 790 |
} |
| 791 |
|
| 792 |
if (hideRes != 0) { |
| 793 |
$("#"+formId+" .ays_question").remove(); |
| 794 |
$("#"+formId+" .hideResults").css("display", "block"); |
| 795 |
} |
| 796 |
else if ( type == "text" ) { |
| 797 |
$("#"+formId+" .ays_question").remove(); |
| 798 |
$("#"+formId+" .hideResults").css("display", "block"); |
| 799 |
$("#"+formId+" .ays_res_mess").fadeIn(); |
| 800 |
} |
| 801 |
else if ( !res.voted_status ) { |
| 802 |
$("#"+formId+" .hideResults").css("display", "block"); |
| 803 |
} |
| 804 |
else { |
| 805 |
form.append('<div class="results-apm" id="pollResultId' +data.poll_id+ '">' + '</div>'); |
| 806 |
var votesSum = 0; |
| 807 |
var votesMax = 0; |
| 808 |
var answer; |
| 809 |
for ( answer in res.answers) { |
| 810 |
votesSum = Math.abs(res.answers[answer].votes) + votesSum; |
| 811 |
if (+res.answers[answer].votes > votesMax) { |
| 812 |
votesMax = +res.answers[answer].votes; |
| 813 |
} |
| 814 |
} |
| 815 |
var answer2 = res.answers; |
| 816 |
|
| 817 |
// Answer Numbering |
| 818 |
|
| 819 |
var widths = sortDate(res.answers.length, votesSum, answer2, formId ); |
| 820 |
//show votes count |
| 821 |
var showvotescounts = true; |
| 822 |
if (res.styles.show_votes_count == 0) { |
| 823 |
showvotescounts = false; |
| 824 |
} |
| 825 |
|
| 826 |
//show result percent |
| 827 |
var showrespercent = true; |
| 828 |
if (res.styles.show_res_percent == 0) { |
| 829 |
showrespercent = false; |
| 830 |
} |
| 831 |
|
| 832 |
var barChartType = typeof res.styles['show_chart_type'] != "undefined" && res.styles['show_chart_type'].length > 0 && res.styles['show_chart_type'] != "" ? res.styles['show_chart_type'] : "default_bar_chart"; |
| 833 |
|
| 834 |
if(barChartType == "google_bar_chart") { |
| 835 |
var chartHeight = typeof res.styles['show_chart_type_google_height'] != "undefined" && res.styles['show_chart_type_google_height'] != "" ? res.styles['show_chart_type_google_height'] : 400; |
| 836 |
var aysBarChartData = new Array(['', '']); |
| 837 |
$("#"+formId+" .ays_res_mess").fadeIn(); |
| 838 |
for (var tox in widths) { |
| 839 |
var chartRealVotes = +answer2[widths[tox].index].votes; |
| 840 |
var answerTextVal = answer2[widths[tox].index].answer; |
| 841 |
//var finalAnswerText = ays_poll_restriction_string( 'words', answerTextVal, 2 ); |
| 842 |
answerTextVal = answerTextVal.replace(/\\/g, ''); |
| 843 |
aysBarChartData.push([ |
| 844 |
answerTextVal, |
| 845 |
parseInt(chartRealVotes) |
| 846 |
]); |
| 847 |
} |
| 848 |
|
| 849 |
google.charts.load('current', {packages: ['corechart', 'bar']}); |
| 850 |
google.charts.setOnLoadCallback(drawBasic); |
| 851 |
|
| 852 |
function drawBasic() { |
| 853 |
var data = google.visualization.arrayToDataTable(aysBarChartData); |
| 854 |
|
| 855 |
var groupData = google.visualization.data.group( |
| 856 |
data, |
| 857 |
[{column: 0, modifier: function () {return 'total'}, type:'string'}], |
| 858 |
[{column: 1, aggregation: google.visualization.data.sum, type: 'number'}] |
| 859 |
); |
| 860 |
|
| 861 |
var formatPercent = new google.visualization.NumberFormat({ |
| 862 |
pattern: '#%' |
| 863 |
}); |
| 864 |
|
| 865 |
var formatShort = new google.visualization.NumberFormat({ |
| 866 |
pattern: 'short' |
| 867 |
}); |
| 868 |
|
| 869 |
var view = new google.visualization.DataView(data); |
| 870 |
view.setColumns([0, 1, { |
| 871 |
calc: function (dt, row) { |
| 872 |
if( groupData.getValue(0, 1) == 0 ){ |
| 873 |
return amount; |
| 874 |
} |
| 875 |
var amount = formatShort.formatValue(dt.getValue(row, 1)); |
| 876 |
var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1)); |
| 877 |
return amount + ' (' + percent + ')'; |
| 878 |
}, |
| 879 |
type: 'string', |
| 880 |
role: 'annotation' |
| 881 |
}]); |
| 882 |
var options = { |
| 883 |
maxWidth: '100%', |
| 884 |
height: chartHeight, |
| 885 |
legend: { position: 'none' }, |
| 886 |
axes: { |
| 887 |
x: { |
| 888 |
0: { side: 'bottom'} |
| 889 |
} |
| 890 |
}, |
| 891 |
bars: 'horizontal', |
| 892 |
bar: { groupWidth: "90%" }, |
| 893 |
}; |
| 894 |
|
| 895 |
var chart = new google.visualization.BarChart(document.getElementById('pollResultId' + pollId)); |
| 896 |
google.visualization.events.addListener(chart, 'ready', function () { |
| 897 |
$.each($('text[text-anchor="end"]'), function (index, label) { |
| 898 |
var labelText = $(label).text(); |
| 899 |
if ($.isArray(userAnswerValue)) { |
| 900 |
for (var i = 0; i < userAnswerValue.length; i++) { |
| 901 |
if (labelText == userAnswerValue[i]) { |
| 902 |
$(this).css('font-weight', '600'); |
| 903 |
} |
| 904 |
} |
| 905 |
} else { |
| 906 |
if (labelText == userAnswerValue) { |
| 907 |
$(this).css('font-weight', '600'); |
| 908 |
} |
| 909 |
} |
| 910 |
}); |
| 911 |
}); |
| 912 |
chart.draw(view,options); |
| 913 |
} |
| 914 |
} else if (barChartType == "default_bar_chart") { |
| 915 |
if(typeof data.answer == "string") { |
| 916 |
var dataAnswerArr = data.answer.split(",") |
| 917 |
} |
| 918 |
else { |
| 919 |
dataAnswerArr = data.answer; |
| 920 |
} |
| 921 |
|
| 922 |
for (var i = 0; i < res.answers.length; i++) { |
| 923 |
var rightAnswerCheck = (jQuery.inArray(res.answers[widths[i].index].id, dataAnswerArr) !== -1) ? 'ays_check' : ''; |
| 924 |
var starAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.star1 : apmIcons.star; |
| 925 |
var emojiAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.emoji1 : apmIcons.emoji; |
| 926 |
var handAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.hand1 : apmIcons.hand; |
| 927 |
var answer = res.answers; |
| 928 |
var percentColor = form.attr('data-percent-color'); |
| 929 |
|
| 930 |
var answerDiv = $('<div class="answer-title flex-apm"></div>'), |
| 931 |
answerBar = $('<div class="answer-percent" data-percent="'+widths[i].width+'"></div>'); |
| 932 |
var userMoreImage; |
| 933 |
if(res.check_user_pic && res.answers[i].avatar){ |
| 934 |
var userpicsMore = res.answers[widths[i].index].avatar; |
| 935 |
var userPicsCount = res.check_user_pic_count; |
| 936 |
var addedMoreImage = "<div class='ays-users-profile-pics'><img src="+res.check_user_pic_url+" width='24' height='24' class='ays-user-image-more' data-answer-id="+res.answers[widths[i].index].id+"></div>"; |
| 937 |
if(userpicsMore.length != 0){ |
| 938 |
userpicsMore = userpicsMore.splice(0 , userPicsCount); |
| 939 |
userpicsMore.push(addedMoreImage); |
| 940 |
} |
| 941 |
userMoreImage = $('<div class="ays-user-count">'+userpicsMore.join(' ')+'</div>'); |
| 942 |
} |
| 943 |
|
| 944 |
if (resultColorsRgba) { |
| 945 |
answerBar.attr('style', 'background-color:'+hexToRgba(percentColor, widths[i].width/100)+' !important; border: 1px solid ' + percentColor +' !important;'); |
| 946 |
} |
| 947 |
else{ |
| 948 |
answerBar.attr('style', 'background-color:'+percentColor); |
| 949 |
} |
| 950 |
|
| 951 |
answerBar.css({ |
| 952 |
width: '1%' |
| 953 |
}); |
| 954 |
|
| 955 |
var answerText = ''; |
| 956 |
var pollShowAnswerImage = false; |
| 957 |
switch (type) { |
| 958 |
case 'choose': |
| 959 |
pollShowAnswerImage = (res.styles.poll_enable_answer_image_after_voting == "on") ? true : false; |
| 960 |
if(pollShowAnswerImage){ |
| 961 |
var answerImage = typeof answer[widths[i].index].answer_img != "undefined" || typeof (answer[widths[i].index].answer_img) != "" ? answer[widths[i].index].answer_img : ""; |
| 962 |
var answerImageBox = $("<div class='ays-poll-answers-image-box-empty-image'></div>"); |
| 963 |
var answerImageIsEmptyClass = "ays-poll-answers-box-no-image"; |
| 964 |
if(answerImage != ""){ |
| 965 |
answerImageIsEmptyClass = "ays-poll-answers-box"; |
| 966 |
answerImageBox = $("<div class='ays-poll-answers-image-box'><img src="+answerImage+" class='ays-poll-answers-current-image'></div>"); |
| 967 |
} |
| 968 |
var answerTextAndPercent = $("<div class='ays-poll-answer-text-and-percent-box'></div>"); |
| 969 |
var answerMainDiv = $('<div class='+answerImageIsEmptyClass+'></div>'); |
| 970 |
} |
| 971 |
|
| 972 |
answerText = $('<span class="answer-text '+rightAnswerCheck+'"></span>'); |
| 973 |
var htmlstr = stripSlashes(answer[widths[i].index].answer); |
| 974 |
|
| 975 |
answerText.html(htmlstr); |
| 976 |
break; |
| 977 |
case 'rate': |
| 978 |
switch (res.view_type) { |
| 979 |
case 'emoji': |
| 980 |
answerText = emojiAnswerCheck[res.answers.length / 2 + 1.5 - widths[i].index]; |
| 981 |
break; |
| 982 |
|
| 983 |
case 'star': |
| 984 |
for (var j = 0; j <= widths[i].index; j++) { |
| 985 |
answerText += starAnswerCheck; |
| 986 |
} |
| 987 |
break; |
| 988 |
} |
| 989 |
answerText = $('<span class="answer-text">'+answerText+'</span>'); |
| 990 |
break; |
| 991 |
case 'vote': |
| 992 |
switch (res.view_type) { |
| 993 |
case 'hand': |
| 994 |
answerText = handAnswerCheck[widths[i].index]; |
| 995 |
break; |
| 996 |
|
| 997 |
case 'emoji': |
| 998 |
answerText = emojiAnswerCheck[2 * widths[i].index + 1]; |
| 999 |
break; |
| 1000 |
} |
| 1001 |
answerText = $('<span class="answer-text">'+answerText+'</span>'); |
| 1002 |
break; |
| 1003 |
} |
| 1004 |
|
| 1005 |
var answerVotes = $('<span class="answer-votes"></span>'); |
| 1006 |
if(showvotescounts){ |
| 1007 |
answerVotes.text(answer[widths[i].index].votes); |
| 1008 |
} |
| 1009 |
if(res.check_admin_approval){ |
| 1010 |
if(type == 'choose'){ |
| 1011 |
answerDiv.append("<span class='ays_grid_answer_span' >"+poll_maker_ajax_public.thank_message+"</span>").appendTo("#"+formId+" .results-apm"); |
| 1012 |
break; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
if(!pollShowAnswerImage){ |
| 1017 |
answerDiv.append(answerText).append(answerVotes).appendTo("#"+formId+" .results-apm"); |
| 1018 |
$("#"+formId+" .results-apm").append(userMoreImage).append(answerBar); |
| 1019 |
} |
| 1020 |
else{ |
| 1021 |
answerMainDiv.appendTo("#"+formId+" .results-apm"); |
| 1022 |
answerImageBox.appendTo(answerMainDiv); |
| 1023 |
answerTextAndPercent.appendTo(answerMainDiv); |
| 1024 |
answerDiv.append(answerText).append(answerVotes).appendTo(answerTextAndPercent); |
| 1025 |
|
| 1026 |
if(typeof userMoreImage != "undefined"){ |
| 1027 |
answerTextAndPercent.append(userMoreImage); |
| 1028 |
} |
| 1029 |
|
| 1030 |
answerBar.appendTo(answerTextAndPercent); |
| 1031 |
} |
| 1032 |
|
| 1033 |
$("#"+formId+" .ays_res_mess").fadeIn(); |
| 1034 |
$('.redirectionAfterVote').show(); |
| 1035 |
|
| 1036 |
} |
| 1037 |
|
| 1038 |
setTimeout(function() { |
| 1039 |
form.find('.answer-percent').each(function () { |
| 1040 |
var percent = $(this).attr('data-percent'); |
| 1041 |
|
| 1042 |
$(this).css({ |
| 1043 |
width: (percent || 1) + '%' |
| 1044 |
}); |
| 1045 |
|
| 1046 |
if (showrespercent) { |
| 1047 |
var aaa = $(this); |
| 1048 |
setTimeout(function() { |
| 1049 |
aaa.text(percent > 5 ? percent + '%' : ''); |
| 1050 |
}, 200); |
| 1051 |
} |
| 1052 |
}); |
| 1053 |
}, 100); |
| 1054 |
} |
| 1055 |
} |
| 1056 |
|
| 1057 |
// Remove disable from next button for category polls start |
| 1058 |
form.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', false); |
| 1059 |
var vvv = form.parents('.ays_poll_category-container').attr("data-var"); |
| 1060 |
window['showNext' + vvv] = true; |
| 1061 |
if (typeof(window['catIndex' + vvv]) != 'undefined') { |
| 1062 |
if (typeof(window['pollsGlobalPool'+vvv]) != 'undefined') { |
| 1063 |
if (window['catIndex' + vvv] == window['pollsGlobalPool' + vvv].length - 1) { |
| 1064 |
form.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', true); |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
if (window['catIndex' + vvv] == 0 && form.parents('.ays_poll_category-container').find('.results-apm').length > 0) { |
| 1069 |
form.parents('.ays_poll_category-container').find('.ays-poll-previous-btn').prop('disabled', true); |
| 1070 |
} |
| 1071 |
} |
| 1072 |
// Remove disable from next button for category polls end |
| 1073 |
|
| 1074 |
if (form.attr('data-show-social') == 1) { |
| 1075 |
socialBtnAdd(formId, pollSocialButtons); |
| 1076 |
} |
| 1077 |
if (form.attr('data-enable-social-links') == 1) { |
| 1078 |
socialLinksAdd(formId, pollSocialLinks); |
| 1079 |
} |
| 1080 |
if (voteURLRedirection == 1) { |
| 1081 |
var url = form.attr('data-url-href'); |
| 1082 |
var answerRedirectDelay = +form.attr('data-delay'); |
| 1083 |
form.append(redirectMessage); |
| 1084 |
if (url !== '') { |
| 1085 |
setTimeout(function() { |
| 1086 |
location.href = url; |
| 1087 |
} , answerRedirectDelay * 1000); |
| 1088 |
}else{ |
| 1089 |
$('.redirectionAfterVote').hide(); |
| 1090 |
} |
| 1091 |
}else{ |
| 1092 |
voteURLRedirection = false; |
| 1093 |
} |
| 1094 |
if (voteRedirection == 1 && voteURLRedirection == false) { |
| 1095 |
var url = form.attr('data-href'); |
| 1096 |
var delay = +form.attr('data-delay'); |
| 1097 |
form.append(redirectMessage); |
| 1098 |
setTimeout(function() { |
| 1099 |
location.href = url; |
| 1100 |
}, delay * 1000); |
| 1101 |
} |
| 1102 |
if (isRestart == 'true') { |
| 1103 |
showRestart(formId); |
| 1104 |
} |
| 1105 |
|
| 1106 |
if(res.check_user_pic){ |
| 1107 |
var checkModal = $(document).find(".ays-poll-avatars-modal-main"); |
| 1108 |
if(checkModal.length < 1){ |
| 1109 |
var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" + |
| 1110 |
"<div class='ays-poll-avatars-modal-content'>" + |
| 1111 |
"<div class='ays-poll-avatars-preloader'>" + |
| 1112 |
"<img class='ays-poll-avatar-pic-loader' src="+res.check_user_pic_loader+">" + |
| 1113 |
"</div>" + |
| 1114 |
"<div class='ays-poll-avatars-modal-header'>" + |
| 1115 |
"<span class='ays-close' id='ays-poll-close-avatars-modal'>×</span>" + |
| 1116 |
"<span style='font-weight: bold;'></span>" + |
| 1117 |
"</div>" + |
| 1118 |
"<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" + |
| 1119 |
"</div>" + |
| 1120 |
"</div>"; |
| 1121 |
$(document.body).append(avatarsModal); |
| 1122 |
} |
| 1123 |
} |
| 1124 |
}, |
| 1125 |
error: function () { |
| 1126 |
loadEffect(formId, false , loadEffectFontSize,loadEffectMessage); |
| 1127 |
$(".user-form-"+formId).fadeOut(); |
| 1128 |
form.parent().next().prop('disabled', false); |
| 1129 |
$('.answer-' + formId).parent().parent().find('.apm-button-box').remove(); |
| 1130 |
$('.answer-' + formId).remove(); |
| 1131 |
btn.remove(); |
| 1132 |
$("#"+formId+" .ays_question").text("Something went wrong. Please reload page."); |
| 1133 |
} |
| 1134 |
}); |
| 1135 |
|
| 1136 |
} |
| 1137 |
|
| 1138 |
function showRestart(formId) { |
| 1139 |
var restartBtn = $('<div class="apm-button-box"><input type="button" class="btn ays-poll-btn btn-restart" onclick="location.reload()" value="' + poll_maker_ajax_public.restart + '"></div>'); |
| 1140 |
$("#"+formId).append(restartBtn); |
| 1141 |
} |
| 1142 |
|
| 1143 |
if ($(document).find('#ays_res_without_see').length > 0) { |
| 1144 |
|
| 1145 |
let btn = $(document).find('#ays_res_without_see'), |
| 1146 |
type = $(document).find('#ays_res_without_see').attr('data-polltype'); |
| 1147 |
|
| 1148 |
voting( btn, type ); |
| 1149 |
} |
| 1150 |
|
| 1151 |
$(document).on('click', '.ays-poll-btn.choosing-btn', function () { |
| 1152 |
voting( $(this), 'choose' ); |
| 1153 |
}); |
| 1154 |
$(document).on('click', '.ays-poll-btn.rating-btn', function () { |
| 1155 |
voting( $(this), 'rate' ); |
| 1156 |
}); |
| 1157 |
$(document).on('click', '.ays-poll-btn.voting-btn', function () { |
| 1158 |
voting( $(this), 'vote' ); |
| 1159 |
}); |
| 1160 |
$(document).on('click', '.ays-poll-btn.text-btn', function () { |
| 1161 |
voting( $(this), 'text' ); |
| 1162 |
}); |
| 1163 |
|
| 1164 |
$(document).on('change', '.apm-answers-without-submit input', function () { |
| 1165 |
if ($(this).parent().hasClass('apm-rating')) { |
| 1166 |
voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'rate'); |
| 1167 |
} else if ($(this).parent().hasClass('apm-voting')) { |
| 1168 |
voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'vote'); |
| 1169 |
} else if ($(this).parent().hasClass('apm-choosing')) { |
| 1170 |
voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'choose'); |
| 1171 |
} |
| 1172 |
}) |
| 1173 |
|
| 1174 |
function delayCountDown(sec) { |
| 1175 |
delaySec = parseInt(sec); |
| 1176 |
var intervalSec = setInterval(function() { |
| 1177 |
if (delaySec > 0) { |
| 1178 |
delaySec--; |
| 1179 |
$('.ays-poll-main').find('p.redirectionAfterVote span').text(delaySec); |
| 1180 |
} else { |
| 1181 |
clearInterval(intervalSec); |
| 1182 |
} |
| 1183 |
}, 1000); |
| 1184 |
} |
| 1185 |
|
| 1186 |
function resetPlaying(audelems) { |
| 1187 |
audelems.pause(); |
| 1188 |
audelems.currentTime = 0; |
| 1189 |
} |
| 1190 |
|
| 1191 |
function validatePhoneNumber(input) { |
| 1192 |
var phoneno = /^[+ 0-9-]+$/; |
| 1193 |
if (typeof input !== 'undefined') { |
| 1194 |
if (input.value.match(phoneno)) { |
| 1195 |
return true; |
| 1196 |
} else { |
| 1197 |
return false; |
| 1198 |
} |
| 1199 |
|
| 1200 |
} |
| 1201 |
} |
| 1202 |
|
| 1203 |
/** |
| 1204 |
* @return {string} |
| 1205 |
*/ |
| 1206 |
function GetFullDateTime(){ |
| 1207 |
var now = new Date(); |
| 1208 |
return [[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")].join(" "); |
| 1209 |
} |
| 1210 |
|
| 1211 |
/** |
| 1212 |
* @return {string} |
| 1213 |
*/ |
| 1214 |
function AddZero(num) { |
| 1215 |
return (num >= 0 && num < 10) ? "0" + num : num + ""; |
| 1216 |
} |
| 1217 |
|
| 1218 |
function hexToRgba(hex, alfa) { |
| 1219 |
var c; |
| 1220 |
if (alfa == null) { |
| 1221 |
alfa = 1; |
| 1222 |
} |
| 1223 |
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) { |
| 1224 |
c= hex.substring(1).split(''); |
| 1225 |
if(c.length== 3){ |
| 1226 |
c= [c[0], c[0], c[1], c[1], c[2], c[2]]; |
| 1227 |
} |
| 1228 |
c= '0x'+c.join(''); |
| 1229 |
return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+alfa+')'; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
|
| 1233 |
function ays_poll_restriction_string( type, x, length ){ |
| 1234 |
var tval = ''; |
| 1235 |
if( x.length > 0 && x != null){ |
| 1236 |
tval = x.trim(); |
| 1237 |
} |
| 1238 |
switch ( type ) { |
| 1239 |
case 'characters': |
| 1240 |
break; |
| 1241 |
case 'words': |
| 1242 |
if(tval.length > 0 && tval != null && tval.length != ''){ |
| 1243 |
var wordsLength = tval.match(/\S+/g).length; |
| 1244 |
if (wordsLength > length) { |
| 1245 |
var trimmed = tval.split(/\s+/, length).join(" "); |
| 1246 |
x = trimmed + '...'; |
| 1247 |
} |
| 1248 |
} |
| 1249 |
break; |
| 1250 |
default: |
| 1251 |
break; |
| 1252 |
} |
| 1253 |
return x; |
| 1254 |
} |
| 1255 |
|
| 1256 |
// Avatars modal start |
| 1257 |
|
| 1258 |
// Open users avatars modal |
| 1259 |
$(document).on('click', '.ays-user-image-more', function(e){ |
| 1260 |
$(document).find('div.ays-poll-avatars-preloader').css('display', 'flex'); |
| 1261 |
$(document).find('.ays-poll-avatars-modal-main').aysModal('show'); |
| 1262 |
var $this = $(this); |
| 1263 |
var answer_id = $(this).data('answerId'); |
| 1264 |
var action = 'ays_poll_get_current_answer_users_pics'; |
| 1265 |
data = {}; |
| 1266 |
data.action = action; |
| 1267 |
data.answer_id = answer_id; |
| 1268 |
$.ajax({ |
| 1269 |
url: poll_maker_ajax_public.ajax_url, |
| 1270 |
dataType: 'json', |
| 1271 |
method:'post', |
| 1272 |
data: data, |
| 1273 |
success: function(response){ |
| 1274 |
for(var avatars of response){ |
| 1275 |
$('div#ays-poll-avatars-body').append(avatars); |
| 1276 |
|
| 1277 |
} |
| 1278 |
var answerTitle = $this.parents(".ays-user-count").prev().find(".answer-text").html(); |
| 1279 |
$(document).find('div.ays-poll-avatars-preloader').css('display', 'none'); |
| 1280 |
$(document).find('div.ays-poll-avatars-modal-header span:nth-child(2)').append(answerTitle); |
| 1281 |
} |
| 1282 |
}); |
| 1283 |
}); |
| 1284 |
|
| 1285 |
// Close users avatars modal |
| 1286 |
$(document).on('click', '.ays-close', function () { |
| 1287 |
$(document).find('.ays-poll-avatars-modal-main').aysModal('hide'); |
| 1288 |
setTimeout(function(){ |
| 1289 |
$(document).find('div#ays-poll-avatars-body').html(''); |
| 1290 |
$(document).find('div.ays-poll-avatars-modal-header span:nth-child(2)').html(''); |
| 1291 |
}, 250); |
| 1292 |
}); |
| 1293 |
|
| 1294 |
// Cldoe users avatars modal with ESC button |
| 1295 |
$(document).on("keydown", function(e){ |
| 1296 |
if(e.keyCode === 27){ |
| 1297 |
$(document).find('.ays-close').trigger('click'); |
| 1298 |
return false; |
| 1299 |
} |
| 1300 |
}); |
| 1301 |
|
| 1302 |
if(typeof idChecker !== 'undefined'){ |
| 1303 |
var checkResShow = $(document).find("#"+idChecker); |
| 1304 |
if(checkResShow.data("loadMethod")){ |
| 1305 |
var checkModal = $(document).find(".ays-poll-avatars-modal-main"); |
| 1306 |
if(checkModal.length < 1){ |
| 1307 |
var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" + |
| 1308 |
"<div class='ays-poll-avatars-modal-content'>" + |
| 1309 |
"<div class='ays-poll-avatars-preloader'>" + |
| 1310 |
"<img class='ays-poll-avatar-pic-loader' src="+resLoader+">" + |
| 1311 |
"</div>" + |
| 1312 |
"<div class='ays-poll-avatars-modal-header'>" + |
| 1313 |
"<span class='ays-close' id='ays-poll-close-avatars-modal'>×</span>" + |
| 1314 |
"<span style='font-weight: bold;'></span>" + |
| 1315 |
"</div>" + |
| 1316 |
"<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" + |
| 1317 |
"</div>" + |
| 1318 |
"</div>"; |
| 1319 |
$(document.body).append(avatarsModal); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
} |
| 1323 |
// Avatars modal end |
| 1324 |
|
| 1325 |
})(jQuery); |