1 /* the widget classes and definitions */ |
1 /* the widget classes and definitions */ |
2 |
2 |
3 /** |
3 /** |
4 * @class Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
4 * @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
5 * |
5 * |
6 * Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
6 * Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
7 * defined in init.js |
7 * defined in init.js |
8 * |
8 * |
9 * @constructor |
9 * @constructor |
10 * @param Popcorn a reference to the popcorn Object |
10 * @param player - a reference to the player widget |
11 * @param config configuration options for the widget |
11 * @param config - configuration options for the widget |
12 * @param Serializer a serializer instance from which the widget reads data fromCharCode |
12 */ |
13 */ |
13 IriSP.Widget = function(player, config) { |
14 IriSP.Widget = function(Popcorn, config, Serializer) { |
|
15 |
14 |
16 if (config === undefined || config === null) { |
15 if( typeof player === "undefined") { |
17 config = {} |
16 /* Probably an abstract call of the class when |
18 } |
17 * individual widgets set their prototype */ |
19 |
18 return; |
20 this._Popcorn = Popcorn; |
19 } |
21 this._config = config; |
20 |
22 this._serializer = Serializer; |
21 /* Setting all the configuration options */ |
23 |
22 var _type = config.type, |
24 if (config.hasOwnProperty("container")) { |
23 _config = IriSP._.defaults({}, config, _player.config.gui.default_options, IriSP.widgetsDefaults[_type]), |
25 this._id = config.container; |
24 _this = this; |
26 this.selector = IriSP.jQuery("#" + this._id); |
25 |
27 } |
26 /* Creating containers if needed */ |
28 |
27 if (typeof _config.container === "undefined") { |
29 if (config.hasOwnProperty("spacer")) { |
28 var _divs = _player.layoutDivs(_type); |
30 this._spacerId = config.spacer; |
29 _config.container = _divs[0]; |
31 this.spacer = IriSP.jQuery("#" + this._spacerId); |
30 _config.spacer = _divs[1]; |
32 } |
31 } |
33 |
32 |
34 |
33 IriSP._(_config).forEach(function(_value, _key) { |
35 if (config.hasOwnProperty("width")) { |
34 _this[_key] = _value; |
36 // this.width and not this._width because we consider it public. |
35 }); |
37 this.width = config.width; |
36 |
38 } |
37 /* Setting this.player at the end in case it's been overriden |
39 |
38 * by a configuration option of the same name :-( |
40 if (config.hasOwnProperty("height")) { |
39 */ |
41 this.height = config.height; |
40 this.player = player; |
42 } |
41 |
43 |
42 /* Getting metadata */ |
44 if (config.hasOwnProperty("heightmax")) { |
43 this.source = _player.loadMetadata(this.metadata); |
45 this.heightmax = config.heightmax; |
44 |
46 } |
45 /* Call draw when loaded */ |
47 |
46 this.source.onLoad(function() { |
48 if (config.hasOwnProperty("widthmax")) { |
47 _this.draw(); |
49 this.widthmax = config.widthmax; |
48 }) |
50 } |
49 |
51 |
50 /* Adding classes and html attributes */ |
52 if (config.hasOwnProperty("layoutManager")) { |
51 this.selector = IriSP.jQuery(this.container); |
53 this.layoutManager = config.layoutManager; |
52 this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type); |
54 } |
53 |
55 if (typeof this.selector != "undefined") { |
54 /* Does the widget require other widgets ? */ |
56 this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget"); |
55 if (typeof this.requires !== "undefined") { |
57 this.selector.attr("widget-type", this._config.type); |
56 for (var _i = 0; _i < this.requires.length; _i++) { |
58 } |
57 var _subconfig = this.requires[_i], |
59 |
58 _div = IriSP.jQuery('<div>'); |
60 // Parsing Widget Defaults |
59 _subconfig.container = IriSP.guid(this.container + '_' + _subconfig.type + '_'); |
61 var _this = this; |
60 _div.id = _subconfig.container; |
62 |
61 this.selector.append(_div); |
63 if (typeof config.type == "string" && typeof IriSP.widgetsDefaults[config.type] == "object") { |
62 this[_subconfig.type] = new IriSP.Widgets(_player, _subconfig); |
64 config = IriSP._.defaults(IriSP.widgetsDefaults[config.type]); |
63 } |
65 } |
64 } |
66 |
65 |
67 }; |
|
68 |
|
69 |
|
70 IriSP.Widget.prototype.currentMedia = function() { |
|
71 return this._serializer.currentMedia(); |
|
72 } |
|
73 |
|
74 IriSP.Widget.prototype.getDuration = function() { |
|
75 return this._serializer.getDuration(); |
|
76 } |
|
77 |
|
78 /** |
|
79 * This method responsible of drawing a widget on screen. |
|
80 */ |
|
81 IriSP.Widget.prototype.draw = function() { |
|
82 /* implemented by "sub-classes" */ |
|
83 }; |
66 }; |
84 |
67 |
85 /** |
68 /** |
86 * Optional method if you want your widget to support redraws. |
69 * This method responsible of drawing a widget on screen. |
87 */ |
70 */ |
|
71 IriSP.Widget.prototype.draw = function() { |
|
72 /* implemented by "sub-classes" */ |
|
73 }; |
|
74 /** |
|
75 * Optional method if you want your widget to support redraws. |
|
76 */ |
88 IriSP.Widget.prototype.redraw = function() { |
77 IriSP.Widget.prototype.redraw = function() { |
89 /* implemented by "sub-classes" */ |
78 /* implemented by "sub-classes" */ |
90 }; |
79 }; |