src/widgets/AnnotationsList.js
changeset 961 e1baacb52075
parent 959 ee11ed1b739e
child 963 d58d0dcdb640
equal deleted inserted replaced
956:7c1d08cf6956 961:e1baacb52075
     4     this.lastIds = [];
     4     this.lastIds = [];
     5     var _this = this;
     5     var _this = this;
     6     this.throttledRefresh = IriSP._.throttle(function() {
     6     this.throttledRefresh = IriSP._.throttle(function() {
     7         _this.refresh(false);
     7         _this.refresh(false);
     8     }, 1500);
     8     }, 1500);
     9     this.mashupMode = (this.source.currentMedia.elementType === "mashup");
       
    10 };
     9 };
    11 
    10 
    12 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
    11 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
    13 
    12 
    14 IriSP.Widgets.AnnotationsList.prototype.defaults = {
    13 IriSP.Widgets.AnnotationsList.prototype.defaults = {
    77 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) {
    76 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) {
    78     this.searchString = typeof searchString !== "undefined" ? searchString : '';
    77     this.searchString = typeof searchString !== "undefined" ? searchString : '';
    79     var _n = this.refresh(true);
    78     var _n = this.refresh(true);
    80     if (this.searchString) {
    79     if (this.searchString) {
    81         if (_n) {
    80         if (_n) {
    82             this.player.popcorn.trigger("IriSP.search.matchFound");
    81             this.player.trigger("search.matchFound");
    83         } else {
    82         } else {
    84             this.player.popcorn.trigger("IriSP.search.noMatchFound");
    83             this.player.trigger("search.noMatchFound");
    85         }
    84         }
    86     }
    85     }
    87 }
    86 }
    88 
    87 
    89 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
    88 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
    90 
    89 
    91 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() {
    90 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() {
    92     var _currentTime = this.player.popcorn.currentTime(),
    91     var _currentTime = this.media.getCurrentTime(),
    93         _duration = this.source.getDuration();
    92         _duration = this.media.duration;
    94     if (typeof _currentTime == "undefined") {
       
    95         _currentTime = 0;
       
    96     }
       
    97     this.lastAjaxQuery = _currentTime;
    93     this.lastAjaxQuery = _currentTime;
    98     _currentTime = Math.floor(1000 * _currentTime);
    94     _currentTime = Math.floor(1000 * _currentTime);
    99     var _url = Mustache.to_html(this.ajax_url, {
    95     var _url = Mustache.to_html(this.ajax_url, {
   100         media : this.source.currentMedia.id,
    96         media : this.source.currentMedia.id,
   101         begin : Math.max(0, _currentTime - this.ajax_granularity),
    97         begin : Math.max(0, _currentTime - this.ajax_granularity),
   105         "url" : _url
   101         "url" : _url
   106     }, this.metadata));
   102     }, this.metadata));
   107 }
   103 }
   108 
   104 
   109 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() {
   105 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() {
   110     var _currentTime = this.player.popcorn.currentTime();
   106     var _currentTime = this.media.getCurrentTime();
   111     if (typeof _currentTime == "undefined") {
   107     var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime);
   112         _currentTime = 0;
       
   113     }
       
   114     var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000);
       
   115     if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) {
   108     if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) {
   116         this.lastMashupAnnotation = _currentAnnotation.id;
   109         this.lastMashupAnnotation = _currentAnnotation.id;
   117         var _currentMedia = _currentAnnotation.getMedia(),
   110         var _currentMedia = _currentAnnotation.getMedia(),
   118             _url = Mustache.to_html(this.ajax_url, {
   111             _url = Mustache.to_html(this.ajax_url, {
   119                 media : _currentMedia.id,
   112                 media : _currentMedia.id,
   130     _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw);
   123     _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw);
   131     if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) {
   124     if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) {
   132         return 0;
   125         return 0;
   133     }
   126     }
   134     var _this = this,
   127     var _this = this,
   135         _currentTime = this.player.popcorn.currentTime();
   128         _currentTime = this.media.getCurrentTime();
   136     if (typeof _currentTime == "undefined") {
       
   137         _currentTime = 0;
       
   138     }
       
   139     var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations();
   129     var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations();
   140     if (this.mashupMode) {
   130     if (this.mashupMode) {
   141         var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000);
   131         var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime);
   142         if (typeof _currentAnnotation !== "undefined") {
   132         if (typeof _currentAnnotation !== "undefined") {
   143             _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds();
   133             _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds();
   144             var _mediaId = _currentAnnotation.getMedia().id;
   134             var _mediaId = _currentAnnotation.getMedia().id;
   145             _list = _list.filter(function(_annotation) {
   135             _list = _list.filter(function(_annotation) {
   146                 return _annotation.getMedia().id === _mediaId;
   136                 return _annotation.getMedia().id === _mediaId;
   244                 _el.detach();
   234                 _el.detach();
   245             }
   235             }
   246         });
   236         });
   247     
   237     
   248         this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() {
   238         this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() {
   249             _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   239             _this.player.trigger("search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   250         })
   240         })
   251         
   241         
   252         if(this.searchString) {
   242         if(this.searchString) {
   253             var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString);
   243             var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString);
   254             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
   244             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
   270     return _list.length;
   260     return _list.length;
   271 }
   261 }
   272 
   262 
   273 IriSP.Widgets.AnnotationsList.prototype.draw = function() {
   263 IriSP.Widgets.AnnotationsList.prototype.draw = function() {
   274     
   264     
       
   265     this.mashupMode = (this.media.elementType === "mashup");
       
   266     
   275     this.renderTemplate();
   267     this.renderTemplate();
   276     
   268     
   277     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   269     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   278     
   270     
   279     this.bindPopcorn("IriSP.search", "onSearch");
   271     this.onMdpEvent("search", "onSearch");
   280     this.bindPopcorn("IriSP.search.closed", "onSearch");
   272     this.onMdpEvent("search.closed", "onSearch");
   281     this.bindPopcorn("IriSP.search.cleared", "onSearch");
   273     this.onMdpEvent("search.cleared", "onSearch");
   282     this.bindPopcorn("IriSP.AnnotationsList.refresh","refresh");
   274     this.onMdpEvent("AnnotationsList.refresh","refresh");
   283     
   275     
   284     var _this = this;
   276     var _this = this;
   285     
   277     
   286     if (this.ajax_url) {
   278     if (this.ajax_url) {
   287         if (this.mashupMode) {
   279         if (this.mashupMode) {
   297         window.setInterval(function() {
   289         window.setInterval(function() {
   298             _this.currentSource.get()
   290             _this.currentSource.get()
   299         }, this.refresh_interval);
   291         }, this.refresh_interval);
   300     }
   292     }
   301     
   293     
       
   294     this.onMdpEvent("createAnnotationWidget.addedAnnotation");
   302     var _events = [
   295     var _events = [
   303         "IriSP.createAnnotationWidget.addedAnnotation",
       
   304         "timeupdate",
   296         "timeupdate",
   305         "seeked",
   297         "seeked",
   306         "loadedmetadata"
   298         "loadedmetadata"
   307     ];
   299     ];
   308     for (var _i = 0; _i < _events.length; _i++) {
   300     for (var _i = 0; _i < _events.length; _i++) {
   309         this.player.popcorn.listen(_events[_i], this.throttledRefresh);
   301         this.onMediaEvent(_events[_i], this.throttledRefresh);
   310     }
   302     }
   311     
   303     
   312     this.throttledRefresh();
   304     this.throttledRefresh();
   313 
   305 
   314 };
   306 };