src/widgets/Annotation.js
changeset 983 97fef7a4b189
parent 982 cfcbac34d020
child 985 9859c4bae904
equal deleted inserted replaced
982:cfcbac34d020 983:97fef7a4b189
    54     show_annotation_type: false
    54     show_annotation_type: false
    55 }
    55 }
    56 
    56 
    57 IriSP.Widgets.Annotation.prototype.draw = function() {
    57 IriSP.Widgets.Annotation.prototype.draw = function() {
    58     
    58     
    59     var _this = this;
    59     var _this = this,
       
    60         currentAnnotation;
    60     
    61     
    61     function timeupdate(_time) {
    62     function timeupdate(_time) {
    62         var _list = _this.getWidgetAnnotationsAtTime();
    63         var _list = _this.getWidgetAnnotationsAtTime();
    63         if (!_list.length) {
    64         if (!_list.length) {
    64             _this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty");
    65             _this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty");
    68             _this.bounds = [ _time, _time ];
    69             _this.bounds = [ _time, _time ];
    69             _this.sendBounds();
    70             _this.sendBounds();
    70         }
    71         }
    71     }
    72     }
    72     
    73     
       
    74     function highlightTitleAndDescription() {
       
    75         if (!currentAnnotation) {
       
    76             return;
       
    77         }
       
    78         var title = currentAnnotation.title,
       
    79             description = currentAnnotation.description.replace(/(^\s+|\s+$)/g,'');
       
    80         if (currentAnnotation.found) {
       
    81             var rgxp = _this.source.getAnnotations().regexp || /^$/,
       
    82                 repl = '<span class="Ldt-Annotation-Highlight">$1</span>';
       
    83             title = title.replace(rgxp,repl);
       
    84             description = description.replace(rgxp,repl);
       
    85         }
       
    86         _this.$.find(".Ldt-Annotation-Title").html(title || "(" + _this.l10n.untitled + ")");
       
    87         if (description) {
       
    88             _this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock");
       
    89             _this.$.find(".Ldt-Annotation-Description").html(description);
       
    90         } else {
       
    91             _this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock");
       
    92         }
       
    93     }
       
    94     
    73     function drawAnnotation(_annotation) {
    95     function drawAnnotation(_annotation) {
       
    96         currentAnnotation = _annotation;
    74         var _url = (typeof _annotation.url !== "undefined" 
    97         var _url = (typeof _annotation.url !== "undefined" 
    75                 ? _annotation.url
    98                 ? _annotation.url
    76                 : (document.location.href.replace(/#.*$/,'') + '#id='  + _annotation.id)),
    99                 : (document.location.href.replace(/#.*$/,'') + '#id='  + _annotation.id)),
    77             _text = _this.l10n.watching + _annotation.title + (_this.site_name ? _this.l10n.on_site + _this.site_name : ''),
   100             _text = _this.l10n.watching + _annotation.title + (_this.site_name ? _this.l10n.on_site + _this.site_name : ''),
    78             _tags = _annotation.getTags(),
   101             _tags = _annotation.getTags(),
    83                 var _trimmedTitle =  _tag.title.replace(/(^\s+|\s+$)/g,'');
   106                 var _trimmedTitle =  _tag.title.replace(/(^\s+|\s+$)/g,'');
    84                 if (_trimmedTitle) {
   107                 if (_trimmedTitle) {
    85                     var _el = IriSP.jQuery('<li class="Ldt-Annotation-TagLabel"></li>').append(IriSP.jQuery('<span>').text(_trimmedTitle));
   108                     var _el = IriSP.jQuery('<li class="Ldt-Annotation-TagLabel"></li>').append(IriSP.jQuery('<span>').text(_trimmedTitle));
    86                     _el.click(function() {
   109                     _el.click(function() {
    87                         if (_this.search_on_tag_click) {
   110                         if (_this.search_on_tag_click) {
    88                             _this.player.trigger("search.triggeredSearch",_trimmedTitle);
   111                             _this.source.getAnnotations().search(_trimmedTitle);
    89                         }
   112                         }
    90                         _tag.trigger("click");
   113                         _tag.trigger("click");
    91                     });
   114                     });
    92                     _tagblock.append(_el);
   115                     _tagblock.append(_el);
    93                 }
   116                 }
    94             });
   117             });
    95         } else {
   118         } else {
    96             _this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock");
   119             _this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock");
    97         }
   120         }
    98         _this.$.find(".Ldt-Annotation-Title").text(_annotation.title || "(" + _this.l10n.untitled + ")");
   121         highlightTitleAndDescription();
    99         var _desc = _annotation.description.replace(/(^\s+|\s+$)/g,'');
       
   100         if (_desc) {
       
   101             _this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock");
       
   102             _this.$.find(".Ldt-Annotation-Description").html(_desc);
       
   103         } else {
       
   104             _this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock");
       
   105         }
       
   106         if (_this.show_annotation_type) {
   122         if (_this.show_annotation_type) {
   107             _this.$.find(".Ldt-Annotation-Type").text(_annotation.getAnnotationType().title)
   123             _this.$.find(".Ldt-Annotation-Type").text(_annotation.getAnnotationType().title)
   108         }
   124         }
   109         _this.$.find(".Ldt-Annotation-Begin").text(_annotation.begin.toString());
   125         _this.$.find(".Ldt-Annotation-Begin").text(_annotation.begin.toString());
   110         _this.$.find(".Ldt-Annotation-End").text(_annotation.end.toString());
   126         _this.$.find(".Ldt-Annotation-End").text(_annotation.end.toString());
   133         _this.sendBounds();
   149         _this.sendBounds();
   134     }
   150     }
   135     
   151     
   136     this.renderTemplate();
   152     this.renderTemplate();
   137     
   153     
   138     if (_this.show_social) {
   154     if (this.show_social) {
   139         this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), { type: "Social" }, "socialWidget");
   155         this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), { type: "Social" }, "socialWidget");
   140     }
   156     }
   141     
   157     
   142     this.insertSubwidget(this.$.find(".Ldt-Annotation-Arrow"), { type: "Arrow" }, "arrow");
   158     this.insertSubwidget(this.$.find(".Ldt-Annotation-Arrow"), { type: "Arrow" }, "arrow");
   143     this.onMediaEvent("timeupdate",timeupdate);
   159     this.onMediaEvent("timeupdate",timeupdate);
   150     this.getWidgetAnnotations().forEach(function(_a) {
   166     this.getWidgetAnnotations().forEach(function(_a) {
   151         _a.on("enter", function() {
   167         _a.on("enter", function() {
   152             drawAnnotation(_a)
   168             drawAnnotation(_a)
   153         });
   169         });
   154     });
   170     });
       
   171     this.source.getAnnotations().on("found", highlightTitleAndDescription);
       
   172     this.source.getAnnotations().on("not-found", highlightTitleAndDescription);
       
   173     this.source.getAnnotations().on("search-cleared", highlightTitleAndDescription);
   155 }
   174 }
   156 
   175 
   157 IriSP.Widgets.Annotation.prototype.sendBounds = function() {
   176 IriSP.Widgets.Annotation.prototype.sendBounds = function() {
   158     this.player.trigger("Annotation.boundsChanged",this.bounds);
   177     this.player.trigger("Annotation.boundsChanged",this.bounds);
   159 }
   178 }