From c1ac473944386b25ffce494ccbb2f86255d0f5ac Mon Sep 17 00:00:00 2001 From: Dave Porter Date: Sun, 20 May 2012 17:27:30 -0400 Subject: [PATCH] Fixing issue where clicking on a content-less collection view would throw an error. --- frameworks/desktop/tests/views/collection/mouse.js | 13 +++++++++++++ frameworks/desktop/views/collection.js | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frameworks/desktop/tests/views/collection/mouse.js b/frameworks/desktop/tests/views/collection/mouse.js index d5559b1e5c..bcde5c178f 100644 --- a/frameworks/desktop/tests/views/collection/mouse.js +++ b/frameworks/desktop/tests/views/collection/mouse.js @@ -153,6 +153,19 @@ test("first responder", function() { equals(view.get('isFirstResponder'), YES, 'view.isFirstResponder should be YES after mouse down'); }); +test("clicking on a collection view with null content should not throw an error", function() { + var failed = NO; + view.set('content', null); + try { + var l = view.get('layer'), + evt = SC.Event.simulateEvent(l, 'mousedown'); + SC.Event.trigger(l, 'mousedown', [evt]); + } + catch (e) { failed = YES; } + ok(!failed, "clicking on a collection view with null content should not throw an error"); +}); + + // .......................................................... // ctrl-click mouse down // diff --git a/frameworks/desktop/views/collection.js b/frameworks/desktop/views/collection.js index 82c7112b3e..19d4166dd5 100644 --- a/frameworks/desktop/views/collection.js +++ b/frameworks/desktop/views/collection.js @@ -2149,8 +2149,11 @@ SC.CollectionView = SC.View.extend(SC.CollectionViewDelegate, SC.CollectionConte @returns {Boolean} Usually YES. */ mouseDown: function(ev) { + var content = this.get('content'); + + if (!content) return this.get('isSelectable'); + var itemView = this.itemViewForEvent(ev), - content = this.get('content'), contentIndex = itemView ? itemView.get('contentIndex') : -1, info, anchor, sel, isSelected, modifierKeyPressed, didSelect = NO, allowsMultipleSel = content.get('allowsMultipleSelection');