add a init callback for calls after page load, MKWS-255
authorWolfram Schneider <wosch@indexdata.dk>
Mon, 11 Aug 2014 14:48:19 +0000 (14:48 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Mon, 11 Aug 2014 14:48:19 +0000 (14:48 +0000)
Usually we put all JS files into one page, and after the DOM is
ready we call mkws init() to register other widgets. That doesn't work
if requirejs load the JS files in background, then the page load
event is lost. requirejs can be configured to load the MKWS javascript
files in the right order, but we have to call back mkws that the last
widget is loaded, and we need to init again.

src/mkws-core.js

index 3c2ff2a..c388084 100644 (file)
@@ -656,8 +656,21 @@ mkws.pagerNext = function(tname) {
       runAutoSearches();
     }
   };
-  $(document).ready(function() {
+
+  // callback for calls after page load, e.g. requirejs
+  mkws.init_widgets = function (message) {
+    if (message) mkws.log(message);
+
     var widgetSelector = selectorForAllWidgets();
-    if (widgetSelector && $(widgetSelector).length !== 0) init();
+    if (widgetSelector && $(widgetSelector).length !== 0) {
+      init();
+    } else {
+       mkws.log("no widgets found");
+    }
+  };
+
+  $(document).ready(function() {
+    mkws.init_widgets();
   });
+
 })(mkws.$);