|
1 /* the widget classes and definitions */ |
|
2 |
|
3 /** |
|
4 * @class Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
|
5 * |
|
6 * Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
|
7 * defined in init.js |
|
8 * |
|
9 * @constructor |
|
10 * @param Popcorn a reference to the popcorn Object |
|
11 * @param config configuration options for the widget |
|
12 * @param Serializer a serializer instance from which the widget reads data fromCharCode |
|
13 */ |
|
14 IriSP.Widget = function(Popcorn, config, Serializer) { |
|
15 |
|
16 if (config === undefined || config === null) { |
|
17 config = {} |
|
18 } |
|
19 |
|
20 this._Popcorn = Popcorn; |
|
21 this._config = config; |
|
22 this._serializer = Serializer; |
|
23 |
|
24 if (config.hasOwnProperty("container")) { |
|
25 this._id = config.container; |
|
26 this.selector = IriSP.jQuery("#" + this._id); |
|
27 } |
|
28 |
|
29 if (config.hasOwnProperty("spacer")) { |
|
30 this._spacerId = config.spacer; |
|
31 this.spacer = IriSP.jQuery("#" + this._spacerId); |
|
32 } |
|
33 |
|
34 |
|
35 if (config.hasOwnProperty("width")) { |
|
36 // this.width and not this._width because we consider it public. |
|
37 this.width = config.width; |
|
38 } |
|
39 |
|
40 if (config.hasOwnProperty("height")) { |
|
41 this.height = config.height; |
|
42 } |
|
43 |
|
44 if (config.hasOwnProperty("heightmax")) { |
|
45 this.heightmax = config.heightmax; |
|
46 } |
|
47 |
|
48 if (config.hasOwnProperty("widthmax")) { |
|
49 this.widthmax = config.widthmax; |
|
50 } |
|
51 |
|
52 if (config.hasOwnProperty("layoutManager")) { |
|
53 this.layoutManager = config.layoutManager; |
|
54 } |
|
55 if (typeof this.selector != "undefined") { |
|
56 this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget"); |
|
57 this.selector.attr("widget-type", this._config.type); |
|
58 } |
|
59 |
|
60 // Parsing Widget Defaults |
|
61 var _this = this; |
|
62 |
|
63 if (typeof config.type == "string" && typeof IriSP.widgetsDefaults[config.type] == "object") { |
|
64 IriSP._(IriSP.widgetsDefaults[config.type]).each(function(_v, _k) { |
|
65 if (typeof config[_k] != "undefined") { |
|
66 _this[_k] = config[_k]; |
|
67 } else { |
|
68 _this[_k] = _v; |
|
69 } |
|
70 }); |
|
71 } |
|
72 |
|
73 }; |
|
74 |
|
75 |
|
76 IriSP.Widget.prototype.currentMedia = function() { |
|
77 return this._serializer.currentMedia(); |
|
78 } |
|
79 |
|
80 IriSP.Widget.prototype.getDuration = function() { |
|
81 return this._serializer.getDuration(); |
|
82 } |
|
83 |
|
84 /** |
|
85 * This method responsible of drawing a widget on screen. |
|
86 */ |
|
87 IriSP.Widget.prototype.draw = function() { |
|
88 /* implemented by "sub-classes" */ |
|
89 }; |
|
90 |
|
91 /** |
|
92 * Optional method if you want your widget to support redraws. |
|
93 */ |
|
94 IriSP.Widget.prototype.redraw = function() { |
|
95 /* implemented by "sub-classes" */ |
|
96 }; |