Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…idation
  • Loading branch information...
commit 7d899fe5485710b142a00ae9b8e297aa3ce1150c 1 parent 644c337
Addy Osmani authored
7 css/todo.css
View
@@ -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;
+}
7 index.html
View
@@ -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>
2  js/application_core/jquery-core.js
View
@@ -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')){
6,234 js/libs/jquery.js
View
4 additions, 6,230 deletions not shown
55 js/modules/modules.js
View
@@ -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,8 +163,6 @@ app.core.define("#todo-list", function (f) {
addItem : function ( todoItem ) {
var entry;
- if(todoItem.value !== ""){
-
entry = f.createElement("li", {
id : "todo-" + todoItem.id,
children : [
@@ -142,7 +170,6 @@ app.core.define("#todo-list", function (f) {
],
'class' : 'todo_entry'
});
-
todo.appendChild(entry);
@@ -150,19 +177,13 @@ app.core.define("#todo-list", function (f) {
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();
Please sign in to comment.
Something went wrong with that request. Please try again.