]> source.dussan.org Git - nextcloud-server.git/commitdiff
oc-1548: prevent user from leaving the page while a file upload is in progress
authorThomas Mueller <thomas.mueller@tmit.eu>
Thu, 30 Aug 2012 22:45:03 +0000 (00:45 +0200)
committerThomas Mueller <thomas.mueller@tmit.eu>
Thu, 30 Aug 2012 22:45:03 +0000 (00:45 +0200)
apps/files/js/files.js

index 5ecc5bc22cb4bfde2f12032fecbbb059467967ac..6165da2283080fd515799be72bf766a9063f00e6 100644 (file)
@@ -389,6 +389,21 @@ $(document).ready(function() {
                })
        });
 
+       $.assocArraySize = function(obj) {
+               // http://stackoverflow.com/a/6700/11236
+               var size = 0, key;
+               for (key in obj) {
+                   if (obj.hasOwnProperty(key)) size++;
+               }
+               return size;
+       };
+
+       // warn user not to leave the page while upload is in progress
+       $(window).bind('beforeunload', function(e) {
+               if ($.assocArraySize(uploadingFiles) > 0)
+                       return t('files','File upload is in progress. Leaving the page now will cancel the upload.');
+       });
+
        //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
        if(navigator.userAgent.search(/konqueror/i)==-1){
                $('.file_upload_start').attr('multiple','multiple')