| author | veltr |
| Fri, 20 Apr 2012 19:13:11 +0200 | |
| branch | new-model |
| changeset 874 | 38b65761a7d5 |
| parent 872 | d777d05a16e4 |
| child 875 | 43629caa77bc |
| 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 |
|
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
37 |
if (typeof this.width === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
38 |
this.width = player.config.gui.width; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
39 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
40 |
|
| 868 | 41 |
/* Setting this.player at the end in case it's been overriden |
42 |
* by a configuration option of the same name :-( |
|
43 |
*/ |
|
44 |
this.player = player; |
|
45 |
|
|
46 |
/* Getting metadata */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
47 |
this.source = player.loadMetadata(this.metadata); |
| 868 | 48 |
|
49 |
/* Call draw when loaded */ |
|
50 |
this.source.onLoad(function() { |
|
51 |
_this.draw(); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
52 |
}); |
| 868 | 53 |
|
54 |
/* Adding classes and html attributes */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
55 |
console.log(this.container); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
56 |
this.$ = IriSP.jQuery('#' + this.container); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
57 |
this.$.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type); |
| 868 | 58 |
|
59 |
/* Does the widget require other widgets ? */ |
|
60 |
if (typeof this.requires !== "undefined") { |
|
61 |
for (var _i = 0; _i < this.requires.length; _i++) { |
|
|
874
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
62 |
var _subconfig = this.requires[_i]; |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
63 |
if (typeof IriSP[_subconfig.type] !== "undefined") { |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
64 |
_subconfig.container = IriSP._.uniqueId(this.container + '_' + _subconfig.type + '_'); |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
65 |
this.$.append(IriSP.jQuery('<div>').attr("id",_subconfig.container)); |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
66 |
console.log(this.$.html()); |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
67 |
this[_subconfig.type] = new IriSP[_subconfig.type](player, _subconfig); |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
68 |
} else { |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
69 |
console.log("Error, Call to Undefined Widget Type : "+_subconfig.type); |
|
38b65761a7d5
TooltipWidget, SliderWidget, corrections in AnnotationList, CSS are now split
veltr
parents:
872
diff
changeset
|
70 |
} |
| 868 | 71 |
} |
72 |
} |
|
73 |
|
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
74 |
}; |
| 74 | 75 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
76 |
IriSP.Widget.prototype.functionWrapper = function(_name) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
77 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
78 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
79 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
80 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
81 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
82 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
83 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
84 |
console.log("Error, Unknown function IriSP." + this.type + "." + _name) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
85 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
86 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
87 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
88 |
IriSP.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
89 |
this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName)) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
90 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
91 |
|
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
92 |
/** |
| 868 | 93 |
* This method responsible of drawing a widget on screen. |
94 |
*/ |
|
95 |
IriSP.Widget.prototype.draw = function() { |
|
96 |
/* implemented by "sub-classes" */ |
|
97 |
}; |
|
98 |
/** |
|
99 |
* Optional method if you want your widget to support redraws. |
|
100 |
*/ |
|
| 74 | 101 |
IriSP.Widget.prototype.redraw = function() { |
| 868 | 102 |
/* implemented by "sub-classes" */ |
| 74 | 103 |
}; |