src/js/widgets/createAnnotationWidget.js
branchpopcorn-port
changeset 833 33a5d5882be4
parent 832 6397a2ca3a67
child 834 573c7ca752e0
equal deleted inserted replaced
832:6397a2ca3a67 833:33a5d5882be4
    59   // change in a textfield.                    
    59   // change in a textfield.                    
    60   this.selector.find(".Ldt-createAnnotation-Description")
    60   this.selector.find(".Ldt-createAnnotation-Description")
    61                .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges));
    61                .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges));
    62                
    62                
    63   /* the cinecast version of the player is supposed to pause when the user clicks on the button */
    63   /* the cinecast version of the player is supposed to pause when the user clicks on the button */
    64   if (this.cinecast_version) {
    64 
    65     this.selector.find(".Ldt-createAnnotation-Description")
       
    66                  .one("propertychange keyup input paste js_mod", 
       
    67                  function() { if (!_this._Popcorn.media.paused) _this._Popcorn.pause() });
       
    68   }
       
    69   /* the cinecast version expects the user to comment on a defined segment.
    65   /* the cinecast version expects the user to comment on a defined segment.
    70      As the widget is always shown, we need a way to update it's content as
    66      As the widget is always shown, we need a way to update it's content as
    71      time passes. We do this like we did with the annotationsWidget : we schedule
    67      time passes. We do this like we did with the annotationsWidget : we schedule
    72      a .code start function which will be called at the right time.
    68      a .code start function which will be called at the right time.
    73   */
    69   */
   192 
   188 
   193 
   189 
   194 /** watch for changes in the textfield and change the buttons accordingly */
   190 /** watch for changes in the textfield and change the buttons accordingly */
   195 IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
   191 IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
   196   var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
   192   var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
   197 
   193   if (this.cinecast_version && !this._Popcorn.media.paused) {
       
   194       this._Popcorn.pause();
       
   195   }
   198   this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() {
   196   this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() {
   199       var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text());
   197       var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text());
   200       if (_rx.test(contents)) {
   198       if (_rx.test(contents)) {
   201           IriSP.jQuery(this).parent().addClass("Ldt-createAnnotation-active-button");
   199           IriSP.jQuery(this).parent().addClass("Ldt-createAnnotation-active-button");
   202       } else {
   200       } else {
   315   var _this = this;
   313   var _this = this;
   316   var apiJson = {annotations : [{}], meta: {}};
   314   var apiJson = {annotations : [{}], meta: {}};
   317   var annotation = apiJson["annotations"][0];
   315   var annotation = apiJson["annotations"][0];
   318   
   316   
   319   annotation["media"] = this._serializer.currentMedia()["id"];
   317   annotation["media"] = this._serializer.currentMedia()["id"];
   320   var duration_part = Math.round(this._serializer.getDuration() / 20);
       
   321   
   318   
   322   if (this.cinecast_version) {   
   319   if (this.cinecast_version) {   
   323       annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000 - duration_part);
   320       annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000);
   324       annotation["end"] = Math.round(this._Popcorn.currentTime() * 1000 + duration_part);      
   321       annotation["end"] = annotation["begin"];      
   325   } else {
   322   } else {
   326     var duration = this._serializer.getDuration();    
   323     var duration = this._serializer.getDuration();    
   327     annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0));
   324     annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0));
   328     annotation["end"] = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0));
   325     annotation["end"] = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0));
   329   }
   326   }