Skip to content

Commit

Permalink
Fix CollectionView
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian-R committed Sep 2, 2015
1 parent a78f929 commit 71551c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/chaplin/views/collection_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ module.exports = class CollectionView extends View
# Set the listEl property with the actual list container.
listSelector = _.result this, 'listSelector'

@listEl = if listSelector then @$(listSelector)[0] else @el
@listEl = if listSelector then @el.querySelector(listSelector) else @el
@$list = Backbone.$ @listEl if Backbone.$

@initFallback()
Expand Down Expand Up @@ -226,6 +226,7 @@ module.exports = class CollectionView extends View

# Set the $fallback property.
@$fallback = @$ @fallbackSelector
@fallback = @el.querySelector @fallbackSelector

# Listen for visible items changes.
@on 'visibilityChange', @toggleFallback
Expand Down Expand Up @@ -259,6 +260,7 @@ module.exports = class CollectionView extends View

# Set the $loading property.
@$loading = @$ @loadingSelector
@loading = @el.querySelector @loadingSelector

# Listen for sync events on the collection.
@listenTo @collection, 'syncStateChange', @toggleLoadingIndicator
Expand Down
17 changes: 9 additions & 8 deletions test/spec/collection_view_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ define [
'chaplin/views/view'
'chaplin/views/collection_view'
'chaplin/lib/sync_machine'
], (_, jQuery, Model, Collection, View, CollectionView, SyncMachine) ->
'chaplin/lib/utils'
], (_, jQuery, Model, Collection, View, CollectionView, SyncMachine, utils) ->
'use strict'

jQuery = null unless jQuery?.fn
Expand Down Expand Up @@ -86,9 +87,9 @@ define [
collectionView.$list.children collectionView.itemSelector
else
if collectionView.itemSelector
(item for item in collectionView.list.children when Backbone.utils.matchesSelector item, collectionView.itemSelector)
(item for item in collectionView.listEl.children when utils.matchesSelector.call item, collectionView.itemSelector)
else
collectionView.list.children
collectionView.listEl.children

getAllChildren = ->
if jQuery
Expand Down Expand Up @@ -176,7 +177,7 @@ define [
expect(collectionView.$list).to.be.a jQuery
expect(collectionView.$list.length).to.be 1
else
expect(collectionView.list).to.be.a Element
expect(collectionView.listEl).to.be.a Element

collectionView.renderAllItems()
viewsMatchCollection()
Expand Down Expand Up @@ -735,10 +736,10 @@ define [
children = getViewChildren()
expect(children.length).to.be collection.length
else
list = collectionView.list
list = collectionView.listEl
expect(list).to.be.true

list2 = collectionView.find(collectionView.listSelector)
list2 = collectionView.el.querySelector(collectionView.listSelector)
expect(list).to.be list2

children = getViewChildren()
Expand Down Expand Up @@ -788,7 +789,7 @@ define [
else
{fallback} = collectionView
expect(fallback).to.be.true
fallback2 = collectionView.find(collectionView.fallbackSelector)
fallback2 = collectionView.el.querySelector(collectionView.fallbackSelector)
expect(fallback).to.be fallback2

it 'should show the fallback element properly', ->
Expand Down Expand Up @@ -857,7 +858,7 @@ define [
else
{loading} = collectionView
expect(loading).to.be.true
loading2 = collectionView.find(collectionView.loadingSelector)
loading2 = collectionView.el.querySelector(collectionView.loadingSelector)
expect(loading).to.be loading2

it 'should show the loading indicator properly', ->
Expand Down

0 comments on commit 71551c1

Please sign in to comment.