Skip to content

Commit

Permalink
fixed lazy loading issues #214
Browse files Browse the repository at this point in the history
  • Loading branch information
psolom committed Aug 6, 2017
1 parent 601e9c2 commit 71f08ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
47 changes: 31 additions & 16 deletions scripts/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
fmModel = new FmModel();
ko.applyBindings(fmModel);

fmModel.itemsModel.initiateLazyLoad();

ko.bindingHandlers.toggleNodeVisibility = {
init: function (element, valueAccessor) {
var node = valueAccessor();
Expand Down Expand Up @@ -1433,21 +1435,6 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
this.descriptivePanel = new RenderModel();
this.lazyLoad = null;

if (config.viewer.image.lazyLoad) {
this.lazyLoad = new LazyLoad({
container: $fileinfo[0], // work only for default scrollbar
callback_load: function (element) {
fm.log("LOADED", element.getAttribute('data-original'));
},
callback_set: function (element) {
fm.log("SET", element.getAttribute('data-original'));
},
callback_processed: function (elementsLeft) {
fm.log("PROCESSED", elementsLeft + " images left");
}
});
}

this.isSelecting.subscribe(function(state) {
if(!state) {
// means selection lasso has been dropped
Expand Down Expand Up @@ -1607,6 +1594,27 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
}
};

this.initiateLazyLoad = function() {
// not configured or already initiated
if (config.viewer.image.lazyLoad !== true || items_model.lazyLoad) {
return;
}

items_model.lazyLoad = new LazyLoad({
container: $fileinfo[0], // work only for default scrollbar
callback_load: function (element) {
fm.log("LOADED", element.getAttribute('data-original'));
},
callback_set: function (element) {
console.log(element);
fm.log("SET", element.getAttribute('data-original'));
},
callback_processed: function (elementsLeft) {
fm.log("PROCESSED", elementsLeft + " images left");
}
});
};

this.objects.subscribe(function(items) {
var totalNumber = 0,
totalSize = 0;
Expand All @@ -1623,7 +1631,14 @@ $.richFilemanagerPlugin = function(element, pluginOptions)
items_model.objectsNumber(totalNumber);
items_model.objectsSize(formatBytes(totalSize));

// context menu
// update
if (items_model.lazyLoad) {
setTimeout(function() {
items_model.lazyLoad.update();
}, 50);
}

// context menu
$viewItems.contextMenu({
selector: '.file, .directory',
zIndex: 100,
Expand Down
Loading

3 comments on commit 71f08ab

@forumarji
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, it solved the issue and showing thumbnails. Thank you.

@psolom
Copy link
Owner Author

@psolom psolom commented on 71f08ab Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been reported that it doesn't work in the IE Edge browser.
Could you confirm or deny this?

@forumarji
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on Microsoft IE Edge browser, I can confirm its working fine. Nice work.

Please sign in to comment.