From 71551c1af99eafea51b6bf3c0c200682ed0e9d3c Mon Sep 17 00:00:00 2001 From: Florian-R Date: Wed, 2 Sep 2015 12:04:27 +0200 Subject: [PATCH] Fix CollectionView --- src/chaplin/views/collection_view.coffee | 4 +++- test/spec/collection_view_spec.coffee | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/chaplin/views/collection_view.coffee b/src/chaplin/views/collection_view.coffee index fa1f8613..59e6654e 100644 --- a/src/chaplin/views/collection_view.coffee +++ b/src/chaplin/views/collection_view.coffee @@ -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() @@ -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 @@ -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 diff --git a/test/spec/collection_view_spec.coffee b/test/spec/collection_view_spec.coffee index f534f736..961e0862 100644 --- a/test/spec/collection_view_spec.coffee +++ b/test/spec/collection_view_spec.coffee @@ -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 @@ -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 @@ -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() @@ -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() @@ -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', -> @@ -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', ->