diff --git a/bower.json b/bower.json index 0286a65d..3b5de7c2 100644 --- a/bower.json +++ b/bower.json @@ -6,12 +6,13 @@ "expect": "0.2.x", "jquery": "1.9.x", "lodash": "2.3.x", - "backbone": "1.1.x", + "backbone": "1.2.0", "benchmark": "git://github.com/bestiejs/benchmark.js.git", "sinon": "http://sinonjs.org/releases/sinon-1.7.1.js", "requirejs": "~2.1.8", "davy": "~0.0.4", - "exoskeleton": "~0.6.0" + "backbone.nativeview": "0.3.1", + "exoskeleton": "~0.7.0" }, "exportsOverride": { "mocha": { diff --git a/package.json b/package.json index 54ff525a..9e048130 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "grunt-istanbul": "0.2.x", "grunt-urequire": "git://github.com/concordusapps/grunt-urequire", "grunt-coffeelint": "0.0.x", - "grunt-mocha": "0.2.x", + "grunt-mocha": "0.4.11", "grunt-transbrute": "~0.2.0", "prompt": "0.2.x", "phantomjs": "1.9.x" diff --git a/src/chaplin/lib/utils.coffee b/src/chaplin/lib/utils.coffee index 14bb787b..7af7897b 100644 --- a/src/chaplin/lib/utils.coffee +++ b/src/chaplin/lib/utils.coffee @@ -2,11 +2,30 @@ _ = require 'underscore' support = require 'chaplin/lib/support' +ElementProto = if typeof Element != 'undefined' then Element.prototype else {} + # Utilities # --------- utils = + # DOM Helpers + # -------------- + + matchesSelector: ElementProto.matches || + ElementProto.webkitMatchesSelector || + ElementProto.mozMatchesSelector || + ElementProto.msMatchesSelector || + ElementProto.oMatchesSelector || + #Make our own `Element#matches` for IE8 + (selector) -> + #Use querySelectorAll to find all elements matching the selector, + #then check if the given element is included in that list. + #Executing the query on the parentNode reduces the resulting nodeList, + #(document doesn't have a parentNode). + nodeList = (@parentNode || document).querySelectorAll(selector) || [] + !!~indexOf(nodeList, this) + # Object Helpers # -------------- diff --git a/src/chaplin/views/collection_view.coffee b/src/chaplin/views/collection_view.coffee index 60dc1e98..59e6654e 100644 --- a/src/chaplin/views/collection_view.coffee +++ b/src/chaplin/views/collection_view.coffee @@ -5,102 +5,57 @@ Backbone = require 'backbone' View = require 'chaplin/views/view' utils = require 'chaplin/lib/utils' -# Shortcut to access the DOM manipulation library. -$ = Backbone.$ - filterChildren = (nodeList, selector) -> return nodeList unless selector - for node in nodeList when Backbone.utils.matchesSelector node, selector + for node in nodeList when utils.matchesSelector.call node, selector node -toggleElement = do -> - if $ - (elem, visible) -> elem.toggle visible +toggleElement = (elem, visible) -> + if Backbone.$ + Backbone.$(elem).toggle visible else - (elem, visible) -> - elem.style.display = (if visible then '' else 'none') + elem.style.display = (if visible then '' else 'none') -addClass = do -> - if $ - (elem, cls) -> elem.addClass cls +startAnimation = (elem, useCssAnimation, cls) -> + if useCssAnimation + elem.classList.add cls else - (elem, cls) -> elem.classList.add cls + elem.style.opacity = 0 -startAnimation = do -> - if $ - (elem, useCssAnimation, cls) -> - if useCssAnimation - addClass elem, cls - else - elem.css 'opacity', 0 - else - (elem, useCssAnimation, cls) -> - if useCssAnimation - addClass elem, cls - else - elem.style.opacity = 0 - -endAnimation = do -> - if $ - (elem, duration) -> elem.animate {opacity: 1}, duration - else - (elem, duration) -> - elem.style.transition = "opacity #{(duration / 1000)}s" - elem.style.opacity = 1 - -insertView = do -> - if $ - (list, viewEl, position, length, itemSelector) -> - insertInMiddle = (0 < position < length) - isEnd = (length) -> length is 0 or position is length - - if insertInMiddle or itemSelector - # Get the children which originate from item views. - children = list.children itemSelector - childrenLength = children.length - - # Check if it needs to be inserted. - unless children[position] is viewEl - if isEnd childrenLength - # Insert at the end. - list.append viewEl - else - # Insert at the right position. - if position is 0 - children.eq(position).before viewEl - else - children.eq(position - 1).after viewEl - else - method = if isEnd length then 'append' else 'prepend' - list[method] viewEl +endAnimation = (elem, duration) -> + if Backbone.$ + Backbone.$(elem).animate {opacity: 1}, duration else - (list, viewEl, position, length, itemSelector) -> - insertInMiddle = (0 < position < length) - isEnd = (length) -> length is 0 or position is length - - if insertInMiddle or itemSelector - # Get the children which originate from item views. - children = filterChildren list.children, itemSelector - childrenLength = children.length - - # Check if it needs to be inserted. - unless children[position] is viewEl - if isEnd childrenLength - # Insert at the end. - list.appendChild viewEl - else if position is 0 - # Insert at the right position. - list.insertBefore viewEl, children[position] - else - last = children[position - 1] - if list.lastChild is last - list.appendChild viewEl - else - list.insertBefore viewEl, last.nextElementSibling - else if isEnd length + elem.style.transition = "opacity #{(duration / 1000)}s" + elem.opacity = 1 + +insertView = (list, viewEl, position, length, itemSelector) -> + insertInMiddle = (0 < position < length) + isEnd = (length) -> length is 0 or position is length + + if insertInMiddle or itemSelector + # Get the children which originate from item views. + children = filterChildren list.children, itemSelector + childrenLength = children.length + + # Check if it needs to be inserted. + unless children[position] is viewEl + if isEnd childrenLength + # Insert at the end. list.appendChild viewEl + else if position is 0 + # Insert at the right position. + list.insertBefore viewEl, children[position] else - list.insertBefore viewEl, list.firstChild + last = children[position - 1] + if list.lastChild is last + list.appendChild viewEl + else + list.insertBefore viewEl, last.nextElementSibling + else if isEnd length + list.appendChild viewEl + else + list.insertBefore viewEl, list.firstChild # General class for rendering Collections. # Derive this class and declare at least `itemView` or override @@ -149,6 +104,7 @@ module.exports = class CollectionView extends View # The actual element which is fetched using `listSelector` $list: null + listEl: null # Selector for a fallback element which is shown if the collection is empty. fallbackSelector: null @@ -164,7 +120,7 @@ module.exports = class CollectionView extends View $loading: null # Selector which identifies child elements belonging to collection - # If empty, all children of $list are considered. + # If empty, all children of listEl are considered. itemSelector: null # Filtering @@ -176,8 +132,8 @@ module.exports = class CollectionView extends View # A function that will be executed after each filter. # Hides excluded items by default. filterCallback: (view, included) -> - view.$el.stop(true, true) if $ - toggleElement (if $ then view.$el else view.el), included + view.$el.stop(true, true) if Backbone.$ + toggleElement view.el, included # View lists # ---------- @@ -235,13 +191,11 @@ module.exports = class CollectionView extends View render: -> super - # Set the $list property with the actual list container. + # Set the listEl property with the actual list container. listSelector = _.result this, 'listSelector' - if $ - @$list = if listSelector then @$(listSelector) else @$el - else - @list = if listSelector then @find(@listSelector) else @el + @listEl = if listSelector then @el.querySelector(listSelector) else @el + @$list = Backbone.$ @listEl if Backbone.$ @initFallback() @initLoadingIndicator() @@ -271,10 +225,8 @@ module.exports = class CollectionView extends View return unless @fallbackSelector # Set the $fallback property. - if $ - @$fallback = @$ @fallbackSelector - else - @fallback = @find @fallbackSelector + @$fallback = @$ @fallbackSelector + @fallback = @el.querySelector @fallbackSelector # Listen for visible items changes. @on 'visibilityChange', @toggleFallback @@ -295,7 +247,7 @@ module.exports = class CollectionView extends View # Assume it is synced. true ) - toggleElement (if $ then @$fallback else @fallback), visible + toggleElement @$fallback[0], visible # Loading indicator # ----------------- @@ -307,10 +259,8 @@ module.exports = class CollectionView extends View typeof @collection.isSyncing is 'function' # Set the $loading property. - if $ - @$loading = @$ @loadingSelector - else - @loading = @find @loadingSelector + @$loading = @$ @loadingSelector + @loading = @el.querySelector @loadingSelector # Listen for sync events on the collection. @listenTo @collection, 'syncStateChange', @toggleLoadingIndicator @@ -325,7 +275,7 @@ module.exports = class CollectionView extends View # show up in this case, you need to overwrite this method to # disable the check. visible = @collection.length is 0 and @collection.isSyncing() - toggleElement (if $ then @$loading else @loading), visible + toggleElement (@$loading[0]), visible # Filtering # --------- @@ -459,12 +409,9 @@ module.exports = class CollectionView extends View else true - # Get the view’s top element. - elem = if $ then view.$el else view.el - # Start animation. if included and enableAnimation - startAnimation elem, @useCssAnimation, @animationStartClass + startAnimation view.el, @useCssAnimation, @animationStartClass # Hide or mark the view if it’s filtered. @filterCallback view, included if @filterer @@ -472,9 +419,7 @@ module.exports = class CollectionView extends View length = @collection.length # Insert the view into the list. - list = if $ then @$list else @list - - insertView list, elem, position, length, @itemSelector + insertView @listEl, view.el, position, length, @itemSelector # Tell the view that it was added to its parent. view.trigger 'addedToParent' @@ -486,10 +431,10 @@ module.exports = class CollectionView extends View if included and enableAnimation if @useCssAnimation # Wait for DOM state change. - setTimeout (=> addClass elem, @animationEndClass), 0 + setTimeout (=> view.el.classList.add @animationEndClass), 0 else # Fade the view in if it was made transparent before. - endAnimation elem, @animationDuration + endAnimation view.el, @animationDuration view @@ -532,7 +477,7 @@ module.exports = class CollectionView extends View return if @disposed # Remove jQuery objects, item view cache and visible items list. - properties = ['$list', '$fallback', '$loading', 'visibleItems'] + properties = ['$list', 'listEl', '$fallback', '$loading', 'visibleItems'] delete this[prop] for prop in properties # Self-disposal. diff --git a/src/chaplin/views/layout.coffee b/src/chaplin/views/layout.coffee index 21cad8d6..1c15c11c 100644 --- a/src/chaplin/views/layout.coffee +++ b/src/chaplin/views/layout.coffee @@ -7,9 +7,6 @@ utils = require 'chaplin/lib/utils' EventBroker = require 'chaplin/lib/event_broker' View = require 'chaplin/views/view' -# Shortcut to access the DOM manipulation library. -$ = Backbone.$ - module.exports = class Layout extends View # Bind to document body by default. el: 'body' @@ -84,17 +81,11 @@ module.exports = class Layout extends View startLinkRouting: -> route = @settings.routeLinks return unless route - if $ - @$el.on 'click', route, @openLink - else - @delegate 'click', route, @openLink + @delegate 'click', route, @openLink stopLinkRouting: -> route = @settings.routeLinks - if $ - @$el.off 'click', route if route - else - @undelegate 'click', route, @openLink + @undelegate 'click', route, @openLink isExternalLink: (link) -> link.target is '_blank' or @@ -106,7 +97,7 @@ module.exports = class Layout extends View openLink: (event) => return if utils.modifierKeyPressed(event) - el = if $ then event.currentTarget else event.delegateTarget + el = if Backbone.$ then event.currentTarget else event.delegateTarget isAnchor = el.nodeName is 'A' # Get the href and perform checks on it. @@ -124,7 +115,7 @@ module.exports = class Layout extends View skipRouting = @settings.skipRouting type = typeof skipRouting return if type is 'function' and not skipRouting(href, el) or - type is 'string' and (if $ then $(el).is(skipRouting) else Backbone.utils.matchesSelector el, skipRouting) + type is 'string' and utils.matchesSelector.call el, skipRouting # Handle external links. external = isAnchor and @isExternalLink el @@ -212,18 +203,13 @@ module.exports = class Layout extends View # Apply the region selector. instance.container = if region.selector is '' - if $ - region.instance.$el - else - region.instance.el + region.instance.el else - if region.instance.noWrap - if $ - $(region.instance.container).find region.selector + root = if region.instance.noWrap + region.instance.container else - region.instance.container.querySelector region.selector - else - region.instance[if $ then '$' else 'find'] region.selector + region.instance.el + root.querySelector region.selector # Disposal # -------- diff --git a/src/chaplin/views/view.coffee b/src/chaplin/views/view.coffee index c331bb6c..fc5ed377 100644 --- a/src/chaplin/views/view.coffee +++ b/src/chaplin/views/view.coffee @@ -6,42 +6,6 @@ mediator = require 'chaplin/mediator' EventBroker = require 'chaplin/lib/event_broker' utils = require 'chaplin/lib/utils' -# Shortcut to access the DOM manipulation library. -$ = Backbone.$ - -# Function bind shortcut. -bind = do -> - if Function::bind - (item, ctx) -> item.bind ctx - else if _.bind - _.bind - -setHTML = do -> - if $ - (elem, html) -> elem.html html - else - (elem, html) -> elem.innerHTML = html - -attach = do -> - if $ - (view) -> - actual = $(view.container) - if typeof view.containerMethod is 'function' - view.containerMethod actual, view.el - else - actual[view.containerMethod] view.el - else - (view) -> - actual = if typeof view.container is 'string' - document.querySelector view.container - else - view.container - - if typeof view.containerMethod is 'function' - view.containerMethod actual, view.el - else - actual[view.containerMethod] view.el - module.exports = class View extends Backbone.View # Mixin an EventBroker. _.extend @prototype, EventBroker @@ -69,7 +33,7 @@ module.exports = class View extends Backbone.View # Method which is used for adding the view to the DOM # Like jQuery’s `html`, `prepend`, `append`, `after`, `before` etc. - containerMethod: if $ then 'append' else 'appendChild' + containerMethod: if Backbone.$ then 'append' else 'appendChild' # Regions # ------- @@ -152,11 +116,11 @@ module.exports = class View extends Backbone.View @el = if region.instance.container? if region.instance.region? - $(region.instance.container).find region.selector + Backbone.$(region.instance.container).find region.selector else region.instance.container else - region.instance.$ region.selector + region.instance.$(region.selector)[0] @el = @container if @container @@ -183,47 +147,6 @@ module.exports = class View extends Backbone.View # User input event handling # ------------------------- - # Event handling using event delegation - # Register a handler for a specific event type - # For the whole view: - # delegate(eventName, handler) - # e.g. - # @delegate('click', @clicked) - # For an element in the passing a selector: - # delegate(eventName, selector, handler) - # e.g. - # @delegate('click', 'button.confirm', @confirm) - delegate: (eventName, second, third) -> - if Backbone.utils - return Backbone.utils.delegate(this, eventName, second, third) - if typeof eventName isnt 'string' - throw new TypeError 'View#delegate: first argument must be a string' - - if arguments.length is 2 - handler = second - else if arguments.length is 3 - selector = second - if typeof selector isnt 'string' - throw new TypeError 'View#delegate: ' + - 'second argument must be a string' - handler = third - else - throw new TypeError 'View#delegate: ' + - 'only two or three arguments are allowed' - - if typeof handler isnt 'function' - throw new TypeError 'View#delegate: ' + - 'handler argument must be function' - - # Add an event namespace, bind handler it to view. - list = ("#{event}.delegate#{@cid}" for event in eventName.split ' ') - events = list.join(' ') - bound = bind handler, this - @$el.on events, (selector or null), bound - - # Return the bound handler. - bound - # Copy of original Backbone method without `undelegateEvents` call. _delegateEvents: (events) -> if Backbone.View::delegateEvents.length is 2 @@ -232,10 +155,10 @@ module.exports = class View extends Backbone.View handler = if typeof value is 'function' then value else this[value] throw new Error "Method '#{value}' does not exist" unless handler match = key.match /^(\S+)\s*(.*)$/ - eventName = "#{match[1]}.delegateEvents#{@cid}" + eventName = match[1] selector = match[2] - bound = bind handler, this - @$el.on eventName, (selector or null), bound + bound = _.bind handler, this + @delegate eventName, (selector or null), bound return # Override Backbones method to combine the events @@ -249,32 +172,6 @@ module.exports = class View extends Backbone.View @_delegateEvents classEvents return - # Remove all handlers registered with @delegate. - undelegate: (eventName, second, third) -> - if Backbone.utils - return Backbone.utils.undelegate(this, eventName, second, third) - if eventName - if typeof eventName isnt 'string' - throw new TypeError 'View#undelegate: first argument must be a string' - - if arguments.length is 2 - if typeof second is 'string' - selector = second - else - handler = second - else if arguments.length is 3 - selector = second - if typeof selector isnt 'string' - throw new TypeError 'View#undelegate: ' + - 'second argument must be a string' - handler = third - - list = ("#{event}.delegate#{@cid}" for event in eventName.split ' ') - events = list.join(' ') - @$el.off events, (selector or null) - else - @$el.off ".delegate#{@cid}" - # Handle declarative event bindings from `listen` delegateListeners: -> return unless @listen @@ -434,11 +331,16 @@ module.exports = class View extends Backbone.View # Delegate events to the top-level container in the template. @setElement el.firstChild, true else - setHTML (if $ then @$el else @el), html + @setHTML html # Return the view. this + # Set the innerHTML of the view's `el`. Override this method to support + # older browsers (IE needs the html empty before, e.g.) + setHTML: (html) -> + @el.innerHTML = html + # This method is called after a specific `render` of a derived class. attach: -> # Attempt to bind this view to its named region. @@ -446,8 +348,25 @@ module.exports = class View extends Backbone.View # Automatically append to DOM if the container element is set. if @container and not document.body.contains @el - attach this - # Trigger an event. + if Backbone.$ + actual = Backbone.$(this.container) + if typeof this.containerMethod is 'function' + this.containerMethod actual, this.el + else + actual[this.containerMethod] this.el + else + actual = if typeof this.container is 'string' + document.querySelector this.container + else + this.container + + if typeof this.containerMethod is 'function' + this.containerMethod actual, this.el + else + actual[this.containerMethod] this.el + + # Hook into this event for things that require the view to be in the DOM + # (like calculating height / width or position). @trigger 'addedToDOM' # Disposal diff --git a/test/initialize.js b/test/initialize.js index e39e8741..61337d06 100644 --- a/test/initialize.js +++ b/test/initialize.js @@ -9,21 +9,27 @@ window.clearInterval = timers.clearInterval; var paths = {}; var componentsFolder = 'bower_components'; -var match = window.location.search.match(/type=([-\w]+)/); +var match = window.location.search.match(/type=([-\w]+)&useDeps=([-\w]+)/); var testType = window.testType || (match ? match[1] : 'backbone'); +var useDeps = window.useDeps || (match ? match[2] : true); var addDeps = function() { - paths.underscore = '../' + componentsFolder + '/lodash/lodash.compat'; - paths.jquery = '../' + componentsFolder + '/jquery/jquery'; + if (useDeps === true) { + paths.jquery = '../' + componentsFolder + '/jquery/jquery'; + paths.underscore = '../' + componentsFolder + '/lodash/lodash.compat'; + } else { + paths.NativeView = '../' + componentsFolder + '/backbone.nativeview/backbone.nativeview'; + } }; if (testType === 'backbone') { - paths.backbone = '../' + componentsFolder + '/backbone/backbone' - addDeps() + paths.backbone = '../' + componentsFolder + '/backbone/backbone'; + addDeps(); } else { - if (testType === 'deps') addDeps(); - paths.backbone = '../' + componentsFolder + '/exoskeleton/exoskeleton' + addDeps(); + paths.backbone = '../' + componentsFolder + '/exoskeleton/exoskeleton'; } + var config = { baseUrl: 'temp/', paths: paths, @@ -31,22 +37,9 @@ var config = { urlArgs: 'bust=' + (new Date()).getTime() }; -if (testType === 'backbone' || testType === 'deps') { - config.shim = { - backbone: { - deps: ['underscore', 'jquery'], - exports: 'Backbone' - }, - underscore: { - exports: '_' - } - }; -} - requirejs.config(config); if (testType === 'exos') { define('jquery', function(){}); - define('underscore', ['backbone'], function(Backbone){return Backbone.utils;}); } mocha.setup({ui: 'bdd', ignoreLeaks: true}); // Wonderful hack to send a message to grunt from inside a mocha test. @@ -86,16 +79,44 @@ window.addEventListener('DOMContentLoaded', function() { 'view', 'utils', 'sync_machine' - ]; - var loaded = []; - for (var i = 0, l = specs.length; i < l; i++) { - loaded.push(specs[i] + '_spec'); - } - require(loaded, function() { + ].map(function(file) { + return file + '_spec'; + }); + + var run = function() { if (window.mochaPhantomJS) { mochaPhantomJS.run(); } else { mocha.run(); } - }); + }; + + if (useDeps === true) { + require(specs, run) + } else { + define('underscore', function(){}); + require(['backbone', 'NativeView'], function(Backbone, NativeView) { + requirejs.undef('underscore') + define('underscore', function(){ + var _ = Backbone.utils + _.bind = function(fn, ctx) { return fn.bind(ctx); } + _.isObject = function(obj) { + var type = typeof obj; + return type === 'function' || type === 'object' && !!obj; + }; + _.clone = function(obj) { + if (!_.isObject(obj)) return obj; + return Array.isArray(obj) ? obj.slice() : _.extend({}, obj); + }; + _.isEmpty = function(obj) { + if (obj == null) return true; + if (obj.length !== undefined) return obj.length === 0; + return Object.keys(obj).length === 0; + }; + return _ + }); + Backbone.View = NativeView; + require(specs, run) + }); + } }, false); diff --git a/test/spec/collection_view_spec.coffee b/test/spec/collection_view_spec.coffee index f27e5b28..961e0862 100644 --- a/test/spec/collection_view_spec.coffee +++ b/test/spec/collection_view_spec.coffee @@ -6,9 +6,12 @@ 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 + describe 'CollectionView', -> # Initialize shared variables collection = null @@ -84,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 @@ -174,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() @@ -410,51 +413,36 @@ define [ it 'should animate the opacity of new items', -> return unless jQuery - $css = sinon.stub jQuery.prototype, 'css', -> this $animate = sinon.stub jQuery.prototype, 'animate', -> this createCollection() collectionView = new AnimatingCollectionView {collection} - expect($css.callCount).to.be collection.length - expect($css).was.calledWith 'opacity', 0 - expect($animate.callCount).to.be collection.length args = $animate.firstCall.args expect(args[0]).to.eql opacity: 1 expect(args[1]).to.be collectionView.animationDuration - expect($css.calledBefore($animate)).to.be true - - addThree() - expect($css.callCount).to.be collection.length - - $css.restore() $animate.restore() it 'should not animate if animationDuration is 0', -> return unless jQuery - $css = sinon.spy jQuery.prototype, 'css' $animate = sinon.spy jQuery.prototype, 'animate' createCollection() collectionView = new TestCollectionView {collection} - expect($css).was.notCalled() expect($animate).was.notCalled() addThree() - expect($css).was.notCalled() expect($animate).was.notCalled() - $css.restore() $animate.restore() it 'should not animate when re-inserting', -> return unless jQuery - $css = sinon.stub jQuery.prototype, 'css', -> this $animate = sinon.stub jQuery.prototype, 'animate', -> this model1 = new Model id: 1 @@ -464,15 +452,12 @@ define [ createCollection [model1, model2] collectionView = new AnimatingCollectionView {collection} - expect($css).was.calledTwice() expect($animate).was.calledTwice() collection.reset [model1, model2, model3] - expect($css.callCount).to.be collection.length expect($animate.callCount).to.be collection.length - $css.restore() $animate.restore() it 'should animate with CSS classes', (done) -> @@ -751,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() @@ -804,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', -> @@ -873,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', -> diff --git a/test/spec/layout_spec.coffee b/test/spec/layout_spec.coffee index 2e9761bb..daaf4037 100644 --- a/test/spec/layout_spec.coffee +++ b/test/spec/layout_spec.coffee @@ -80,9 +80,9 @@ define [ after -> document.body.removeEventListener 'click', preventDefault unless $ - it 'should have el, $el and $ props / methods', -> - expect(layout.el).to.be document.body - expect(layout.$el).to.be.a $ if $ + # it 'should have el, $el and $ props / methods', -> + # expect(layout.el).to.be document.body + # expect(layout.$el).to.be.a $ if $ it 'should set the document title', (done) -> spy = sinon.spy() @@ -343,12 +343,8 @@ define [ instance2 = new Test2View {region: 'test2'} instance3 = new Test2View {region: 'test0'} - if $ - expect(instance2.container.attr('id')).to.be 'test2' - expect(instance3.container).to.be instance1.$el - else - expect(instance2.container.id).to.be 'test2' - expect(instance3.container).to.be instance1.el + expect(instance2.container.id).to.be 'test2' + expect(instance3.container).to.be instance1.el instance1.dispose() instance2.dispose() @@ -375,10 +371,8 @@ define [ instance1 = new Test1View() instance2 = new Test2View() instance3 = new Test3View {region: 'test2'} - if $ - expect(instance3.container.attr('id')).to.be 'test5' - else - expect(instance3.container.id).to.be 'test5' + + expect(instance3.container.id).to.be 'test5' instance1.dispose() instance2.dispose() @@ -407,10 +401,8 @@ define [ instance2 = new Test2View() instance2.stale = true instance3 = new Test3View {region: 'test2'} - if $ - expect(instance3.container.attr('id')).to.be 'test2' - else - expect(instance3.container.id).to.be 'test2' + + expect(instance3.container.id).to.be 'test2' instance1.dispose() instance2.dispose() diff --git a/test/spec/view_spec.coffee b/test/spec/view_spec.coffee index 6e01dcaf..adcdd3c1 100644 --- a/test/spec/view_spec.coffee +++ b/test/spec/view_spec.coffee @@ -224,26 +224,22 @@ define [ expect(view.undelegate).to.be.a 'function' spy = sinon.spy() - handler = view.delegate 'click', spy - expect(handler).to.be.a 'function' + view.delegate 'click', spy view.render() window.clickOnElement view.el expect(spy).was.called() - view.undelegate() + view.undelegateEvents() window.clickOnElement view.el expect(spy.callCount).to.be 1 spy = sinon.spy() - handler = view.delegate 'click', 'p', spy - expect(handler).to.be.a 'function' + view.delegate 'click', 'p', spy p = view.el.querySelector('p') window.clickOnElement p expect(spy).was.called() - expect(-> view.delegate spy).to.throwError() - - view.undelegate() + view.undelegateEvents() window.clickOnElement p expect(spy.callCount).to.be 1 @@ -292,13 +288,13 @@ define [ expect(spy).was.calledOnce() expect(spy2).was.calledOnce() - it 'should check delegate parameters', -> - expect(-> view.delegate 1, 2, 3).to.throwError() - expect(-> view.delegate 'click', 'foo').to.throwError() - expect(-> view.delegate 'click', 'foo', 'bar').to.throwError() - expect(-> view.delegate 'click', 123).to.throwError() - # expect(-> view.delegate 'click', (->), 123).to.throwError() - # expect(-> view.delegate 'click', 'foo', (->), 'other').to.throwError() + # it 'should check delegate parameters', -> + # expect(-> view.delegate 1, 2, 3).to.throwError() + # expect(-> view.delegate 'click', 'foo').to.throwError() + # expect(-> view.delegate 'click', 'foo', 'bar').to.throwError() + # expect(-> view.delegate 'click', 123).to.throwError() + # # expect(-> view.delegate 'click', (->), 123).to.throwError() + # # expect(-> view.delegate 'click', 'foo', (->), 'other').to.throwError() it 'should correct inheritance of events object', (done) -> class A extends TestView