server/src/remie/static/remie/metadataplayer/Renkan.js
author durandn
Fri, 18 Sep 2015 15:11:24 +0200
changeset 155 46fa7451f951
permissions -rw-r--r--
Updated metadataplayer by building it from official repo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
155
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     1
IriSP.Widgets.Renkan = function(player, config) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     2
    IriSP.Widgets.Widget.call(this, player, config);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     3
};
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     4
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     5
IriSP.Widgets.Renkan.prototype = new IriSP.Widgets.Widget();
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     6
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     7
IriSP.Widgets.Renkan.prototype.defaults = {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     8
    annotation_regexp: /player\/([a-zA-Z0-9_-]+)\/.*id=([a-zA-Z0-9_-]+)/,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
     9
    tag_regexp: /search=([^&=]+)/,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    10
    min_duration: 5000,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    11
    renkan_options: {}
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    12
};
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    13
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    14
IriSP.Widgets.Renkan.prototype.messages = {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    15
    "fr": {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    16
    },
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    17
    "en": {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    18
    }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    19
};
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    20
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    21
IriSP.Widgets.Renkan.prototype.template =
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    22
    '<div class="Ldt-Renkan-Container"><div class="Ldt-Renkan"></div></div>';
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    23
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    24
IriSP.Widgets.Renkan.prototype.draw = function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    25
    this.renderTemplate();
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    26
    var _id = IriSP.Model.getUID();
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    27
    this.$.find(".Ldt-Renkan").attr("id", _id);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    28
    var renkan_options = IriSP._.extend({
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    29
        container: _id,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    30
        editor_mode: false,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    31
        show_bins: false,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    32
        show_top_bar: false,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    33
        force_resize: true,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    34
        language: IriSP.language
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    35
    }, this.renkan_options);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    36
    this.renkan = new Rkns.Renkan(renkan_options);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    37
    this.node_times = [];
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    38
    var _this = this,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    39
        _list = this.getWidgetAnnotations();
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    40
    this.renkan.project.on("add:nodes", function(_node) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    41
        var _uri = _node.get("uri"),
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    42
            _annmatch = _uri.match(_this.annotation_regexp);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    43
        if (_annmatch) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    44
            var _annotations = _list.filter(function(_ann) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    45
                return _ann.getMedia().id == _annmatch[1] && _ann.id == _annmatch[2];
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    46
            });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    47
            _annotations.forEach(function(_ann) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    48
                var _duration = _ann.getDuration(),
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    49
                    _preroll = + ( _duration < _this.min_duration ) * ( _this.min_duration / 2);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    50
                var _nt = {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    51
                    uri: _uri,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    52
                    selected: false,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    53
                    node: _node,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    54
                    annotation: _ann,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    55
                    begin: _ann.begin - _preroll,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    56
                    end: _ann.end + _preroll
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    57
                };
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    58
                _this.node_times.push(_nt);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    59
                var _annselected = false,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    60
                    _nodeselected = false;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    61
                _ann.on("select", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    62
                    _annselected = true;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    63
                    if (!_nodeselected) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    64
                        _node.trigger("select",true);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    65
                    }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    66
                });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    67
                _node.on("selected", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    68
                    _nodeselected = true;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    69
                    if (!_annselected) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    70
                        _ann.trigger("select",true);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    71
                    }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    72
                });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    73
                _ann.on("unselect", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    74
                    _annselected = false;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    75
                    if (_nodeselected) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    76
                        _node.trigger("unselect",true);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    77
                    }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    78
                });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    79
                _node.on("unselected", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    80
                    _nodeselected = false;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    81
                    _nt.selected = false;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    82
                    if (_annselected) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    83
                        _ann.trigger("unselect",true);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    84
                    }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    85
                });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    86
                _node.on("clicked", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    87
                    _ann.trigger("click");
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    88
                });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    89
            });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    90
        }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    91
        var _tagmatch = _uri.match(_this.tag_regexp);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    92
        if (_tagmatch) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    93
            _node.on("select", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    94
                _this.source.getAnnotations().search(_tagmatch[1]);
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    95
            });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    96
            _node.on("unselect", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    97
                _this.source.getAnnotations().search("");
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    98
            });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
    99
        }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   100
    });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   101
    Rkns.jsonIO(this.renkan, {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   102
        url: this.data
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   103
    });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   104
    
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   105
    this.onMediaEvent("timeupdate","onTimeupdate");
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   106
    
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   107
    this.$.find(".Rk-Editor").on("click", "a", function() {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   108
        var href = this.href,
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   109
            times = _this.node_times.filter(function(t) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   110
                return t.uri == href;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   111
            });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   112
        if (times.length) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   113
            IriSP._(times).each(function(t) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   114
                t.annotation.trigger("click");
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   115
            });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   116
            return false;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   117
        }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   118
    });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   119
};
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   120
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   121
IriSP.Widgets.Renkan.prototype.onTimeupdate = function(_time) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   122
    IriSP._(this.node_times).each(function(_nt) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   123
        if (_nt.begin <= _time && _nt.end >= _time) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   124
            if (!_nt.selected) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   125
                _nt.selected = true;
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   126
                _nt.node.trigger("select");
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   127
            }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   128
        } else {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   129
            if (_nt.selected) {
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   130
                _nt.node.trigger("unselect");
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   131
            }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   132
        }
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   133
    });
46fa7451f951 Updated metadataplayer by building it from official repo
durandn
parents:
diff changeset
   134
};