src/widgets/Highlighter.js
author durandn
Tue, 01 Sep 2015 15:31:46 +0200
changeset 1046 eb77616c245f
parent 1033 c20df1c080e6
child 1072 ac1eacb3aa33
permissions -rw-r--r--
Updated LatestAnnotation, CurrentSegmentInfobox, AnnotationController and AnnotationList widgets to use timerange to find the current segment when the corresponding option is used + CurrentSegmentInfobox now has an option for editing the current segment + LatestAnnotation now has a "Copy and edit" button that allows to use the text from the currently displayed annotation into the CreateAnnotation widget textarea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
IriSP.Widgets.Highlighter = function(player, config) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
    var _this = this;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
    IriSP.Widgets.Widget.call(this, player, config);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    this.throttledRefresh = IriSP._.throttle(function() {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
        console.log("highlighter Refresh");
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
        _this.update();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    }, 800);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
};
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Highlighter widget
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * This widgets highlights the current annotations by setting the
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * .activeAnnotation class on appropriate .Ldt-Highlighter-Annotation
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * elements. These elements *must* have data-begin and data-end properties specifying their bounds (in ms) (and data-media specifying the media-id)
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
IriSP.Widgets.Highlighter.prototype = new IriSP.Widgets.Widget();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
IriSP.Widgets.Highlighter.prototype.defaults =  {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
}
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
IriSP.Widgets.Highlighter.prototype.update = function() {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    var  _this = this;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    var _currentTime = _this.media.getCurrentTime();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    _this.$.find(".Ldt-Highlighter-Annotation", document).toggleClass("currentAnnotation", function () {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        return (this.dataset.media === _this.media.id && this.dataset.begin <= _currentTime && _currentTime < this.dataset.end);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    });
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    console.log(_this.$.find(".currentAnnotation"));
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    return false;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
};
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
IriSP.Widgets.Highlighter.prototype.draw = function() {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    var  _this = this;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    var _events = [
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        "timeupdate",
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        "seeked",
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        "loadedmetadata"
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    ];
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    for (var _i = 0; _i < _events.length; _i++) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        _this.onMediaEvent(_events[_i], _this.throttledRefresh);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    }
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    _this.throttledRefresh();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
};