Permalink
Browse files

updates to UI, version of jQuery used and some further cleanup of val…

…idation
  • Loading branch information...
1 parent 644c337 commit 7d899fe5485710b142a00ae9b8e297aa3ce1150c @addyosmani committed Feb 9, 2012
Showing with 57 additions and 6,248 deletions.
  1. +7 −0 css/todo.css
  2. +7 −0 index.html
  3. +1 −1 js/application_core/jquery-core.js
  4. +4 −6,230 js/libs/jquery.js
  5. +38 −17 js/modules/modules.js
View
7 css/todo.css
@@ -534,3 +534,10 @@ select,
}
+#credits {
+ width: 520px;
+ margin: 30px auto;
+ color: #999;
+ text-shadow: rgba(255, 255, 255, 0.8) 0 1px 0;
+ text-align: center;
+}
View
7 index.html
@@ -23,6 +23,7 @@
<button class="btn">Add</button>
</div>
+ <div id="validate"></div>
<div id="error">
<div id="alert">
@@ -34,6 +35,12 @@
</div>
+ <div id="credits">
+ By
+ Addy Osmani, based on prior concepts<br>discussed by
+ N.Zakas, A.Burgess and others.
+ </div>
+
<!-- uncomment the set of libraries and core you would like to use -->
<!--
<script src="js/libs/dojo.js"></script>
View
2 js/application_core/jquery-core.js
@@ -149,7 +149,7 @@ app.core = (function(){
//jQuery object
if(el instanceof jQuery){
- q = el.attr(attribs);
+ q = el.attr(attribs);
}else{
//string
if(app.utils.typeEqual(el, 'string')){
View
6,234 js/libs/jquery.js
4 additions, 6,230 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
55 js/modules/modules.js
@@ -7,7 +7,7 @@ app.core.define('#todo-counter', function(f){
init:function(){
counter = f.find('#count')[0];
f.subscribe({
- 'new-entry' : this.updateCounter
+ 'entry-validated' : this.updateCounter
});
},
@@ -36,7 +36,7 @@ app.core.define('#todo-field', function(f){
input = f.getEl();
f.subscribe({
- 'new-entry' : this.clearEntry
+ 'entry-validated' : this.clearEntry
});
},
destroy:function(){
@@ -89,28 +89,58 @@ app.core.define('#todo-entry', function(f){
+app.core.define('#validate', function(f){
+ return {
+ init: function(){
+ f.subscribe({
+ 'new-entry' : this.validateEntry
+ });
+ },
+
+ destroy: function(){
+ },
+
+ validateEntry: function ( todoItem ){
+ if(todoItem.value == ""){
+ f.publish({
+ type : 'input-error',
+ data : {value: 'Please ensure your input is valid'}
+ });
+ }else{
+ f.publish({
+ type : 'entry-validated',
+ data : todoItem
+ });
+ }
+ }
+ }
+});
+
+
app.core.define('#error', function(f){
- var errorHolder;
+ var errorNotice;
return {
init: function(){
- errorHolder = f.find('#alert')[0];
+ errorNotice = f.find('#alert')[0];
f.subscribe({
'input-error' : this.showError
});
+
},
destroy: function(){
- errorHolder = null;
+ errorNotice = null;
},
showError: function( msg ){
- f.setHTML(errorHolder, msg.value);
+ f.setHTML(errorNotice, msg.value);
}
}
});
+
app.core.define("#todo-list", function (f) {
var todo, todoItems, renderedItems;
@@ -120,7 +150,7 @@ app.core.define("#todo-list", function (f) {
todoItems = {};
f.subscribe({
- 'new-entry' : this.addItem
+ 'entry-validated' : this.addItem
});
},
@@ -133,36 +163,27 @@ app.core.define("#todo-list", function (f) {
addItem : function ( todoItem ) {
var entry;
- if(todoItem.value !== ""){
-
entry = f.createElement("li", {
id : "todo-" + todoItem.id,
children : [
f.createElement("span", { 'class' : 'item_name',text : todoItem.value })
],
'class' : 'todo_entry'
});
-
todo.appendChild(entry);
entry = f.find('#todo-' + todoItem.id)[0];
f.css(entry, {'color': f.getRandomColor(), 'background': f.getRandomColor()});
f.animate(entry, {'line-height':'50'}, 500);
todoItems[todoItem.id] = 1;
-
- }else{
- f.publish({
- type : 'input-error',
- data : {value: 'Please input a valid todo entry'}
- });
- }
}
};
});
+
app.core.startAll();

0 comments on commit 7d899fe

Please sign in to comment.