Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 01ce69d7844e1859fd4b2d30071a8bc7865cd9c7 Pinhook committed Feb 19, 2011
0 README
No changes.
@@ -0,0 +1,15 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../funcunit/qunit/qunit.css" />
+ <title>todo FuncUnit Test</title>
+ <script type='text/javascript' src='../steal/steal.js?todo/test/funcunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">todo Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <link rel="stylesheet" type="text/css" href="../funcunit/qunit/qunit.css" />
+ <title>todo QUnit Test</title>
+ <script type='text/javascript'>
+ steal = {ignoreControllers: true}
+ </script>
+ <script type='text/javascript' src='../steal/steal.js?todo/test/qunit'></script>
+ </head>
+ <body>
+
+ <h1 id="qunit-header">todo Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <div id="test-content"></div>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-test-area"></div>
+ </body>
+</html>
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>todo Build Page</title>
+ </head>
+ <body>
+ <h1>todo Build Page</h1>
+ <p>This is a dummy page that loads your app so steal can
+ get all the files.
+ </p>
+ <p>If you built your app
+ to depend on HTML in the page before DOMContent loaded or
+ onload, you can add the HTML here, or you can change the
+ build.js script to point to a better html file.
+ </p>
+ <script type='text/javascript'
+ src='../../steal/steal.js?todo'>
+ </script>
+ </body>
+</html>
@@ -0,0 +1,6 @@
+//steal/js todo/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/build','steal/build/scripts','steal/build/styles',function(){
+ steal.build('todo/scripts/build.html',{to: 'todo'});
+});
@@ -0,0 +1,17 @@
+//steal/js todo/scripts/compress.js
+
+load("steal/rhino/steal.js");
+steal.plugins('steal/clean',function(){
+ steal.clean('todo/todo.html',{
+ indent_size: 1,
+ indent_char: '\t',
+ jslint : false,
+ ignore: /jquery\/jquery.js/,
+ predefined: {
+ steal: true,
+ jQuery: true,
+ $ : true,
+ window : true
+ }
+ });
+});
@@ -0,0 +1,6 @@
+//js todo/scripts/doc.js
+
+load('steal/rhino/steal.js');
+steal.plugins("documentjs").then(function(){
+ DocumentJS('todo/todo.html');
+});
@@ -0,0 +1,3 @@
+steal
+ .plugins("funcunit")
+ .then("todo_test");
@@ -0,0 +1,9 @@
+module("todo test", {
+ setup: function(){
+ S.open("//todo/todo.html");
+ }
+});
+
+test("Copy Test", function(){
+ equals(S("h1").text(), "Welcome to JavaScriptMVC 3.0!","welcome text");
+});
@@ -0,0 +1,3 @@
+steal
+ .plugins("funcunit/qunit", "todo")
+ .then("todo_test");
@@ -0,0 +1,5 @@
+module("todo");
+
+test("todo testing works", function(){
+ ok(true,"an assert is run");
+});
@@ -0,0 +1,43 @@
+body {
+ font-family: verdana;
+ background-image: url("http://javascriptmvc.com/jmvc/images/backgrounds/body.png");
+ padding: 0px; margin: 0px;
+}
+#todos {
+ -moz-background-clip: border;
+ -moz-background-origin: padding;
+ -moz-background-size: auto auto;
+ -moz-box-shadow: 0 5px 6px 0 rgba(0, 0, 0, 0.2);
+ background-attachment: scroll;
+ background-color: white;
+ background-image: none;
+ background-position: 0 0;
+ background-repeat: repeat;
+ margin: 0 auto 40px auto;
+ padding: 20px;
+ width: 480px;
+}
+
+h1{
+ text-align: center;
+}
+.create, input.text {
+ font-size: 1.4em;
+ width: 100%;
+}
+
+ul {
+ margin: 0px;padding: 0px;
+}
+.todo {
+ list-style: none;
+ border-bottom: solid 1px #CCCCCC;
+ padding: 5px 1px;
+ font-size: 1.4em;
+}
+#todo-stats {
+ margin-top: 20px;
+}
+#list {
+ margin-top: 20px;
+}
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+ <head>
+ <title>todo</title>
+ </head>
+ <body>
+ <div id='todos'>
+ <h1>Todos</h1>
+ <input type='text' class='create'/>
+ <ul id='list'></ul>
+ <div id='todo-stats'>
+
+ </div>
+ </div>
+
+ <script type='text/ejs' id='todosEJS'>
+ <% for(var i =0; i < this.length ; i++){ %>
+ <li <%= this[i]%>>
+ <%= $.View('todoEJS',this[i] ) %>
+ </li>
+ <% } %>
+ </script>
+ <script type='text/ejs' id='todoEJS'>
+ <input type='checkbox' name='complete'
+ <%= this.complete ? "checked" : "" %>>
+ <span class=''><%= (this.text || "empty todo ...")%></span>
+ <span class='destroy'></span>
+ </script>
+ <script type='text/ejs' id='statsEJS'>
+ <% if (total) { %>
+ <span class="todo-count">
+ <span class="number"><%= remaining %></span>
+ <span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left.
+ </span>
+ <% } %>
+ <% if (completed) { %>
+ <span class="todo-clear">
+ <a href="#">
+ Clear <span class="number-done"><%= completed %></span>
+ completed <span class="word-done"><%= completed == 1 ? 'item' : 'items' %></span>
+ </a>
+ </span>
+ <% } %>
+
+ </script>
+ <script type='text/javascript'
+ src='../steal/steal.js?todo,development'>
+ </script>
+ </body>
+</html>
@@ -0,0 +1,167 @@
+steal.css('todo')
+ .plugins('jquery/model/list',
+ 'jquery/controller',
+ 'jquery/view/ejs',
+ 'jquery/lang/json').then(function($){
+
+// a helper for retrieving JSON data from localStorage
+var localStore = function(name, cb, self){
+ var data = $.evalJSON( window.localStorage[name] || (window.localStorage[name] = "{}") ),
+ res = cb.call(self, data);
+ if(res !== false){
+ window.localStorage[name] = $.toJSON(data);
+ }
+};
+
+// A todo model for CRUDing todos.
+$.Model('Todo',{
+ findAll : function(ids, success, error){
+ localStore("todos", function(todos){
+ instances = [];
+ for(var id in todos){
+ if(!ids || !ids.length || $.inArray(id, ids)){
+ instances.push( new this( todos[id]) )
+ }
+ }
+ success && success(instances)
+ }, this)
+ },
+ destroyAll : function(ids, success, error){
+ localStore("todos",function(todos){
+ $.each(ids, function(){
+ delete todos[this]
+ });
+ });
+ success();
+ },
+ destroy : function(id, success){
+ localStore("todos",function(todos){
+ delete[id]
+ })
+ success();
+ },
+ create : function(attrs, success, error){
+ localStore("todos",function(todos){
+ attrs.id = attrs.id || parseInt(100000 *Math.random())
+ todos[attrs.id] = attrs;
+ });
+ success({id : attrs.id})
+ },
+ update : function(id, attrs, success){
+ localStore("todos",function(todos){
+ var todo = todos[id];
+ $.extend(todo, attrs);
+ });
+ success({});
+ }
+},{});
+
+// A list of todos.
+$.Model.List('Todo.List',{
+
+ // A helper for making a list of completed todos.
+ completed : function(){
+ return this.grep(function(item){
+ return item.complete === true;
+ })
+ }
+});
+
+
+// A todos widget
+$.Controller('Todos',{
+
+ //setup and finding
+ init : function(){
+ this.find(".create").val("")[0].focus();
+ this.options.list.findAll();
+ },
+
+ //adds existing and created to the list
+ "{list} add" : function(list, ev, items){
+ this.find('#list').append("todosEJS",items)
+ this.updateStats();
+ },
+
+ //creating
+ ".create keyup" : function(el, ev){
+ if(ev.keyCode == 13){
+ new Todo({
+ text : el.val(),
+ complete : false
+ }).save(this.callback('created'));
+
+ el.val("");
+ }
+ },
+ "created" : function(todo){
+ this.options.list.push(todo); //triggers 'add' on the list
+ },
+
+ //destroying
+ ".clear click" : function(){
+ this.options.list.completed()
+ .destroyAll(); //this is calling on the list, needs to be implemented
+ //but confusing
+ },
+
+
+ ".todo mouseover" : function(){
+ //show delete
+ },
+ ".todo .destroy click" : function(el){
+ el.closest('.todo').model().destroy();
+ },
+ "{list} remove" : function(list, ev, items){
+ items.elements(this.element).slideUp(function(){
+ $(this).remove();
+ });
+ this.updateStats();
+ },
+
+ ".todo-clear click" : function(){
+ this.options.list.completed().destroyAll();
+ },
+
+ // Update
+
+ ".todo [name=complete] change" : function(el, ev){
+ var todo = el.closest('.todo').model().update({
+ complete : el.is(':checked')
+ });
+ },
+
+ ".todo dblclick" : function(el){
+ var input = $("<input name='text' class='text'/>").val(el.model().text)
+ el.html(input);
+ input[0].focus();
+ },
+ ".todo [name=text] focusout" : function(el, ev){
+ var todo = el.closest('.todo').model().update({
+ text : el.val()
+ });
+ },
+ "{list} update" : function(list, ev, item){
+ item.elements().html("todoEJS", item);
+ this.updateStats();
+ //update completed
+ },
+ updateStats : function(){
+ var list = this.options.list,
+ completed = list.completed().length;
+ $("#todo-stats").html("statsEJS",{
+ completed : completed,
+ total : list.length,
+ remaining : list.length - completed
+ })
+ }
+})
+
+
+
+$(function(){
+ $("#todos").todos({list : new Todo.List()});
+})
+
+
+});

0 comments on commit 01ce69d

Please sign in to comment.