diff --git a/app/templates/play/modal/play-items-modal.jade b/app/templates/play/modal/play-items-modal.jade index 6c75c1773..66f85f5cc 100644 --- a/app/templates/play/modal/play-items-modal.jade +++ b/app/templates/play/modal/play-items-modal.jade @@ -31,15 +31,14 @@ if item.silhouetted && !item.owned span.glyphicon.glyphicon-lock.bolder span.glyphicon.glyphicon-lock - img.item-silhouette(src=item.getPortraitURL(), draggable="false") + img.item-silhouette(draggable="false") // dynamically loaded by view on scroll if item.level .required-level div(data-i18n="general.player_level") div= item.level else strong.big-font= item.name - img.item-img(src=item.getPortraitURL(), draggable="false") - //img.item-shadow(src=item.getPortraitURL(), draggable="false") // Not performant, takes too much memory with filter + img.item-img(draggable="false") // dynamically loaded by view on scroll if item.owned span.big-font.owned(data-i18n="play.owned") diff --git a/app/views/play/modal/PlayItemsModal.coffee b/app/views/play/modal/PlayItemsModal.coffee index 206b94747..0c182c1e8 100644 --- a/app/views/play/modal/PlayItemsModal.coffee +++ b/app/views/play/modal/PlayItemsModal.coffee @@ -51,8 +51,10 @@ module.exports = class PlayItemsModal extends ModalView 'click .buy-gems-prompt-button': 'onBuyGemsPromptButtonClicked' 'click #close-modal': 'hide' 'click': 'onClickedSomewhere' + 'update .tab-pane .nano': 'onScrollItemPane' constructor: (options) -> + @onScrollItemPane = _.throttle(_.bind(@onScrollItemPane, @), 200) super options @items = new Backbone.Collection() @itemCategoryCollections = {} @@ -143,7 +145,21 @@ module.exports = class PlayItemsModal extends ModalView onTabClicked: (e) -> @playSound 'game-menu-tab-switch' - $($(e.target).attr('href')).find('.nano').nanoScroller({alwaysVisible: true}) + nano = $($(e.target).attr('href')).find('.nano') + nano.nanoScroller({alwaysVisible: true}) + @paneNanoContent = nano.find('.nano-content') + @onScrollItemPane() + + onScrollItemPane: -> + # dynamically load visible items when the user scrolls enough to see them + items = @paneNanoContent.find('.item:not(.loaded)') + threshold = @paneNanoContent.height() + 100 + for itemEl in items + itemEl = $(itemEl) + if itemEl.position().top < threshold + $(itemEl).addClass('loaded') + item = @idToItem[itemEl.data('item-id')] + itemEl.find('.item-silhouette, .item-img').attr('src', item.getPortraitURL()) onUnlockButtonClicked: (e) -> e.stopPropagation()