-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically adding and removing cards from the stack #4
Comments
I'd appreciate this as well — haven't gone through the source yet, but I'm having trouble getting it to behave properly. |
Can you describe a scenario? http://gajus.com/sandbox/swing/examples/card-state/ Example shows how to throw out card. Throw in would be close to the same. |
What I was trying to do was add cards to the bottom of the stack without throwing them in. I eventually added an extra |
any updates or examples on this? What would be nice is to add cards to the bottom of the stack as cards are swiped from the top |
I've been looking into how to dynamically add new cards to the bottom of the stack, and I seem to have something working. As far as I can tell, the issue seems to be a combination of two things: HTML display order (in the absence of declared z-indexes, nodes at the bottom of the tree appear on top of nodes earlier in the tree), and the Card object's My solution was to remove the I declared the new method directly after Card.insertBelow = function (element) {
var parent = element.parentNode;
parent.removeChild(element);
parent.insertBefore(element,parent.firstChild);
}; (Originally I attempted to alter Code-wise, I don't know if this is a good solution, since it adds an extra DOM manipulation everytime a card is added (whereas |
Nice! I will have to try that out later in a meteor project I was working on. |
@ronobot: do you have some working code to provide? I'm faving the same issue than you... |
@HugoHeneault The project I was working on this for got indefinitely delayed, so I wasn't able to test it further. But basically what I did was:
That's it—now the createCard method uses insertBelow instead of appendToParent. |
Has anyone ever managed to make this work? I want to be able to add a card to the bottom of the stack, and |
I have some working prototype. Maybe it might help you (please note that, this is pseudocode): var cards = []; // In a list
var queue = []; // In a queue
var stackMaxLength = 2;
var stack = Swing.Stack();
var ul = document.querySelector('ul.stack'); // Should be initially empty
var allCards = [
document.createElement('ul'),
document.createElement('ul'),
document.createElement('ul'),
document.createElement('ul'),
document.createElement('ul')
];
allCards.forEach(addOrKeep);
function addOrKeep(element) {
if (cards.length < stackMaxLength) {
cards.push(card);
// Adding element to DOM tree, as far as I remember to create it have to be in a DOM tree.
ul.prepend(element);
var card = stack.createCard(element);
// On front
ul.prepend(element);
card.on('throwout', function () {
var card = queue.shift();
if (card) {
stackMaxLength++;
addOrKeep(card);
}
});
} else {
// We don't want to have it in a DOM.
card.$element.remove();
queue.push(card);
}
} If you want me to make it working example, let me know. |
If you have some time to implement it, it'll be really awesome!! 2016-01-07 23:30 GMT+01:00 Artur Delura [email protected]:
|
I spent a couple of hours trying to add cards to the stack dynamically but I finally made it! The problem is the following: When you call the function createCard() the function creates a new Card object and its constructor calls the function appendToParent(), which makes the Card appear on top of all other cards. If you change this function call, you can prepend cards to the stack. An even better solution would be to have two separate functions or a function parameter. 1.) Do what @ronobot suggested: 2.) Write a function in JS (I used jQuery) to add a Card to the stack: function addNewCard(data,id) {
var newCard = $(cardTemplate).clone();
$(newCard).find('.content').html(data);
$(newCard).attr('id','card_' + id);
$('.stack').prepend($(newCard));
stack.createCard(document.getElementById('card_' + id));
} I'm no JS / jQuery expert so this might not be best practice but it seems to work so far. I have a working extended example here: Hope this helps someone out and thanks to @gajus for the awesome plugin! |
tried the first solution . I am unable to get it working . In my case I do not add cards one by one. Cards are created when i initialize it with an array from an API call. One more card is thrown out when first card is thrown out. What does This is my card.js
in Please help. |
The issue was caused by |
Hey guys, Having a similar issue... I'm looking to add cards into the stack when a checkbox is turned on. When a user clicks a checkbox, the associated cards are entered into the stack and users are able to swipe through them. I can't seem to get the card stack to update when the Would appreciate any help / advice. Cheers `export default class Cards extends Component {
} componentDidMount() {
} componentWillUnmount() { configStack(){
} //Controls keycodes //Controls throwout right with key //Controls throwout left with key //Controls swipe/grab
} //Resets the deck on finish
} //Controls checkboxes removeArray(e){ handleChange(e){
} render() { {selectedCards.map((card, i) => { return ( <Card selectedCategories={this.state.selectedCategories} key={card.advice} ref={c => this.cardRefs.set(i, c)} advice={card.advice} id={card.id} tag={card.tag} isSelected={this.state.selectedCategories.indexOf(card.id) > -1} active={i === this.state.currentCard} next={i === this.state.currentCard - 1} previous={i > this.state.currentCard} dragging={ (i === this.state.currentCard && this.state.dragging) || this.state.resetting } /> ) })} { filterData.map((item, i) => {
} |
* Bugfix [onSpringUpdate used Card.transform instead of config.transform] * Optionally prepend cards instead of appending. Possible fix for #4 * Syntax consistency + fixed comments
I've got the cards working perfectly in a prototype Meteor.js app, and I'm trying to add and remove elements from the stack. I haven't spent too much time trying, but I thought it might make a good example. Thanks again!
The text was updated successfully, but these errors were encountered: