public
Description: Upload progress bar working with apache, nginx and lighttpd upload progress modules
Homepage: http://drogomir.com/blog/2008/6/30/upload-progress-script-with-safari-support
Clone URL: git://github.com/drogus/jquery-upload-progress.git
Safari support (thanks to Michele Finotto for idea)

Safari can't send ajax requests while submitting form, so we must create hidden 
iframe and send ajax requests from inside of it.
drogus (author)
Sun Jun 29 17:59:31 -0700 2008
commit  cc8ebce8acbb54febb3d24c7a77118c1501a922f
tree    ea1aeea80995810bd91706710c3ca6517eb422bf
parent  6e5485b75b0e583e952913ea9e9341dd2ad22a3d
...
7
8
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
...
37
38
39
40
41
 
 
42
43
44
...
56
57
58
59
 
 
 
60
61
62
...
68
69
70
71
72
 
...
7
8
9
 
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
62
63
64
 
 
65
66
67
68
69
...
81
82
83
 
84
85
86
87
88
89
...
95
96
97
 
98
99
0
@@ -7,8 +7,33 @@
0
  *   http://www.opensource.org/licenses/mit-license.php
0
  *
0
  */
0
-
0
 (function($) {
0
+  if($.browser.safari && $('iframe[name=progressFrame]', parent.document).length == 0) {
0
+    $(function() {
0
+      iframe = document.createElement('iframe');
0
+      iframe.name = "progressFrame";
0
+      $(iframe).css({width: '0', height: '0', position: 'absolute', top: -3000});
0
+      document.body.appendChild(iframe);
0
+      
0
+      var d = iframe.contentWindow.document;
0
+      d.open();
0
+      /* weird - safari won't load scripts without this lines... */
0
+      d.write('<html><head></head><body></body></html>');
0
+      d.close();
0
+      
0
+      var b = d.body;
0
+      var s = d.createElement('script');
0
+      s.src = "../lib/jquery.js";
0
+      /* must be sure that jquery is loaded */
0
+      s.onload = function() {
0
+        var s1 = d.createElement('script');
0
+        s1.src = "../jquery.uploadProgress.js";
0
+        b.appendChild(s1);
0
+      }
0
+      b.appendChild(s);
0
+    });
0
+    }
0
+
0
   $.fn.uploadProgress = function(options) {
0
   return this.each(function(){
0
     $(this).bind('submit', function() {
0
@@ -37,8 +62,8 @@
0
                         } else {
0
         $(this).attr("action", jQuery(this).attr("action") + "?X-Progress-ID=" + uuid);
0
       }
0
-      
0
-      options.timer = window.setInterval(function() { $.uploadProgress(this, options) }, options.interval);
0
+      var uploadProgress = $.browser.safari ? progressFrame.jQuery.uploadProgress : jQuery.uploadProgress;
0
+      options.timer = window.setInterval(function() { uploadProgress(this, options) }, options.interval);
0
     });
0
   });
0
   };
0
@@ -56,7 +81,9 @@ jQuery.uploadProgress = function(e, options) {
0
         upload = $.extend({
0
           percents: Math.floor((upload.received / upload.size)*1000)/10
0
         }, upload);
0
-              $(options.progressBar).width(Math.floor(upload.percents) + '%');
0
+        
0
+      bar = $.browser.safari ? $(options.progressBar, parent.document) : $(options.progressBar);
0
+                  bar.width(Math.floor(upload.percents) + '%');
0
         options.uploading(upload);
0
       }
0
       /* we are done, stop the interval */
0
@@ -68,4 +95,4 @@ jQuery.uploadProgress = function(e, options) {
0
   });
0
 };
0
 
0
-})(jQuery);
0
\ No newline at end of file
0
+})(jQuery);

Comments