AlkantarClanX12
Current Path : /proc/self/root/home/thanudqk/siamfreetour.com/wp-content/plugins/hd-quiz/assets/ |
Current File : //proc/self/root/home/thanudqk/siamfreetour.com/wp-content/plugins/hd-quiz/assets/admin_bundled.js |
(()=>{var c=async function(e="",t={}){let n=await o(e,t),a=null;if(ajaxurl&&(a=ajaxurl),ajaxurl===null){console.error("No ajax url found");return}let i=new FormData;i.append("action",e);for(let[m,g]of Object.entries(t))i.append(m,g);let s=document.getElementById("hd_wpnonce").value;i.append("HD_NONCE",s);let l=await fetch(a,{method:"POST",credentials:"same-origin",body:i});return l=await l.json(),l;async function o(m,g){let w="";for(let y in g)w+="&"+y+"="+g[y];return`action=${m}`+w}function h(m){console.log(m)}};var f={get:async function(e,t=null){console.log("getting the dashboard");let n=await f.getData();await f.render(n),_hd.init();let a=document.getElementById("hd_save");a.setAttribute("tabindex",0),document.getElementById("hdq_quiz_name").addEventListener("keyup",function(s){s.key==="Enter"&&a.click()});let i=document.getElementsByClassName("hdq_quiz_item");for(let s=0;s<i.length;s++)i[s].addEventListener("click",function(l){l.target.tagName=="CODE"&&l.preventDefault()})},getData:async function(){return await c("hdq_get_view_dashboard",{})},render:async function(e){document.getElementById("hdq_content").innerHTML=e.html,document.getElementById("hdq_content").scrollTo(0,0),document.getElementById("hdq_loading").classList.remove("active")}};var r={get:async function(e,t=null){console.log("getting the quiz ID "+t);let n=await r.getData(t);await r.render(n)},getData:async function(e){let t=1;e[1]&&(t=e[1]);let n={quiz_id:e[0],paged:t};return console.log(n),await c("hdq_get_view_quiz",n)},render:async function(e){document.getElementById("hdq_content").innerHTML=e.html,document.getElementById("hdq_content").scrollTo(0,0),document.getElementById("hdq_loading").classList.remove("active"),_hd.init(),HDQ.form.createEditors(),HDQ.form.tabs(),document.getElementById("hdq_copy_shortcode").addEventListener("click",function(){navigator.clipboard.writeText(this.innerText)}),e.type==="personality"&&r.personality.init(),HDQ.sort.init(),r.question_order.init();let t=document.getElementById("hd_delete_quiz");if(!t)return;t.addEventListener("click",async function(){confirm("You are about to delete this entire quiz and all attached questions. Continue?")&&n(this)});async function n(a){let i={quiz_id:parseInt(a.getAttribute("data-quiz"))},s=await c("hdq_delete_quiz",i);console.log(s),HDQ.router.views.dashboard.get(null,[])}return e},question_order:{init:function(){_hd.validate.field.hdq_field_question_order=r.question_order.validate},validate:async function(e){return{value:await r.question_order.getData(e),status:!0}},getData:async function(){let e=document.getElementsByClassName("hdq_quiz_question"),t=[];for(let n=0;n<e.length;n++){let a=parseInt(e[n].getAttribute("data-id"));t.push(a)}return t}},personality:{saved:{hasAdded:!1,hasSaved:!1},init:function(){_hd.validate.field.hdq_field_personality_results=r.personality.validate,document.getElementById("hdq_add_new_personality_outcome").addEventListener("click",function(){r.personality.create()}),r.personality.remove.init(),document.getElementById("hd_save").addEventListener("click",function(e){r.personality.saved.hasSaved=!0}),document.getElementById("hdq_add_new_quiz").addEventListener("click",function(e){r.personality.saved.hasAdded&&!r.personality.saved.hasSaved&&document.getElementsByClassName("hdq_outcome_label").length>1&&(e.preventDefault(),confirm("You have added a new outcome but have not saved. Contunue to adding a new question?")&&(window.location=this.href))})},remove:{init:function(){let e=document.getElementsByClassName("hdq_remove_outcome");for(let t=0;t<e.length;t++)e[t].addEventListener("click",function(){this.parentElement.remove()})}},validate:async function(e){await tinyMCE.triggerSave();let t=e.getAttribute("id"),n=[],a=e.getElementsByClassName("hdq_outcome_label"),i=e.getElementsByClassName("hd_editor_input");for(let o=0;o<a.length;o++)n.push({label:a[o].value,id:a[o].value.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi,"").replaceAll(" ","_").toLowerCase()+""+o,content:i[o].value});let s=!0;for(let o=0;o<n.length;o++)n[o].label==""?(s=!1,a[o].classList.add("hd_error")):a[o].classList.remove("hd_error");return{value:n,status:s}},create:function(){r.personality.saved.hasAdded=!0;let e=document.getElementById("personality_results").getElementsByClassName("hd_input_item").length;e=String.fromCharCode(e+65);let t=`<div class="hd_input_item"> <div class="hdq_remove_outcome" title="Remove this outcome">x</div> <label class="hd_input_label" for="hdq_result_${e}"><span class="hd_required_icon"></span> Outcome title <span class="hd_tooltip_item">?<span class="hd_tooltip"><div class="hd_tooltip_content">NOTE: If you rename this outcome, you will need to re-edit your questions to set the correct answer.</div></span></span></label> <input type="text" data-type="text" data-required="required" class="hd_input hdq_outcome_label" id="hdq_result_${e}" value="Result ${e}" placeholder="Result title..." data-tab="Results" /> <div id="wp-hdq_result_content_result_${e}-wrap" class="wp-core-ui wp-editor-wrap tmce-active"> <link rel="stylesheet" id="dashicons-css" href="https://hdquiz.local/wp-includes/css/dashicons.min.css?ver=6.6.2" media="all" /> <link rel="stylesheet" id="editor-buttons-css" href="https://hdquiz.local/wp-includes/css/editor.min.css?ver=6.6.2" media="all" /> <div id="wp-hdq_result_content_result_${e}-editor-tools" class="wp-editor-tools hide-if-no-js"> <div id="wp-hdq_result_content_result_${e}-media-buttons" class="wp-media-buttons"> <button type="button" id="insert-media-button" class="button insert-media add_media" data-editor="hdq_result_content_result_${e}"><span class="wp-media-buttons-icon"></span> Add Media</button> </div> <div class="wp-editor-tabs"> <button type="button" id="hdq_result_content_result_${e}-tmce" class="wp-switch-editor switch-tmce" data-wp-editor-id="hdq_result_content_result_${e}">Visual</button> <button type="button" id="hdq_result_content_result_${e}-html" class="wp-switch-editor switch-html" data-wp-editor-id="hdq_result_content_result_${e}">Text</button> </div> </div> <div id="wp-hdq_result_content_result_${e}-editor-container" class="wp-editor-container"> <div id="qt_hdq_result_content_result_${e}_toolbar" class="quicktags-toolbar hide-if-no-js"></div> <textarea class="hd_input hd_editor_input wp-editor-area" style="height: 240px" autocomplete="off" cols="40" name="hdq_result_content_result_${e}" id="hdq_result_content_result_${e}" data-type="editor" data-lt-tmp-id="lt-8142" spellcheck="false" data-gramm="false"></textarea> </div> </div> </div>`;document.getElementById("personality_results").insertAdjacentHTML("beforeend",t),HDQ.form.createEditors(),r.personality.remove.init()}}};var d={get:async function(e,t=null){console.log("getting the question ID "+t[1]);let n=await d.getData(t);await d.render(n)},getData:async function(e){let t={quiz_id:parseInt(e[0]),question_id:parseInt(e[1])};return await c("hdq_get_view_question",t)},render:async function(e){document.getElementById("hdq_content").innerHTML=e.html,document.getElementById("hdq_content").scrollTo(0,0),document.getElementById("hdq_loading").classList.remove("active"),_hd.init(),HDQ.form.createEditors(),HDQ.form.tabs(),d.answers.data.question_id=e.question_id,d.answers.data.quiz_id=e.quiz_id,d.answers.init();let t=document.getElementById("hd_delete_question");if(!t)return;t.addEventListener("click",async function(){confirm("You are about to delete this question. Continue?")&&n(this)});async function n(a){let i={quiz_id:parseInt(a.getAttribute("data-quiz")),question_id:parseInt(a.getAttribute("data-id"))},s=await c("hdq_delete_question",i);HDQ.router.views.quiz.get(s.action.data,s.action.data2);let l={quiz_id:s.action.data2};history.pushState(l,"")}},update:function(e){document.getElementById("question_id").value=parseInt(e[0]),document.getElementById("hd_delete_question").setAttribute("data-id",parseInt(e[0]))},answers:{data:{answers:[],question_id:0,quiz_id:0,defaults:{value:"",image:"",imageURL:"",selected:""}},init:function(){d.answers.onChangeQuestionType(),d.fieldAnswers.init()},onChangeQuestionType:function(){let e=document.getElementById("question_type");e&&(e.addEventListener("change",async function(){d.answers.changeQuestionType(this)}),setTimeout(function(){e.options[0].selected&&(e.options[1].selected=!0);let t=new Event("change");e.dispatchEvent(t)},10))},changeQuestionType:async function(e){document.getElementById("hdq_loading").classList.add("active");let t=document.getElementById("question_type"),n=e.value;if(n===""||n===null){t.options[1].selected=!0;let i=new Event("change");t.dispatchEvent(i);return}let a={question_type:n,question_id:d.answers.data.question_id,quiz_id:d.answers.data.quiz_id};d.answers.data.answers=await d.answers.getAnswerData(),a=await c("hdq_get_question_type",a),a.status&&a.status==="success"?(document.getElementById("question_answers").innerHTML=a.html,a.action&&a.action.name&&(console.log("running action "+a.action.name),HDQ[a.action.name]()),d.answers.setAnswerData(d.answers),document.getElementById("hdq_loading").classList.remove("active")):console.log(a)},getAnswerData:async function(e=document.getElementById("question_answers")){let t=e.getElementsByClassName("hdq_answer_row");if(t.length===0)return[[],!1];let n=[];for(let i=0;i<t.length;i++){let s=JSON.parse(JSON.stringify(d.answers.data.defaults)),l=t[i].getElementsByClassName("hdq_answer_item_input");for(let o=0;o<l.length;o++){let h=l[o].getAttribute("data-answer-type");l[o].getAttribute("type")=="checkbox"?l[o].checked&&(s[h]="yes"):l[o].getAttribute("data-value")?s[h]=l[o].getAttribute("data-value"):s[h]=l[o].value}n.push(s)}let a=[];for(let i=0;i<n.length;i++)n[i].value&&n[i].value!==""&&a.push(n[i]);return[a,!0]},setAnswerData:async function(){let e=d.answers.data.answers[0];if(e.length===0)return;let t=document.getElementsByClassName("hdq_answer_row");for(let n=0;n<t.length;n++){let a=t[n].getElementsByClassName("hdq_answer_item_input");for(let i=0;i<a.length;i++){let s=a[i].getAttribute("data-answer-type");e[n]&&e[n][s]&&(a[i].getAttribute("type")=="checkbox"?a[i].checked=!0:a[i].getAttribute("data-value")?(a[i].setAttribute("data-value",e[n][s]),s==="image"&&(a[i].innerHTML="",a[i].insertAdjacentElement("beforeend",e[n].imageURL),a[i].nextElementSibling.classList.add("active"))):a[i].value=e[n][s])}}}},fieldAnswers:{init:function(){_hd.validate.field.hdq_field_answers=d.fieldAnswers.validate},validate:async function(e){let t=!0,n=await d.answers.getAnswerData(e),a=n[0];return n[1]&&a.length==0&&(t=!1),{value:a,status:t}}}};var v={dashboard:f,quiz:r,question:d,reload:{get:function(e){location.reload(!0)}}};var u={views:v,init:async function(){await u.getView(),window.addEventListener("hashchange",async function(){u.getView()})},getHash:async function(){let e=window.location.hash;return e.length==0&&(e="#/dashboard"),e},getView:async function(e=null){let t=await u.getHash();return t=t.replaceAll("#/",""),e=t.split("/"),e.shift(),t=t.split("/")[0],v[t]?u.views[t].get(t,e):console.error("HD Quiz: View "+t+" could not be found"),document.getElementById("hdq_loading").classList.add("active"),t}};var q={tabs:function(){let e=document.getElementsByClassName("hdq_quiz_tab");for(let n=0;n<e.length;n++)e[n].addEventListener("click",function(){t(),this.classList.add("hdq_quiz_tab_active");let a=this.getAttribute("data-id");document.getElementById(a).classList.add("hdq_tab_content_active")});function t(){let n=document.getElementsByClassName("hdq_quiz_tab_active");for(;n.length>0;)n[0].classList.remove("hdq_quiz_tab_active");let a=document.getElementsByClassName("hdq_tab_content_active");for(;a.length>0;)a[0].classList.remove("hdq_tab_content_active")}},createEditors:function(){let e=document.getElementsByClassName("hd_editor_input");for(let n=0;n<e.length;n++){let a=e[n].getAttribute("id");tinyMCE.execCommand("mceRemoveEditor",!1,a)}setTimeout(t,1600);function t(){tinyMCE.init({mode:"textareas",relative_urls:!1,remove_script_host:!1,convert_urls:!0,browser_spellcheck:!0,entity_encoding:"raw",keep_styles:!1,resize:!0,content_style:"body { height: 100vh; min-height: 120px }",menubar:!1,branding:!1,wpeditimage_html5_captions:!0,plugins:"charmap,colorpicker,hr,lists,media,paste,tabfocus,textcolor,wordpress,wpautoresize,wpeditimage,wpemoji,wpgallery,wplink,wpdialogs,wptextpattern,wpview",wpautop:!0,indent:!1,toolbar1:"formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,dfw,wp_adv",toolbar2:"strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help",toolbar3:"",toolbar4:"",tabfocus_elements:"content-html,save-post",wp_autoresize_on:!0,add_unload_trigger:!1,block_formats:"Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Code=code"})}}};var _={init:function(){let e=document.getElementById("hdq_questions_list").getElementsByClassName("hdq_quiz_question");for(let t=0;t<e.length;t++)_.enableDragItem(e[t])},enableDragItem:function(e){e.setAttribute("draggable",!0),e.ondrag=_.handleDrag,e.ondragend=_.handleDrop},handleDrag:function(e){let t=e.target,n=e.clientX,a=e.clientY,i=[document.getElementById("hdq_questions_list")];t.classList.add("drag-sort-active");let s=document.elementFromPoint(n,a)===null?t:document.elementFromPoint(n,a);if(s!==null&&s.getAttribute("draggable")=="true")for(let l=0;l<i.length;l++)s!==null&&i[l]===s.parentNode&&(s=s!==t.nextSibling?s:s.nextSibling,i[l].insertBefore(t,s))},handleDrop:function(e){e.target.classList.remove("drag-sort-active"),document.getElementById("hdq_questions_list").classList.add("hderp")}};var p={init:async function(){console.log("HD Quiz v"+HDQ_VERSION+" init");async function e(){await p.router.init()}await e(),p.form.createEditors()},router:u,form:q,sort:_,images:function(){_hd.images.init()},reload:function(e){let t=e.getAttribute("href");window.location.href.includes(t)&&window.location.reload()}};p.init();window.HDQ=p;})(); //# sourceMappingURL=admin_bundled.js.map