UNPKG

adxutil

Version:

Utilities tools for Askia Design eXtension

1 lines 4.59 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(){if(f)return void(g=!0);f=!0,g=!1,a.ajax({url:"AskiaExt.dll",data:a.serializeForm(document.forms[0],"DoLiveRouting"),success:j,complete:k})}function j(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 k(){f=!1,h=!1,g&&setTimeout(i,250)}if(window.arrLiveRoutingInputCode&&!(window.arrLiveRoutingInputCode.length<=0)){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(){if(!a.triggerEvent("askiaAnswer"))return!1;a.defaultEventActions.askiaAnswer()};var f=!1,g=!1,h=!0;document.addEventListener("DOMContentLoaded",function(){document.addEventListener("change",function(b){var c=b.target||b.srcElement,d=/^[a-z]+([0-9]+)(?:\s*|\_*)/i.exec(c.name);d&&window.arrLiveRoutingInputCode.indexOf(d[1])>-1&&("INPUT"===c.nodeName&&(c.parentElement.className.indexOf("askia-response")>=0||c.parentElement.className.indexOf("askia-control")>=0||c.parentElement.className.indexOf("askia-grid-row")>=0||c.parentElement.parentElement.className.indexOf("askia-grid-row")>=0)&&("radio"===c.type||"checkbox"===c.type)||"SELECT"===c.nodeName)&&a.triggerAnswer()}),document.addEventListener("input",function(b){var c=b.target||b.srcElement,d=/^[a-z]+([0-9]+)(?:\s*|\_*)/i.exec(c.name);d&&window.arrLiveRoutingInputCode.indexOf(d[1])>-1&&("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))&&(c.parentElement.className.indexOf("askia-response")>=0||c.parentElement.className.indexOf("askia-control")>=0||c.parentElement.className.indexOf("askia-grid-row")>=0||c.parentElement.parentElement.className.indexOf("askia-grid-row")>=0||c.className.indexOf("askia-live")>=0)&&a.triggerAnswer()}),a.triggerAnswer()})}}();