Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/js/ui.feedback.js
blob: f9304c5a7644ada4922d0d30d9e73bd785a1bc5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* @fileOverview a scoreboard widget
* @author Bryan Berry <bryan@olenepal.org> 
*  uses MIT License
*/



(function($){

     // This is a dummy function, just here as placeholder to
     // to make the jsdoc tool happy
     /** @name $.ui.feedback
      * @namespace Feedback widget
      */
     $.ui.feedback = function(){};

     $.widget('ui.feedback',
	      /** @lends $.ui.feedback.prototype */
	      {
		  /** Displays the correct icon in the center of the screen
		   *  and plays the sound "correct" if loaded
		   */
		  correct: function(){
		      var $correct = this.$correct.css('display','block');
		      setTimeout ( function() {
				       $correct.fadeOut(500);
				   }, 500);
		      if (Karma && Karma.audio && Karma.audio.correct){
			  Karma.audio.correct.play();
		      }
		      
		  },
		  /** Displays the incorrect icon in the center of the screen
		   *  and plays the sound "incorrect" if loaded
		   */
		  incorrect: function(){
		      
		      var $incorrect = this.$incorrect.css('display','block');
		      setTimeout ( function() {
				       $incorrect.fadeOut(500);
				   }, 500);

		      //this.$incorrect.css('display','block').fadeOut(3000);
		      if (Karma && Karma.audio && Karma.audio.incorrect){
			  Karma.audio.incorrect.play();
		      }
		      
		  },
		  win: function(){
		      this.$win.show();
		      this.$overlay.show();
		  },
		  lose: function(){
		      this.$lose.show();
		      this.$overlay.show();
		  },
		  _init : function(){
		      var self = this;
		      
		      this.element
			  .addClass('ui-feedback')
			  .css({position:'absolute', 
				top: '40%', left: '40%'});
		      
		      this.$correct = $('<div></div>')
			  .addClass('ui-feedback-correct')
			  .appendTo(this.element);

		      this.$incorrect = $('<div></div>')
			  .addClass('ui-feedback-incorrect')
			  .appendTo(this.element);
		      
		      this.$win = $("<div class='ui-feedback-over'>" +
				     "<div class='ui-feedback-win'></div>" +
				     "<div class='ui-feedback-txt'>You win!" +
				     "</div></div>")
				    .click(
					function(){
					    self.$win.hide();
					    self.$overlay.hide();
					}
				    )
				    .appendTo(this.element);

		      this.$lose = $("<div class='ui-feedback-over'>" +
				     "<div class='ui-feedback-lose'></div>" +
				     "<div class='ui-feedback-txt'>You lose!" +
				     "</div></div>")
				     .click(
					 function(){
					     self.$lose.hide();
					     self.$overlay.hide();
					 }
				     )
				     .appendTo(this.element);
		      
		      this.$overlay = $('<div></div>')
			  .addClass('ui-feedback-overlay')
			  .appendTo($('body'));

		      

		      $('body')
			  .bind('feedbackCorrect', function(){
				    self.correct();
				})
			  .bind('feedbackIncorrect', function(){
				    self.incorrect();
				});
		     
		  },
		  /** Removes the feedback widget and all related data from the DOM */
		  destroy : function(){
		      this.element.remove();
		      $.widget.prototype.destroy.apply(this, arguments);
		  }

		  
	      });

	      $.ui.feedback.getter = [];
		
		/** Default settings for the feedback widget
		 * @namespace Default settings for the feedback widget
		 * @extends $.ui.feedback
		 */			   
	      $.ui.feedback.defaults = {
	      };

 })(jQuery);