Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ <h3>Example</h3>
})
</code>
</pre>
<p>You can also include an object as a third argument to prevent the card component from flipping when clicked. If this argument is not specified, the default behavior is to flip when clicked.</p>

<pre>
<code>
var card = ui.card('&lt;p&gt;I will not flip when clicked&lt;/p&gt;', '&lt;p&gt;You must have clicked another element&lt;/p&gt;', {self_flip: false});
card.el.appendTo('#card');
</code>
</pre>
</section>
</section>

Expand Down Expand Up @@ -626,4 +634,4 @@ <h3>Example</h3>
</section>
</div>
</body>
</html>
</html>
17 changes: 11 additions & 6 deletions lib/components/card/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ exports.Card = Card;
*
* @param {Mixed} front
* @param {Mixed} back
* @param {Object} options
* @return {Card}
* @api public
*/

exports.card = function(front, back){
return new Card(front, back);
exports.card = function(front, back, options){
return new Card(front, back, options);
};

/**
Expand All @@ -26,15 +27,17 @@ exports.card = function(front, back){
*
* @param {Mixed} front
* @param {Mixed} back
* @param {Object} options
* @api public
*/

function Card(front, back) {
function Card(front, back, options) {
ui.Emitter.call(this);
this._front = front || $('<p>front</p>');
this._back = back || $('<p>back</p>');
this.template = html;
this.render();
this.options = options || {self_flip: true};
this.render(this.options);
};

/**
Expand Down Expand Up @@ -110,6 +113,8 @@ Card.prototype.render = function(options){
el.find('.front').empty().append(this._front.el || $(this._front));
el.find('.back').empty().append(this._back.el || $(this._back));
el.click(function(){
self.flip();
if (options.self_flip === true) {
self.flip();
}
});
};
};