The PlayItemsModal now dynamically loads portrait images as they scroll into view.

This commit is contained in:
Scott Erickson 2014-12-01 17:33:37 -08:00
parent 4f9dc39567
commit 7f97a3b91e
2 changed files with 19 additions and 4 deletions

View file

@ -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")

View file

@ -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()