| 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 |
jQuery(this).find('.ays-modal-content').css('animation-name', 'zoomOut'); |
| 36 |
setTimeout(function(){ |
| 37 |
jQuery(document.body).removeClass('modal-open'); |
| 38 |
jQuery(document).find('.ays-modal-backdrop').remove(); |
| 39 |
jQuerythis.hide(); |
| 40 |
}, 250); |
| 41 |
break; |
| 42 |
case 'show': |
| 43 |
default: |
| 44 |
jQuerythis.show(); |
| 45 |
jQuery(this).find('.ays-modal-content').css('animation-name', 'zoomIn'); |
| 46 |
jQuery(document).find('.modal-backdrop').remove(); |
| 47 |
jQuery(document.body).append('<div class="ays-modal-backdrop"></div>'); |
| 48 |
jQuery(document.body).addClass('modal-open'); |
| 49 |
break; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
function checkTrue(flag) { |
| 54 |
return flag === true; |
| 55 |
} |
| 56 |
|
| 57 |
function openMediaUploaderForImage(e, element) { |
| 58 |
e.preventDefault(); |
| 59 |
var aysUploader = wp.media({ |
| 60 |
title: 'Upload', |
| 61 |
button: { |
| 62 |
text: 'Upload' |
| 63 |
}, |
| 64 |
library: { |
| 65 |
type: 'image' |
| 66 |
}, |
| 67 |
multiple: false |
| 68 |
}).on('select', function () { |
| 69 |
var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 70 |
var wrap = element.parents('.ays-image-wrap'); |
| 71 |
wrap.find('.ays-image-container img').attr('src', attachment.url); |
| 72 |
wrap.find('input.ays-image-path').val(attachment.url); |
| 73 |
wrap.find('.ays-image-container').fadeIn(); |
| 74 |
wrap.find('a.ays-add-image').hide(); |
| 75 |
}).open(); |
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
// function openMediaUploader(e, element) { |
| 80 |
// e.preventDefault(); |
| 81 |
// var aysUploader = wp.media({ |
| 82 |
// title: 'Upload', |
| 83 |
// button: { |
| 84 |
// text: 'Upload' |
| 85 |
// }, |
| 86 |
// library: { |
| 87 |
// type: 'image' |
| 88 |
// }, |
| 89 |
// multiple: false |
| 90 |
// }).on('select', function () { |
| 91 |
// var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 92 |
// element.text('Edit Image'); |
| 93 |
// element.parent().parent().find('.ays-question-image-container').fadeIn(); |
| 94 |
// element.parent().parent().find('img#ays-question-img').attr('src', attachment.url); |
| 95 |
// element.parent().parent().find('input#ays-question-image').val(attachment.url); |
| 96 |
// }).open(); |
| 97 |
// return false; |
| 98 |
// } |
| 99 |
|
| 100 |
|
| 101 |
function openMediaUploader(e, element, type) { |
| 102 |
e.preventDefault(); |
| 103 |
var aysUploader = wp.media({ |
| 104 |
title: 'Upload', |
| 105 |
button: { |
| 106 |
text: 'Upload' |
| 107 |
}, |
| 108 |
library: { |
| 109 |
type: 'image' |
| 110 |
}, |
| 111 |
multiple: false |
| 112 |
}).on('select', function () { |
| 113 |
var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 114 |
switch(type){ |
| 115 |
case 'questionImgButton': |
| 116 |
var $this = element.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-image-container'); |
| 117 |
var hiddenInp = $this.find('.ays-survey-question-img-src'); |
| 118 |
var img = $this.find('img.ays-survey-question-img'); |
| 119 |
|
| 120 |
$this.removeAttr('style'); |
| 121 |
img.attr('src', attachment.url); |
| 122 |
hiddenInp.val(attachment.url); |
| 123 |
break; |
| 124 |
case 'answerImgButton': |
| 125 |
var answerImgCont = element.parents('.ays-survey-answer-row').find('.ays-survey-answer-image-container'); |
| 126 |
var parent = element.parents('.ays-survey-section-box'); |
| 127 |
|
| 128 |
var section_id = parent.data('id'); |
| 129 |
var question_id = element.parents('.ays-survey-question-answer-conteiner').data('id'); |
| 130 |
var answer_id = element.parents('.ays-survey-answer-row').data('id'); |
| 131 |
var imgInputName = element.parents('.ays-survey-answer-row').find('input.ays-survey-input').attr('name'); |
| 132 |
var checkInputName = imgInputName.indexOf('ays_section_add'); |
| 133 |
var inputName = false; |
| 134 |
if (checkInputName >= 0) { |
| 135 |
inputName = true; |
| 136 |
} |
| 137 |
|
| 138 |
var name = 'section'; |
| 139 |
if (inputName) { |
| 140 |
name = 'section_add'; |
| 141 |
} |
| 142 |
// var inputNameAttr = $html_name_prefix+name+'['+section_id+'][question]['+question_id+'][answers]['+answer_id+'][image]'; |
| 143 |
|
| 144 |
var img = answerImgCont.find('img.ays-survey-answer-img'); |
| 145 |
var hiddenInp = answerImgCont.find('input.ays-survey-answer-img-src'); |
| 146 |
|
| 147 |
img.attr('src', attachment.url); |
| 148 |
hiddenInp.val(attachment.url); |
| 149 |
answerImgCont.show(); |
| 150 |
img.removeClass('Fade'); |
| 151 |
break; |
| 152 |
} |
| 153 |
|
| 154 |
}).open(); |
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
function openMediaUploaderQuestionBg(e, element) { |
| 160 |
e.preventDefault(); |
| 161 |
var aysUploader = wp.media({ |
| 162 |
title: 'Upload Question Background', |
| 163 |
button: { |
| 164 |
text: 'Upload' |
| 165 |
}, |
| 166 |
library: { |
| 167 |
type: 'image' |
| 168 |
}, |
| 169 |
multiple: false |
| 170 |
}).on('select', function () { |
| 171 |
var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 172 |
element.text('Edit Image'); |
| 173 |
element.parent().parent().find('.ays-question-bg-image-container').fadeIn(); |
| 174 |
element.parent().parent().find('img#ays-question-bg-img').attr('src', attachment.url); |
| 175 |
element.parent().parent().find('input#ays-question-bg-image').val(attachment.url); |
| 176 |
}).open(); |
| 177 |
return false; |
| 178 |
} |
| 179 |
|
| 180 |
function openMusicMediaUploader(e, element) { |
| 181 |
e.preventDefault(); |
| 182 |
var aysUploader = wp.media({ |
| 183 |
title: 'Upload music', |
| 184 |
button: { |
| 185 |
text: 'Upload' |
| 186 |
}, |
| 187 |
library: { |
| 188 |
type: 'audio' |
| 189 |
}, |
| 190 |
multiple: false |
| 191 |
}).on('select', function () { |
| 192 |
var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 193 |
element.next().attr('src', attachment.url); |
| 194 |
element.parent().find('input.ays_quiz_bg_music').val(attachment.url); |
| 195 |
}).open(); |
| 196 |
return false; |
| 197 |
} |
| 198 |
|
| 199 |
function openQuizMediaUploader(e, element) { |
| 200 |
e.preventDefault(); |
| 201 |
var aysUploader = wp.media({ |
| 202 |
title: 'Upload', |
| 203 |
button: { |
| 204 |
text: 'Upload' |
| 205 |
}, |
| 206 |
library: { |
| 207 |
type: 'image' |
| 208 |
}, |
| 209 |
multiple: false |
| 210 |
}).on('select', function () { |
| 211 |
var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 212 |
if(element.hasClass('add-quiz-bg-image')){ |
| 213 |
element.parent().find('img#ays-quiz-bg-img').attr('src', attachment.url); |
| 214 |
element.parent().find('.ays-quiz-bg-image-container').fadeIn(); |
| 215 |
element.next().val(attachment.url); |
| 216 |
jQuery(document).find('.ays-quiz-live-container').css({'background-image': 'url("'+attachment.url+'")'}); |
| 217 |
element.hide(); |
| 218 |
}else if(element.hasClass('ays-edit-quiz-bg-img')){ |
| 219 |
element.parent().find('.ays-quiz-bg-image-container').fadeIn(); |
| 220 |
element.parent().find('img#ays-quiz-bg-img').attr('src', attachment.url); |
| 221 |
jQuery(document).find('#ays_quiz_bg_image').val(attachment.url); |
| 222 |
jQuery(document).find('.ays-quiz-live-container').css({'background-image': 'url("'+attachment.url+'")'}); |
| 223 |
}else{ |
| 224 |
element.text('Edit Image'); |
| 225 |
element.parent().parent().find('.ays-quiz-image-container').fadeIn(); |
| 226 |
element.parent().parent().find('img#ays-quiz-img').attr('src', attachment.url); |
| 227 |
jQuery('input#ays-quiz-image').val(attachment.url); |
| 228 |
var ays_quiz_theme = jQuery(document).find('input[name="ays_quiz_theme"]:checked').val(); |
| 229 |
switch (ays_quiz_theme) { |
| 230 |
case 'elegant_dark': |
| 231 |
case 'elegant_light': |
| 232 |
case 'rect_light': |
| 233 |
case 'rect_dark': |
| 234 |
case 'classic_dark': |
| 235 |
case 'classic_light': |
| 236 |
jQuery(document).find('#ays-quiz-live-image').attr('src', attachment.url); |
| 237 |
jQuery(document).find('#ays-quiz-live-image').css({'display': 'block'}); |
| 238 |
break; |
| 239 |
case 'modern_light': |
| 240 |
case 'modern_dark': |
| 241 |
jQuery(document).find('.ays-quiz-live-container').css({'background-image':'url('+attachment.url+')'}); |
| 242 |
jQuery(document).find('#ays-quiz-live-image').css({'display': 'none'}); |
| 243 |
jQuery(document).find('#ays-quiz-live-button').css('border','1px solid'); |
| 244 |
break; |
| 245 |
default: |
| 246 |
jQuery(document).find('#ays-quiz-live-image').attr('src', attachment.url); |
| 247 |
jQuery(document).find('#ays-quiz-live-image').css({'display': 'block'}); |
| 248 |
break; |
| 249 |
|
| 250 |
} |
| 251 |
} |
| 252 |
}).open(); |
| 253 |
|
| 254 |
return false; |
| 255 |
} |
| 256 |
|
| 257 |
function openAnswerMediaUploader(e, element) { |
| 258 |
e.preventDefault(); |
| 259 |
var aysUploader = wp.media({ |
| 260 |
title: 'Upload', |
| 261 |
button: { |
| 262 |
text: 'Upload' |
| 263 |
}, |
| 264 |
library: { |
| 265 |
type: 'image' |
| 266 |
}, |
| 267 |
multiple: false |
| 268 |
}).on('select', function () { |
| 269 |
var attachment = aysUploader.state().get('selection').first().toJSON(); |
| 270 |
element.parents().eq(1).find('.add-answer-image').css({'display': 'none'}) |
| 271 |
element.parent().parent().find('.ays-answer-image-container').fadeIn(); |
| 272 |
element.parent().parent().find('img.ays-answer-img').attr('src', attachment.url); |
| 273 |
element.parents('tr').find('input.ays-answer-image-path').val(attachment.url); |
| 274 |
if(element.hasClass('add-interval-image')){ |
| 275 |
element.parent().parent().find('img').attr('src', attachment.url); |
| 276 |
element.parents('tr').find('input.ays-answer-image').val(attachment.url); |
| 277 |
} |
| 278 |
}).open(); |
| 279 |
return false; |
| 280 |
} |
| 281 |
|
| 282 |
function show_hide_rows(page) { |
| 283 |
|
| 284 |
var rows = jQuery('table.ays-add-questions-table tbody tr'); |
| 285 |
rows.each(function (index) { |
| 286 |
jQuery(this).css('display', 'none'); |
| 287 |
}); |
| 288 |
var counter = page * 5 - 4; |
| 289 |
for (var i = counter; i < (counter + 5); i++) { |
| 290 |
rows.eq(i - 1).css('display', 'table-row'); |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
function createPagination(pagination, pagesCount, pageShow) { |
| 295 |
(function (baseElement, pages, pageShow) { |
| 296 |
var pageNum = 0, pageOffset = 0; |
| 297 |
|
| 298 |
function _initNav() { |
| 299 |
var appendAble = ''; |
| 300 |
for (var i = 0; i < pagesCount; i++) { |
| 301 |
var activeClass = (i === 0) ? 'active' : ''; |
| 302 |
appendAble += '<li class="' + activeClass + ' ays-question-page" data-page="' + (i + 1) + '">' + (i + 1) + '</li>'; |
| 303 |
} |
| 304 |
jQuery('ul.ays-question-nav-pages').html(appendAble); |
| 305 |
var pagePos = (jQuery('div.ays-question-pagination').width()/2) - (parseInt(jQuery('ul.ays-question-nav-pages>li:first-child').css('width'))/2); |
| 306 |
jQuery('ul.ays-question-nav-pages').css({ |
| 307 |
'margin-left': pagePos, |
| 308 |
}); |
| 309 |
//init events |
| 310 |
var toPage; |
| 311 |
baseElement.on('click', '.ays-question-nav-pages li, .ays-question-nav-btn', function (e) { |
| 312 |
if (jQuery(e.target).is('.ays-question-nav-btn')) { |
| 313 |
toPage = jQuery(this).hasClass('ays-question-prev') ? pageNum - 1 : pageNum + 1; |
| 314 |
} else { |
| 315 |
toPage = jQuery(this).index(); |
| 316 |
} |
| 317 |
var page = Number(toPage) + 1; |
| 318 |
show_hide_rows(page); |
| 319 |
_navPage(toPage); |
| 320 |
}); |
| 321 |
} |
| 322 |
|
| 323 |
function _navPage(toPage) { |
| 324 |
var sel = jQuery('.ays-question-nav-pages li', baseElement), w = sel.first().outerWidth(), |
| 325 |
diff = toPage - pageNum; |
| 326 |
|
| 327 |
if (toPage >= 0 && toPage <= pages - 1) { |
| 328 |
sel.removeClass('active').eq(toPage).addClass('active'); |
| 329 |
pageNum = toPage; |
| 330 |
} else { |
| 331 |
return false; |
| 332 |
} |
| 333 |
|
| 334 |
if (toPage <= (pages - (pageShow + (diff > 0 ? 0 : 1))) && toPage >= 0) { |
| 335 |
pageOffset = pageOffset + -w * diff; |
| 336 |
} else { |
| 337 |
pageOffset = (toPage > 0) ? -w * (pages - pageShow) : 0; |
| 338 |
} |
| 339 |
|
| 340 |
sel.parent().css('left', pageOffset + 'px'); |
| 341 |
} |
| 342 |
|
| 343 |
_initNav(); |
| 344 |
|
| 345 |
})(pagination, pagesCount, pageShow); |
| 346 |
} |
| 347 |
|
| 348 |
// window.onload = function () { |
| 349 |
// if (document.getElementById('import_button')) { |
| 350 |
// document.getElementById('import_button').addEventListener('click', function () { |
| 351 |
// document.getElementById('import_file').click(); |
| 352 |
// }); |
| 353 |
//// document.getElementById('example_button').addEventListener('click', function () { |
| 354 |
//// document.getElementById('example_file').click(); |
| 355 |
//// }); |
| 356 |
// } |
| 357 |
// } |
| 358 |
|
| 359 |
function activate_question(element){ |
| 360 |
element.find('.ays_question_overlay').addClass('display_none'); |
| 361 |
element.find('.ays_fa.ays_fa_times').parent() |
| 362 |
.removeClass('show_remove_answer') |
| 363 |
.addClass('active_remove_answer'); |
| 364 |
element.find('.ays_add_answer').parents().eq(1).removeClass('show_add_answer'); |
| 365 |
element.addClass('active_question'); |
| 366 |
var this_question = element.find('.ays_question').text(); |
| 367 |
element.find('.ays_question').remove(); |
| 368 |
element.prepend('<input type="text" value="' + this_question + '" class="ays_question_input">'); |
| 369 |
var answers_tr = element.find('.ays_answers_table tr'); |
| 370 |
for (var i = 0; i < answers_tr.length; i++) { |
| 371 |
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'"; |
| 372 |
jQuery(answers_tr.eq(i)).find('.ays_answer_td').empty(); |
| 373 |
jQuery(answers_tr.eq(i)).find('.ays_answer_td').append('<input type="text" ' + answer_text + ' class="ays_answer">'); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
function deactivate_questions() { |
| 378 |
if (jQuery('.active_question').length !== 0) { |
| 379 |
var question = jQuery('.active_question').eq(0); |
| 380 |
if(!jQuery(question).find('input[name^="ays_answer_radio"]:checked').length){ |
| 381 |
jQuery(question).find('input[name^="ays_answer_radio"]').eq(0).attr('checked',true) |
| 382 |
} |
| 383 |
jQuery(question).find('.ays_add_answer').parents().eq(1).addClass('show_add_answer'); |
| 384 |
jQuery(question).find('.fa.fa-times').parent().removeClass('active_remove_answer').addClass('show_remove_answer'); |
| 385 |
|
| 386 |
var question_text = jQuery(question).find('.ays_question_input').val(); |
| 387 |
jQuery(question).find('.ays_question_input').remove(); |
| 388 |
jQuery(question).prepend('<p class="ays_question">' + question_text + '</p>'); |
| 389 |
var answers_tr = jQuery(question).find('.ays_answers_table tr'); |
| 390 |
for (var i = 0; i < answers_tr.length; i++) { |
| 391 |
var answer_text = (jQuery(answers_tr.eq(i)).find('.ays_answer').val()) ? jQuery(answers_tr.eq(i)).find('.ays_answer').val() : ''; |
| 392 |
jQuery(answers_tr.eq(i)).find('.ays_answer_td').empty(); |
| 393 |
var answer_html = '<p class="ays_answer">' + answer_text + '</p>'+((answer_text == '')?'<p>Answer</p>':''); |
| 394 |
jQuery(answers_tr.eq(i)).find('.ays_answer_td').append(answer_html) |
| 395 |
} |
| 396 |
jQuery('.active_question').find('.ays_question_overlay').removeClass('display_none'); |
| 397 |
jQuery('.active_question').removeClass('active_question'); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
function searchForPage(params, data) { |
| 402 |
// If there are no search terms, return all of the data |
| 403 |
if (jQuery.trim(params.term) === '') { |
| 404 |
return data; |
| 405 |
} |
| 406 |
|
| 407 |
// Do not display the item if there is no 'text' property |
| 408 |
if (typeof data.text === 'undefined') { |
| 409 |
return null; |
| 410 |
} |
| 411 |
var searchText = data.text.toLowerCase(); |
| 412 |
// `params.term` should be the term that is used for searching |
| 413 |
// `data.text` is the text that is displayed for the data object |
| 414 |
if (searchText.indexOf(params.term) > -1) { |
| 415 |
var modifiedData = jQuery.extend({}, data, true); |
| 416 |
modifiedData.text += ' (matched)'; |
| 417 |
|
| 418 |
// You can return modified objects from here |
| 419 |
// This includes matching the `children` how you want in nested data sets |
| 420 |
return modifiedData; |
| 421 |
} |
| 422 |
|
| 423 |
// Return `null` if the term should not be displayed |
| 424 |
return null; |
| 425 |
} |
| 426 |
|
| 427 |
function selectElementContents(el) { |
| 428 |
if (window.getSelection && document.createRange) { |
| 429 |
var sel = window.getSelection(); |
| 430 |
var range = document.createRange(); |
| 431 |
range.selectNodeContents(el); |
| 432 |
sel.removeAllRanges(); |
| 433 |
sel.addRange(range); |
| 434 |
} else if (document.selection && document.body.createTextRange) { |
| 435 |
var textRange = document.body.createTextRange(); |
| 436 |
textRange.moveToElementText(el); |
| 437 |
textRange.select(); |
| 438 |
} |
| 439 |
} |
| 440 |
//})(jQuery); |
| 441 |
|