src/js/widgets-container/widget.js
changeset 1001 3210bf928a11
parent 998 9521347ede1d
child 1013 392ddcd212d7
equal deleted inserted replaced
1000:91023037f841 1001:3210bf928a11
    25     }
    25     }
    26     
    26     
    27     this.__subwidgets = [];
    27     this.__subwidgets = [];
    28     
    28     
    29     /* Setting all the configuration options */
    29     /* Setting all the configuration options */
    30     var _type = config.type,
    30     var _type = config.type || "(unknown)",
    31         _config = IriSP._.defaults({}, config, player.config.default_options, this.defaults),
    31         _config = IriSP._.defaults({}, config, (player && player.config ? player.config.default_options : {}), this.defaults),
    32         _this = this;
    32         _this = this;
    33     
    33     
    34     IriSP._(_config).forEach(function(_value, _key) {
    34     IriSP._(_config).forEach(function(_value, _key) {
    35        _this[_key] = _value;
    35        _this[_key] = _value;
    36     });
    36     });
    48     }
    48     }
    49     
    49     
    50     /* Setting this.player at the end in case it's been overriden
    50     /* Setting this.player at the end in case it's been overriden
    51      * by a configuration option of the same name :-(
    51      * by a configuration option of the same name :-(
    52      */
    52      */
    53     this.player = player;
    53     this.player = player || new IriSP.FakeClass(["on","trigger","off","loadWidget","loadMetadata"]);
    54     
    54     
    55     /* Adding classes and html attributes */
    55     /* Adding classes and html attributes */
    56     this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type);
    56     this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type);
    57     
    57     
    58     this.l10n = (
    58     this.l10n = (
    64             : this.messages["en"]
    64             : this.messages["en"]
    65         )
    65         )
    66     );
    66     );
    67     
    67     
    68     /* Loading Metadata if required */
    68     /* Loading Metadata if required */
       
    69    
       
    70     function onsourceloaded() {
       
    71         if (_this.media_id) {
       
    72                 _this.media = this.getElement(_this.media_id);
       
    73             } else {
       
    74                 var _mediaopts = {
       
    75                     is_mashup: _this.is_mashup || false
       
    76                 }
       
    77                 _this.media = _this.source.getCurrentMedia(_mediaopts);
       
    78             }
       
    79             
       
    80         _this.draw();
       
    81         _this.player.trigger("widget-loaded");
       
    82     }
    69     
    83     
    70     if (this.metadata) {
    84     if (this.metadata) {
    71         /* Getting metadata */
    85         /* Getting metadata */
    72         this.source = player.loadMetadata(this.metadata);
    86         this.source = player.loadMetadata(this.metadata);
    73         
    87         
    74         /* Call draw when loaded */
    88         /* Call draw when loaded */
    75         this.source.onLoad(function() {
    89         this.source.onLoad(onsourceloaded);
    76             if (_this.media_id) {
       
    77                 _this.media = this.getElement(_this.media_id);
       
    78             } else {
       
    79                 var _mediaopts = {
       
    80                     is_mashup: _this.is_mashup || false
       
    81                 }
       
    82                 _this.media = this.getCurrentMedia(_mediaopts);
       
    83             }
       
    84             
       
    85             _this.draw();
       
    86             player.trigger("widget-loaded");
       
    87         });
       
    88     } else {
    90     } else {
    89         this.draw();
    91         if (this.source) {
       
    92             onsourceloaded();
       
    93         }
    90     }
    94     }
    91     
    95     
    92     
    96     
    93 };
    97 };
    94 
    98 
    95 IriSP.Widgets.Widget.prototype.defaults = {};
    99 IriSP.Widgets.Widget.prototype.defaults = {};
    96 
   100 
    97 IriSP.Widgets.Widget.prototype.template = '';
   101 IriSP.Widgets.Widget.prototype.template = '';
    98 
   102 
    99 IriSP.Widgets.Widget.prototype.messages = {"en":{}};
   103 IriSP.Widgets.Widget.prototype.messages = {"en":{}};
       
   104 
       
   105 IriSP.Widgets.Widget.prototype.toString = function() {
       
   106     return "Widget " + this.type;
       
   107 };
   100 
   108 
   101 IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) {
   109 IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) {
   102     return Mustache.to_html(_template, this);
   110     return Mustache.to_html(_template, this);
   103 };
   111 };
   104 
   112