Created
August 22, 2012 11:35
-
-
Save ayrton/3424708 to your computer and use it in GitHub Desktop.
Coffeescript (after) vs. JavaScript (before)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Card | |
constructor: (selector) -> | |
@$container = $('.cards') | |
@$element = @$container.find(selector) | |
@$text = @$element.find('.card-menu li:first-child a span') | |
toggleClass: -> | |
@$element.toggleClass('is-favorited') | |
changeText: -> | |
cardText = if @$element.favorited then 'Unfavorite' else 'Favorite' | |
@$text.text(cardText) | |
sort: -> | |
@$container.trigger('isotope:sort') | |
favorited: -> | |
@$element.hasClass('is-favorited') | |
$ -> | |
card = new Card('#card-<%= @id %>') | |
card.toggleClass() | |
card.changeText() | |
card.sort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$container = $('.cards'); | |
$card = $container.find('#card-<%= @id %>'); | |
$cardText = $card.find('.card-menu li:first-child a span'); | |
$card.toggleClass('is-favorited'); | |
if ($card.hasClass('is-favorited')) { | |
cardText = 'Unfavorite'; | |
} else { | |
cardText = 'Favorite'; | |
} | |
$cardText.text(cardText); | |
$container.trigger('isotope:sort'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment