added a .selector object to all the widgets. popcorn-port
authorhamidouk
Fri, 21 Oct 2011 14:06:29 +0200
branchpopcorn-port
changeset 114 eda061f1aa75
parent 113 ebfd0d17e427
child 115 464e3e892915
added a .selector object to all the widgets.
src/js/widgets.js
unittests/tests/widget.js
--- a/src/js/widgets.js	Fri Oct 21 14:05:59 2011 +0200
+++ b/src/js/widgets.js	Fri Oct 21 14:06:29 2011 +0200
@@ -1,9 +1,19 @@
 /* the widget classes and definitions */
 
 IriSP.Widget = function(Popcorn, config, Serializer) {
+
+  if (config === undefined || config === null) {
+    config = {}
+  }
+  
   this._Popcorn = Popcorn;
   this._config = config;  
   this._serializer = Serializer;
+  
+  if (config.hasOwnProperty("divId")) {
+     this._id = config.divId;
+     this.selector = IriSP.jQuery("#" + this._id);
+  }  
 };
 
 IriSP.Widget.prototype.draw = function() {
@@ -13,8 +23,3 @@
 IriSP.Widget.prototype.redraw = function() {
   /* implemented by "sub-classes" */  
 };
-
-IriSP.PlayerWidget = function(Popcorn, config, Serializer) {
-  IriSP.Widget.call(this, Popcorn, config, Serializer);
-  
-};
\ No newline at end of file
--- a/unittests/tests/widget.js	Fri Oct 21 14:05:59 2011 +0200
+++ b/unittests/tests/widget.js	Fri Oct 21 14:06:29 2011 +0200
@@ -10,8 +10,10 @@
   );
   
   test("test initialisation", function() {
-    var wid = new IriSP.Widget(this.Popcorn, {parent: "widget-div"}, this.ser);
-    deepEqual(wid._config, {parent: "widget-div"}, "Check if the parent div is set correctly");
+    var config = {divId: "mydiv"};
+    var wid = new IriSP.Widget(this.Popcorn, config, this.ser);
+    deepEqual(wid._config, config, "Check if the parent div is set correctly");
+    ok(wid.selector, "Check if the jquery selector is set");
     
   });