src/js/widgets/annotationsListWidget.js
branchpopcorn-port
changeset 838 03b03865eb9b
parent 836 526f91f5253e
child 840 ac66e2240e1e
equal deleted inserted replaced
837:353a78021ebc 838:03b03865eb9b
     5  
     5  
     6   this.checkOption('ajax_mode');
     6   this.checkOption('ajax_mode');
     7   this.checkOption('project_url');
     7   this.checkOption('project_url');
     8   this.checkOption('default_thumbnail');
     8   this.checkOption('default_thumbnail');
     9   this.checkOption("cinecast_version", false);
     9   this.checkOption("cinecast_version", false);
       
    10   this.searchRe = null;
       
    11   this._ajax_cache = [];
    10   var _this = this;
    12   var _this = this;
       
    13   
       
    14   this._Popcorn.listen("IriSP.search", function(searchString) {
       
    15       _this.searchHandler(searchString);
       
    16   });
       
    17   this._Popcorn.listen("IriSP.search.closed", function() {
       
    18       _this.searchHandler(false);
       
    19   });
       
    20   this._Popcorn.listen("IriSP.search.cleared", function() {
       
    21       _this.searchHandler(false);
       
    22   });
    11 };
    23 };
    12 
    24 
    13 
    25 
    14 IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();
    26 IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();
    15 
    27 
    16 IriSP.AnnotationsListWidget.prototype.clear = function() {
    28 IriSP.AnnotationsListWidget.prototype.clear = function() {
    17 };
    29 };
    18 
    30 
    19 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
    31 IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
    20 };
    32 };
       
    33 
       
    34 IriSP.AnnotationsListWidget.prototype.searchHandler = function(searchString) {
       
    35   this.searchRe = (searchString && searchString.length) ? IriSP.regexpFromText(searchString) : null;
       
    36   if (this.ajax_mode) {
       
    37       var _this = this,
       
    38         _annotations = (
       
    39             this.searchRe === null
       
    40             ? this._ajax_cache
       
    41             : IriSP.underscore.filter(this._ajax_cache, function(_a) {
       
    42                return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); 
       
    43             })
       
    44         );
       
    45     this.do_redraw(_annotations);
       
    46     if (_annotations.length) {
       
    47         this._Popcorn.trigger("IriSP.search.matchFound");
       
    48       } else {
       
    49         this._Popcorn.trigger("IriSP.search.noMatchFound");
       
    50       }    
       
    51   } else {
       
    52       this.drawList();
       
    53   }
       
    54 }
    21 
    55 
    22 /** effectively redraw the widget - called by drawList */
    56 /** effectively redraw the widget - called by drawList */
    23 IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) {
    57 IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) {
    24     var widgetMarkup = IriSP.templToHTML(IriSP.annotationsListWidget_template, {annotations: list});
    58     var _html = IriSP.templToHTML(
    25     this.selector.html(widgetMarkup);
    59         IriSP.annotationsListWidget_template, {
       
    60             annotations: list
       
    61         }),
       
    62         _this = this;
       
    63       
       
    64     this.selector.html(_html);
       
    65     
       
    66     if (this.searchRe !== null) {
       
    67         this.selector.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description")
       
    68             .each(function()  {
       
    69                 var _$ = IriSP.jQuery(this);
       
    70                 _$.html(_$.text().replace(_this.searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
       
    71             })
       
    72     }
    26 };
    73 };
    27 
    74 
    28 IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
    75 IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
    29     var _this = this
    76     var _this = this
    30     return {
    77     return {
    81         list.push(obj);
   128         list.push(obj);
    82     }
   129     }
    83     
   130     
    84   }
   131   }
    85   
   132   
       
   133     if (this.searchRe !== null) {
       
   134         list = list.filter(function(_a) {
       
   135             return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); 
       
   136         });
       
   137         if (list.length) {
       
   138             this._Popcorn.trigger("IriSP.search.matchFound");
       
   139           } else {
       
   140             this._Popcorn.trigger("IriSP.search.noMatchFound");
       
   141           }
       
   142     }
       
   143   
    86   list = IriSP.underscore(list)
   144   list = IriSP.underscore(list)
    87     .chain()
   145     .chain()
    88     .sortBy(function(_o) {
   146     .sortBy(function(_o) {
    89         return _o.distance;
   147         return _o.distance;
    90     })
   148     })
   174             // obj.url = document.location.href.split("#")[0] + "/" + annotation.meta.project;
   232             // obj.url = document.location.href.split("#")[0] + "/" + annotation.meta.project;
   175           }
   233           }
   176           }
   234           }
   177       l.push(obj);
   235       l.push(obj);
   178   }
   236   }
   179 
   237   this._ajax_cache = l;
   180   this.do_redraw(l);
   238   this.do_redraw(l);
   181 };
   239 };
   182 IriSP.AnnotationsListWidget.prototype.draw = function() {
   240 IriSP.AnnotationsListWidget.prototype.draw = function() {
   183   
   241   
   184   /* build a table of the annotations present in the document for faster 
   242   /* build a table of the annotations present in the document for faster 
   190   var i = 0;
   248   var i = 0;
   191   for(i = 0; i < annotations.length; i++) {
   249   for(i = 0; i < annotations.length; i++) {
   192     this.annotations_ids.push(annotations[i]["id"]);
   250     this.annotations_ids.push(annotations[i]["id"]);
   193   }
   251   }
   194   
   252   
   195   this.drawList();
       
   196   
       
   197   var _this = this;
   253   var _this = this;
   198     
   254     
   199   if (!this.ajax_mode) {
   255     if (!this.ajax_mode) {
   200       var _throttled = IriSP.underscore.throttle(function() {
   256         var _throttled = IriSP.underscore.throttle(function() {
   201       _this.drawList();
   257             _this.drawList();
   202     }, 1500);
   258         }, 1500);
   203     this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled);
   259         _throttled();
   204     this._Popcorn.listen("timeupdate", _throttled);
   260         this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled);
       
   261         this._Popcorn.listen("timeupdate", _throttled);
   205   } else {
   262   } else {
   206     /* update the widget when the video has finished loading and when it's seeked and paused */
   263     /* update the widget when the video has finished loading and when it's seeked and paused */
   207     this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
   264     this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
   208     this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
   265     this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
   209     this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));
   266     this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));