var code = 'EKM1-1'; var checklist = '0'; window.addEventListener ? window.addEventListener("load",ekkofyExpress,false) : window.attachEvent && window.attachEvent("onload",ekkofyExpress); function ekkofyExpress() { document.body.innerHTML += ""; //Valores por defecto ekkofyExpressConfigDefault = { "idContenedor" : null, // Id del elemento donde se van a cargar los contenidos de ekkofy "flotante" : null, // Si es un botón flotante {top:"auto",bottom:"10%",left:"auto",right:"5px"} "idEmail" : null, // id o id's de los campos de email del vocero o afiliado para cuando el campo ya existe en el formulario "idCelular" : null, // id o id's de los campos de celular del vocero o afiliado para cuando el campo ya existe en el formulario "idNombre" : null, // id o id's de los campos de nombre del vocero o afiliado para cuando el campo ya existe en el formulario "idApellido" : null, // id o id's de los campos de apellido del vocero o afiliado para cuando el campo ya existe en el formulario "idDateBirth" : null, // id o id's de los campos de dateBirth del vocero o afiliado para cuando el campo ya existe en el formulario "idBoton" : null, // id o id's de los botones/enlaces que van a abrir el modal "textoBoton" : null, //Texto del botón que aparece luego de confirmar el bono "classBoton" : null, //Clase(s) del botón que aparece luego de confirmar el bono "html" : null, // Botón que aprece luego de confirmar el bono (reemplaza textoBoton y classBoton) "conJquery" : true, // si se carga jQuery 3.4.1 o no "conBootstrap" : true, // si se carga Bootstrap 4.4.1 o no "conPopper" : true, // si se carga Popper 1.16.0 o no "conFontAwesome" : true, // si se carga FontAwesome 5 o no }; // Obtener el tag del script y las opciones de configuración var scriptTag = document.getElementById("ekkofyExpressScript"); if (typeof scriptTag === 'undefined' || scriptTag === null){ var scriptTags = document.getElementsByTagName('script'); if (scriptTags.length > 0){ scriptTag = scriptTags[scriptTags.length -1]; } } if (typeof scriptTag !== 'undefined' && scriptTag !== null){ if (scriptTag.hasAttribute('data-config')){ ekkofyExpressConfig = JSON.parse(scriptTag.getAttribute('data-config')); } } //Estandarizar valores de configuración if (typeof ekkofyExpressConfig === 'undefined') { ekkofyExpressConfig = ekkofyExpressConfigDefault; }else{ for (const key in ekkofyExpressConfigDefault) { if (ekkofyExpressConfigDefault.hasOwnProperty(key)) { if (!(key in ekkofyExpressConfig)) { ekkofyExpressConfig[key] = ekkofyExpressConfigDefault[key]; }else if (ekkofyExpressConfig[key] === undefined){ ekkofyExpressConfig[key] = ekkofyExpressConfigDefault[key]; } } } } if (ekkofyExpressConfig["flotante"] !== null){ ekkofyExpressConfig["flotante"] = JSON.parse(ekkofyExpressConfig["flotante"].toString()); } console.log("EkkofyExpressConfig",ekkofyExpressConfig); var contenedorPrincipal = null; //Carga la info propia en el contenedor designado if (ekkofyExpressConfig["idContenedor"] !== null){ contenedorPrincipal = document.getElementById(ekkofyExpressConfig["idContenedor"]); if (typeof contenedorPrincipal === "undefined" || contenedorPrincipal === null){ document.body.innerHTML += '
'; contenedorPrincipal = document.getElementById(ekkofyExpressConfig['idContenedor']); } }else{ document.body.innerHTML += '
'; contenedorPrincipal = document.getElementById("ekkofyExpressContainer"); } if (typeof contenedorPrincipal === "undefined" || contenedorPrincipal === null){ contenedorPrincipal = document.body; } contenedorPrincipal.innerHTML += '
X
'; if (ekkofyExpressConfig["idBoton"] !== null){ // Enlazar acción al botón if (Array.isArray(ekkofyExpressConfig["idBoton"])){ ekkofyExpressConfig["idBoton"].forEach(function(idBoton){ var boton = getElement(idBoton); if (boton !== false){ boton.addEventListener("click", function(event){ event.preventDefault(); extraParam = getExtraParam(); mostrarEkkofyModal(boton, extraParam); }); } }); }else if ((typeof ekkofyExpressConfig["idBoton"]) == "string"){ var boton = getElement(ekkofyExpressConfig["idBoton"]); if (boton !== false){ boton.addEventListener("click", function(event){ event.preventDefault(); extraParam = getExtraParam(); mostrarEkkofyModal(boton, extraParam); }); } } }else { var boton = null; if (ekkofyExpressConfig["html"] !== null){ var div = document.createElement('div'); div.innerHTML = ekkofyExpressConfig["html"].trim(); boton = div.firstChild; }else if (ekkofyExpressConfig["flotante"] !== null){ boton = document.createElement('BUTTON'); var stylesFlotante = "position:fixed;width:50px;height:50px;z-index:8000;"; stylesFlotante += "border-radius:50%;border:0px;background-color:white;background-image:url('https://www.ekkofy.com/android-chrome-192x192.png');background-size:contain;background-repeat:no-repeat;background-position:center;"; if (ekkofyExpressConfig["flotante"]["top"] !== null){ stylesFlotante += "top:" + ekkofyExpressConfig["flotante"]["top"] + ";"; }else{ stylesFlotante += "top:auto;"; } if (ekkofyExpressConfig["flotante"]["bottom"] !== null){ stylesFlotante += "bottom:" + ekkofyExpressConfig["flotante"]["bottom"] + ";"; }else{ stylesFlotante += "bottom:10%;"; } if (ekkofyExpressConfig["flotante"]["left"] !== null){ stylesFlotante += "left:" + ekkofyExpressConfig["flotante"]["left"] + ";"; }else{ stylesFlotante += "left:auto;"; } if (ekkofyExpressConfig["flotante"]["right"] !== null){ stylesFlotante += "right:" + ekkofyExpressConfig["flotante"]["right"] + ";"; }else{ stylesFlotante += "right:5px;"; } boton.setAttribute("style",stylesFlotante); boton.setAttribute("type","button"); }else if ((ekkofyExpressConfig["textoBoton"] !== null || ekkofyExpressConfig["classBoton"] !== null) ){ boton = document.createElement('BUTTON'); if (ekkofyExpressConfig["classBoton"] !== null){ boton.setAttribute("class",ekkofyExpressConfig["classBoton"]); }else{ boton.setAttribute("class","btn btn-primary"); } if (ekkofyExpressConfig["textoBoton"] !== null){ boton.appendChild(document.createTextNode(ekkofyExpressConfig["textoBoton"])); }else{ boton.appendChild(document.createTextNode("Compartir esta campaña")); } boton.setAttribute("type","button"); } if(boton != null){ boton.addEventListener("click", function(event){ event.preventDefault(); extraParam = getExtraParam(); mostrarEkkofyModal(boton, extraParam); }); console.log("el contenedor es", contenedorPrincipal); contenedorPrincipal.insertBefore(boton, contenedorPrincipal.firstChild);; } } if (ekkofyExpressConfig["conJquery"] !== false){ scriptLoader('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js',false,""); scriptLoaderCreator('jquery_min_js',"cargarRestoJquery();"); }else{ cargarRestoJquery(); } } function getExtraParam(){ auxParams = ""; if (ekkofyExpressConfig["idEmail"] !== null){ var email = getUnValorStr(ekkofyExpressConfig["idEmail"]); if (email != ""){ auxParams = auxParams + "&email=" + email.toString(); } } if (ekkofyExpressConfig["idCelular"] !== null){ var celular = getUnValorStr(ekkofyExpressConfig["idCelular"]); if (celular != ""){ auxParams = auxParams + "&phone=" + celular.toString(); } } if (ekkofyExpressConfig["idNombre"] !== null){ var nombre = getUnValorStr(ekkofyExpressConfig["idNombre"]); if (nombre != ""){ auxParams = auxParams + "&name=" + nombre.toString(); } } if (ekkofyExpressConfig["idApellido"] !== null){ var apellido = getUnValorStr(ekkofyExpressConfig["idApellido"]); if (apellido != ""){ auxParams = auxParams + "&lastName=" + apellido.toString(); } } if (ekkofyExpressConfig["idDateBirth"] !== null){ var dateBirth = getUnValorStr(ekkofyExpressConfig["idDateBirth"]); if (dateBirth != ""){ auxParams = auxParams + "&dateBirth=" + dateBirth.toString(); } } return auxParams; } function cargarRestoJquery(){ console.log("cargarRestoJquery", ekkofyExpressConfig); if (ekkofyExpressConfig["conBootstrap"] !== false){ linkTagLoader('https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css','stylesheet','text/css'); if (ekkofyExpressConfig["conPopper"] !== false){ scriptLoader('https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js',false,""); scriptLoaderCreator('popper_min_js',"cargarRestoPopper();"); }else{ cargarRestoPopper(); } }else{ cargarRestoPopper(); } } function cargarRestoPopper(){ if (ekkofyExpressConfig["conBootstrap"] !== false){ scriptLoader('https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js',false,""); scriptLoaderCreator('bootstrap_min_js',"cargarRestoBootstrap();"); }else{ cargarRestoBootstrap(); } } function cargarRestoBootstrap(){ if (ekkofyExpressConfig["conFontAwesome"] !== false){ scriptLoader('https://kit.fontawesome.com/808ec082dc.js',false,""); } linkTagLoader('https://www.ekkofy.com/vendor/sirgrimorum/confirm/css/jquery-confirm.min.css','stylesheet','text/css'); scriptLoader('https://www.ekkofy.com/vendor/sirgrimorum/confirm/js/jquery-confirm.min.js',false,""); scriptLoader('https://www.ekkofy.com/vendor/sirgrimorum/confirm/js/rails.js',false,""); linkTagLoader('https://www.ekkofy.com/css/styles_express_modal.css','stylesheet','text/css'); scriptLoader('https://www.ekkofy.com/js/copiarAClipboard.js',false,""); scriptLoader('',false,"modalExpressCargado"); } /** * Obtiene un elemento por id, nombre o clase (el primer elemento) * @param {string} id el id, nombre o clase * @return {object} el primer elemento o false */ function getElement(id){ var element = document.getElementById(id); if (typeof element === 'undefined' || element === null){ element = document.getElementsByName(id); if (typeof element === 'undefined' || element === null || element.length <= 0){ element = document.getElementsByClassName(id); if (typeof element === 'undefined' || element === null || element.length <= 0){ return false; }else{ element = element[0]; } }else{ element = element[0]; } } return element; } /** * Obtiene un valor String válido de un array de posibles elementos por id, nombre o clase * @param {array} arr array de ids, nombres y/o clases * @return {string} el último valor del array o "" */ function getUnValorStr(arr){ var valor = ""; if (arr !== null){ if (Array.isArray(arr)){ arr.forEach(function(idCodigo){ valor = getValor(idCodigo); }); }else if ((typeof arr) == "string"){ valor = getValor(arr); } } return valor; } /** * Obtiene el valor de un elemento a partir del id, nombre o clase (el primer elemento). Primero busca si el valor de ese elemento ya estaba guardado * @param {string} id , nombre o clase * @param {boolean} numerico si es un valor númerico o no, false por defecto * @return {string} el valor guardado, del primer elemento o false */ function getValor(id, numerico = false){ var input = getElement(id); if (typeof input === 'undefined' || input === null || input === false){ return false; } if (numerico){ return getValorDeElemento(input).replace(/[^0-9.-]+/g,""); } return getValorDeElemento(input); } /** * Obtiene un valor de un elemento * @param {object} elemento, el elemento * @return {string} el valor del elemento */ function getValorDeElemento(elemento){ var tagName = elemento.tagName.toLowerCase(); if (tagName === "input"){ var type = elemento.getAttribute('type').toLowerCase(); var inputTypes = ['text', 'hidden', 'password', 'number', 'email', 'tel', 'url', 'search', 'date', 'datetime', 'datetime-local', 'time', 'month', 'week']; if (inputTypes.indexOf(type)>=0){ return elemento.value; } }else if (tagName === "select" || tagName == "textarea"){ return elemento.value; }else { return elemento.innerText || elemento.textContent; } } function linkTagLoader(path, rel = 'stylesheet', type = 'text/css'){let links = Array .from(document.querySelectorAll('link')).map(href => href.href);if (!links.includes(path) || path == ''){var tag = document.createElement('link');tag.type = type;tag.rel = rel;if (path != ''){tag.href = path;}document.getElementsByTagName('head')[document.getElementsByTagName('head').length-1].appendChild(tag);}} var callbacksFunctions = []; function scriptLoaderCreator(callbackName, functionBody){if(!(callbackName in callbacksFunctions)){callbacksFunctions[callbackName] = [];}callbacksFunctions[callbackName].push(new Function(functionBody));}function scriptLoaderRunner(callbackName){if(callbackName in callbacksFunctions){for (var i = 0; i < callbacksFunctions[callbackName].length; i++){callbacksFunctions[callbackName][i]();}}}function scriptLoader(path, diferir, inner=''){let scripts = Array .from(document.querySelectorAll('script')).map(scr => scr.src);var callbackName = inner;if (inner=='' && path != ''){callbackName = path.split('/').pop().split('#')[0].split('?')[0].replaceAll('.','_');}if (!scripts.includes(path) || path == ''){var tag = document.createElement('script');tag.type = 'text/javascript';if (callbackName!= ''){if(tag.readyState) {tag.onreadystatechange = function() {if ( tag.readyState === 'loaded' || tag.readyState === 'complete' ) {tag.onreadystatechange = null;scriptLoaderRunner(callbackName);}};}else{tag.onload = function() {scriptLoaderRunner(callbackName);};}}if (path != ''){tag.src = path;}if (diferir){var attd = document.createAttribute('defer');tag.setAttributeNode(attd);}if (inner != ''){var innerBlock = document.getElementById(inner);if (typeof innerBlock !== 'undefined' && innerBlock !== null){tag.innerHTML = innerBlock.innerHTML;}}document.getElementsByTagName('body')[document.getElementsByTagName('body').length-1].appendChild(tag);}else{if (callbackName!= ''){if(callbackName in window){window[callbackName]();}}}}