src/widgets/AnnotationsList.js
changeset 983 97fef7a4b189
parent 969 353b0881a0b9
child 988 eefd336335f9
equal deleted inserted replaced
982:cfcbac34d020 983:97fef7a4b189
     1 IriSP.Widgets.AnnotationsList = function(player, config) {
     1 IriSP.Widgets.AnnotationsList = function(player, config) {
     2     IriSP.Widgets.Widget.call(this, player, config);
     2     IriSP.Widgets.Widget.call(this, player, config);
     3     this.searchString = false;
       
     4     this.lastIds = [];
     3     this.lastIds = [];
     5     var _this = this;
     4     var _this = this;
     6     this.throttledRefresh = IriSP._.throttle(function() {
     5     this.throttledRefresh = IriSP._.throttle(function() {
     7         _this.refresh(false);
     6         _this.refresh(false);
     8     }, 1500);
     7     }, 800);
       
     8     this.searchString = false;
       
     9     this.lastSearch = false;
     9 };
    10 };
    10 
    11 
    11 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
    12 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
    12 
    13 
    13 IriSP.Widgets.AnnotationsList.prototype.defaults = {
    14 IriSP.Widgets.AnnotationsList.prototype.defaults = {
    85     + '</ul>'
    86     + '</ul>'
    86     + '{{/tags.length}}'
    87     + '{{/tags.length}}'
    87     + '{{#audio}}<div class="Ldt-AnnotationsList-Play" data-audio={{audio}}>{{l10n.voice_annotation}}</div>{{/audio}}'
    88     + '{{#audio}}<div class="Ldt-AnnotationsList-Play" data-audio={{audio}}>{{l10n.voice_annotation}}</div>{{/audio}}'
    88     + '</li>';
    89     + '</li>';
    89 
    90 
    90 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) {
       
    91     this.searchString = typeof searchString !== "undefined" ? searchString : '';
       
    92     var _n = this.refresh(true);
       
    93     if (this.searchString) {
       
    94         if (_n) {
       
    95             this.player.trigger("search.matchFound");
       
    96         } else {
       
    97             this.player.trigger("search.noMatchFound");
       
    98         }
       
    99     }
       
   100 }
       
   101 
       
   102 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
    91 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
   103 
    92 
   104 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() {
    93 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() {
   105     var _currentTime = this.media.getCurrentTime(),
    94     var _currentTime = this.media.getCurrentTime(),
   106         _duration = this.media.duration;
    95         _duration = this.media.duration;
   148             _list = _list.filter(function(_annotation) {
   137             _list = _list.filter(function(_annotation) {
   149                 return _annotation.getMedia().id === _mediaId;
   138                 return _annotation.getMedia().id === _mediaId;
   150             });
   139             });
   151         }
   140         }
   152     }
   141     }
   153     if (this.searchString) {
   142     _list = _list.filter(function(_annotation) {
   154         _list = _list.searchByTextFields(this.searchString);
   143         return _annotation.found !== false;
   155     }
   144     });
   156     if (this.limit_count) {
   145     if (this.limit_count) {
   157         /* Get the n annotations closest to current timecode */
   146         /* Get the n annotations closest to current timecode */
   158         _list = _list.sortBy(function(_annotation) {
   147         _list = _list.sortBy(function(_annotation) {
   159             return Math.abs((_annotation.begin + _annotation.end) / 2 - _currentTime);
   148             return Math.abs((_annotation.begin + _annotation.end) / 2 - _currentTime);
   160         }).slice(0, this.limit_count)
   149         }).slice(0, this.limit_count)
   169         });
   158         });
   170     }
   159     }
   171     
   160     
   172     var _ids = _list.idIndex;
   161     var _ids = _list.idIndex;
   173     
   162     
   174     if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds)) {
   163     if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds) || this.searchString !== this.lastSearch) {
   175         /* This part only gets executed if the list needs updating */
   164         /* This part only gets executed if the list needs updating */
       
   165         this.lastSearch = this.searchString;
   176         this.lastIds = _ids;
   166         this.lastIds = _ids;
   177         this.list_$.html("");
   167         this.list_$.html("");
   178         _list.forEach(function(_annotation) {
   168         _list.forEach(function(_annotation) {
   179             var _url = (
   169             var _url = (
   180                 ( typeof _annotation.url !== "undefined" && _annotation.url)
   170                 ( typeof _annotation.url !== "undefined" && _annotation.url)
   256                 _el.remove();
   246                 _el.remove();
   257             }
   247             }
   258         });
   248         });
   259     
   249     
   260         this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() {
   250         this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() {
   261             _this.player.trigger("search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   251             _this.source.getAnnotations().search(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   262         });
   252         });
   263         
   253         
   264         this.$.find(".Ldt-AnnotationsList-Play").click(function() {
   254         this.$.find(".Ldt-AnnotationsList-Play").click(function() {
   265             var _el = IriSP.jQuery(this),
   255             var _el = IriSP.jQuery(this),
   266                 _audiofile = _el.attr("data-audio").replace(_this.rtmp_streamer,"");
   256                 _audiofile = _el.attr("data-audio").replace(_this.rtmp_streamer,"");
   272             _this.jwplayer.play(true);
   262             _this.jwplayer.play(true);
   273             _this.media.pause();
   263             _this.media.pause();
   274             _this.jw_paused_media = true;
   264             _this.jw_paused_media = true;
   275         });
   265         });
   276         
   266         
   277         if(this.searchString) {
   267         if (this.source.getAnnotations().searching) {
   278             var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString);
       
   279             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
   268             this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() {
   280                 var _$ = IriSP.jQuery(this);
   269                 var _$ = IriSP.jQuery(this);
   281                 _$.html(_$.text().replace(/(^\s+|\s+$)/g,'').replace(_searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
   270                 _$.html(_$.text().replace(/(^\s+|\s+$)/g,'').replace(_this.source.getAnnotations().regexp, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
   282             })
   271             })
   283         }
   272         }
   284     }
   273     }
   285     
   274     
   286     if (this.ajax_url) {
   275     if (this.ajax_url) {
   326     }
   315     }
   327     
   316     
   328     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   317     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
   329     
   318     
   330     
   319     
   331     this.onMdpEvent("search", "onSearch");
   320     this.source.getAnnotations().on("search", function(_text) {
   332     this.onMdpEvent("search.closed", "onSearch");
   321         _this.searchString = _text;
   333     this.onMdpEvent("search.cleared", "onSearch");
   322         if (_this.source !== _this.currentSource) {
       
   323             _this.currentSource.getAnnotations().search(_text);
       
   324             _this.throttledRefresh();
       
   325         }
       
   326     });
       
   327     this.source.getAnnotations().on("found", function() {
       
   328         _this.throttledRefresh();
       
   329     });
       
   330     this.source.getAnnotations().on("not-found", function() {
       
   331         _this.throttledRefresh();
       
   332     });
       
   333     this.source.getAnnotations().on("clear-search", function() {
       
   334         _this.searchString = false;
       
   335         if (_this.source !== _this.currentSource) {
       
   336             _this.currentSource.getAnnotations().trigger("clear-search");
       
   337         }
       
   338     });
       
   339     this.source.getAnnotations().on("search-cleared", function() {
       
   340         _this.throttledRefresh();
       
   341     });
       
   342     
   334     this.onMdpEvent("AnnotationsList.refresh", function() {
   343     this.onMdpEvent("AnnotationsList.refresh", function() {
   335         if (_this.ajax_url) {
   344         if (_this.ajax_url) {
   336             if (_this.mashupMode) {
   345             if (_this.mashupMode) {
   337                 _this.ajaxMashup();
   346                 _this.ajaxMashup();
   338             } else {
   347             } else {