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