Created
December 13, 2011 18:50
-
-
Save 4bu/1473327 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<title>wishlist</title> | |
</head> | |
<body> | |
<script type='text/javascript' src='../steal/steal.js?wishlist'></script> | |
You have <span class="js-wish-counter">0</span> wishes. | |
<form class="js-add-wish"> | |
<input type="text" placeholder="pleace add your wish"/> | |
<input type="submit" value="add"/> | |
</form> | |
<ul class="js-wish-list"></ul> | |
<script id="wish-template" type="text/html"> | |
<li> | |
${ wish } | |
<input type="button" class="js-delete" value="remove" /> | |
</li> | |
</script> | |
<script type="text/javascript"> | |
(function () { | |
steal("jquery/controller", "jquery/view/tmpl", function () { | |
$.Controller("WishCounter", { | |
dec: function () { | |
var count = this.element.html(); | |
this.element.html(parseInt(count, 10) - 1); | |
}, | |
inc: function () { | |
var count = this.element.html(); | |
this.element.html(parseInt(count, 10) + 1); | |
} | |
}); | |
$.Controller("WishEntry", { | |
remove: function () { | |
this.element.remove(); | |
$('.js-wish-counter').wish_counter('dec'); | |
}, | |
"input click": function () { | |
this.remove(); | |
} | |
}); | |
$.Controller("WishForm", { | |
add: function () { | |
var input = $('input[type="text"]', this.element), | |
wish = input.val(); | |
if (wish.trim() === '') { | |
return; | |
} | |
$('.js-wish-list').append($.tmpl($('#wish-template'), {wish: wish})); | |
$('li:last-child', $('.js-wish-list')).wish_entry(); | |
$('.js-wish-counter').wish_counter('inc'); | |
input.val(''); | |
}, | |
"submit" : function(el, event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
this.add(); | |
} | |
}); | |
$('.js-add-wish').wish_form(); | |
$('.js-wish-counter').wish_counter(); | |
}); | |
}()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment