Skip to content

Commit

Permalink
use select-index to select the card on creation
Browse files Browse the repository at this point in the history
if select-index is available on the deck on creation
and if no children has the selected attribute it will automatically
select the card.
  • Loading branch information
kentaromiura committed Aug 13, 2014
1 parent ecb4447 commit e4c9cd2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dist/brick-deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@

BrickDeckElementPrototype.createdCallback = function() {
this.ns = {};
var children = this.children, i, max;
var children = this.children, i, max, anyChildSelected = false;

for(i=0, max=children.length; i<max; i++){
ensureIsCard(children[i]);
anyChildSelected = anyChildSelected || children[i].hasAttribute('selected')
}

var observer = new MutationObserver(function(mutations) {
Expand All @@ -190,6 +191,9 @@
});

observer.observe(this, { childList: true });
if(!anyChildSelected){
this.showCard(this.selectedIndex, {skipTransition:true});
}
};

BrickDeckElementPrototype.attachedCallback = function() {
Expand Down
6 changes: 5 additions & 1 deletion src/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@

BrickDeckElementPrototype.createdCallback = function() {
this.ns = {};
var children = this.children, i, max;
var children = this.children, i, max, anyChildSelected = false;

for(i=0, max=children.length; i<max; i++){
ensureIsCard(children[i]);
anyChildSelected = anyChildSelected || children[i].hasAttribute('selected')
}

var observer = new MutationObserver(function(mutations) {
Expand All @@ -105,6 +106,9 @@
});

observer.observe(this, { childList: true });
if(!anyChildSelected){
this.showCard(this.selectedIndex, {skipTransition:true});
}
};

BrickDeckElementPrototype.attachedCallback = function() {
Expand Down

0 comments on commit e4c9cd2

Please sign in to comment.