]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix race condition in lazy preview loading
authorJörn Friedrich Dreyer <jfd@butonic.de>
Thu, 19 Sep 2013 12:46:33 +0000 (14:46 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Thu, 19 Sep 2013 12:46:33 +0000 (14:46 +0200)
apps/files/js/files.js

index ccb40e7216f06891f03dda29ae6e4f4155faf25e..5ec65d87457063867f630f35f2076afa04a1cd1e 100644 (file)
@@ -628,18 +628,24 @@ function getPathForPreview(name) {
 }
 
 function lazyLoadPreview(path, mime, ready, width, height) {
-       getMimeIcon(mime,ready);
-       if (!width) {
-               width = $('#filestable').data('preview-x');
-       }
-       if (!height) {
-               height = $('#filestable').data('preview-y');
-       }
-       var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height});
-       $.get(previewURL, function() {
-               previewURL = previewURL.replace('(','%28');
-               previewURL = previewURL.replace(')','%29');
-               ready(previewURL + '&reload=true');
+       // get mime icon url
+       getMimeIcon(mime, function(iconURL) {
+               ready(iconURL); // set mimeicon URL
+               
+               // now try getting a preview thumbnail URL
+               if ( ! width ) {
+                       width = $('#filestable').data('preview-x');
+               }
+               if ( ! height ) {
+                       height = $('#filestable').data('preview-y');
+               }
+               var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height});
+               $.get(previewURL, function() {
+                       previewURL = previewURL.replace('(', '%28');
+                       previewURL = previewURL.replace(')', '%29');
+                       //set preview thumbnail URL
+                       ready(previewURL + '&reload=true');
+               });
        });
 }