src/js/widgets.js
branchnew-model
changeset 870 2c025db10a10
parent 868 a525cc2214e7
child 872 d777d05a16e4
equal deleted inserted replaced
868:a525cc2214e7 870:2c025db10a10
    18         return;
    18         return;
    19     }
    19     }
    20     
    20     
    21     /* Setting all the configuration options */
    21     /* Setting all the configuration options */
    22     var _type = config.type,
    22     var _type = config.type,
    23         _config = IriSP._.defaults({}, config, _player.config.gui.default_options, IriSP.widgetsDefaults[_type]),
    23         _config = IriSP._.defaults({}, config, player.config.gui.default_options, IriSP.widgetsDefaults[_type]),
    24         _this = this;
    24         _this = this;
    25     
    25     
    26     /* Creating containers if needed */
    26     /* Creating containers if needed */
    27     if (typeof _config.container === "undefined") {
    27     if (typeof _config.container === "undefined") {
    28         var _divs = _player.layoutDivs(_type);
    28         var _divs = player.layoutDivs(_type);
    29         _config.container = _divs[0];
    29         _config.container = _divs[0];
    30         _config.spacer = _divs[1];
    30         _config.spacer = _divs[1];
    31     }
    31     }
    32     
    32     
    33     IriSP._(_config).forEach(function(_value, _key) {
    33     IriSP._(_config).forEach(function(_value, _key) {
    38      * by a configuration option of the same name :-(
    38      * by a configuration option of the same name :-(
    39      */
    39      */
    40     this.player = player;
    40     this.player = player;
    41     
    41     
    42     /* Getting metadata */
    42     /* Getting metadata */
    43     this.source = _player.loadMetadata(this.metadata);
    43     this.source = player.loadMetadata(this.metadata);
    44     
    44     
    45     /* Call draw when loaded */
    45     /* Call draw when loaded */
    46     this.source.onLoad(function() {
    46     this.source.onLoad(function() {
    47         _this.draw();
    47         _this.draw();
    48     })
    48     });
    49    
    49    
    50     /* Adding classes and html attributes */
    50     /* Adding classes and html attributes */
    51     this.selector = IriSP.jQuery(this.container);
    51     console.log(this.container);
    52     this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type);
    52     this.$ = IriSP.jQuery('#' + this.container);
       
    53     this.$.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type);
    53     
    54     
    54     /* Does the widget require other widgets ? */
    55     /* Does the widget require other widgets ? */
    55     if (typeof this.requires !== "undefined") {
    56     if (typeof this.requires !== "undefined") {
    56         for (var _i = 0; _i < this.requires.length; _i++) {
    57         for (var _i = 0; _i < this.requires.length; _i++) {
    57             var _subconfig = this.requires[_i],
    58             var _subconfig = this.requires[_i],
    58                 _div = IriSP.jQuery('<div>');
    59                 _div = IriSP.jQuery('<div>');
    59             _subconfig.container = IriSP.guid(this.container + '_' + _subconfig.type + '_');
    60             _subconfig.container = IriSP._.uniqueId(this.container + '_' + _subconfig.type + '_');
    60             _div.id = _subconfig.container;
    61             _div.id = _subconfig.container;
    61             this.selector.append(_div);
    62             this.$.append(_div);
    62             this[_subconfig.type] = new IriSP.Widgets(_player, _subconfig);
    63             this[_subconfig.type] = new IriSP.Widgets(player, _subconfig);
    63         }
    64         }
    64     }
    65     }
    65     
    66     
    66 };
    67 };
       
    68 
       
    69 IriSP.Widget.prototype.functionWrapper = function(_name) {
       
    70     var _this = this,
       
    71         _function = this[_name];
       
    72     if (typeof _function !== "undefined") {
       
    73         return function() {
       
    74             return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
       
    75         }
       
    76     } else {
       
    77         console.log("Error, Unknown function IriSP." + this.type + "." + _name)
       
    78     }
       
    79 }
       
    80 
       
    81 IriSP.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) {
       
    82     this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName))
       
    83 }
    67 
    84 
    68 /**
    85 /**
    69  * This method responsible of drawing a widget on screen.
    86  * This method responsible of drawing a widget on screen.
    70  */
    87  */
    71 IriSP.Widget.prototype.draw = function() {
    88 IriSP.Widget.prototype.draw = function() {