src/widgets/Controller.js
changeset 1068 7623f9af9272
parent 1033 c20df1c080e6
child 1069 2409cb4cebaf
equal deleted inserted replaced
1067:539c9bee5372 1068:7623f9af9272
     9 
     9 
    10 IriSP.Widgets.Controller.prototype.defaults = {
    10 IriSP.Widgets.Controller.prototype.defaults = {
    11     disable_annotate_btn: false,
    11     disable_annotate_btn: false,
    12     disable_search_btn: false,
    12     disable_search_btn: false,
    13     disable_ctrl_f: false,
    13     disable_ctrl_f: false,
    14     always_show_search: false
    14     always_show_search: false,
       
    15     enable_quiz_toggle: undefined
    15 };
    16 };
    16 
    17 
    17 IriSP.Widgets.Controller.prototype.template =
    18 IriSP.Widgets.Controller.prototype.template =
    18     '<div class="Ldt-Ctrl">'
    19     '<div class="Ldt-Ctrl">'
    19     + '<div class="Ldt-Ctrl-Left">'
    20     + '<div class="Ldt-Ctrl-Left">'
    23     + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Annotate Ldt-TraceMe" title="{{l10n.annotate}}"></div>'
    24     + '<div class="Ldt-Ctrl-button Ldt-Ctrl-Annotate Ldt-TraceMe" title="{{l10n.annotate}}"></div>'
    24     + '<div class="Ldt-Ctrl-spacer"></div>'
    25     + '<div class="Ldt-Ctrl-spacer"></div>'
    25     + '{{/disable_annotate_btn}}'
    26     + '{{/disable_annotate_btn}}'
    26     + '{{^disable_search_btn}}'
    27     + '{{^disable_search_btn}}'
    27     + '<div class="Ldt-Ctrl-button Ldt-Ctrl-SearchBtn Ldt-TraceMe" title="{{l10n.search}}"></div>'
    28     + '<div class="Ldt-Ctrl-button Ldt-Ctrl-SearchBtn Ldt-TraceMe" title="{{l10n.search}}"></div>'
    28     + '<div class="Ldt-Ctrl-spacer"></div>'
       
    29     + '{{/disable_search_btn}}'
    29     + '{{/disable_search_btn}}'
    30     + '<div class="Ldt-Ctrl-Search">'
    30     + '<div class="Ldt-Ctrl-Search">'
    31     + '<input placeholder="{{ l10n.search }}" type="search" class="Ldt-Ctrl-SearchInput Ldt-TraceMe"></input>'
    31     + '<input placeholder="{{ l10n.search }}" type="search" class="Ldt-Ctrl-SearchInput Ldt-TraceMe"></input>'
    32     + '</div>'
    32     + '</div>'
       
    33     + '<div class="Ldt-Ctrl-Quiz-Enable Ldt-TraceMe" title="Activer/Désactiver le quiz"></div>'
       
    34     + '<div class="Ldt-Ctrl-Quiz-Create Ldt-TraceMe" ></div>'
    33     + '</div>'
    35     + '</div>'
    34     + '<div class="Ldt-Ctrl-Right">'
    36     + '<div class="Ldt-Ctrl-Right">'
       
    37     + '<div class="Ldt-Ctrl-Fullscreen-Button Ldt-TraceMe" title="Passer le lecteur en plein-écran"></div>'
    35     + '<div class="Ldt-Ctrl-spacer"></div>'
    38     + '<div class="Ldt-Ctrl-spacer"></div>'
    36     + '<div class="Ldt-Ctrl-Time">'
    39     + '<div class="Ldt-Ctrl-Time">'
    37     + '<div class="Ldt-Ctrl-Time-Elapsed" title="{{l10n.elapsed_time}}">00:00</div>'
    40     + '<div class="Ldt-Ctrl-Time-Elapsed" title="{{l10n.elapsed_time}}">00:00</div>'
    38     + '<div class="Ldt-Ctrl-Time-Separator">/</div>'
    41     + '<div class="Ldt-Ctrl-Time-Separator">/</div>'
    39     + '<div class="Ldt-Ctrl-Time-Total" title="{{l10n.total_time}}">00:00</div>'
    42     + '<div class="Ldt-Ctrl-Time-Total" title="{{l10n.total_time}}">00:00</div>'
    57         annotate: "Annotate",
    60         annotate: "Annotate",
    58         search: "Search",
    61         search: "Search",
    59         elapsed_time: "Elapsed time",
    62         elapsed_time: "Elapsed time",
    60         total_time: "Total duration",
    63         total_time: "Total duration",
    61         volume: "Volume",
    64         volume: "Volume",
    62         volume_control: "Volume control"
    65         volume_control: "Volume control",
       
    66         enable_quiz: "Enable quiz"
    63     },
    67     },
    64     fr: {
    68     fr: {
    65         play_pause: "Lecture/Pause",
    69         play_pause: "Lecture/Pause",
    66         mute_unmute: "Couper/Activer le son",
    70         mute_unmute: "Couper/Activer le son",
    67         play: "Lecture",
    71         play: "Lecture",
    71         annotate: "Annoter",
    75         annotate: "Annoter",
    72         search: "Rechercher",
    76         search: "Rechercher",
    73         elapsed_time: "Temps écoulé",
    77         elapsed_time: "Temps écoulé",
    74         total_time: "Durée totale",
    78         total_time: "Durée totale",
    75         volume: "Niveau sonore",
    79         volume: "Niveau sonore",
    76         volume_control: "Réglage du niveau sonore"
    80         volume_control: "Réglage du niveau sonore",
       
    81         enable_quiz: "Activer le quiz"
    77     }
    82     }
    78 };
    83 };
    79 
    84 
    80 IriSP.Widgets.Controller.prototype.draw = function() {
    85 IriSP.Widgets.Controller.prototype.draw = function() {
    81     var _this = this;
    86     var _this = this;
    82     this.renderTemplate();
    87     this.renderTemplate();
    83     
    88 
    84     // Define blocks
    89     // Define blocks
    85     this.$playButton = this.$.find(".Ldt-Ctrl-Play");
    90     this.$playButton = this.$.find(".Ldt-Ctrl-Play");
    86     this.$searchBlock = this.$.find(".Ldt-Ctrl-Search");
    91     this.$searchBlock = this.$.find(".Ldt-Ctrl-Search");
    87     this.$searchInput = this.$.find(".Ldt-Ctrl-SearchInput");
    92     this.$searchInput = this.$.find(".Ldt-Ctrl-SearchInput");
    88     this.$volumeBar = this.$.find(".Ldt-Ctrl-Volume-Bar");
    93     this.$volumeBar = this.$.find(".Ldt-Ctrl-Volume-Bar");
    89     
    94 
    90     // handle events
    95     // handle events
    91     this.onMediaEvent("play","playButtonUpdater");
    96     this.onMediaEvent("play","playButtonUpdater");
    92     this.onMediaEvent("pause","playButtonUpdater");
    97     this.onMediaEvent("pause","playButtonUpdater");
    93     this.onMediaEvent("volumechange","volumeUpdater");
    98     this.onMediaEvent("volumechange","volumeUpdater");
    94     this.onMediaEvent("timeupdate","timeDisplayUpdater");
    99     this.onMediaEvent("timeupdate","timeDisplayUpdater");
    95     this.onMediaEvent("loadedmetadata","volumeUpdater");
   100     this.onMediaEvent("loadedmetadata","volumeUpdater");
    96     
   101 
    97     // handle clicks
   102     // handle clicks
    98     this.$playButton.click(this.functionWrapper("playHandler"));
   103     this.$playButton.click(this.functionWrapper("playHandler"));
    99     
   104 
       
   105     if (this.enable_quiz_toggle !== undefined) {
       
   106         if (this.enable_quiz_toggle) {
       
   107             $(".Ldt-Ctrl-Quiz-Enable").addClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   108             $(".Ldt-Ctrl-Quiz-Create").addClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   109             // this.player.trigger("QuizCreator.show");
       
   110             $("#QuizEditContainer").show();
       
   111         }
       
   112         else
       
   113         {
       
   114             $(".Ldt-Ctrl-Quiz-Enable").removeClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   115             $(".Ldt-Ctrl-Quiz-Create").removeClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   116             this.player.trigger("QuizCreator.hide");
       
   117             $("#QuizEditContainer").hide();
       
   118         }
       
   119     } else {
       
   120             $(".Ldt-Ctrl-Quiz-Enable").hide();
       
   121     }
       
   122 
   100     this.$.find(".Ldt-Ctrl-Annotate").click(function() {
   123     this.$.find(".Ldt-Ctrl-Annotate").click(function() {
   101         _this.player.trigger("CreateAnnotation.toggle");
   124         _this.player.trigger("CreateAnnotation.toggle");
   102     });
   125     });
   103     this.$.find(".Ldt-Ctrl-SearchBtn").click(this.functionWrapper("searchButtonHandler"));
   126     this.$.find(".Ldt-Ctrl-SearchBtn").click(this.functionWrapper("searchButtonHandler"));
   104     
   127 
   105     this.$searchInput.keyup(this.functionWrapper("searchHandler"));
   128     this.$searchInput.keyup(this.functionWrapper("searchHandler"));
   106     this.$searchInput.on("search", this.functionWrapper("searchHandler"));
   129     this.$searchInput.on("search", this.functionWrapper("searchHandler"));
   107   
   130 
   108 	var _volctrl = this.$.find(".Ldt-Ctrl-Volume-Control");
   131     // Fullscreen handling
       
   132     this.$.find(".Ldt-Ctrl-Fullscreen-Button").click(this.functionWrapper("toggleFullscreen"));
       
   133     var fullscreen_event_name = IriSP.getFullscreenEventname();
       
   134     if (fullscreen_event_name) {
       
   135         document.addEventListener(fullscreen_event_name, function() {
       
   136             if (IriSP.isFullscreen() && IriSP.getFullscreenElement() == _this.$[0]) {
       
   137                 _this.$.addClass("Ldt-Fullscreen-Element");
       
   138             } else {
       
   139                 _this.$.removeClass("Ldt-Fullscreen-Element");
       
   140             }
       
   141         });
       
   142     };
       
   143 
       
   144     // Quiz activation
       
   145     this.$.find(".Ldt-Ctrl-Quiz-Enable").click(this.functionWrapper("toggleQuiz"));
       
   146     this.$.find(".Ldt-Ctrl-Quiz-Create").click(this.functionWrapper("createQuiz"));
       
   147 
       
   148     var _volctrl = this.$.find(".Ldt-Ctrl-Volume-Control");
   109     this.$.find('.Ldt-Ctrl-Sound')
   149     this.$.find('.Ldt-Ctrl-Sound')
   110         .click(this.functionWrapper("muteHandler"))
   150         .click(this.functionWrapper("muteHandler"))
   111         .mouseover(function() {
   151         .mouseover(function() {
   112             _volctrl.show();
   152             _volctrl.show();
   113         })
   153         })
   117     _volctrl.mouseover(function() {
   157     _volctrl.mouseover(function() {
   118         _volctrl.show();
   158         _volctrl.show();
   119     }).mouseout(function() {
   159     }).mouseout(function() {
   120         _volctrl.hide();
   160         _volctrl.hide();
   121     });
   161     });
   122     
   162 
   123     // Handle CTRL-F
   163     // Handle CTRL-F
   124     if (!this.disable_ctrl_f) {
   164     if (!this.disable_ctrl_f) {
   125         var _fKey = "F".charCodeAt(0),
   165         var _fKey = "F".charCodeAt(0),
   126             _lastCtrlFTime = 0;
   166             _lastCtrlFTime = 0;
   127         IriSP.jQuery(document).keydown(function(_event) {
   167         IriSP.jQuery(document).keydown(function(_event) {
   133                 _lastCtrlFTime = _time;
   173                 _lastCtrlFTime = _time;
   134                 return false;
   174                 return false;
   135             }
   175             }
   136         });
   176         });
   137     }
   177     }
   138     
   178 
   139     // Allow Volume Cursor Dragging
   179     // Allow Volume Cursor Dragging
   140     this.$volumeBar.slider({
   180     this.$volumeBar.slider({
   141         slide: function(event, ui) {
   181         slide: function(event, ui) {
   142             _this.$volumeBar.attr("title",_this.l10n.volume+': ' + ui.value + '%');
   182             _this.$volumeBar.attr("title",_this.l10n.volume+': ' + ui.value + '%');
   143             _this.media.setVolume(ui.value / 100);
   183             _this.media.setVolume(ui.value / 100);
   147 
   187 
   148     // trigger an IriSP.Player.MouseOver to the widgets that are interested (i.e : sliderWidget)
   188     // trigger an IriSP.Player.MouseOver to the widgets that are interested (i.e : sliderWidget)
   149     this.$.hover(
   189     this.$.hover(
   150         function() {
   190         function() {
   151             _this.player.trigger("Player.MouseOver");
   191             _this.player.trigger("Player.MouseOver");
   152         }, 
   192         },
   153         function() {
   193         function() {
   154             _this.player.trigger("Player.MouseOut");
   194             _this.player.trigger("Player.MouseOut");
   155         });
   195         });
   156     
   196 
   157     this.timeDisplayUpdater(new IriSP.Model.Time(0));
   197     this.timeDisplayUpdater(new IriSP.Model.Time(0));
   158     
   198 
   159     var annotations = this.source.getAnnotations();
   199     var annotations = this.source.getAnnotations();
   160     annotations.on("search", function(_text) {
   200     annotations.on("search", function(_text) {
   161         _this.$searchInput.val(_text);
   201         _this.$searchInput.val(_text);
   162         _this.showSearchBlock();
   202         _this.showSearchBlock();
   163     });
   203     });
   175     }
   215     }
   176 };
   216 };
   177 
   217 
   178 /* Update the elasped time div */
   218 /* Update the elasped time div */
   179 IriSP.Widgets.Controller.prototype.timeDisplayUpdater = function(_time) {
   219 IriSP.Widgets.Controller.prototype.timeDisplayUpdater = function(_time) {
   180   
   220 
   181     // we get it at each call because it may change.
   221     // we get it at each call because it may change.
   182     var _totalTime = this.media.duration;
   222     var _totalTime = this.media.duration;
   183     this.$.find(".Ldt-Ctrl-Time-Elapsed").html(_time.toString());
   223     this.$.find(".Ldt-Ctrl-Time-Elapsed").html(_time.toString());
   184     this.$.find(".Ldt-Ctrl-Time-Total").html(_totalTime.toString());
   224     this.$.find(".Ldt-Ctrl-Time-Total").html(_totalTime.toString());
   185 };
   225 };
   201             .removeClass("Ldt-Ctrl-Play-PlayState")
   241             .removeClass("Ldt-Ctrl-Play-PlayState")
   202             .addClass("Ldt-Ctrl-Play-PauseState");
   242             .addClass("Ldt-Ctrl-Play-PauseState");
   203     }
   243     }
   204 };
   244 };
   205 
   245 
       
   246 //FullScreen
       
   247 IriSP.Widgets.Controller.prototype.toggleFullscreen = function() {
       
   248     if (IriSP.isFullscreen()) {
       
   249         IriSP.setFullScreen(this.$[0], false);
       
   250     } else {
       
   251         IriSP.setFullScreen(this.$[0], true);
       
   252     }
       
   253 };
       
   254 
       
   255 //Quiz
       
   256 IriSP.Widgets.Controller.prototype.createQuiz = function() {
       
   257     this.player.trigger("Quiz.hide");
       
   258     this.media.pause();
       
   259     this.player.trigger("QuizCreator.create");
       
   260 };
       
   261 
       
   262 IriSP.Widgets.Controller.prototype.toggleQuiz = function() {
       
   263     this.enable_quiz_toggle = !this.enable_quiz_toggle;
       
   264     if (this.enable_quiz_toggle) {
       
   265         $(".Ldt-Ctrl-Quiz-Enable").addClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   266         $(".Ldt-Ctrl-Quiz-Create").addClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   267         this.player.trigger("Quiz.activate");
       
   268     }
       
   269     else
       
   270     {
       
   271         $(".Ldt-Ctrl-Quiz-Enable").removeClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   272         $(".Ldt-Ctrl-Quiz-Create").removeClass("Ldt-Ctrl-Quiz-Toggle-Active");
       
   273         this.player.trigger("Quiz.deactivate");
       
   274         this.player.trigger("QuizCreator.hide");
       
   275     }
       
   276 };
   206 
   277 
   207 IriSP.Widgets.Controller.prototype.playHandler = function() {
   278 IriSP.Widgets.Controller.prototype.playHandler = function() {
   208     if (this.media.getPaused()) {        
   279     if (this.media.getPaused()) {
   209         this.media.play();
   280         this.media.play();
   210     } else {
   281     } else {
   211         this.media.pause();
   282         this.media.pause();
   212     }  
   283     }
   213 };
   284 };
   214 
   285 
   215 IriSP.Widgets.Controller.prototype.muteHandler = function() {
   286 IriSP.Widgets.Controller.prototype.muteHandler = function() {
   216     this.media.setMuted(!this.media.getMuted());
   287     this.media.setMuted(!this.media.getMuted());
   217 };
   288 };
   222     if (_vol === false) {
   293     if (_vol === false) {
   223         _vol = .5;
   294         _vol = .5;
   224     }
   295     }
   225     var _soundCtl = this.$.find(".Ldt-Ctrl-Sound");
   296     var _soundCtl = this.$.find(".Ldt-Ctrl-Sound");
   226     _soundCtl.removeClass("Ldt-Ctrl-Sound-Mute Ldt-Ctrl-Sound-Half Ldt-Ctrl-Sound-Full");
   297     _soundCtl.removeClass("Ldt-Ctrl-Sound-Mute Ldt-Ctrl-Sound-Half Ldt-Ctrl-Sound-Full");
   227     if (_muted) {        
   298     if (_muted) {
   228         _soundCtl.attr("title", this.l10n.unmute)
   299         _soundCtl.attr("title", this.l10n.unmute)
   229             .addClass("Ldt-Ctrl-Sound-Mute");    
   300             .addClass("Ldt-Ctrl-Sound-Mute");
   230     } else {
   301     } else {
   231         _soundCtl.attr("title", this.l10n.mute)
   302         _soundCtl.attr("title", this.l10n.mute)
   232             .addClass(_vol < .5 ? "Ldt-Ctrl-Sound-Half" : "Ldt-Ctrl-Sound-Full" );
   303             .addClass(_vol < .5 ? "Ldt-Ctrl-Sound-Half" : "Ldt-Ctrl-Sound-Full" );
   233     }
   304     }
   234     this.$volumeBar.slider("value", _muted ? 0 : 100 * _vol);
   305     this.$volumeBar.slider("value", _muted ? 0 : 100 * _vol);
   266         this.$searchBlock.css({ width:"160px" });
   337         this.$searchBlock.css({ width:"160px" });
   267         this.$searchInput.css('background-color','#fff');
   338         this.$searchInput.css('background-color','#fff');
   268     }
   339     }
   269     var _val = this.$searchInput.val();
   340     var _val = this.$searchInput.val();
   270     this._positiveMatch = false;
   341     this._positiveMatch = false;
   271     
   342 
   272     // do nothing if the search field is empty, instead of highlighting everything.
   343     // do nothing if the search field is empty, instead of highlighting everything.
   273     if (_val !== this.lastSearchValue) {
   344     if (_val !== this.lastSearchValue) {
   274         if (_val) {
   345         if (_val) {
   275             this.source.getAnnotations().search(_val);
   346             this.source.getAnnotations().search(_val);
   276         } else {
   347         } else {
   278             this.$searchInput.css('background-color','');
   349             this.$searchInput.css('background-color','');
   279         }
   350         }
   280     }
   351     }
   281     this.lastSearchValue = _val;
   352     this.lastSearchValue = _val;
   282 };
   353 };
   283