jquery.iframe-transport.min.js 1.6 KB

1
  1. (function(t,e){"use strict";t.ajaxPrefilter(function(t,e,n){if(t.iframe){return"iframe"}});t.ajaxTransport("iframe",function(e,n,a){var i=null,r=null,o="iframe-"+t.now(),u=t(e.files).filter(":file:enabled"),l=null;function d(){l.replaceWith(function(t){return u.get(t)});i.remove();r.attr("src","javascript:false;").remove()}e.dataTypes.shift();if(u.length){i=t("<form enctype='multipart/form-data' method='post'></form>").hide().attr({action:e.url,target:o});if(typeof e.data==="string"&&e.data.length>0){t.error("data must not be serialized")}t.each(e.data||{},function(e,n){if(t.isPlainObject(n)){e=n.name;n=n.value}t("<input type='hidden' />").attr({name:e,value:n}).appendTo(i)});t("<input type='hidden' value='IFrame' name='X-Requested-With' />").appendTo(i);l=u.after(function(e){return t(this).clone().prop("disabled",true)}).next();u.appendTo(i);return{send:function(e,n){r=t("<iframe src='javascript:false;' name='"+o+"' id='"+o+"' style='display:none'></iframe>");r.bind("load",function(){r.unbind("load").bind("load",function(){var t=this.contentWindow?this.contentWindow.document:this.contentDocument?this.contentDocument:this.document,e=t.documentElement?t.documentElement:t.body,a=e.getElementsByTagName("textarea")[0],i=a?a.getAttribute("data-type"):null,r=a?a.getAttribute("data-status"):200,o=a?a.getAttribute("data-statusText"):"OK",u={html:e.innerHTML,text:i?a.value:e?e.textContent||e.innerText:null};d();n(r,o,u,i?"Content-Type: "+i:null)});i[0].submit()});t("body").append(i,r)},abort:function(){if(r!==null){r.unbind("load").attr("src","javascript:false;");d()}}}}})})(jQuery);