Commits

Alex Efros committed dc8769d

added widget Sum

  • Participants
  • Parent commits d35c568

Comments (0)

Files changed (2)

     <script type="text/javascript" src="w.addphrase.js"></script>
     <script type="text/javascript" src="w.phrase.js"></script>
     <script type="text/javascript" src="w.spellcheck.js"></script>
+    <script type="text/javascript" src="w.sum.js"></script>
 </head>
 <body>
 <script type="text/javascript">
 notice = (function(){
     var w = {
         addphrase: null,
-        phrase: {}
+        phrase: {},
+        sum: null
     };
+    var spellerrors = {};
     return function(e,data){
         switch (e) {
         case 'document ready':
             w.addphrase = new W.AddPhrase('addphrase');
             $('#addphrase input').focus();
+            w.sum = new W.Sum('sum');
             break;
         case 'add phrase':
             if(data.phrase in w.phrase)
             w.phrase[data.phrase].$.remove();
             delete w.phrase[data.phrase];
             $('#addphrase input').focus();
+            if(data.phrase in spellerrors){
+                w.sum.sub(spellerrors[data.phrase]);
+                delete spellerrors[data.phrase];
+            }
             break;
         case 'spellcheck: started':
             break;
         case 'spellcheck: success':
+            w.sum.add(data.spellerrors);
+            spellerrors[data.phrase] = data.spellerrors;
             break;
         default:
             alert('notice: unknown event "'+e+'"');
         <% } %>
     </script>
 </div>
+<p><b>Итого: <span id="sum"></span> ошибок.</b></p>
 </body>
 </html>
+/*
+ * <span id="sum"></span>
+ *
+ * w = new W.Sum('sum');
+ * w.add(5);
+ * w.sub(3);
+ *
+ */
+var W; W = W || {};
+
+W.Sum = function(id){
+    this.$      = $( '#'+id );
+    this.$.html(0);
+};
+
+W.Sum.prototype.add = function(n){
+    this.$.html( parseInt(this.$.html()) + n );
+};
+
+W.Sum.prototype.sub = function(n){
+    this.$.html( parseInt(this.$.html()) - n );
+};