src/js/widgets-container/widget.js
author durandn
Fri, 18 Sep 2015 14:39:45 +0200
changeset 1049 4e8b3df6e5be
parent 1033 c20df1c080e6
child 1068 7623f9af9272
permissions -rw-r--r--
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
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) {
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
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
    }
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    26
    
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
    27
    this.__subwidgets = [];
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
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;
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    33
    
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
    });
a525cc2214e7 Started big refactoring
veltr
parents: 866
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);
eefd336335f9 Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents: 986
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
    }
566b590aaf8f height bugfix
veltr
parents: 988
diff changeset
    45
    
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
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
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"]);
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    54
    
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);
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
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
    );
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
    67
    
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    68
    /* Loading Metadata if required */
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    69
   
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    70
    function onsourceloaded() {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    71
        if (_this.media_id) {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    72
                _this.media = this.getElement(_this.media_id);
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    73
            } else {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    74
                var _mediaopts = {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    75
                    is_mashup: _this.is_mashup || false
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1001
diff changeset
    76
                };
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    77
                _this.media = _this.source.getCurrentMedia(_mediaopts);
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    78
            }
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    79
            
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
    80
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
    81
        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
    82
            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
    83
        }
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
        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
    85
            _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
    86
        }
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    87
        _this.player.trigger("widget-loaded");
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    88
    }
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    89
    
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    90
    if (this.metadata) {
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    91
        /* Getting metadata */
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    92
        this.source = player.loadMetadata(this.metadata);
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    93
        
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    94
        /* Call draw when loaded */
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    95
        this.source.onLoad(onsourceloaded);
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
    96
    } else {
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    97
        if (this.source) {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    98
            onsourceloaded();
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
    99
        }
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   100
    }
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   101
    
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 984
diff changeset
   102
    
66
13013b9452af Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff changeset
   103
};
74
d7a7d7216371 lots of changes to the player widget...
hamidouk
parents: 66
diff changeset
   104
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   105
IriSP.Widgets.Widget.prototype.defaults = {};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   106
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   107
IriSP.Widgets.Widget.prototype.template = '';
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   108
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   109
IriSP.Widgets.Widget.prototype.messages = {"en":{}};
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   110
1001
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   111
IriSP.Widgets.Widget.prototype.toString = function() {
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   112
    return "Widget " + this.type;
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   113
};
3210bf928a11 Enabled loading widgets without the widgeting framework
veltr
parents: 998
diff changeset
   114
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   115
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   116
    return Mustache.to_html(_template, this);
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   117
};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   118
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   119
IriSP.Widgets.Widget.prototype.renderTemplate = function() {
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   120
    this.$.append(this.templateToHtml(this.template));
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   121
};
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   122
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   123
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   124
    var _this = this,
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   125
        _function = this[_name];
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   126
    if (typeof _function !== "undefined") {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   127
        return function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   128
            return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1001
diff changeset
   129
        };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   130
    } else {
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1001
diff changeset
   131
        console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name);
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   132
    }
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   133
};
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   134
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   135
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   136
    switch (typeof _functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   137
        case "function":
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   138
            return _functionOrName;
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   139
        case "string":
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   140
            return this.functionWrapper(_functionOrName);
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   141
        default:
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   142
            return undefined;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   143
    }
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   144
};
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   145
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   146
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   147
    this.player.on(_eventName, this.getFunctionOrName(_functionOrName));
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   148
};
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   149
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   150
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) {
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   151
    this.media.on(_eventName, this.getFunctionOrName(_functionOrName));
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   152
};
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   153
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
   154
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() {
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   155
    var result = null;
982
cfcbac34d020 Added Multi Segments Widget
veltr
parents: 965
diff changeset
   156
    if (typeof this.annotation_type === "undefined") {
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   157
        result = this.media.getAnnotations();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   158
    } else if (this.annotation_type.elementType === "annotationType") {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   159
        result = this.annotation_type.getAnnotations();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   160
    } else {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   161
        result = this.media.getAnnotationsByTypeTitle(this.annotation_type);
982
cfcbac34d020 Added Multi Segments Widget
veltr
parents: 965
diff changeset
   162
    }
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   163
    if (typeof this.annotation_filter !== "undefined") {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   164
        return this.annotation_filter(result);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   165
    } else {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   166
        return result;
982
cfcbac34d020 Added Multi Segments Widget
veltr
parents: 965
diff changeset
   167
    }
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   168
};
876
03967b6ada7c ArrowWidget, AnnotationWidget
veltr
parents: 875
diff changeset
   169
922
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   170
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() {
957
4da0a5740b6c Starting 'players-as-widgets' branch
veltr
parents: 927
diff changeset
   171
    var _time = this.media.getCurrentTime();
922
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   172
    return this.getWidgetAnnotations().filter(function(_annotation) {
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   173
        return _annotation.begin <= _time && _annotation.end > _time;
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   174
    });
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   175
};
922
096c06aea8b5 Minor changes
veltr
parents: 916
diff changeset
   176
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   177
IriSP.Widgets.Widget.prototype.isLoaded = function() {
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   178
    var isloaded = !IriSP._(this.__subwidgets).any(function(w) {
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   179
        return !(w && w.isLoaded());
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   180
    });
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   181
    return isloaded;
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   182
};
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   183
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   184
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) {
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   185
    var _id = _selector.attr("id"),
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   186
        _this = this,
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   187
        _type = _widgetoptions.type,
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   188
        $L = $LAB,
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   189
        key = this.__subwidgets.length;
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   190
    this.__subwidgets.push(null);
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   191
    if (typeof _id == "undefined") {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   192
        _id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type);
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   193
        _selector.attr("id", _id);
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   194
    }
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   195
    _widgetoptions.container = _id;
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   196
    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
   197
        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
   198
            $L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j]));
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   199
        }
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
    $L.wait(function() {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   202
        _this.player.loadWidget(_widgetoptions, function(_widget) {
959
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   203
            if (_propname) {
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   204
                _this[_propname] = _widget;
ee11ed1b739e Mashup Player and Dailymotion are now widgets
veltr
parents: 958
diff changeset
   205
            }
984
e034099276f6 Added keyword passing between related videos
veltr
parents: 982
diff changeset
   206
            _this.__subwidgets[key] = _widget;
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
   207
        });
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   208
    });
998
9521347ede1d Refactoring
veltr
parents: 992
diff changeset
   209
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents: 922
diff changeset
   210
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   211
/*
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   212
 * 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
   213
 *
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   214
 * Parameter: offset: -1 for previous annotation, +1 for next annotation
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   215
 */
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   216
IriSP.Widgets.Widget.prototype.navigate = function(offset) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   217
    // 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
   218
    var _this = this;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   219
    var currentTime = _this.media.getCurrentTime();
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   220
    var annotations = _this.source.getAnnotations().sortBy(function(_annotation) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   221
        return _annotation.begin;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   222
    });
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   223
    for (var i = 0; i < annotations.length; i++) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   224
        if (annotations[i].begin <= currentTime && currentTime < annotations[i].end) {
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   225
            // 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
   226
            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
   227
            _this.media.setCurrentTime(annotations[i].begin);
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   228
            break;
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   229
        }
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
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents: 287
diff changeset
   234
/**
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   235
 * This method responsible of drawing a widget on screen.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   236
 */
875
43629caa77bc Big refactoring of widget files + started migration of segmentwidget
veltr
parents: 874
diff changeset
   237
IriSP.Widgets.Widget.prototype.draw = function() {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   238
    /* implemented by "sub-classes" */
1033
c20df1c080e6 integrate changes from github
ymh <ymh.work@gmail.com>
parents: 1013
diff changeset
   239
};