Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some cleanup in the response handling code.

  • Loading branch information...
commit 1d21adb909011acbb2a854d4ad0fffdd7984e8c9 1 parent dd78bfd
@cmlenz authored
Showing with 28 additions and 35 deletions.
  1. +24 −24 demo/client.js
  2. +4 −11 jquery.iframe-transport.js
View
48 demo/client.js
@@ -1,30 +1,30 @@
(function($) {
- $("form :file").change(function() {
- var form = $(this.form);
- form.addClass("loading");
- $.ajax(form.prop("action"), {
- files: form.find(":file")
- }).complete(function() {
- form.removeClass("loading");
- }).success(function(data) {
- $.each(data.files, function(idx, file) {
- $("<li><b></b> (<span class='size'></span>, <span class='mime'></span>)</li>")
- .find("b").text(file.filename).end()
- .find(".size").text(formatSize(file.length)).end()
- .find(".mime").text(file.mime).end()
- .appendTo("#filelist");
- });
- form.find(":file").val("");
+ $("form :file").change(function() {
+ var form = $(this.form);
+ form.addClass("loading");
+ $.ajax(form.prop("action"), {
+ files: form.find(":file")
+ }).complete(function() {
+ form.removeClass("loading");
+ }).success(function(data) {
+ $.each(data.files, function(idx, file) {
+ $("<li><b></b> (<span class='size'></span>, <span class='mime'></span>)</li>")
+ .find("b").text(file.filename).end()
+ .find(".size").text(formatSize(file.length)).end()
+ .find(".mime").text(file.mime).end()
+ .appendTo("#filelist");
});
+ form.find(":file").val("");
});
+ });
- function formatSize(size) {
- var units = ["B", "KB", "MB", "GB"];
- var idx = 0;
- while (size >= 1024) {
- size /= 1024;
- idx++;
- }
- return size.toFixed(0) + units[idx];
+ function formatSize(size) {
+ var units = ["B", "KB", "MB", "GB"];
+ var idx = 0;
+ while (size >= 1024) {
+ size /= 1024;
+ idx++;
}
+ return size.toFixed(0) + " " + units[idx];
+ }
})(jQuery);
View
15 jquery.iframe-transport.js
@@ -163,17 +163,10 @@
(this.contentDocument ? this.contentDocument : this.document),
root = doc.documentElement ? doc.documentElement : doc.body,
textarea = root.getElementsByTagName("textarea")[0],
- dataType = textarea ? textarea.getAttribute("data-type") : null,
- headers = {},
- contents = {};
- if (dataType) {
- headers = "Content-Type: " + dataType;
- contents.text = textarea.value;
- } else {
- headers = "Content-Type: text/html";
- contents.text = root ? root.innerHTML : null;
- }
- completeCallback(200, "OK", contents, headers);
+ type = textarea ? textarea.getAttribute("data-type") : null;
+ completeCallback(200, "OK", {
+ text: type ? textarea.value : root ? root.innerHTML : null
+ }, "Content-Type: " + (type ? type : "text/html"));
setTimeout(cleanUp, 50);
});
Please sign in to comment.
Something went wrong with that request. Please try again.