1 /** 2 * @fileOverview a scoreboard widget 3 * @author Bryan Berry <bryan@olenepal.org> 4 * uses MIT License 5 */ 6 7 8 9 (function($){ 10 11 // This is a dummy function, just here as placeholder to 12 // to make the jsdoc tool happy 13 /** @name $.ui.feedback 14 * @namespace Feedback widget 15 */ 16 $.ui.feedback = function(){}; 17 18 $.widget('ui.feedback', 19 /** @lends $.ui.feedback.prototype */ 20 { 21 /** Displays the correct icon in the center of the screen 22 * and plays the sound "correct" if loaded 23 */ 24 correct: function(){ 25 var $correct = this.$correct.css('display','block'); 26 setTimeout ( function() { 27 $correct.fadeOut(500); 28 }, 500); 29 if (Karma && Karma.audio && Karma.audio.correct){ 30 Karma.audio.correct.play(); 31 } 32 33 }, 34 /** Displays the incorrect icon in the center of the screen 35 * and plays the sound "incorrect" if loaded 36 */ 37 incorrect: function(){ 38 39 var $incorrect = this.$incorrect.css('display','block'); 40 setTimeout ( function() { 41 $incorrect.fadeOut(500); 42 }, 500); 43 44 //this.$incorrect.css('display','block').fadeOut(3000); 45 if (Karma && Karma.audio && Karma.audio.incorrect){ 46 Karma.audio.incorrect.play(); 47 } 48 49 }, 50 _init : function(){ 51 var self = this; 52 53 this.element 54 .addClass('ui-feedback') 55 .css({position:'absolute', 56 top: '40%', left: '40%'}); 57 58 this.$correct = $('<div></div>') 59 .addClass('ui-feedback-correct') 60 .appendTo(this.element); 61 62 this.$incorrect = $('<div></div>') 63 .addClass('ui-feedback-incorrect') 64 .appendTo(this.element); 65 66 $('body') 67 .bind('feedbackCorrect', function(){ 68 self.correct(); 69 }) 70 .bind('feedbackIncorrect', function(){ 71 self.incorrect(); 72 }); 73 74 }, 75 /** Removes the feedback widget and all related data from the DOM */ 76 destroy : function(){ 77 this.element.remove(); 78 $.widget.prototype.destroy.apply(this, arguments); 79 } 80 81 82 }); 83 84 $.ui.feedback.getter = []; 85 86 /** Default settings for the feedback widget 87 * @namespace Default settings for the feedback widget 88 * @extends $.ui.feedback 89 */ 90 $.ui.feedback.defaults = { 91 }; 92 93 })(jQuery);