src/js/widgets-container/widget.js
author ymh <ymh.work@gmail.com>
Fri, 02 Oct 2015 11:27:17 +0200
changeset 1068 7623f9af9272
parent 1049 4e8b3df6e5be
child 1072 ac1eacb3aa33
permissions -rw-r--r--
merge pull request #3 from O. Auber
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
     1
/* widgetsDefinition of an ancestor for the Widget classes */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     2
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     3
if (typeof IriSP.Widgets === "undefined") {
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
     4
    IriSP.Widgets = {};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
     5
}
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
     6
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
     7
/**
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     8
 * @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     9
 *
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    10
 *  Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    11
 *  defined in init.js
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    12
 *
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    13
 * @constructor
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    14
 * @param player - a reference to the player widget
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    15
 * @param config - configuration options for the widget
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    16
 */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    17
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    18
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    19
IriSP.Widgets.Widget = function(player, config) {
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    20
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    21
    if( typeof player === "undefined") {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    22
        /* Probably an abstract call of the class when
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    23
         * individual widgets set their prototype */
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    24
        return;
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    25
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    26
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
    27
    this.__subwidgets = [];
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    28
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    29
    /* Setting all the configuration options */
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    30
    var _type = config.type || "(unknown)",
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    31
        _config = IriSP._.defaults({}, config, (player && player.config ? player.config.default_options : {}), this.defaults),
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    32
        _this = this;
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    33
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    34
    IriSP._(_config).forEach(function(_value, _key) {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    35
       _this[_key] = _value;
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    36
    });
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    37
988
eefd336335f9 Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents: 986
diff changeset
    38
    this.$ = IriSP.jQuery('#' + this.container);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    39
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    40
    if (typeof this.width === "undefined") {
988
eefd336335f9 Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents: 986
diff changeset
    41
        this.width = this.$.width();
992
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    42
    } else {
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    43
        this.$.css("width", this.width);
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    44
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    45
992
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    46
    if (typeof this.height !== "undefined") {
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    47
        this.$.css("height", this.height);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    48
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    49
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    50
    /* Setting this.player at the end in case it's been overriden
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    51
     * by a configuration option of the same name :-(
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    52
     */
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    53
    this.player = player || new IriSP.FakeClass(["on","trigger","off","loadWidget","loadMetadata"]);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    54
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    55
    /* Adding classes and html attributes */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    56
    this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type);
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    57
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    58
    this.l10n = (
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    59
        typeof this.messages[IriSP.language] !== "undefined"
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    60
        ? this.messages[IriSP.language]
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    61
        : (
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    62
            IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined"
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    63
            ? this.messages[IriSP.language.substr(0,2)]
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    64
            : this.messages["en"]
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    65
        )
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 908
diff changeset
    66
    );
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    67
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    68
    /* Loading Metadata if required */
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    69
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    70
    function onsourceloaded() {
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    71
        if (_this.localannotations) {
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    72
            _this.localsource = player.loadLocalAnnotations(_this.localannotations);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    73
            _this.source.merge(_this.localsource);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    74
        }
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    75
        if (_this.media_id) {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    76
                _this.media = this.getElement(_this.media_id);
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    77
            } else {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    78
                var _mediaopts = {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    79
                    is_mashup: _this.is_mashup || false
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1001
diff changeset
    80
                };
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    81
                _this.media = _this.source.getCurrentMedia(_mediaopts);
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    82
            }
1049
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
    83
        if (_this.pre_draw_callback){
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
    84
            IriSP.jQuery.when(_this.pre_draw_callback()).done(_this.draw());
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
    85
        }
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
    86
        else {
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
    87
            _this.draw();
4e8b3df6e5be Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents: 1033
diff changeset
    88
        }
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    89
        _this.player.trigger("widget-loaded");
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    90
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
    91
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    92
    if (this.metadata) {
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    93
        /* Getting metadata */
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    94
        this.source = player.loadMetadata(this.metadata);
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    95
        /* Call draw when loaded */
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    96
        this.source.onLoad(onsourceloaded);
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    97
    } else {
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    98
        if (this.source) {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    99
            onsourceloaded();
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   100
        }
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   101
    }
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   102
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   103
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
   104
};
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
   105
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   106
IriSP.Widgets.Widget.prototype.defaults = {};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   107
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   108
IriSP.Widgets.Widget.prototype.template = '';
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   109
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   110
IriSP.Widgets.Widget.prototype.messages = {"en":{}};
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   111
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   112
IriSP.Widgets.Widget.prototype.toString = function() {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   113
    return "Widget " + this.type;
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   114
};
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   115
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   116
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   117
    return Mustache.to_html(_template, this);
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   118
};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   119
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   120
IriSP.Widgets.Widget.prototype.renderTemplate = function() {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   121
    this.$.append(this.templateToHtml(this.template));
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   122
};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   123
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   124
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   125
    var _this = this,
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   126
        _function = this[_name];
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   127
    if (typeof _function !== "undefined") {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   128
        return function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   129
            return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1001
diff changeset
   130
        };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   131
    } else {
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1001
diff changeset
   132
        console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name);
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   133
    }
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   134
};
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   135
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   136
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   137
    switch (typeof _functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   138
        case "function":
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   139
            return _functionOrName;
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   140
        case "string":
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   141
            return this.functionWrapper(_functionOrName);
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   142
        default:
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   143
            return undefined;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   144
    }
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   145
};
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   146
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   147
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   148
    this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   149
};
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   150
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   151
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   152
    this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   153
};
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   154
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
   155
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() {
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   156
    var result = null;
982
cfcbac34d020 Added Multi Segments Widget
veltr
parents: 965
diff changeset
   157
    if (typeof this.annotation_type === "undefined") {
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   158
        result = this.media.getAnnotations();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   159
    } else if (this.annotation_type.elementType === "annotationType") {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   160
        result = this.annotation_type.getAnnotations();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   161
    } else {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   162
        result = this.media.getAnnotationsByTypeTitle(this.annotation_type);
982
cfcbac34d020 Added Multi Segments Widget
veltr
parents: 965
diff changeset
   163
    }
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   164
    if (typeof this.annotation_filter !== "undefined") {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   165
        return this.annotation_filter(result);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   166
    } else {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   167
        return result;
982
cfcbac34d020 Added Multi Segments Widget
veltr
parents: 965
diff changeset
   168
    }
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   169
};
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
   170
922
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   171
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   172
    var _time = this.media.getCurrentTime();
922
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   173
    return this.getWidgetAnnotations().filter(function(_annotation) {
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   174
        return _annotation.begin <= _time && _annotation.end > _time;
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   175
    });
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   176
};
922
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   177
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   178
IriSP.Widgets.Widget.prototype.isLoaded = function() {
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   179
    var isloaded = !IriSP._(this.__subwidgets).any(function(w) {
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   180
        return !(w && w.isLoaded());
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   181
    });
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   182
    return isloaded;
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   183
};
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   184
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   185
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) {
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   186
    var _id = _selector.attr("id"),
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   187
        _this = this,
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   188
        _type = _widgetoptions.type,
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   189
        $L = $LAB,
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   190
        key = this.__subwidgets.length;
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   191
    this.__subwidgets.push(null);
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   192
    if (typeof _id == "undefined") {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   193
        _id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type);
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   194
        _selector.attr("id", _id);
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   195
    }
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   196
    _widgetoptions.container = _id;
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   197
    if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   198
        for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   199
            $L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j]));
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   200
        }
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   201
    }
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   202
    $L.wait(function() {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   203
        _this.player.loadWidget(_widgetoptions, function(_widget) {
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   204
            if (_propname) {
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   205
                _this[_propname] = _widget;
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   206
            }
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   207
            _this.__subwidgets[key] = _widget;
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   208
        });
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   209
    });
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   210
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   211
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   212
/*
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   213
 * Position the player to the next/previous annotations based on current player position
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   214
 *
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   215
 * Parameter: offset: -1 for previous annotation, +1 for next annotation
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   216
 */
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   217
IriSP.Widgets.Widget.prototype.navigate = function(offset) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   218
    // offset is normally either -1 (previous slide) or +1 (next slide)
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   219
    var _this = this;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   220
    var currentTime = _this.media.getCurrentTime();
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   221
    var annotations = _this.getWidgetAnnotations().sortBy(function(_annotation) {
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   222
        return _annotation.begin;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   223
    });
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   224
    for (var i = 0; i < annotations.length; i++) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   225
        if (annotations[i].begin <= currentTime && currentTime < annotations[i].end) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   226
            // Found a current annotation - clamp i+offset value to [0, length - 1]
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   227
            i = Math.min(annotations.length - 1, Math.max(0, i + offset));
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   228
            _this.media.setCurrentTime(annotations[i].begin);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   229
            break;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   230
        }
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   231
    };
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   232
};
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   233
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   234
/*
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   235
 * Propose an export of the widget's annotations
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   236
 *
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   237
 * Parameter: a list of annotations. If not specified, the widget's annotations will be exported.
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   238
 */
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   239
IriSP.Widgets.Widget.prototype.exportAnnotations = function(annotations) {
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   240
    var widget = this;
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   241
    if (annotations === undefined)
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   242
        annotations = this.getWidgetAnnotations();
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   243
    var $ = IriSP.jQuery;
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   244
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   245
    // FIXME: this should belong to a proper serialize/deserialize component?
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   246
    var content = Mustache.to_html("[video:{{url}}]\n", {url: widget.media.url}) + annotations.map( function(a) { return Mustache.to_html("[{{ a.begin }}]{{ a.title }} {{ a.description }}[{{ a.end }}]", { a: a }); }).join("\n");
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   247
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   248
    var el = $("<pre>")
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   249
            .addClass("exportContainer")
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   250
            .text(content)
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   251
            .dialog({
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   252
                title: "Annotation export",
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   253
                open: function( event, ui ) {
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   254
                    // Select text
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   255
                    var range;
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   256
                    if (document.selection) {
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   257
		                range = document.body.createTextRange();
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   258
                        range.moveToElementText(this[0]);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   259
		                range.select();
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   260
		            } else if (window.getSelection) {
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   261
		                range = document.createRange();
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   262
		                range.selectNode(this[0]);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   263
		                window.getSelection().addRange(range);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   264
		            }
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   265
                },
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   266
                autoOpen: true,
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   267
                width: '80%',
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   268
                minHeight: '400',
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   269
                height: 400,
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   270
                buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } },
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   271
                           { text: "Download", click: function () {
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   272
                               a = document.createElement('a');
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   273
                               a.setAttribute('href', 'data:text/plain;base64,' + btoa(content));
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   274
                               a.setAttribute('download', 'Annotations - ' + widget.media.title.replace(/[^ \w]/g, '') + '.txt');
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   275
                               a.click();
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   276
                           } } ]
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   277
            });
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1049
diff changeset
   278
};
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   279
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
   280
/**
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   281
 * This method responsible of drawing a widget on screen.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   282
 */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   283
IriSP.Widgets.Widget.prototype.draw = function() {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   284
    /* implemented by "sub-classes" */
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   285
};