You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
1.5 KiB
1 lines
1.5 KiB
(function(){var a=function(e){var d=Array.prototype.slice.call(arguments,1);for(var c=0,b=d.length;c<b;c++){for(var f in d[c]){e[f]=d[c][f]}}return e};this.janky=function(b){janky._form(function(d,e){b=a({},janky._default_opts,b);if(!b.url){throw new Error("Must include a URL to send data to.")}e.setAttribute("action",b.url);e.setAttribute("method",b.method);b.data=a({},b.data,{_origin:location.href});janky._input(d,e,b.data);var c=function(f){window.detachEvent&&window.detachEvent("onmessage",c);window.removeEventListener&&window.removeEventListener("message",c);setTimeout(function(){document.body.removeChild(d)},1);b.success&&b.success(JSON.parse(f.data))};window.attachEvent&&window.attachEvent("onmessage",c);window.addEventListener&&window.addEventListener("message",c,false);d.onreadystatechange=function(){if(typeof(window.postMessage)!="undefined"||d.readyState!="complete"){return}c({data:d.contentWindow.name})};e.submit()})};this.janky._form=function(b){var c=document.createElement("iframe");document.body.appendChild(c);c.style.display="none";setTimeout(function(){var d=c.contentWindow.document.createElement("form");c.contentWindow.document.body.appendChild(d);b(c,d)},0)};this.janky._default_opts={method:"get"};this.janky.is_string=function(b){return !!(b===""||(b&&b.charCodeAt&&b.substr))};this.janky._input=function(c,e,f){for(var b in f){var g=f[b];if(!janky.is_string(g)){g=JSON.stringify(g)}var d=c.contentWindow.document.createElement("input");d.setAttribute("type","hidden");d.setAttribute("name",b);d.value=g;e.appendChild(d)}}})(); |