Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
@@ -534,3 +534,10 @@ select,
534 534 }
535 535
536 536
  537 +#credits {
  538 + width: 520px;
  539 + margin: 30px auto;
  540 + color: #999;
  541 + text-shadow: rgba(255, 255, 255, 0.8) 0 1px 0;
  542 + text-align: center;
  543 +}
7 index.html
@@ -23,6 +23,7 @@
23 23 <button class="btn">Add</button>
24 24 </div>
25 25
  26 + <div id="validate"></div>
26 27 <div id="error">
27 28 <div id="alert">
28 29
@@ -34,6 +35,12 @@
34 35
35 36 </div>
36 37
  38 + <div id="credits">
  39 + By
  40 + Addy Osmani, based on prior concepts<br>discussed by
  41 + N.Zakas, A.Burgess and others.
  42 + </div>
  43 +
37 44 <!-- uncomment the set of libraries and core you would like to use -->
38 45 <!--
39 46 <script src="js/libs/dojo.js"></script>
2  js/application_core/jquery-core.js
@@ -149,7 +149,7 @@ app.core = (function(){
149 149
150 150 //jQuery object
151 151 if(el instanceof jQuery){
152   - q = el.attr(attribs);
  152 + q = el.attr(attribs);
153 153 }else{
154 154 //string
155 155 if(app.utils.typeEqual(el, 'string')){
6,234 js/libs/jquery.js
4 additions, 6,230 deletions not shown
55 js/modules/modules.js
@@ -7,7 +7,7 @@ app.core.define('#todo-counter', function(f){
7 7 init:function(){
8 8 counter = f.find('#count')[0];
9 9 f.subscribe({
10   - 'new-entry' : this.updateCounter
  10 + 'entry-validated' : this.updateCounter
11 11 });
12 12
13 13 },
@@ -36,7 +36,7 @@ app.core.define('#todo-field', function(f){
36 36 input = f.getEl();
37 37
38 38 f.subscribe({
39   - 'new-entry' : this.clearEntry
  39 + 'entry-validated' : this.clearEntry
40 40 });
41 41 },
42 42 destroy:function(){
@@ -89,28 +89,58 @@ app.core.define('#todo-entry', function(f){
89 89
90 90
91 91
  92 +app.core.define('#validate', function(f){
  93 + return {
  94 + init: function(){
  95 + f.subscribe({
  96 + 'new-entry' : this.validateEntry
  97 + });
  98 + },
  99 +
  100 + destroy: function(){
  101 + },
  102 +
  103 + validateEntry: function ( todoItem ){
  104 + if(todoItem.value == ""){
  105 + f.publish({
  106 + type : 'input-error',
  107 + data : {value: 'Please ensure your input is valid'}
  108 + });
  109 + }else{
  110 + f.publish({
  111 + type : 'entry-validated',
  112 + data : todoItem
  113 + });
  114 + }
  115 + }
  116 + }
  117 +});
  118 +
  119 +
92 120 app.core.define('#error', function(f){
93   - var errorHolder;
  121 + var errorNotice;
94 122
95 123 return {
96 124 init: function(){
97   - errorHolder = f.find('#alert')[0];
  125 + errorNotice = f.find('#alert')[0];
98 126
99 127 f.subscribe({
100 128 'input-error' : this.showError
101 129 });
  130 +
102 131 },
103 132
104 133 destroy: function(){
105   - errorHolder = null;
  134 + errorNotice = null;
106 135 },
107 136
108 137 showError: function( msg ){
109   - f.setHTML(errorHolder, msg.value);
  138 + f.setHTML(errorNotice, msg.value);
110 139 }
111 140 }
112 141 });
113 142
  143 +
114 144 app.core.define("#todo-list", function (f) {
115 145 var todo, todoItems, renderedItems;
116 146
@@ -120,7 +150,7 @@ app.core.define("#todo-list", function (f) {
120 150 todoItems = {};
121 151
122 152 f.subscribe({
123   - 'new-entry' : this.addItem
  153 + 'entry-validated' : this.addItem
124 154 });
125 155
126 156 },
@@ -133,8 +163,6 @@ app.core.define("#todo-list", function (f) {
133 163 addItem : function ( todoItem ) {
134 164 var entry;
135 165
136   - if(todoItem.value !== ""){
137   -
138 166 entry = f.createElement("li", {
139 167 id : "todo-" + todoItem.id,
140 168 children : [
@@ -142,7 +170,6 @@ app.core.define("#todo-list", function (f) {
142 170 ],
143 171 'class' : 'todo_entry'
144 172 });
145   -
146 173
147 174 todo.appendChild(entry);
148 175
@@ -150,19 +177,13 @@ app.core.define("#todo-list", function (f) {
150 177 f.css(entry, {'color': f.getRandomColor(), 'background': f.getRandomColor()});
151 178 f.animate(entry, {'line-height':'50'}, 500);
152 179 todoItems[todoItem.id] = 1;
153   -
154   - }else{
155   - f.publish({
156   - type : 'input-error',
157   - data : {value: 'Please input a valid todo entry'}
158   - });
159   - }
160 180
161 181 }
162 182 };
163 183 });
164 184
165 185
  186 +
166 187 app.core.startAll();
167 188
168 189

0 comments on commit 7d899fe

Please sign in to comment.
Something went wrong with that request. Please try again.