UNPKG

adxutil

Version:

Utilities tools for Askia Design eXtension

1 lines 4.62 kB
!function(){function a(a,b){b=b||{bubbles:!1,cancelable:!1,detail:void 0};var c=document.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c}a.prototype=window.Event.prototype,window.CustomEvent=a}(),function(){function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}function c(a,b){if("function"==typeof b){var g,h,c=/^(?:submit|button|image|reset|file)$/i,d=/^(?:input|select|textarea|keygen)/i,e=/^(?:checkbox|radio)$/i,f=a.elements;for(g=0,h=f.length;g<h;g+=1){var i=f[g];!i.name||i.disabled||null===i.value||c.test(i.type)||!d.test(i.nodeName)||e.test(i.type)&&!i.checked||b(i)}}}function d(a){if(a.question.inputCode>=0){var e,f,b=/^(?:show)/i.test(a.action),c=".askia-question-"+a.question.inputCode,d=document.querySelectorAll(c);for(e=0,f=d.length;e<f;e+=1)d[e].style.display=b?"":"none"}}function e(){h||window.location.reload()}function i(){return f?void(g=!0):(f=!0,g=!1,void a.ajax({url:"AskiaExt.dll",data:a.serializeForm(document.forms[0],"DoLiveRouting"),success:k,complete:l}))}function k(c){var f,g,h,i,d=JSON.parse(c),e=d.actions||[];for(f=0,g=e.length;f<g;f+=1)h=e[f],i="askia"+b(h.action),a.triggerEvent(i,h)&&"function"==typeof a.defaultEventActions[i]&&a.defaultEventActions[i](h)}function l(){f=!1,h=!1,g&&setTimeout(i,250)}function m(a){for(var c=(a.name,a.parentNode.parentNode.parentNode),d=1;j=c.children.length,d<j;d++)a.parentNode.className.indexOf("exclusive")>=0&&c.children[d].children[0]!==a&&c.children[d].className.indexOf("selected")>=0?(document.getElementById(c.children[d].children[0].attributes.id.value).checked=!1,removeClass(c.children[d],"selected")):!(a.parentNode.className.indexOf("exclusive")>=0)&&c.children[d].children[0]!==a&&c.children[d].className.indexOf("selected")>=0&&c.children[d].className.indexOf("exclusive")>=0&&(document.getElementById(c.children[d].children[0].attributes.id.value).checked=!1,removeClass(c.children[d],"selected"))}window.AskiaScript&&(AskiaScript.executeLiveRouting=function(){});var a=window.askia||{};window.askia||(window.askia=a),a.serializeForm=function(b,d){var e=[];return c(b,function(a){var b=a.name,c=a.value.replace(/\r?\n/gi,"\r\n");d&&/^(?:action)$/i.test(a.name)&&(c=d.replace(/\r?\n/gi,"\r\n")),e.push(encodeURIComponent(b)+"="+encodeURIComponent(c))}),e.join("&")},a.ajax=function(b){if(!b)return void(console&&console.warn("The `query` argument must be a valid object for askia.ajax()"));if(!b.url||"string"!=typeof b.url)return void(console&&console.warn("The `query.url` argument must be a valid string for askia.ajax()"));if(b.method=(b.method&&b.method.toString()||"POST").toUpperCase(),!/^(?:GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|CONNECT)$/.test(b.method))return void(console&&console.warn("The `query.method` argument must be a valid HTTP method for askia.ajax()"));var c=new XMLHttpRequest;c.open(b.method,b.url,!0),c.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),c.onload=function(){var d=c.responseText;c.status>=200&&c.status<400?"function"==typeof b.success&&b.success(d,c):"function"==typeof b.error&&b.error(d,c),"function"==typeof b.complete&&b.complete(d,c)},c.onerror=function(){"function"==typeof b.error&&b.error(text,c),"function"==typeof b.complete&&b.complete(text,c)},c.send(b.data||null)},a.defaultEventActions={askiaAnswer:i,askiaShowQuestion:d,askiaHideQuestion:d,askiaShowResponses:null,askiaHideResponses:null,askiaReload:e,askiaSetValue:null,askiaShowMessage:null,askiaChangeQuestionsOrder:null,askiaChangeResponsesOrder:null,askiaInfo:null},a.triggerEvent=function(b,c){var d=void 0!==c?{detail:c}:void 0,e=new CustomEvent(b,d);return document.dispatchEvent(e)},a.triggerAnswer=function(){return!!a.triggerEvent("askiaAnswer")&&void a.defaultEventActions.askiaAnswer()};var f=!1,g=!1,h=!0;document.addEventListener("DOMContentLoaded",function(){document.addEventListener("click",function(a){var b=a.target||a.srcElement;"INPUT"===b.nodeName&&"checkbox"===b.type&&b.className.indexOf("askia-exclusive")>=0&&m(b)}),document.addEventListener("change",function(b){var c=b.target||b.srcElement;("INPUT"!==c.nodeName||"radio"!==c.type&&"checkbox"!==c.type)&&"SELECT"!==c.nodeName||a.triggerAnswer()}),document.addEventListener("input",function(b){var c=b.target||b.srcElement;"TEXTAREA"!==c.nodeName&&("INPUT"!==c.nodeName||"color"!==c.type&&"date"!==c.type&&"datetime"!==c.type&&"email"!==c.type&&"month"!==c.type&&"number"!==c.type&&"password"!==c.type&&"range"!==c.type&&"search"!==c.type&&"tel"!==c.type&&"text"!==c.type&&"time"!==c.type&&"url"!==c.type&&"week"!==c.type)||a.triggerAnswer()}),a.triggerAnswer()})}();