web/res/metadataplayer/LdtPlayer-core.js
changeset 726 d82d070cf23e
parent 719 d0d3a9369f84
child 755 d50aeed9a54b
--- a/web/res/metadataplayer/LdtPlayer-core.js	Wed Nov 28 18:33:32 2012 +0100
+++ b/web/res/metadataplayer/LdtPlayer-core.js	Tue Dec 04 10:56:04 2012 +0100
@@ -96,7 +96,7 @@
 IriSP.Metadataplayer.prototype.onLibsLoaded = function() {
     IriSP.log("IriSP.Metadataplayer.prototype.onLibsLoaded");
     if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") {
-        IriSP.jQuery = window.jQuery.noConflict();
+        IriSP.jQuery = window.jQuery;
     }
     if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") {
         IriSP._ = window._;
@@ -115,12 +115,28 @@
       
     this.widgets = [];
     var _this = this;
-    for(var i = 0; i < this.config.widgets.length; i++) {
-        this.loadWidget(this.config.widgets[i], function(_widget) {
-            _this.widgets.push(_widget)
+    IriSP._(this.config.widgets).each(function(widgetconf, key) {
+        _this.widgets.push(null);
+        _this.loadWidget(widgetconf, function(widget) {
+            _this.widgets[key] = widget;
         });
-    };
+    });
     this.$.find('.Ldt-Loader').detach();
+    
+    var endload = false;
+    
+    this.on("widget-loaded", function() {
+        if (endload) {
+            return;
+        }
+        var isloaded = !IriSP._(_this.widgets).any(function(w) {
+            return !(w && w.isLoaded())
+        });
+        if (isloaded) {
+            endload = true;
+            _this.trigger("widgets-loaded");
+        }
+    });   
 }
 
 IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) {
@@ -1548,13 +1564,15 @@
 
 
 IriSP.Widgets.Widget = function(player, config) {
-
+    
     if( typeof player === "undefined") {
         /* Probably an abstract call of the class when
          * individual widgets set their prototype */
         return;
     }
     
+    this.__subwidgets = [];
+    
     /* Setting all the configuration options */
     var _type = config.type,
         _config = IriSP._.defaults({}, config, player.config.default_options, this.defaults),
@@ -1588,6 +1606,7 @@
         }
         
         _this.draw();
+        player.trigger("widget-loaded");
     });
    
     /* Adding classes and html attributes */
@@ -1668,11 +1687,20 @@
     });
 }
 
+IriSP.Widgets.Widget.prototype.isLoaded = function() {
+    var isloaded = !IriSP._(this.__subwidgets).any(function(w) {
+        return !(w && w.isLoaded());
+    });
+    return isloaded;
+}
+
 IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) {
     var _id = _selector.attr("id"),
         _this = this,
         _type = _widgetoptions.type,
-        $L = $LAB;
+        $L = $LAB,
+        key = this.__subwidgets.length;
+    this.__subwidgets.push(null);
     if (typeof _id == "undefined") {
         _id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type);
         _selector.attr("id", _id);
@@ -1688,6 +1716,7 @@
             if (_propname) {
                 _this[_propname] = _widget;
             }
+            _this.__subwidgets[key] = _widget;
         });
     });
 }