| @@ -1,675 +1,669 @@ | ||
| 1 | -// (function($){ | |
| 2 | - | |
| 3 | - var $html_name_prefix = 'ays_'; | |
| 4 | - String.prototype.hexToRgbA = function(a) { | |
| 5 | - | |
| 6 | - if (typeof a === 'undefined'){ | |
| 7 | - a = 1; | |
| 8 | - } | |
| 9 | - var ays_rgb; | |
| 10 | - var result1 = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})jQuery/i.exec(this); | |
| 11 | - var result2 = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})jQuery/i.exec(this); | |
| 12 | - if(result1){ | |
| 13 | - ays_rgb = { | |
| 14 | - r: parseInt(result1[1], 16), | |
| 15 | - g: parseInt(result1[2], 16), | |
| 16 | - b: parseInt(result1[3], 16) | |
| 17 | - }; | |
| 18 | - return 'rgba('+ays_rgb.r+','+ays_rgb.g+','+ays_rgb.b+','+a+')'; | |
| 19 | - }else if(result2){ | |
| 20 | - ays_rgb = { | |
| 21 | - r: parseInt(result2[1]+''+result2[1], 16), | |
| 22 | - g: parseInt(result2[2]+''+result2[2], 16), | |
| 23 | - b: parseInt(result2[3]+''+result2[3], 16) | |
| 24 | - }; | |
| 25 | - return 'rgba('+ays_rgb.r+','+ays_rgb.g+','+ays_rgb.b+','+a+')'; | |
| 26 | - }else{ | |
| 27 | - return null; | |
| 28 | - } | |
| 29 | - } | |
| 30 | - | |
| 31 | - jQuery.fn.aysModal = function(action){ | |
| 32 | - var jQuerythis = jQuery(this); | |
| 33 | - switch(action){ | |
| 34 | - case 'hide': | |
| 35 | - jQuerythis.find('.ays-modal-content').css('animation-name', 'zoomOut'); | |
| 36 | - setTimeout(function(){ | |
| 37 | - jQuerythis.removeClass('ays-modal-opened'); | |
| 38 | - if( jQuery(document).find('div[class^="ays-modal-backdrop"]').length <= 1 ){ | |
| 39 | - jQuery(document.body).removeClass('modal-open'); | |
| 40 | - } | |
| 41 | - jQuery(document).find('.ays-modal-backdrop-'+ jQuerythis.attr('id')).remove(); | |
| 42 | - jQuerythis.hide(); | |
| 43 | - | |
| 44 | - jQuery(document).trigger('ays-chart:modal:close', {}); | |
| 45 | - }, 250); | |
| 46 | - break; | |
| 47 | - case 'hide-preloader': | |
| 48 | - jQuerythis.find('.ays-preloader').removeClass('show'); | |
| 49 | - break; | |
| 50 | - case 'show-preloader': | |
| 51 | - jQuerythis.find('.ays-preloader').addClass('show'); | |
| 52 | - break; | |
| 53 | - case 'show': | |
| 54 | - default: | |
| 55 | - jQuerythis.show(); | |
| 56 | - jQuerythis.addClass('ays-modal-opened'); | |
| 57 | - jQuerythis.find('.ays-modal-content').css('animation-name', 'zoomIn'); | |
| 58 | - if( jQuery(document).find('div[class^="ays-modal-backdrop"]').length < 1 ){ | |
| 59 | - jQuery(document.body).addClass('modal-open'); | |
| 60 | - } | |
| 61 | - jQuery(document).find('.modal-backdrop').remove(); | |
| 62 | - jQuery(document.body).append('<div class="ays-modal-backdrop-'+ jQuerythis.attr('id') +'"></div>'); | |
| 63 | - break; | |
| 64 | - } | |
| 65 | - } | |
| 66 | - | |
| 67 | - function checkTrue(flag) { | |
| 68 | - return flag === true; | |
| 69 | - } | |
| 70 | - | |
| 71 | - function openMediaUploaderForLogoImage(e, element) { | |
| 72 | - e.preventDefault(); | |
| 73 | - var aysUploader = wp.media({ | |
| 74 | - title: 'Upload', | |
| 75 | - button: { | |
| 76 | - text: 'Upload' | |
| 77 | - }, | |
| 78 | - library: { | |
| 79 | - type: 'image' | |
| 80 | - }, | |
| 81 | - multiple: false | |
| 82 | - }).on('select', function () { | |
| 83 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 84 | - var answerImgCont = element.parents('.ays-form-image-container').find('.ays-form-image-body'); | |
| 85 | - var img = answerImgCont.find('img.ays-form-img'); | |
| 86 | - var hiddenInp = answerImgCont.find('input.ays-form-img-src'); | |
| 87 | - | |
| 88 | - element.text( aysChartBuilderAdmin.editImage ); | |
| 89 | - img.attr('src', attachment.url); | |
| 90 | - hiddenInp.val(attachment.url); | |
| 91 | - answerImgCont.show(); | |
| 92 | - img.removeClass('fade'); | |
| 93 | - jQuery(document).find(".ays-form-logo-url-box").removeClass("display_none_not_important"); | |
| 94 | - var checkImgUrl = jQuery(document).find("#ays_form_logo_enable_image_url").prop("checked"); | |
| 95 | - element.parents('.ays-form-image-container').parent().find('.ays-form-logo-open').show(); | |
| 96 | - if(checkImgUrl){ | |
| 97 | - element.parents('.ays-form-image-container').parent().find('.ays-form-logo-open-close').show(); | |
| 98 | - } | |
| 99 | - }).open(); | |
| 100 | - return false; | |
| 101 | - } | |
| 102 | - | |
| 103 | - function openMediaUploaderForImage(e, element) { | |
| 104 | - e.preventDefault(); | |
| 105 | - var aysUploader = wp.media({ | |
| 106 | - title: 'Upload', | |
| 107 | - button: { | |
| 108 | - text: 'Upload' | |
| 109 | - }, | |
| 110 | - library: { | |
| 111 | - type: 'image' | |
| 112 | - }, | |
| 113 | - multiple: false | |
| 114 | - }).on('select', function () { | |
| 115 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 116 | - var answerImgCont = element.parents('.ays-form-image-container').find('.ays-form-image-body'); | |
| 117 | - var img = answerImgCont.find('img.ays-form-img'); | |
| 118 | - var hiddenInp = answerImgCont.find('input.ays-form-img-src'); | |
| 119 | - var thisParent = element.parents(".ays_form_cover_image_main"); | |
| 120 | - thisParent.find('.ays-form-cover-image-options').css("display" , "flex"); | |
| 121 | - thisParent.find('.ays-form-cover-image-options-hr').fadeIn(500); | |
| 122 | - | |
| 123 | - element.text( aysChartBuilderAdmin.editImage ); | |
| 124 | - img.attr('src', attachment.url); | |
| 125 | - hiddenInp.val(attachment.url); | |
| 126 | - answerImgCont.show(); | |
| 127 | - img.removeClass('fade'); | |
| 128 | - | |
| 129 | - }).open(); | |
| 130 | - return false; | |
| 131 | - } | |
| 132 | - | |
| 133 | - // function openMediaUploader(e, element) { | |
| 134 | - // e.preventDefault(); | |
| 135 | - // var aysUploader = wp.media({ | |
| 136 | - // title: 'Upload', | |
| 137 | - // button: { | |
| 138 | - // text: 'Upload' | |
| 139 | - // }, | |
| 140 | - // library: { | |
| 141 | - // type: 'image' | |
| 142 | - // }, | |
| 143 | - // multiple: false | |
| 144 | - // }).on('select', function () { | |
| 145 | - // var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 146 | - // element.text('Edit Image'); | |
| 147 | - // element.parent().parent().find('.ays-question-image-container').fadeIn(); | |
| 148 | - // element.parent().parent().find('img#ays-question-img').attr('src', attachment.url); | |
| 149 | - // element.parent().parent().find('input#ays-question-image').val(attachment.url); | |
| 150 | - // }).open(); | |
| 151 | - // return false; | |
| 152 | - // } | |
| 153 | - | |
| 154 | - | |
| 155 | - function openMediaUploader(e, element, type) { | |
| 156 | - e.preventDefault(); | |
| 157 | - var aysUploader = wp.media({ | |
| 158 | - title: 'Upload', | |
| 159 | - button: { | |
| 160 | - text: 'Upload' | |
| 161 | - }, | |
| 162 | - library: { | |
| 163 | - type: 'image' | |
| 164 | - }, | |
| 165 | - multiple: false | |
| 166 | - }).on('select', function () { | |
| 167 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 168 | - switch(type){ | |
| 169 | - case 'questionImgButton': | |
| 170 | - var $this = element.parents('.ays-form-question-answer-conteiner').find('.ays-form-question-image-container'); | |
| 171 | - var hiddenInp = $this.find('.ays-form-question-img-src'); | |
| 172 | - var img = $this.find('img.ays-form-question-img'); | |
| 173 | - | |
| 174 | - $this.removeAttr('style'); | |
| 175 | - img.attr('src', attachment.url); | |
| 176 | - hiddenInp.val(attachment.url); | |
| 177 | - break; | |
| 178 | - case 'answerImgButton': | |
| 179 | - var answerImgCont = element.parents('.ays-form-answer-row').find('.ays-form-answer-image-container'); | |
| 180 | - var parent = element.parents('.ays-form-section-box'); | |
| 181 | - | |
| 182 | - var section_id = parent.data('id'); | |
| 183 | - var question_id = element.parents('.ays-form-question-answer-conteiner').data('id'); | |
| 184 | - var answer_id = element.parents('.ays-form-answer-row').data('id'); | |
| 185 | - var imgInputName = element.parents('.ays-form-answer-row').find('input.ays-form-input').attr('name'); | |
| 186 | - var checkInputName = imgInputName.indexOf('ays_section_add'); | |
| 187 | - var inputName = false; | |
| 188 | - if (checkInputName >= 0) { | |
| 189 | - inputName = true; | |
| 190 | - } | |
| 191 | - | |
| 192 | - var name = 'section'; | |
| 193 | - if (inputName) { | |
| 194 | - name = 'section_add'; | |
| 195 | - } | |
| 196 | - // var inputNameAttr = $html_name_prefix+name+'['+section_id+'][question]['+question_id+'][answers]['+answer_id+'][image]'; | |
| 197 | - | |
| 198 | - var img = answerImgCont.find('img.ays-form-answer-img'); | |
| 199 | - var hiddenInp = answerImgCont.find('input.ays-form-answer-img-src'); | |
| 200 | - | |
| 201 | - img.attr('src', attachment.url); | |
| 202 | - hiddenInp.val(attachment.url); | |
| 203 | - answerImgCont.show(); | |
| 204 | - img.removeClass('Fade'); | |
| 205 | - break; | |
| 206 | - } | |
| 207 | - | |
| 208 | - }).open(); | |
| 209 | - return false; | |
| 210 | - } | |
| 211 | - | |
| 212 | - | |
| 213 | - function openMediaUploaderQuestionBg(e, element) { | |
| 214 | - e.preventDefault(); | |
| 215 | - var aysUploader = wp.media({ | |
| 216 | - title: 'Upload Question Background', | |
| 217 | - button: { | |
| 218 | - text: 'Upload' | |
| 219 | - }, | |
| 220 | - library: { | |
| 221 | - type: 'image' | |
| 222 | - }, | |
| 223 | - multiple: false | |
| 224 | - }).on('select', function () { | |
| 225 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 226 | - element.text('Edit Image'); | |
| 227 | - element.parent().parent().find('.ays-question-bg-image-container').fadeIn(); | |
| 228 | - element.parent().parent().find('img#ays-question-bg-img').attr('src', attachment.url); | |
| 229 | - element.parent().parent().find('input#ays-question-bg-image').val(attachment.url); | |
| 230 | - }).open(); | |
| 231 | - return false; | |
| 232 | - } | |
| 233 | - | |
| 234 | - function openMusicMediaUploader(e, element) { | |
| 235 | - e.preventDefault(); | |
| 236 | - var aysUploader = wp.media({ | |
| 237 | - title: 'Upload music', | |
| 238 | - button: { | |
| 239 | - text: 'Upload' | |
| 240 | - }, | |
| 241 | - library: { | |
| 242 | - type: 'audio' | |
| 243 | - }, | |
| 244 | - multiple: false | |
| 245 | - }).on('select', function () { | |
| 246 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 247 | - element.next().attr('src', attachment.url); | |
| 248 | - element.parent().find('input.ays_quiz_bg_music').val(attachment.url); | |
| 249 | - }).open(); | |
| 250 | - return false; | |
| 251 | - } | |
| 252 | - | |
| 253 | - function openQuizMediaUploader(e, element) { | |
| 254 | - e.preventDefault(); | |
| 255 | - var aysUploader = wp.media({ | |
| 256 | - title: 'Upload', | |
| 257 | - button: { | |
| 258 | - text: 'Upload' | |
| 259 | - }, | |
| 260 | - library: { | |
| 261 | - type: 'image' | |
| 262 | - }, | |
| 263 | - multiple: false | |
| 264 | - }).on('select', function () { | |
| 265 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 266 | - if(element.hasClass('add-quiz-bg-image')){ | |
| 267 | - element.parent().find('img#ays-quiz-bg-img').attr('src', attachment.url); | |
| 268 | - element.parent().find('.ays-quiz-bg-image-container').fadeIn(); | |
| 269 | - element.next().val(attachment.url); | |
| 270 | - jQuery(document).find('.ays-quiz-live-container').css({'background-image': 'url("'+attachment.url+'")'}); | |
| 271 | - element.hide(); | |
| 272 | - }else if(element.hasClass('ays-edit-quiz-bg-img')){ | |
| 273 | - element.parent().find('.ays-quiz-bg-image-container').fadeIn(); | |
| 274 | - element.parent().find('img#ays-quiz-bg-img').attr('src', attachment.url); | |
| 275 | - jQuery(document).find('#ays_quiz_bg_image').val(attachment.url); | |
| 276 | - jQuery(document).find('.ays-quiz-live-container').css({'background-image': 'url("'+attachment.url+'")'}); | |
| 277 | - }else{ | |
| 278 | - element.text('Edit Image'); | |
| 279 | - element.parent().parent().find('.ays-quiz-image-container').fadeIn(); | |
| 280 | - element.parent().parent().find('img#ays-quiz-img').attr('src', attachment.url); | |
| 281 | - jQuery('input#ays-quiz-image').val(attachment.url); | |
| 282 | - var ays_quiz_theme = jQuery(document).find('input[name="ays_quiz_theme"]:checked').val(); | |
| 283 | - switch (ays_quiz_theme) { | |
| 284 | - case 'elegant_dark': | |
| 285 | - case 'elegant_light': | |
| 286 | - case 'rect_light': | |
| 287 | - case 'rect_dark': | |
| 288 | - case 'classic_dark': | |
| 289 | - case 'classic_light': | |
| 290 | - jQuery(document).find('#ays-quiz-live-image').attr('src', attachment.url); | |
| 291 | - jQuery(document).find('#ays-quiz-live-image').css({'display': 'block'}); | |
| 292 | - break; | |
| 293 | - case 'modern_light': | |
| 294 | - case 'modern_dark': | |
| 295 | - jQuery(document).find('.ays-quiz-live-container').css({'background-image':'url('+attachment.url+')'}); | |
| 296 | - jQuery(document).find('#ays-quiz-live-image').css({'display': 'none'}); | |
| 297 | - jQuery(document).find('#ays-quiz-live-button').css('border','1px solid'); | |
| 298 | - break; | |
| 299 | - default: | |
| 300 | - jQuery(document).find('#ays-quiz-live-image').attr('src', attachment.url); | |
| 301 | - jQuery(document).find('#ays-quiz-live-image').css({'display': 'block'}); | |
| 302 | - break; | |
| 303 | - | |
| 304 | - } | |
| 305 | - } | |
| 306 | - }).open(); | |
| 307 | - | |
| 308 | - return false; | |
| 309 | - } | |
| 310 | - | |
| 311 | - function openAnswerMediaUploader(e, element) { | |
| 312 | - e.preventDefault(); | |
| 313 | - var aysUploader = wp.media({ | |
| 314 | - title: 'Upload', | |
| 315 | - button: { | |
| 316 | - text: 'Upload' | |
| 317 | - }, | |
| 318 | - library: { | |
| 319 | - type: 'image' | |
| 320 | - }, | |
| 321 | - multiple: false | |
| 322 | - }).on('select', function () { | |
| 323 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 324 | - element.parents().eq(1).find('.add-answer-image').css({'display': 'none'}) | |
| 325 | - element.parent().parent().find('.ays-answer-image-container').fadeIn(); | |
| 326 | - element.parent().parent().find('img.ays-answer-img').attr('src', attachment.url); | |
| 327 | - element.parents('tr').find('input.ays-answer-image-path').val(attachment.url); | |
| 328 | - if(element.hasClass('add-interval-image')){ | |
| 329 | - element.parent().parent().find('img').attr('src', attachment.url); | |
| 330 | - element.parents('tr').find('input.ays-answer-image').val(attachment.url); | |
| 331 | - } | |
| 332 | - }).open(); | |
| 333 | - return false; | |
| 334 | - } | |
| 335 | - | |
| 336 | - function openMediaUploaderForGifLoader(e, element) { | |
| 337 | - e.preventDefault(); | |
| 338 | - var aysUploader = wp.media({ | |
| 339 | - title: 'Upload', | |
| 340 | - button: { | |
| 341 | - text: 'Upload' | |
| 342 | - }, | |
| 343 | - library: { | |
| 344 | - type: 'image' | |
| 345 | - }, | |
| 346 | - multiple: false | |
| 347 | - }).on('select', function () { | |
| 348 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 349 | - var wrap = element.parents('.ays-form-image-wrap'); | |
| 350 | - wrap.find('.ays-form-image-container img.ays_form_img_loader_custom_gif').attr('src', attachment.url); | |
| 351 | - wrap.find('input.ays-form-image-path').val(attachment.url); | |
| 352 | - wrap.find('.ays-form-image-container').fadeIn(); | |
| 353 | - wrap.find('a.add_form_loader_custom_gif').hide(); | |
| 354 | - }).open(); | |
| 355 | - return false; | |
| 356 | - } | |
| 357 | - | |
| 358 | - function show_hide_rows(page) { | |
| 359 | - | |
| 360 | - var rows = jQuery('table.ays-add-questions-table tbody tr'); | |
| 361 | - rows.each(function (index) { | |
| 362 | - jQuery(this).css('display', 'none'); | |
| 363 | - }); | |
| 364 | - var counter = page * 5 - 4; | |
| 365 | - for (var i = counter; i < (counter + 5); i++) { | |
| 366 | - rows.eq(i - 1).css('display', 'table-row'); | |
| 367 | - } | |
| 368 | - } | |
| 369 | - | |
| 370 | - function createPagination(pagination, pagesCount, pageShow) { | |
| 371 | - (function (baseElement, pages, pageShow) { | |
| 372 | - var pageNum = 0, pageOffset = 0; | |
| 373 | - | |
| 374 | - function _initNav() { | |
| 375 | - var appendAble = ''; | |
| 376 | - for (var i = 0; i < pagesCount; i++) { | |
| 377 | - var activeClass = (i === 0) ? 'active' : ''; | |
| 378 | - appendAble += '<li class="' + activeClass + ' ays-question-page" data-page="' + (i + 1) + '">' + (i + 1) + '</li>'; | |
| 379 | - } | |
| 380 | - jQuery('ul.ays-question-nav-pages').html(appendAble); | |
| 381 | - var pagePos = (jQuery('div.ays-question-pagination').width()/2) - (parseInt(jQuery('ul.ays-question-nav-pages>li:first-child').css('width'))/2); | |
| 382 | - jQuery('ul.ays-question-nav-pages').css({ | |
| 383 | - 'margin-left': pagePos, | |
| 384 | - }); | |
| 385 | - //init events | |
| 386 | - var toPage; | |
| 387 | - baseElement.on('click', '.ays-question-nav-pages li, .ays-question-nav-btn', function (e) { | |
| 388 | - if (jQuery(e.target).is('.ays-question-nav-btn')) { | |
| 389 | - toPage = jQuery(this).hasClass('ays-question-prev') ? pageNum - 1 : pageNum + 1; | |
| 390 | - } else { | |
| 391 | - toPage = jQuery(this).index(); | |
| 392 | - } | |
| 393 | - var page = Number(toPage) + 1; | |
| 394 | - show_hide_rows(page); | |
| 395 | - _navPage(toPage); | |
| 396 | - }); | |
| 397 | - } | |
| 398 | - | |
| 399 | - function _navPage(toPage) { | |
| 400 | - var sel = jQuery('.ays-question-nav-pages li', baseElement), w = sel.first().outerWidth(), | |
| 401 | - diff = toPage - pageNum; | |
| 402 | - | |
| 403 | - if (toPage >= 0 && toPage <= pages - 1) { | |
| 404 | - sel.removeClass('active').eq(toPage).addClass('active'); | |
| 405 | - pageNum = toPage; | |
| 406 | - } else { | |
| 407 | - return false; | |
| 408 | - } | |
| 409 | - | |
| 410 | - if (toPage <= (pages - (pageShow + (diff > 0 ? 0 : 1))) && toPage >= 0) { | |
| 411 | - pageOffset = pageOffset + -w * diff; | |
| 412 | - } else { | |
| 413 | - pageOffset = (toPage > 0) ? -w * (pages - pageShow) : 0; | |
| 414 | - } | |
| 415 | - | |
| 416 | - sel.parent().css('left', pageOffset + 'px'); | |
| 417 | - } | |
| 418 | - | |
| 419 | - _initNav(); | |
| 420 | - | |
| 421 | - })(pagination, pagesCount, pageShow); | |
| 422 | - } | |
| 423 | - | |
| 424 | -// window.onload = function () { | |
| 425 | -// if (document.getElementById('import_button')) { | |
| 426 | -// document.getElementById('import_button').addEventListener('click', function () { | |
| 427 | -// document.getElementById('import_file').click(); | |
| 428 | -// }); | |
| 429 | -//// document.getElementById('example_button').addEventListener('click', function () { | |
| 430 | -//// document.getElementById('example_file').click(); | |
| 431 | -//// }); | |
| 432 | -// } | |
| 433 | -// } | |
| 434 | - | |
| 435 | - function activate_question(element){ | |
| 436 | - element.find('.ays_question_overlay').addClass('display_none'); | |
| 437 | - element.find('.ays_fa.ays_fa_times').parent() | |
| 438 | - .removeClass('show_remove_answer') | |
| 439 | - .addClass('active_remove_answer'); | |
| 440 | - element.find('.ays_add_answer').parents().eq(1).removeClass('show_add_answer'); | |
| 441 | - element.addClass('active_question'); | |
| 442 | - var this_question = element.find('.ays_question').text(); | |
| 443 | - element.find('.ays_question').remove(); | |
| 444 | - element.prepend('<input type="text" value="' + this_question + '" class="ays_question_input">'); | |
| 445 | - var answers_tr = element.find('.ays_answers_table tr'); | |
| 446 | - for (var i = 0; i < answers_tr.length; i++) { | |
| 447 | - var answer_text = (jQuery(answers_tr.eq(i)).find('.ays_answer').text() && jQuery(answers_tr.eq(i)).find('.ays_answer').text() !== "Answer") ? "value='" + jQuery(answers_tr.eq(i)).find('.ays_answer').text() + "'" : "placeholder='Answer text'"; | |
| 448 | - jQuery(answers_tr.eq(i)).find('.ays_answer_td').empty(); | |
| 449 | - jQuery(answers_tr.eq(i)).find('.ays_answer_td').append('<input type="text" ' + answer_text + ' class="ays_answer">'); | |
| 450 | - } | |
| 451 | - } | |
| 452 | - | |
| 453 | - function deactivate_questions() { | |
| 454 | - if (jQuery('.active_question').length !== 0) { | |
| 455 | - var question = jQuery('.active_question').eq(0); | |
| 456 | - if(!jQuery(question).find('input[name^="ays_answer_radio"]:checked').length){ | |
| 457 | - jQuery(question).find('input[name^="ays_answer_radio"]').eq(0).attr('checked',true) | |
| 458 | - } | |
| 459 | - jQuery(question).find('.ays_add_answer').parents().eq(1).addClass('show_add_answer'); | |
| 460 | - jQuery(question).find('.fa.fa-times').parent().removeClass('active_remove_answer').addClass('show_remove_answer'); | |
| 461 | - | |
| 462 | - var question_text = jQuery(question).find('.ays_question_input').val(); | |
| 463 | - jQuery(question).find('.ays_question_input').remove(); | |
| 464 | - jQuery(question).prepend('<p class="ays_question">' + question_text + '</p>'); | |
| 465 | - var answers_tr = jQuery(question).find('.ays_answers_table tr'); | |
| 466 | - for (var i = 0; i < answers_tr.length; i++) { | |
| 467 | - var answer_text = (jQuery(answers_tr.eq(i)).find('.ays_answer').val()) ? jQuery(answers_tr.eq(i)).find('.ays_answer').val() : ''; | |
| 468 | - jQuery(answers_tr.eq(i)).find('.ays_answer_td').empty(); | |
| 469 | - var answer_html = '<p class="ays_answer">' + answer_text + '</p>'+((answer_text == '')?'<p>Answer</p>':''); | |
| 470 | - jQuery(answers_tr.eq(i)).find('.ays_answer_td').append(answer_html) | |
| 471 | - } | |
| 472 | - jQuery('.active_question').find('.ays_question_overlay').removeClass('display_none'); | |
| 473 | - jQuery('.active_question').removeClass('active_question'); | |
| 474 | - } | |
| 475 | - } | |
| 476 | - | |
| 477 | - function searchForPage(params, data) { | |
| 478 | - // If there are no search terms, return all of the data | |
| 479 | - if (jQuery.trim(params.term) === '') { | |
| 480 | - return data; | |
| 481 | - } | |
| 482 | - | |
| 483 | - // Do not display the item if there is no 'text' property | |
| 484 | - if (typeof data.text === 'undefined') { | |
| 485 | - return null; | |
| 486 | - } | |
| 487 | - var searchText = data.text.toLowerCase(); | |
| 488 | - // `params.term` should be the term that is used for searching | |
| 489 | - // `data.text` is the text that is displayed for the data object | |
| 490 | - if (searchText.indexOf(params.term) > -1) { | |
| 491 | - var modifiedData = jQuery.extend({}, data, true); | |
| 492 | - modifiedData.text += ' (matched)'; | |
| 493 | - | |
| 494 | - // You can return modified objects from here | |
| 495 | - // This includes matching the `children` how you want in nested data sets | |
| 496 | - return modifiedData; | |
| 497 | - } | |
| 498 | - | |
| 499 | - // Return `null` if the term should not be displayed | |
| 500 | - return null; | |
| 501 | - } | |
| 502 | - | |
| 503 | - function selectElementContents(el) { | |
| 504 | - if (window.getSelection && document.createRange) { | |
| 505 | - // var sel = window.getSelection(); | |
| 506 | - // var range = document.createRange(); | |
| 507 | - // range.selectNodeContents(el); | |
| 508 | - // sel.removeAllRanges(); | |
| 509 | - // sel.addRange(range); | |
| 510 | - | |
| 511 | - // var _this = jQuery(document).find('strong.ays-form-shortcode-box'); | |
| 512 | - var _this = jQuery(document).find( el ); | |
| 513 | - | |
| 514 | - var text = el.textContent; | |
| 515 | - var textField = document.createElement('textarea'); | |
| 516 | - | |
| 517 | - textField.innerText = text; | |
| 518 | - document.body.appendChild(textField); | |
| 519 | - textField.select(); | |
| 520 | - document.execCommand('copy'); | |
| 521 | - textField.remove(); | |
| 522 | - | |
| 523 | - var selection = window.getSelection(); | |
| 524 | - selection.setBaseAndExtent(el,0,el,1); | |
| 525 | - | |
| 526 | - _this.attr( "data-original-title", aysChartBuilderAdmin.copied ); | |
| 527 | - _this.attr( "title", aysChartBuilderAdmin.copied ); | |
| 528 | - | |
| 529 | - _this.tooltip("show"); | |
| 530 | - | |
| 531 | - } else if (document.selection && document.body.createTextRange) { | |
| 532 | - var textRange = document.body.createTextRange(); | |
| 533 | - textRange.moveToElementText(el); | |
| 534 | - textRange.select(); | |
| 535 | - } | |
| 536 | - } | |
| 537 | - | |
| 538 | - function nl2br (str, is_xhtml) { | |
| 539 | - if (typeof str === 'undefined' || str === null) { | |
| 540 | - return ''; | |
| 541 | - } | |
| 542 | - var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>'; | |
| 543 | - return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2'); | |
| 544 | - } | |
| 545 | - | |
| 546 | - /** | |
| 547 | - * @return {string} | |
| 548 | - */ | |
| 549 | - function aysEscapeHtml(text) { | |
| 550 | - var map = { | |
| 551 | - '&': '&', | |
| 552 | - '<': '<', | |
| 553 | - '>': '>', | |
| 554 | - '"': '"', | |
| 555 | - "'": ''' | |
| 556 | - }; | |
| 557 | - return text.replace(/[&<>\"']/g, function(m) { return map[m]; }); | |
| 558 | - } | |
| 559 | - | |
| 560 | - function aysFormRgba2hex(orig, isAlpha) { | |
| 561 | - if( orig.indexOf('#') !== -1 ){ | |
| 562 | - if( isAlpha ){ | |
| 563 | - orig += "29"; | |
| 564 | - } | |
| 565 | - return orig; | |
| 566 | - } | |
| 567 | - | |
| 568 | - var a, isPercent, | |
| 569 | - rgb = orig.replace(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+),?([^,\s)]+)?/i), | |
| 570 | - alpha = (rgb && rgb[4] || "").trim(), | |
| 571 | - hex = rgb ? | |
| 572 | - (rgb[1] | 1 << 8).toString(16).slice(1) + | |
| 573 | - (rgb[2] | 1 << 8).toString(16).slice(1) + | |
| 574 | - (rgb[3] | 1 << 8).toString(16).slice(1) : orig; | |
| 575 | - | |
| 576 | - if (alpha !== "") { | |
| 577 | - a = alpha; | |
| 578 | - } else { | |
| 579 | - a = 01; | |
| 580 | - } | |
| 581 | - | |
| 582 | - // multiply before convert to HEX | |
| 583 | - if( isAlpha ){ | |
| 584 | - a = ((a * 255) | 1 << 8).toString(16).slice(1); | |
| 585 | - }else{ | |
| 586 | - a = ''; | |
| 587 | - } | |
| 588 | - | |
| 589 | - if( hex == '000000' || hex == '000' ){ | |
| 590 | - hex = '3366cc'; | |
| 591 | - } | |
| 592 | - | |
| 593 | - hex = '#' + hex + a; | |
| 594 | - | |
| 595 | - return hex; | |
| 596 | - } | |
| 597 | - | |
| 598 | - function openMediaUploaderForConditions(e, element) { | |
| 599 | - e.preventDefault(); | |
| 600 | - var aysUploader = wp.media({ | |
| 601 | - title: 'Upload', | |
| 602 | - button: { | |
| 603 | - text: 'Upload' | |
| 604 | - }, | |
| 605 | - multiple: false | |
| 606 | - }).on('select', function () { | |
| 607 | - var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 608 | - var $this = element; | |
| 609 | - var $thisParent = $this.parents('.ays-form-email-message-files'); | |
| 610 | - $thisParent.find('input.ays-form-email-message-editor-file').val(attachment.url); | |
| 611 | - $thisParent.find('.ays-form-email-message-files-content-text').html(attachment.filename); | |
| 612 | - $thisParent.find('.ays-form-email-message-files-content-text').attr("href" , attachment.url); | |
| 613 | - $thisParent.find('.ays-form-email-message-files-content-text').attr("download" , attachment.url); | |
| 614 | - $thisParent.find('.ays-form-email-message-editor-file-name').val(attachment.filename); | |
| 615 | - $thisParent.find('.ays-form-email-message-files-wrapper').removeClass("display_none_not_important"); | |
| 616 | - $thisParent.find('.ays-form-email-message-files-body').removeClass("display_none_not_important"); | |
| 617 | - $thisParent.find('.ays-form-add-email-message-files').html("Edit file"); | |
| 618 | - $thisParent.find('.ays-form-email-message-editor-file-id').val(attachment.id); | |
| 619 | - }).open(); | |
| 620 | - return false; | |
| 621 | - } | |
| 622 | - | |
| 623 | - function selectElementContentsCopy(element) { | |
| 624 | - var _this = element; | |
| 625 | - var text = _this.attr("data-clipboard-text"); | |
| 626 | - var newElement = jQuery('<textarea>').appendTo('body').val(text).select(); | |
| 627 | - document.execCommand('copy'); | |
| 628 | - newElement.remove(); | |
| 629 | - _this.attr( "data-original-title", aysChartBuilderAdmin.copied ); | |
| 630 | - _this.attr( "title", aysChartBuilderAdmin.copied ); | |
| 631 | - _this.tooltip("show"); | |
| 632 | - } | |
| 633 | - | |
| 634 | - function getEachSubmission(e){ | |
| 635 | - var notToTrigger = jQuery(e.target); | |
| 636 | - if(!notToTrigger.hasClass("ays-form-no-trigger")){ | |
| 637 | - var innerInput = jQuery(this).find(".ays_form_result"); | |
| 638 | - var innerInputVal = innerInput.val(); | |
| 639 | - var submissionIdStr = jQuery("#questions").find('.ays_submissions_id_str').val(); | |
| 640 | - var submissionIdArr = submissionIdStr.split(","); | |
| 641 | - var newSubmissionArr = []; | |
| 642 | - | |
| 643 | - for(var i = 0; i < submissionIdArr.length; i++ ){ | |
| 644 | - newSubmissionArr[i+1] = submissionIdArr[i]; | |
| 645 | - } | |
| 646 | - | |
| 647 | - var forInput = newSubmissionArr.indexOf(innerInputVal); | |
| 648 | - changeTabTo("questions"); | |
| 649 | - jQuery(document).find('.ays_number_of_result').val(forInput); | |
| 650 | - | |
| 651 | - setTimeout(function(){ | |
| 652 | - jQuery(document).find('.ays_number_of_result').trigger('change'); | |
| 653 | - }, 500); | |
| 654 | - | |
| 655 | - jQuery(document.body).goTo(); | |
| 656 | - } | |
| 657 | - } | |
| 658 | - | |
| 659 | - function changeTabTo(href){ | |
| 660 | - var newHref = "#"+href; | |
| 661 | - jQuery(document).find('.nav-tab-wrapper a.nav-tab').each(function () { | |
| 662 | - if (jQuery(this).hasClass('nav-tab-active')) { | |
| 663 | - jQuery(this).removeClass('nav-tab-active'); | |
| 664 | - } | |
| 665 | - }); | |
| 666 | - jQuery(document).find('a[href='+newHref+']').addClass('nav-tab-active'); | |
| 667 | - | |
| 668 | - jQuery(document).find('.ays-form-tab-content').each(function () { | |
| 669 | - jQuery(this).css('display', 'none'); | |
| 670 | - }); | |
| 671 | - | |
| 672 | - jQuery('.ays-form-tab-content' + newHref).css('display', 'block'); | |
| 673 | - } | |
| 674 | - | |
| 675 | -//})(jQuery); | |
| 1 | +// (function($){ | |
| 2 | + | |
| 3 | + var $html_name_prefix = 'ays_'; | |
| 4 | + String.prototype.hexToRgbA = function(a) { | |
| 5 | + | |
| 6 | + if (typeof a === 'undefined'){ | |
| 7 | + a = 1; | |
| 8 | + } | |
| 9 | + var ays_rgb; | |
| 10 | + var result1 = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})jQuery/i.exec(this); | |
| 11 | + var result2 = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})jQuery/i.exec(this); | |
| 12 | + if(result1){ | |
| 13 | + ays_rgb = { | |
| 14 | + r: parseInt(result1[1], 16), | |
| 15 | + g: parseInt(result1[2], 16), | |
| 16 | + b: parseInt(result1[3], 16) | |
| 17 | + }; | |
| 18 | + return 'rgba('+ays_rgb.r+','+ays_rgb.g+','+ays_rgb.b+','+a+')'; | |
| 19 | + }else if(result2){ | |
| 20 | + ays_rgb = { | |
| 21 | + r: parseInt(result2[1]+''+result2[1], 16), | |
| 22 | + g: parseInt(result2[2]+''+result2[2], 16), | |
| 23 | + b: parseInt(result2[3]+''+result2[3], 16) | |
| 24 | + }; | |
| 25 | + return 'rgba('+ays_rgb.r+','+ays_rgb.g+','+ays_rgb.b+','+a+')'; | |
| 26 | + }else{ | |
| 27 | + return null; | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 31 | + jQuery.fn.aysModal = function(action){ | |
| 32 | + var jQuerythis = jQuery(this); | |
| 33 | + switch(action){ | |
| 34 | + case 'hide': | |
| 35 | + jQuerythis.find('.ays-modal-content').css('animation-name', 'zoomOut'); | |
| 36 | + setTimeout(function(){ | |
| 37 | + jQuerythis.removeClass('ays-modal-opened'); | |
| 38 | + if( jQuery(document).find('div[class^="ays-modal-backdrop"]').length <= 1 ){ | |
| 39 | + jQuery(document.body).removeClass('modal-open'); | |
| 40 | + } | |
| 41 | + jQuery(document).find('.ays-modal-backdrop-'+ jQuerythis.attr('id')).remove(); | |
| 42 | + jQuerythis.hide(); | |
| 43 | + | |
| 44 | + jQuery(document).trigger('ays-chart:modal:close', {}); | |
| 45 | + }, 250); | |
| 46 | + break; | |
| 47 | + case 'hide-preloader': | |
| 48 | + jQuerythis.find('.ays-preloader').removeClass('show'); | |
| 49 | + break; | |
| 50 | + case 'show-preloader': | |
| 51 | + jQuerythis.find('.ays-preloader').addClass('show'); | |
| 52 | + break; | |
| 53 | + case 'show': | |
| 54 | + default: | |
| 55 | + jQuerythis.show(); | |
| 56 | + jQuerythis.addClass('ays-modal-opened'); | |
| 57 | + jQuerythis.find('.ays-modal-content').css('animation-name', 'zoomIn'); | |
| 58 | + if( jQuery(document).find('div[class^="ays-modal-backdrop"]').length < 1 ){ | |
| 59 | + jQuery(document.body).addClass('modal-open'); | |
| 60 | + } | |
| 61 | + jQuery(document).find('.modal-backdrop').remove(); | |
| 62 | + jQuery(document.body).append('<div class="ays-modal-backdrop-'+ jQuerythis.attr('id') +'"></div>'); | |
| 63 | + break; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + function checkTrue(flag) { | |
| 68 | + return flag === true; | |
| 69 | + } | |
| 70 | + | |
| 71 | + function openMediaUploaderForLogoImage(e, element) { | |
| 72 | + e.preventDefault(); | |
| 73 | + var aysUploader = wp.media({ | |
| 74 | + title: 'Upload', | |
| 75 | + button: { | |
| 76 | + text: 'Upload' | |
| 77 | + }, | |
| 78 | + library: { | |
| 79 | + type: 'image' | |
| 80 | + }, | |
| 81 | + multiple: false | |
| 82 | + }).on('select', function () { | |
| 83 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 84 | + var answerImgCont = element.parents('.ays-form-image-container').find('.ays-form-image-body'); | |
| 85 | + var img = answerImgCont.find('img.ays-form-img'); | |
| 86 | + var hiddenInp = answerImgCont.find('input.ays-form-img-src'); | |
| 87 | + | |
| 88 | + element.text( aysChartBuilderAdmin.editImage ); | |
| 89 | + img.attr('src', attachment.url); | |
| 90 | + hiddenInp.val(attachment.url); | |
| 91 | + answerImgCont.show(); | |
| 92 | + img.removeClass('fade'); | |
| 93 | + jQuery(document).find(".ays-form-logo-url-box").removeClass("display_none_not_important"); | |
| 94 | + var checkImgUrl = jQuery(document).find("#ays_form_logo_enable_image_url").prop("checked"); | |
| 95 | + element.parents('.ays-form-image-container').parent().find('.ays-form-logo-open').show(); | |
| 96 | + if(checkImgUrl){ | |
| 97 | + element.parents('.ays-form-image-container').parent().find('.ays-form-logo-open-close').show(); | |
| 98 | + } | |
| 99 | + }).open(); | |
| 100 | + return false; | |
| 101 | + } | |
| 102 | + | |
| 103 | + function openMediaUploaderForImage(e, element) { | |
| 104 | + e.preventDefault(); | |
| 105 | + var aysUploader = wp.media({ | |
| 106 | + title: 'Upload', | |
| 107 | + button: { | |
| 108 | + text: 'Upload' | |
| 109 | + }, | |
| 110 | + library: { | |
| 111 | + type: 'image' | |
| 112 | + }, | |
| 113 | + multiple: false | |
| 114 | + }).on('select', function () { | |
| 115 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 116 | + var answerImgCont = element.parents('.ays-form-image-container').find('.ays-form-image-body'); | |
| 117 | + var img = answerImgCont.find('img.ays-form-img'); | |
| 118 | + var hiddenInp = answerImgCont.find('input.ays-form-img-src'); | |
| 119 | + var thisParent = element.parents(".ays_form_cover_image_main"); | |
| 120 | + thisParent.find('.ays-form-cover-image-options').css("display" , "flex"); | |
| 121 | + thisParent.find('.ays-form-cover-image-options-hr').fadeIn(500); | |
| 122 | + | |
| 123 | + element.text( aysChartBuilderAdmin.editImage ); | |
| 124 | + img.attr('src', attachment.url); | |
| 125 | + hiddenInp.val(attachment.url); | |
| 126 | + answerImgCont.show(); | |
| 127 | + img.removeClass('fade'); | |
| 128 | + | |
| 129 | + }).open(); | |
| 130 | + return false; | |
| 131 | + } | |
| 132 | + | |
| 133 | + // function openMediaUploader(e, element) { | |
| 134 | + // e.preventDefault(); | |
| 135 | + // var aysUploader = wp.media({ | |
| 136 | + // title: 'Upload', | |
| 137 | + // button: { | |
| 138 | + // text: 'Upload' | |
| 139 | + // }, | |
| 140 | + // library: { | |
| 141 | + // type: 'image' | |
| 142 | + // }, | |
| 143 | + // multiple: false | |
| 144 | + // }).on('select', function () { | |
| 145 | + // var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 146 | + // element.text('Edit Image'); | |
| 147 | + // element.parent().parent().find('.ays-question-image-container').fadeIn(); | |
| 148 | + // element.parent().parent().find('img#ays-question-img').attr('src', attachment.url); | |
| 149 | + // element.parent().parent().find('input#ays-question-image').val(attachment.url); | |
| 150 | + // }).open(); | |
| 151 | + // return false; | |
| 152 | + // } | |
| 153 | + | |
| 154 | + | |
| 155 | + function openMediaUploader(e, element, type) { | |
| 156 | + e.preventDefault(); | |
| 157 | + var aysUploader = wp.media({ | |
| 158 | + title: 'Upload', | |
| 159 | + button: { | |
| 160 | + text: 'Upload' | |
| 161 | + }, | |
| 162 | + library: { | |
| 163 | + type: 'image' | |
| 164 | + }, | |
| 165 | + multiple: false | |
| 166 | + }).on('select', function () { | |
| 167 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 168 | + switch(type){ | |
| 169 | + case 'questionImgButton': | |
| 170 | + var $this = element.parents('.ays-form-question-answer-conteiner').find('.ays-form-question-image-container'); | |
| 171 | + var hiddenInp = $this.find('.ays-form-question-img-src'); | |
| 172 | + var img = $this.find('img.ays-form-question-img'); | |
| 173 | + | |
| 174 | + $this.removeAttr('style'); | |
| 175 | + img.attr('src', attachment.url); | |
| 176 | + hiddenInp.val(attachment.url); | |
| 177 | + break; | |
| 178 | + case 'answerImgButton': | |
| 179 | + var answerImgCont = element.parents('.ays-form-answer-row').find('.ays-form-answer-image-container'); | |
| 180 | + var parent = element.parents('.ays-form-section-box'); | |
| 181 | + | |
| 182 | + var section_id = parent.data('id'); | |
| 183 | + var question_id = element.parents('.ays-form-question-answer-conteiner').data('id'); | |
| 184 | + var answer_id = element.parents('.ays-form-answer-row').data('id'); | |
| 185 | + var imgInputName = element.parents('.ays-form-answer-row').find('input.ays-form-input').attr('name'); | |
| 186 | + var checkInputName = imgInputName.indexOf('ays_section_add'); | |
| 187 | + var inputName = false; | |
| 188 | + if (checkInputName >= 0) { | |
| 189 | + inputName = true; | |
| 190 | + } | |
| 191 | + | |
| 192 | + var name = 'section'; | |
| 193 | + if (inputName) { | |
| 194 | + name = 'section_add'; | |
| 195 | + } | |
| 196 | + // var inputNameAttr = $html_name_prefix+name+'['+section_id+'][question]['+question_id+'][answers]['+answer_id+'][image]'; | |
| 197 | + | |
| 198 | + var img = answerImgCont.find('img.ays-form-answer-img'); | |
| 199 | + var hiddenInp = answerImgCont.find('input.ays-form-answer-img-src'); | |
| 200 | + | |
| 201 | + img.attr('src', attachment.url); | |
| 202 | + hiddenInp.val(attachment.url); | |
| 203 | + answerImgCont.show(); | |
| 204 | + img.removeClass('Fade'); | |
| 205 | + break; | |
| 206 | + } | |
| 207 | + | |
| 208 | + }).open(); | |
| 209 | + return false; | |
| 210 | + } | |
| 211 | + | |
| 212 | + | |
| 213 | + function openMediaUploaderQuestionBg(e, element) { | |
| 214 | + e.preventDefault(); | |
| 215 | + var aysUploader = wp.media({ | |
| 216 | + title: 'Upload Question Background', | |
| 217 | + button: { | |
| 218 | + text: 'Upload' | |
| 219 | + }, | |
| 220 | + library: { | |
| 221 | + type: 'image' | |
| 222 | + }, | |
| 223 | + multiple: false | |
| 224 | + }).on('select', function () { | |
| 225 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 226 | + element.text('Edit Image'); | |
| 227 | + element.parent().parent().find('.ays-question-bg-image-container').fadeIn(); | |
| 228 | + element.parent().parent().find('img#ays-question-bg-img').attr('src', attachment.url); | |
| 229 | + element.parent().parent().find('input#ays-question-bg-image').val(attachment.url); | |
| 230 | + }).open(); | |
| 231 | + return false; | |
| 232 | + } | |
| 233 | + | |
| 234 | + function openMusicMediaUploader(e, element) { | |
| 235 | + e.preventDefault(); | |
| 236 | + var aysUploader = wp.media({ | |
| 237 | + title: 'Upload music', | |
| 238 | + button: { | |
| 239 | + text: 'Upload' | |
| 240 | + }, | |
| 241 | + library: { | |
| 242 | + type: 'audio' | |
| 243 | + }, | |
| 244 | + multiple: false | |
| 245 | + }).on('select', function () { | |
| 246 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 247 | + element.next().attr('src', attachment.url); | |
| 248 | + element.parent().find('input.ays_quiz_bg_music').val(attachment.url); | |
| 249 | + }).open(); | |
| 250 | + return false; | |
| 251 | + } | |
| 252 | + | |
| 253 | + function openQuizMediaUploader(e, element) { | |
| 254 | + e.preventDefault(); | |
| 255 | + var aysUploader = wp.media({ | |
| 256 | + title: 'Upload', | |
| 257 | + button: { | |
| 258 | + text: 'Upload' | |
| 259 | + }, | |
| 260 | + library: { | |
| 261 | + type: 'image' | |
| 262 | + }, | |
| 263 | + multiple: false | |
| 264 | + }).on('select', function () { | |
| 265 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 266 | + if(element.hasClass('add-quiz-bg-image')){ | |
| 267 | + element.parent().find('img#ays-quiz-bg-img').attr('src', attachment.url); | |
| 268 | + element.parent().find('.ays-quiz-bg-image-container').fadeIn(); | |
| 269 | + element.next().val(attachment.url); | |
| 270 | + jQuery(document).find('.ays-quiz-live-container').css({'background-image': 'url("'+attachment.url+'")'}); | |
| 271 | + element.hide(); | |
| 272 | + }else if(element.hasClass('ays-edit-quiz-bg-img')){ | |
| 273 | + element.parent().find('.ays-quiz-bg-image-container').fadeIn(); | |
| 274 | + element.parent().find('img#ays-quiz-bg-img').attr('src', attachment.url); | |
| 275 | + jQuery(document).find('#ays_quiz_bg_image').val(attachment.url); | |
| 276 | + jQuery(document).find('.ays-quiz-live-container').css({'background-image': 'url("'+attachment.url+'")'}); | |
| 277 | + }else{ | |
| 278 | + element.text('Edit Image'); | |
| 279 | + element.parent().parent().find('.ays-quiz-image-container').fadeIn(); | |
| 280 | + element.parent().parent().find('img#ays-quiz-img').attr('src', attachment.url); | |
| 281 | + jQuery('input#ays-quiz-image').val(attachment.url); | |
| 282 | + var ays_quiz_theme = jQuery(document).find('input[name="ays_quiz_theme"]:checked').val(); | |
| 283 | + switch (ays_quiz_theme) { | |
| 284 | + case 'elegant_dark': | |
| 285 | + case 'elegant_light': | |
| 286 | + case 'rect_light': | |
| 287 | + case 'rect_dark': | |
| 288 | + case 'classic_dark': | |
| 289 | + case 'classic_light': | |
| 290 | + jQuery(document).find('#ays-quiz-live-image').attr('src', attachment.url); | |
| 291 | + jQuery(document).find('#ays-quiz-live-image').css({'display': 'block'}); | |
| 292 | + break; | |
| 293 | + case 'modern_light': | |
| 294 | + case 'modern_dark': | |
| 295 | + jQuery(document).find('.ays-quiz-live-container').css({'background-image':'url('+attachment.url+')'}); | |
| 296 | + jQuery(document).find('#ays-quiz-live-image').css({'display': 'none'}); | |
| 297 | + jQuery(document).find('#ays-quiz-live-button').css('border','1px solid'); | |
| 298 | + break; | |
| 299 | + default: | |
| 300 | + jQuery(document).find('#ays-quiz-live-image').attr('src', attachment.url); | |
| 301 | + jQuery(document).find('#ays-quiz-live-image').css({'display': 'block'}); | |
| 302 | + break; | |
| 303 | + | |
| 304 | + } | |
| 305 | + } | |
| 306 | + }).open(); | |
| 307 | + | |
| 308 | + return false; | |
| 309 | + } | |
| 310 | + | |
| 311 | + function openAnswerMediaUploader(e, element) { | |
| 312 | + e.preventDefault(); | |
| 313 | + var aysUploader = wp.media({ | |
| 314 | + title: 'Upload', | |
| 315 | + button: { | |
| 316 | + text: 'Upload' | |
| 317 | + }, | |
| 318 | + library: { | |
| 319 | + type: 'image' | |
| 320 | + }, | |
| 321 | + multiple: false | |
| 322 | + }).on('select', function () { | |
| 323 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 324 | + element.parents().eq(1).find('.add-answer-image').css({'display': 'none'}) | |
| 325 | + element.parent().parent().find('.ays-answer-image-container').fadeIn(); | |
| 326 | + element.parent().parent().find('img.ays-answer-img').attr('src', attachment.url); | |
| 327 | + element.parents('tr').find('input.ays-answer-image-path').val(attachment.url); | |
| 328 | + if(element.hasClass('add-interval-image')){ | |
| 329 | + element.parent().parent().find('img').attr('src', attachment.url); | |
| 330 | + element.parents('tr').find('input.ays-answer-image').val(attachment.url); | |
| 331 | + } | |
| 332 | + }).open(); | |
| 333 | + return false; | |
| 334 | + } | |
| 335 | + | |
| 336 | + function openMediaUploaderForGifLoader(e, element) { | |
| 337 | + e.preventDefault(); | |
| 338 | + var aysUploader = wp.media({ | |
| 339 | + title: 'Upload', | |
| 340 | + button: { | |
| 341 | + text: 'Upload' | |
| 342 | + }, | |
| 343 | + library: { | |
| 344 | + type: 'image' | |
| 345 | + }, | |
| 346 | + multiple: false | |
| 347 | + }).on('select', function () { | |
| 348 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 349 | + var wrap = element.parents('.ays-form-image-wrap'); | |
| 350 | + wrap.find('.ays-form-image-container img.ays_form_img_loader_custom_gif').attr('src', attachment.url); | |
| 351 | + wrap.find('input.ays-form-image-path').val(attachment.url); | |
| 352 | + wrap.find('.ays-form-image-container').fadeIn(); | |
| 353 | + wrap.find('a.add_form_loader_custom_gif').hide(); | |
| 354 | + }).open(); | |
| 355 | + return false; | |
| 356 | + } | |
| 357 | + | |
| 358 | + function show_hide_rows(page) { | |
| 359 | + | |
| 360 | + var rows = jQuery('table.ays-add-questions-table tbody tr'); | |
| 361 | + rows.each(function (index) { | |
| 362 | + jQuery(this).css('display', 'none'); | |
| 363 | + }); | |
| 364 | + var counter = page * 5 - 4; | |
| 365 | + for (var i = counter; i < (counter + 5); i++) { | |
| 366 | + rows.eq(i - 1).css('display', 'table-row'); | |
| 367 | + } | |
| 368 | + } | |
| 369 | + | |
| 370 | + function createPagination(pagination, pagesCount, pageShow) { | |
| 371 | + (function (baseElement, pages, pageShow) { | |
| 372 | + var pageNum = 0, pageOffset = 0; | |
| 373 | + | |
| 374 | + function _initNav() { | |
| 375 | + var appendAble = ''; | |
| 376 | + for (var i = 0; i < pagesCount; i++) { | |
| 377 | + var activeClass = (i === 0) ? 'active' : ''; | |
| 378 | + appendAble += '<li class="' + activeClass + ' ays-question-page" data-page="' + (i + 1) + '">' + (i + 1) + '</li>'; | |
| 379 | + } | |
| 380 | + jQuery('ul.ays-question-nav-pages').html(appendAble); | |
| 381 | + var pagePos = (jQuery('div.ays-question-pagination').width()/2) - (parseInt(jQuery('ul.ays-question-nav-pages>li:first-child').css('width'))/2); | |
| 382 | + jQuery('ul.ays-question-nav-pages').css({ | |
| 383 | + 'margin-left': pagePos, | |
| 384 | + }); | |
| 385 | + //init events | |
| 386 | + var toPage; | |
| 387 | + baseElement.on('click', '.ays-question-nav-pages li, .ays-question-nav-btn', function (e) { | |
| 388 | + if (jQuery(e.target).is('.ays-question-nav-btn')) { | |
| 389 | + toPage = jQuery(this).hasClass('ays-question-prev') ? pageNum - 1 : pageNum + 1; | |
| 390 | + } else { | |
| 391 | + toPage = jQuery(this).index(); | |
| 392 | + } | |
| 393 | + var page = Number(toPage) + 1; | |
| 394 | + show_hide_rows(page); | |
| 395 | + _navPage(toPage); | |
| 396 | + }); | |
| 397 | + } | |
| 398 | + | |
| 399 | + function _navPage(toPage) { | |
| 400 | + var sel = jQuery('.ays-question-nav-pages li', baseElement), w = sel.first().outerWidth(), | |
| 401 | + diff = toPage - pageNum; | |
| 402 | + | |
| 403 | + if (toPage >= 0 && toPage <= pages - 1) { | |
| 404 | + sel.removeClass('active').eq(toPage).addClass('active'); | |
| 405 | + pageNum = toPage; | |
| 406 | + } else { | |
| 407 | + return false; | |
| 408 | + } | |
| 409 | + | |
| 410 | + if (toPage <= (pages - (pageShow + (diff > 0 ? 0 : 1))) && toPage >= 0) { | |
| 411 | + pageOffset = pageOffset + -w * diff; | |
| 412 | + } else { | |
| 413 | + pageOffset = (toPage > 0) ? -w * (pages - pageShow) : 0; | |
| 414 | + } | |
| 415 | + | |
| 416 | + sel.parent().css('left', pageOffset + 'px'); | |
| 417 | + } | |
| 418 | + | |
| 419 | + _initNav(); | |
| 420 | + | |
| 421 | + })(pagination, pagesCount, pageShow); | |
| 422 | + } | |
| 423 | + | |
| 424 | +// window.onload = function () { | |
| 425 | +// if (document.getElementById('import_button')) { | |
| 426 | +// document.getElementById('import_button').addEventListener('click', function () { | |
| 427 | +// document.getElementById('import_file').click(); | |
| 428 | +// }); | |
| 429 | +//// document.getElementById('example_button').addEventListener('click', function () { | |
| 430 | +//// document.getElementById('example_file').click(); | |
| 431 | +//// }); | |
| 432 | +// } | |
| 433 | +// } | |
| 434 | + | |
| 435 | + function activate_question(element){ | |
| 436 | + element.find('.ays_question_overlay').addClass('display_none'); | |
| 437 | + element.find('.ays_fa.ays_fa_times').parent() | |
| 438 | + .removeClass('show_remove_answer') | |
| 439 | + .addClass('active_remove_answer'); | |
| 440 | + element.find('.ays_add_answer').parents().eq(1).removeClass('show_add_answer'); | |
| 441 | + element.addClass('active_question'); | |
| 442 | + var this_question = element.find('.ays_question').text(); | |
| 443 | + element.find('.ays_question').remove(); | |
| 444 | + element.prepend('<input type="text" value="' + this_question + '" class="ays_question_input">'); | |
| 445 | + var answers_tr = element.find('.ays_answers_table tr'); | |
| 446 | + for (var i = 0; i < answers_tr.length; i++) { | |
| 447 | + var answer_text = (jQuery(answers_tr.eq(i)).find('.ays_answer').text() && jQuery(answers_tr.eq(i)).find('.ays_answer').text() !== "Answer") ? "value='" + jQuery(answers_tr.eq(i)).find('.ays_answer').text() + "'" : "placeholder='Answer text'"; | |
| 448 | + jQuery(answers_tr.eq(i)).find('.ays_answer_td').empty(); | |
| 449 | + jQuery(answers_tr.eq(i)).find('.ays_answer_td').append('<input type="text" ' + answer_text + ' class="ays_answer">'); | |
| 450 | + } | |
| 451 | + } | |
| 452 | + | |
| 453 | + function deactivate_questions() { | |
| 454 | + if (jQuery('.active_question').length !== 0) { | |
| 455 | + var question = jQuery('.active_question').eq(0); | |
| 456 | + if(!jQuery(question).find('input[name^="ays_answer_radio"]:checked').length){ | |
| 457 | + jQuery(question).find('input[name^="ays_answer_radio"]').eq(0).attr('checked',true) | |
| 458 | + } | |
| 459 | + jQuery(question).find('.ays_add_answer').parents().eq(1).addClass('show_add_answer'); | |
| 460 | + jQuery(question).find('.fa.fa-times').parent().removeClass('active_remove_answer').addClass('show_remove_answer'); | |
| 461 | + | |
| 462 | + var question_text = jQuery(question).find('.ays_question_input').val(); | |
| 463 | + jQuery(question).find('.ays_question_input').remove(); | |
| 464 | + jQuery(question).prepend('<p class="ays_question">' + question_text + '</p>'); | |
| 465 | + var answers_tr = jQuery(question).find('.ays_answers_table tr'); | |
| 466 | + for (var i = 0; i < answers_tr.length; i++) { | |
| 467 | + var answer_text = (jQuery(answers_tr.eq(i)).find('.ays_answer').val()) ? jQuery(answers_tr.eq(i)).find('.ays_answer').val() : ''; | |
| 468 | + jQuery(answers_tr.eq(i)).find('.ays_answer_td').empty(); | |
| 469 | + var answer_html = '<p class="ays_answer">' + answer_text + '</p>'+((answer_text == '')?'<p>Answer</p>':''); | |
| 470 | + jQuery(answers_tr.eq(i)).find('.ays_answer_td').append(answer_html) | |
| 471 | + } | |
| 472 | + jQuery('.active_question').find('.ays_question_overlay').removeClass('display_none'); | |
| 473 | + jQuery('.active_question').removeClass('active_question'); | |
| 474 | + } | |
| 475 | + } | |
| 476 | + | |
| 477 | + function searchForPage(params, data) { | |
| 478 | + // If there are no search terms, return all of the data | |
| 479 | + if (jQuery.trim(params.term) === '') { | |
| 480 | + return data; | |
| 481 | + } | |
| 482 | + | |
| 483 | + // Do not display the item if there is no 'text' property | |
| 484 | + if (typeof data.text === 'undefined') { | |
| 485 | + return null; | |
| 486 | + } | |
| 487 | + var searchText = data.text.toLowerCase(); | |
| 488 | + // `params.term` should be the term that is used for searching | |
| 489 | + // `data.text` is the text that is displayed for the data object | |
| 490 | + if (searchText.indexOf(params.term) > -1) { | |
| 491 | + var modifiedData = jQuery.extend({}, data, true); | |
| 492 | + modifiedData.text += ' (matched)'; | |
| 493 | + | |
| 494 | + // You can return modified objects from here | |
| 495 | + // This includes matching the `children` how you want in nested data sets | |
| 496 | + return modifiedData; | |
| 497 | + } | |
| 498 | + | |
| 499 | + // Return `null` if the term should not be displayed | |
| 500 | + return null; | |
| 501 | + } | |
| 502 | + | |
| 503 | + function selectElementContents(el) { | |
| 504 | + if (window.getSelection && document.createRange) { | |
| 505 | + var _this = jQuery(document).find( el ); | |
| 506 | + | |
| 507 | + var text = el.textContent; | |
| 508 | + var textField = document.createElement('textarea'); | |
| 509 | + | |
| 510 | + textField.innerText = text; | |
| 511 | + document.body.appendChild(textField); | |
| 512 | + textField.select(); | |
| 513 | + document.execCommand('copy'); | |
| 514 | + textField.remove(); | |
| 515 | + | |
| 516 | + var selection = window.getSelection(); | |
| 517 | + selection.setBaseAndExtent(el,0,el,1); | |
| 518 | + | |
| 519 | + _this.attr( "data-original-title", aysChartBuilderAdmin.copied ); | |
| 520 | + _this.attr( "data-bs-original-title", aysChartBuilderAdmin.copied ); | |
| 521 | + _this.attr( "title", aysChartBuilderAdmin.copied ); | |
| 522 | + | |
| 523 | + _this.tooltip("show"); | |
| 524 | + | |
| 525 | + } else if (document.selection && document.body.createTextRange) { | |
| 526 | + var textRange = document.body.createTextRange(); | |
| 527 | + textRange.moveToElementText(el); | |
| 528 | + textRange.select(); | |
| 529 | + } | |
| 530 | + } | |
| 531 | + | |
| 532 | + function nl2br (str, is_xhtml) { | |
| 533 | + if (typeof str === 'undefined' || str === null) { | |
| 534 | + return ''; | |
| 535 | + } | |
| 536 | + var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>'; | |
| 537 | + return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2'); | |
| 538 | + } | |
| 539 | + | |
| 540 | + /** | |
| 541 | + * @return {string} | |
| 542 | + */ | |
| 543 | + function aysEscapeHtml(text) { | |
| 544 | + var map = { | |
| 545 | + '&': '&', | |
| 546 | + '<': '<', | |
| 547 | + '>': '>', | |
| 548 | + '"': '"', | |
| 549 | + "'": ''' | |
| 550 | + }; | |
| 551 | + return text.replace(/[&<>\"']/g, function(m) { return map[m]; }); | |
| 552 | + } | |
| 553 | + | |
| 554 | + function aysFormRgba2hex(orig, isAlpha) { | |
| 555 | + if( orig.indexOf('#') !== -1 ){ | |
| 556 | + if( isAlpha ){ | |
| 557 | + orig += "29"; | |
| 558 | + } | |
| 559 | + return orig; | |
| 560 | + } | |
| 561 | + | |
| 562 | + var a, isPercent, | |
| 563 | + rgb = orig.replace(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+),?([^,\s)]+)?/i), | |
| 564 | + alpha = (rgb && rgb[4] || "").trim(), | |
| 565 | + hex = rgb ? | |
| 566 | + (rgb[1] | 1 << 8).toString(16).slice(1) + | |
| 567 | + (rgb[2] | 1 << 8).toString(16).slice(1) + | |
| 568 | + (rgb[3] | 1 << 8).toString(16).slice(1) : orig; | |
| 569 | + | |
| 570 | + if (alpha !== "") { | |
| 571 | + a = alpha; | |
| 572 | + } else { | |
| 573 | + a = 01; | |
| 574 | + } | |
| 575 | + | |
| 576 | + // multiply before convert to HEX | |
| 577 | + if( isAlpha ){ | |
| 578 | + a = ((a * 255) | 1 << 8).toString(16).slice(1); | |
| 579 | + }else{ | |
| 580 | + a = ''; | |
| 581 | + } | |
| 582 | + | |
| 583 | + if( hex == '000000' || hex == '000' ){ | |
| 584 | + hex = '3366cc'; | |
| 585 | + } | |
| 586 | + | |
| 587 | + hex = '#' + hex + a; | |
| 588 | + | |
| 589 | + return hex; | |
| 590 | + } | |
| 591 | + | |
| 592 | + function openMediaUploaderForConditions(e, element) { | |
| 593 | + e.preventDefault(); | |
| 594 | + var aysUploader = wp.media({ | |
| 595 | + title: 'Upload', | |
| 596 | + button: { | |
| 597 | + text: 'Upload' | |
| 598 | + }, | |
| 599 | + multiple: false | |
| 600 | + }).on('select', function () { | |
| 601 | + var attachment = aysUploader.state().get('selection').first().toJSON(); | |
| 602 | + var $this = element; | |
| 603 | + var $thisParent = $this.parents('.ays-form-email-message-files'); | |
| 604 | + $thisParent.find('input.ays-form-email-message-editor-file').val(attachment.url); | |
| 605 | + $thisParent.find('.ays-form-email-message-files-content-text').html(attachment.filename); | |
| 606 | + $thisParent.find('.ays-form-email-message-files-content-text').attr("href" , attachment.url); | |
| 607 | + $thisParent.find('.ays-form-email-message-files-content-text').attr("download" , attachment.url); | |
| 608 | + $thisParent.find('.ays-form-email-message-editor-file-name').val(attachment.filename); | |
| 609 | + $thisParent.find('.ays-form-email-message-files-wrapper').removeClass("display_none_not_important"); | |
| 610 | + $thisParent.find('.ays-form-email-message-files-body').removeClass("display_none_not_important"); | |
| 611 | + $thisParent.find('.ays-form-add-email-message-files').html("Edit file"); | |
| 612 | + $thisParent.find('.ays-form-email-message-editor-file-id').val(attachment.id); | |
| 613 | + }).open(); | |
| 614 | + return false; | |
| 615 | + } | |
| 616 | + | |
| 617 | + function selectElementContentsCopy(element) { | |
| 618 | + var _this = element; | |
| 619 | + var text = _this.attr("data-clipboard-text"); | |
| 620 | + var newElement = jQuery('<textarea>').appendTo('body').val(text).select(); | |
| 621 | + document.execCommand('copy'); | |
| 622 | + newElement.remove(); | |
| 623 | + _this.attr( "data-original-title", aysChartBuilderAdmin.copied ); | |
| 624 | + _this.attr( "title", aysChartBuilderAdmin.copied ); | |
| 625 | + _this.tooltip("show"); | |
| 626 | + } | |
| 627 | + | |
| 628 | + function getEachSubmission(e){ | |
| 629 | + var notToTrigger = jQuery(e.target); | |
| 630 | + if(!notToTrigger.hasClass("ays-form-no-trigger")){ | |
| 631 | + var innerInput = jQuery(this).find(".ays_form_result"); | |
| 632 | + var innerInputVal = innerInput.val(); | |
| 633 | + var submissionIdStr = jQuery("#questions").find('.ays_submissions_id_str').val(); | |
| 634 | + var submissionIdArr = submissionIdStr.split(","); | |
| 635 | + var newSubmissionArr = []; | |
| 636 | + | |
| 637 | + for(var i = 0; i < submissionIdArr.length; i++ ){ | |
| 638 | + newSubmissionArr[i+1] = submissionIdArr[i]; | |
| 639 | + } | |
| 640 | + | |
| 641 | + var forInput = newSubmissionArr.indexOf(innerInputVal); | |
| 642 | + changeTabTo("questions"); | |
| 643 | + jQuery(document).find('.ays_number_of_result').val(forInput); | |
| 644 | + | |
| 645 | + setTimeout(function(){ | |
| 646 | + jQuery(document).find('.ays_number_of_result').trigger('change'); | |
| 647 | + }, 500); | |
| 648 | + | |
| 649 | + jQuery(document.body).goTo(); | |
| 650 | + } | |
| 651 | + } | |
| 652 | + | |
| 653 | + function changeTabTo(href){ | |
| 654 | + var newHref = "#"+href; | |
| 655 | + jQuery(document).find('.nav-tab-wrapper a.nav-tab').each(function () { | |
| 656 | + if (jQuery(this).hasClass('nav-tab-active')) { | |
| 657 | + jQuery(this).removeClass('nav-tab-active'); | |
| 658 | + } | |
| 659 | + }); | |
| 660 | + jQuery(document).find('a[href='+newHref+']').addClass('nav-tab-active'); | |
| 661 | + | |
| 662 | + jQuery(document).find('.ays-form-tab-content').each(function () { | |
| 663 | + jQuery(this).css('display', 'none'); | |
| 664 | + }); | |
| 665 | + | |
| 666 | + jQuery('.ays-form-tab-content' + newHref).css('display', 'block'); | |
| 667 | + } | |
| 668 | + | |
| 669 | +//})(jQuery); | |