Browse files

added cardview, using runloop

  • Loading branch information...
1 parent 3f5faa6 commit 3d83b35a811a4953eda6f068e7ecbc74ca9b3c8f @qoobaa committed Aug 15, 2011
Showing with 17 additions and 9 deletions.
  1. +5 −1 index.html
  2. +12 −8 lib/main.js
View
6 index.html
@@ -6,13 +6,17 @@
<body>
<h1>Ficha</h1>
- <script type="text/x-handlebars">
+ <script id="card" type="text/x-handlebars">
<p>
{{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.front" placeholder="Front side"}}
</p>
<p>
{{view Ficha.SideView valueBinding="Ficha.cardController.currentCard.back" placeholder="Back side"}}
</p>
+ </script>
+
+ <script type="text/x-handlebars">
+ {{view Ficha.CardView}}
{{#collection contentBinding="Ficha.cardsController" tagName="ul"}}
{{content.front}} {{content.back}}
View
20 lib/main.js
@@ -41,18 +41,22 @@ Ficha.cardController = SC.Object.create({
Ficha.cardsController.pushObject(this.get("currentCard"));
this.newCard();
}
- },
-
- sideViewInsertNewline: function (event) {
- this.createCard();
- setTimeout(function () {
- $(event.target).parents(".sc-view").find("input[type='text'][value='']:first").focus();
- }, 0);
}
});
Ficha.SideView = SC.TextField.extend({
insertNewline: function (event) {
- Ficha.cardController.sideViewInsertNewline(event);
+ this.get("parentView").sideViewInsertNewline();
+ }
+});
+
+Ficha.CardView = SC.View.extend({
+ templateName: "card",
+
+ sideViewInsertNewline: function () {
+ SC.RunLoop.begin();
+ Ficha.cardController.createCard();
+ SC.RunLoop.end();
+ this.$("input[type='text'][value='']:first").focus();
}
});

0 comments on commit 3d83b35

Please sign in to comment.