astroport/doc/Turning the database inside.../teknkl-simpledto-1.js

8 lines
1.7 KiB
JavaScript

/*
@author Sanford Whiteman, TEKNKL (blog.teknkl.com / sandy@teknkl.com)
@version v1.0.2
@copyright Copyright 2016, 2017 FigureOne, Inc.
@license MIT License: You must include this license and the above credits in all uses & reproductions of this software.
*/
function SimpleDTO(e){var t=Function.prototype.call.bind(Array.prototype.slice);try{e.debug&&console.log("SimpleDTO: Unifying domains "+[document.domain,e.domain].join(", ")),document.domain=e.domain}catch(t){throw"SimpleDTO: Domain unification error, domain: "+e.domain}if("receive"==e.mode){var n=document.createElement("iframe");this.setSource=function(e){n.src=e},this.getSource=function(){return o},n.addEventListener("load",function(){this.data||this.src?(e.debug&&console.log("SimpleDTO: running callback"),e.cb&&e.cb.call(this,i)):console.warn("SimpleDTO: skipping load event due to empty data src or callback")}),n.setAttribute("data-transfer-object","true"),[["visibility","hidden"],["position","absolute"]].forEach(function(e){n.style.setProperty.apply(n.style,e)});var o=document.createElement("a");o.href=e.dataSrc||"",e.noReplaceQuery||(o.search=document.location.search),e.noInit||this.setSource(o.href),document.body.appendChild(n)}var i=this;return{getGlobal:function(){return n.contentWindow},cleanup:function(){var e=n.contentWindow.frameElement;e.parentNode.removeChild(e)},parse:function(e){e=document.querySelector('.dto-xml[data-field-collection="'+e+'"]').innerHTML;var n=(e=(new DOMParser).parseFromString(e,"application/xml")).querySelector("mktoPreFillFields");n=n.getAttribute("varName")||n.tagName;var o={};return t(e.querySelectorAll("mktoPreFillFields mktoField")).forEach(function(e){o[e.getAttribute("inputName")]=e.textContent}),self[n]=o}}}window.SimpleDTO=SimpleDTO;