Add mkws.objectWithParent function -- not yet used.
[mkws-moved-to-github.git] / src / mkws-core.js
index cc8c63f..893951c 100644 (file)
@@ -102,6 +102,16 @@ mkws.log = function(string) {
 };
 
 
+mkws.objectWithParent = function(parent) {
+    function thing() {} // Must be function so `prototype' works
+
+    thing.prototype = parent;
+    var res = new thing();
+    thing.prototype = null;
+    return res;
+};
+
+
 mkws.registerWidgetType = function(name, fn) {
     mkws.widgetType2function[name] = fn;
     mkws.log("registered widget-type '" + name + "'");
@@ -155,6 +165,46 @@ mkws.defaultMkwsConfig = function() {
 };
 
 
+// The following functions are dispatchers for team methods that
+// are called from the UI using a team-name rather than implicit
+// context.
+mkws.switchView = function(tname, view) {
+    mkws.teams[tname].switchView(view);
+};
+
+mkws.showDetails = function(tname, prefixRecId) {
+    mkws.teams[tname].showDetails(prefixRecId);
+};
+
+mkws.limitTarget  = function(tname, id, name) {
+    mkws.teams[tname].limitTarget(id, name);
+};
+
+mkws.limitQuery  = function(tname, field, value) {
+    mkws.teams[tname].limitQuery(field, value);
+};
+
+mkws.delimitTarget = function(tname, id) {
+    mkws.teams[tname].delimitTarget(id);
+};
+
+mkws.delimitQuery = function(tname, field, value) {
+    mkws.teams[tname].delimitQuery(field, value);
+};
+
+mkws.showPage = function(tname, pageNum) {
+    mkws.teams[tname].showPage(pageNum);
+};
+
+mkws.pagerPrev = function(tname) {
+    mkws.teams[tname].pagerPrev();
+};
+
+mkws.pagerNext = function(tname) {
+    mkws.teams[tname].pagerNext();
+};
+
+
 // wrapper to call team() after page load
 (function(j) {
     var log = mkws.log;
@@ -217,47 +267,6 @@ mkws.defaultMkwsConfig = function() {
     };
 
 
-    // The following functions are dispatchers for team methods that
-    // are called from the UI using a team-name rather than implicit
-    // context. Apart from mkws.log, they are the ONLY public UI to
-    // this module.
-    mkws.switchView = function(tname, view) {
-       mkws.teams[tname].switchView(view);
-    };
-
-    mkws.showDetails = function(tname, prefixRecId) {
-       mkws.teams[tname].showDetails(prefixRecId);
-    };
-
-    mkws.limitTarget  = function(tname, id, name) {
-       mkws.teams[tname].limitTarget(id, name);
-    };
-
-    mkws.limitQuery  = function(tname, field, value) {
-       mkws.teams[tname].limitQuery(field, value);
-    };
-
-    mkws.delimitTarget = function(tname, id) {
-       mkws.teams[tname].delimitTarget(id);
-    };
-
-    mkws.delimitQuery = function(tname, field, value) {
-       mkws.teams[tname].delimitQuery(field, value);
-    };
-
-    mkws.showPage = function(tname, pageNum) {
-       mkws.teams[tname].showPage(pageNum);
-    };
-
-    mkws.pagerPrev = function(tname) {
-       mkws.teams[tname].pagerPrev();
-    };
-
-    mkws.pagerNext = function(tname) {
-       mkws.teams[tname].pagerNext();
-    };
-
-
     /*
      * Run service-proxy authentication in background (after page load).
      * The username/password is configured in the apache config file
@@ -311,11 +320,6 @@ mkws.defaultMkwsConfig = function() {
     $(document).ready(function() {
        mkws.defaultMkwsConfig();
 
-       if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
-           log("Reset query width: " + mkws_config.query_width);
-           mkws_config.query_width = 50;
-       }
-
        for (var key in mkws_config) {
            if (mkws_config.hasOwnProperty(key)) {
                if (key.match(/^language_/)) {
@@ -327,12 +331,9 @@ mkws.defaultMkwsConfig = function() {
            }
        }
 
-       if (mkws_config.responsive_design_width) {
-           // Responsive web design - change layout on the fly based on
-           // current screen width. Required for mobile devices.
-           $(window).resize(resizePage);
-           // initial check after page load
-           $(document).ready(resizePage);
+       if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
+           log("Reset query width: " + mkws_config.query_width);
+           mkws_config.query_width = 50;
        }
 
        // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
@@ -341,6 +342,14 @@ mkws.defaultMkwsConfig = function() {
            log("adjust protocol independent links: " + mkws_config.pazpar2_url);
        }
 
+       if (mkws_config.responsive_design_width) {
+           // Responsive web design - change layout on the fly based on
+           // current screen width. Required for mobile devices.
+           $(window).resize(resizePage);
+           // initial check after page load
+           $(document).ready(resizePage);
+       }
+
        // Backwards compatibility: set new magic class names on any
        // elements that have the old magic IDs.
        var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",