Skip to content

Commit

Permalink
fix(item): clicks climb 5 levels looking for an item to activate, but…
Browse files Browse the repository at this point in the history
… not 6. Fixes #1921
  • Loading branch information
perrygovier committed Aug 19, 2014
1 parent 0bf6bc5 commit 840c014
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/utils/activator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
var ele = e.target;
var eleToActivate;

for(var x=0; x<4; x++) {
for(var x=0; x<6; x++) {
if(!ele || ele.nodeType !== 1) break;
if(eleToActivate && ele.classList.contains('item')) {
eleToActivate = ele;
Expand All @@ -32,6 +32,10 @@
eleToActivate = ele;
break;
}
// no sense climbing past these
if(ele.classList.contains('pane') || ele.tagName == 'BODY' || ele.tagName == 'ION-CONTENT'){
break;
}
ele = ele.parentElement;
}

Expand Down
29 changes: 29 additions & 0 deletions test/unit/utils/activator.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ describe('Ionic Element Activator', function() {
expect(itemContentEle.classList.contains('activated')).toEqual(false);
expect(aEle.classList.contains('activated')).toEqual(true);
});
it('Should activate 5 levels up, but not 6', function() {
var itemEle = document.createElement('div');
itemEle.className = 'item';

var itemContentEle = document.createElement('a');
itemContentEle.className = 'item-content';
itemEle.appendChild(itemContentEle);

var div1 = document.createElement('div');
itemContentEle.appendChild(div1);
var div2 = document.createElement('div');
div1.appendChild(div2);
var div3 = document.createElement('div');
div2.appendChild(div3);
var div4 = document.createElement('div');
div3.appendChild(div4);
var div5 = document.createElement('div');
div4.appendChild(div5);
var div6 = document.createElement('div');
div5.appendChild(div6);

var e = { target: div6 };
ionic.activator.start(e);
expect(itemContentEle.classList.contains('activated')).toEqual(false);

var e = { target: div5 };
ionic.activator.start(e);
expect(itemContentEle.classList.contains('activated')).toEqual(true);
});

it('Should activate child "div.item-content div[ng-click]" of a .item', function() {
var itemEle = document.createElement('div');
Expand Down

0 comments on commit 840c014

Please sign in to comment.