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