src/js/widgets.js
branchnew-model
changeset 870 2c025db10a10
parent 868 a525cc2214e7
child 872 d777d05a16e4
--- a/src/js/widgets.js	Tue Apr 17 20:19:46 2012 +0200
+++ b/src/js/widgets.js	Wed Apr 18 18:58:44 2012 +0200
@@ -20,12 +20,12 @@
     
     /* Setting all the configuration options */
     var _type = config.type,
-        _config = IriSP._.defaults({}, config, _player.config.gui.default_options, IriSP.widgetsDefaults[_type]),
+        _config = IriSP._.defaults({}, config, player.config.gui.default_options, IriSP.widgetsDefaults[_type]),
         _this = this;
     
     /* Creating containers if needed */
     if (typeof _config.container === "undefined") {
-        var _divs = _player.layoutDivs(_type);
+        var _divs = player.layoutDivs(_type);
         _config.container = _divs[0];
         _config.spacer = _divs[1];
     }
@@ -40,31 +40,48 @@
     this.player = player;
     
     /* Getting metadata */
-    this.source = _player.loadMetadata(this.metadata);
+    this.source = player.loadMetadata(this.metadata);
     
     /* Call draw when loaded */
     this.source.onLoad(function() {
         _this.draw();
-    })
+    });
    
     /* Adding classes and html attributes */
-    this.selector = IriSP.jQuery(this.container);
-    this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type);
+    console.log(this.container);
+    this.$ = IriSP.jQuery('#' + this.container);
+    this.$.addClass("Ldt-TraceMe").addClass("Ldt-Widget").attr("widget-type", _type);
     
     /* Does the widget require other widgets ? */
     if (typeof this.requires !== "undefined") {
         for (var _i = 0; _i < this.requires.length; _i++) {
             var _subconfig = this.requires[_i],
                 _div = IriSP.jQuery('<div>');
-            _subconfig.container = IriSP.guid(this.container + '_' + _subconfig.type + '_');
+            _subconfig.container = IriSP._.uniqueId(this.container + '_' + _subconfig.type + '_');
             _div.id = _subconfig.container;
-            this.selector.append(_div);
-            this[_subconfig.type] = new IriSP.Widgets(_player, _subconfig);
+            this.$.append(_div);
+            this[_subconfig.type] = new IriSP.Widgets(player, _subconfig);
         }
     }
     
 };
 
+IriSP.Widget.prototype.functionWrapper = function(_name) {
+    var _this = this,
+        _function = this[_name];
+    if (typeof _function !== "undefined") {
+        return function() {
+            return _function.apply(_this, Array.prototype.slice.call(arguments, 0));
+        }
+    } else {
+        console.log("Error, Unknown function IriSP." + this.type + "." + _name)
+    }
+}
+
+IriSP.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) {
+    this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName))
+}
+
 /**
  * This method responsible of drawing a widget on screen.
  */