| author | veltr |
| Wed, 18 Apr 2012 18:58:44 +0200 | |
| branch | new-model |
| changeset 870 | 2c025db10a10 |
| parent 868 | a525cc2214e7 |
| child 872 | d777d05a16e4 |
| permissions | -rw-r--r-- |
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
1 |
/* the widget classes and definitions */ |
|
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
2 |
|
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
3 |
/** |
| 868 | 4 |
* @class IriSP.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 player - a reference to the player widget |
|
11 |
* @param config - configuration options for the widget |
|
12 |
*/ |
|
13 |
IriSP.Widget = function(player, config) { |
|
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
170
diff
changeset
|
14 |
|
| 868 | 15 |
if( typeof player === "undefined") { |
16 |
/* Probably an abstract call of the class when |
|
17 |
* individual widgets set their prototype */ |
|
18 |
return; |
|
19 |
} |
|
20 |
|
|
21 |
/* Setting all the configuration options */ |
|
22 |
var _type = config.type, |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
23 |
_config = IriSP._.defaults({}, config, player.config.gui.default_options, IriSP.widgetsDefaults[_type]), |
| 868 | 24 |
_this = this; |
25 |
|
|
26 |
/* Creating containers if needed */ |
|
27 |
if (typeof _config.container === "undefined") { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
28 |
var _divs = player.layoutDivs(_type); |
| 868 | 29 |
_config.container = _divs[0]; |
30 |
_config.spacer = _divs[1]; |
|
31 |
} |
|
32 |
|
|
33 |
IriSP._(_config).forEach(function(_value, _key) { |
|
34 |
_this[_key] = _value; |
|
35 |
}); |
|
36 |
|
|
37 |
/* Setting this.player at the end in case it's been overriden |
|
38 |
* by a configuration option of the same name :-( |
|
39 |
*/ |
|
40 |
this.player = player; |
|
41 |
|
|
42 |
/* Getting metadata */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
43 |
this.source = player.loadMetadata(this.metadata); |
| 868 | 44 |
|
45 |
/* Call draw when loaded */ |
|
46 |
this.source.onLoad(function() { |
|
47 |
_this.draw(); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
48 |
}); |
| 868 | 49 |
|
50 |
/* Adding classes and html attributes */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
51 |
console.log(this.container); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
52 |
this.$ = IriSP.jQuery('#' + this.container); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
53 |
this.$.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type); |
| 868 | 54 |
|
55 |
/* Does the widget require other widgets ? */ |
|
56 |
if (typeof this.requires !== "undefined") { |
|
57 |
for (var _i = 0; _i < this.requires.length; _i++) { |
|
58 |
var _subconfig = this.requires[_i], |
|
59 |
_div = IriSP.jQuery('<div>'); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
60 |
_subconfig.container = IriSP._.uniqueId(this.container + '_' + _subconfig.type + '_'); |
| 868 | 61 |
_div.id = _subconfig.container; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
62 |
this.$.append(_div); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
63 |
this[_subconfig.type] = new IriSP.Widgets(player, _subconfig); |
| 868 | 64 |
} |
65 |
} |
|
66 |
|
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
67 |
}; |
| 74 | 68 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
69 |
IriSP.Widget.prototype.functionWrapper = function(_name) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
70 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
71 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
72 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
73 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
74 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
75 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
76 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
77 |
console.log("Error, Unknown function IriSP." + this.type + "." + _name) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
78 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
79 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
80 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
81 |
IriSP.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
82 |
this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName)) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
83 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
84 |
|
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
85 |
/** |
| 868 | 86 |
* This method responsible of drawing a widget on screen. |
87 |
*/ |
|
88 |
IriSP.Widget.prototype.draw = function() { |
|
89 |
/* implemented by "sub-classes" */ |
|
90 |
}; |
|
91 |
/** |
|
92 |
* Optional method if you want your widget to support redraws. |
|
93 |
*/ |
|
| 74 | 94 |
IriSP.Widget.prototype.redraw = function() { |
| 868 | 95 |
/* implemented by "sub-classes" */ |
| 74 | 96 |
}; |