src/js/widgets/annotationsListWidget.js
branchpopcorn-port
changeset 842 4ae2247a59f4
parent 841 8da49ff273e0
child 852 eefb64f74a3f
equal deleted inserted replaced
841:8da49ff273e0 842:4ae2247a59f4
     1 IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
     1 IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
     2   IriSP.Widget.call(this, Popcorn, config, Serializer);
     2   IriSP.Widget.call(this, Popcorn, config, Serializer);
     3   this.__counter = 0;
     3   this.__counter = 0;
     4   this.__oldList = [];
     4   this.__oldList = [];
     5  
       
     6   this.checkOption('ajax_mode');
       
     7   this.checkOption('project_url');
       
     8   this.checkOption('default_thumbnail');
       
     9   this.checkOption("cinecast_version", false);
       
    10   this.checkOption("ajax_url");
       
    11   this.searchRe = null;
     5   this.searchRe = null;
    12   this._ajax_cache = [];
     6   this._ajax_cache = [];
    13   var _this = this;
     7   var _this = this;
    14   
     8   
    15   this._Popcorn.listen("IriSP.search", function(searchString) {
     9   this._Popcorn.listen("IriSP.search", function(searchString) {
    32 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
    26 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
    33 };
    27 };
    34 
    28 
    35 IriSP.AnnotationsListWidget.prototype.searchHandler = function(searchString) {
    29 IriSP.AnnotationsListWidget.prototype.searchHandler = function(searchString) {
    36   this.searchRe = (searchString && searchString.length) ? IriSP.regexpFromText(searchString) : null;
    30   this.searchRe = (searchString && searchString.length) ? IriSP.regexpFromText(searchString) : null;
    37   if (this.ajax_mode) {
    31   if (this.ajax_mode && !this.cinecast_version) {
    38       var _this = this,
    32       var _this = this,
    39         _annotations = (
    33         _annotations = (
    40             this.searchRe === null
    34             this.searchRe === null
    41             ? this._ajax_cache
    35             ? this._ajax_cache
    42             : IriSP.underscore.filter(this._ajax_cache, function(_a) {
    36             : IriSP.underscore.filter(this._ajax_cache, function(_a) {
    62         }),
    56         }),
    63         _this = this;
    57         _this = this;
    64       
    58       
    65     this.selector.html(_html);
    59     this.selector.html(_html);
    66     
    60     
       
    61     this.selector.find('.Ldt-AnnotationsList-Tag-Li').click(function() {
       
    62         _this._Popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().trim());
       
    63     })
       
    64     
    67     if (this.searchRe !== null) {
    65     if (this.searchRe !== null) {
    68         this.selector.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description")
    66         this.selector.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description")
    69             .each(function()  {
    67             .each(function()  {
    70                 var _$ = IriSP.jQuery(this);
    68                 var _$ = IriSP.jQuery(this);
    71                 _$.html(_$.text().replace(_this.searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
    69                 _$.html(_$.text().trim().replace(_this.searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
    72             })
    70             })
    73     }
    71     }
    74 };
    72 };
    75 
    73 
    76 IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
    74 IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
   153     })
   151     })
   154     .value();
   152     .value();
   155   var idList = IriSP.underscore.pluck(list, "id").sort();
   153   var idList = IriSP.underscore.pluck(list, "id").sort();
   156 
   154 
   157   
   155   
   158   if (!IriSP.underscore.isEqual(this.__oldList, idList) || typeof(force_redraw) !== "undefined") {
   156   if (!IriSP.underscore.isEqual(this.__oldList, idList) || this.lastSearch !== this.searchRe || typeof(force_redraw) !== "undefined") {
   159     this.do_redraw(list);
   157     this.do_redraw(list);
   160     this.__oldList = idList;
   158     this.__oldList = idList;
       
   159     this.lastSearch = this.searchRe;
   161   }
   160   }
   162    /* save for next call */
   161    /* save for next call */
   163   
   162   
   164   
   163   
   165 };
   164 };
   179   /* the platform gives us a special url - of the type : http://path/{{media}}/{{begin}}/{{end}}
   178   /* the platform gives us a special url - of the type : http://path/{{media}}/{{begin}}/{{end}}
   180      we double the braces using regexps and we feed it to mustache to build the correct url
   179      we double the braces using regexps and we feed it to mustache to build the correct url
   181      we have to do that because the platform only knows at run time what view it's displaying.
   180      we have to do that because the platform only knows at run time what view it's displaying.
   182   */
   181   */
   183      
   182      
   184   var media_id = this._serializer.currentMedia()["id"];
   183   var media_id = this.currentMedia()["id"];
   185   var duration = this._serializer.getDuration();
   184   var duration = this.getDuration();
   186   
   185   
   187   var begin_timecode = (Math.floor(tcode) - 300) * 1000;
   186   var begin_timecode = (Math.floor(tcode) - 300) * 1000;
   188   if (begin_timecode < 0)
   187   if (begin_timecode < 0)
   189     begin_timecode = 0;
   188     begin_timecode = 0;
   190     
   189     
   211   commented in case we wanted to discriminate against some annotation types.
   210   commented in case we wanted to discriminate against some annotation types.
   212   var view_types = serializer.getIds("Contributions");
   211   var view_types = serializer.getIds("Contributions");
   213   */
   212   */
   214   var l = [];
   213   var l = [];
   215   
   214   
   216   var media = this._serializer.currentMedia()["id"];
   215   var media = this.currentMedia()["id"];
   217   
   216   
   218   for (i = 0; i < annotations.length; i++) {
   217   for (i = 0; i < annotations.length; i++) {
   219     var obj = this.transformAnnotation(annotations[i])
   218     var obj = this.transformAnnotation(annotations[i])
   220       if (typeof obj.url == "undefined" || !obj.url) {
   219       if (typeof obj.url == "undefined" || !obj.url) {
   221           /* only if the annotation isn't present in the document create an
   220           /* only if the annotation isn't present in the document create an
   244     return _a.id.toLowerCase();
   243     return _a.id.toLowerCase();
   245   });
   244   });
   246   
   245   
   247   var _this = this;
   246   var _this = this;
   248     
   247     
   249     if (!this.ajax_mode) {
   248     if (!this.ajax_mode || this.cinecast_version) {
   250         var _throttled = IriSP.underscore.throttle(function() {
   249         var _throttled = IriSP.underscore.throttle(function() {
   251             _this.drawList();
   250             _this.drawList();
   252         }, 1500);
   251         }, 1500);
   253         _throttled();
   252         _throttled();
   254         this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled);
   253         this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled);
   255         this._Popcorn.listen("timeupdate", _throttled);
   254         this._Popcorn.listen("timeupdate", _throttled);
       
   255         if (this.cinecast_version) {
       
   256             window.setInterval(function() {
       
   257                 var _tmpSerializer = new IriSP.JSONSerializer(IriSP.__dataloader,  _this._config.metadata.src, true);
       
   258                 _tmpSerializer.sync(function(json) {
       
   259                     IriSP.underscore(json.annotations).each(function(_a) {
       
   260                         var _j = _this.annotations_ids.indexOf(_a.id);
       
   261                         if (_j == -1) {
       
   262                             _this._serializer._data.annotations.push(_a);
       
   263                             _this.annotations_ids.push(_a.id);
       
   264                         } else {
       
   265                             _this._serializer._data.annotations[_j] = _a;
       
   266                         }
       
   267                         _throttled();
       
   268                     });
       
   269                 }, true); // true is for force_refresh
       
   270             },this.refresh_interval);
       
   271         }
   256   } else {
   272   } else {
   257     /* update the widget when the video has finished loading and when it's seeked and paused */
   273     /* update the widget when the video has finished loading and when it's seeked and paused */
   258     this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
   274     this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
   259     this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
   275     this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
   260     this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));
   276     this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));