Merge branch 'master' into templateallthemarkup
authorJason Skomorowski <jason@indexdata.com>
Mon, 18 Aug 2014 13:19:57 +0000 (09:19 -0400)
committerJason Skomorowski <jason@indexdata.com>
Mon, 18 Aug 2014 13:19:57 +0000 (09:19 -0400)
15 files changed:
examples/htdocs/jasmine-local-popup.html
examples/htdocs/jasmine-popup.html
examples/htdocs/mkws-widget-ru-requirejs.html [new file with mode: 0644]
examples/htdocs/mkws-widget-ru.js
examples/htdocs/robots.txt [new file with mode: 0644]
src/mkws-core.js
src/mkws-team.js
src/mkws-widget-categories.js
test/bin/apache-template-update
test/spec/mkws-config.js
tools/apache2/jasmine-dev.apache-modules-2.4.debian.conf [new file with mode: 0644]
tools/apache2/jasmine-dev.apache-modules.ubuntu.conf [deleted file]
tools/apache2/jasmine-dev.template
tools/apache2/jasmine-dev.template-2.4
tools/htdocs/robots.txt [new file with mode: 0644]

index 12af4ac..cde7ac2 100644 (file)
@@ -57,7 +57,7 @@
     var jasmine_config = {
       search_query: "netbsd",
       expected_hits: 10,
-      active_clients: 12,
+      active_clients: 13,
       check_motd: false,
       check_sortby: true,
       show_record_url: true
index 2f14059..b2c7450 100644 (file)
@@ -59,7 +59,7 @@
     var jasmine_config = {
       search_query: "netbsd",
       expected_hits: 10,
-      active_clients: 12,
+      active_clients: 13,
       check_motd: false,
       show_record_url: true
     };
diff --git a/examples/htdocs/mkws-widget-ru-requirejs.html b/examples/htdocs/mkws-widget-ru-requirejs.html
new file mode 100644 (file)
index 0000000..a311cb2
--- /dev/null
@@ -0,0 +1,32 @@
+<html>
+<head>
+  <title>MKWS Reference Universe</title>
+  <link rel="stylesheet" type="text/css" href="mkws-widget-ru.css" />
+</head>
+
+<body>
+  <script src="http://requirejs.org/docs/release/2.1.14/minified/require.js" type="text/javascript"></script>
+  <script type="text/javascript">
+  require.config({
+    paths: {
+        mkws           : "//mkws.indexdata.com/mkws-complete",
+        mkws_widget_ru : "mkws-widget-ru"
+    },
+    shim : {
+        mkws : {
+          exports : "mkws"
+        },
+        mkws_widget_ru : {
+          deps    : [ "mkws" ]
+        }
+    }
+  });
+
+  require(['mkws_widget_ru'], function() { mkws.init("requirejs is done"); } );
+  </script>
+
+  <div style="max-width: 18em; margin: 1.5em 1.5em">
+    <div class="mkwsReferenceUniverse" autosearch="sushi"></div>
+  </div>
+</body>
+</html>
index c358f8f..55b4488 100644 (file)
@@ -1,4 +1,6 @@
-var mkws_config = {service_proxy_auth: "http://mkws.indexdata.com/service-proxy/?command=auth&action=login&username=paratext&password=paratext_mkc"};
+var mkws_config = {
+   service_proxy_auth: "http://mkws.indexdata.com/service-proxy/?command=auth&action=login&username=paratext&password=paratext_mkc"
+};
 
 mkws.registerWidgetType('ReferenceUniverse', function() {
   if (!this.config.perpage) this.config.perpage = 5;
@@ -31,3 +33,4 @@ mkws.registerWidgetType('ReferenceUniverse', function() {
   }); 
   that.autosearch();
 });
+
diff --git a/examples/htdocs/robots.txt b/examples/htdocs/robots.txt
new file mode 100644 (file)
index 0000000..f94de5d
--- /dev/null
@@ -0,0 +1,5 @@
+# Copyright (c) 2014 IndexData ApS. http://indexdata.com
+
+User-agent: *
+Disallow: /service-proxy
+
index 4d6550c..98d32c0 100644 (file)
@@ -14,6 +14,7 @@
 window.mkws = {
   $: $, // Our own local copy of the jQuery object
   authenticated: false,
+  active: false,
   log_level: 1, // Will be overridden from mkws.config, but
                 // initial value allows jQuery popup to use logging.
   teams: {},
@@ -418,7 +419,11 @@ mkws.pagerNext = function(tname) {
 
 
   function makeWidgetsWithin(level, node) {
-    node.find(selectorForAllWidgets()).each(function() {
+    if (node) var widgetNodes = node.find(selectorForAllWidgets());
+    else widgetNodes = $(selectorForAllWidgets());
+    // Return false if we parse no widgets
+    if (widgetNodes.length < 1) return false;
+    widgetNodes.each(function() {
       handleNodeWithTeam(this, function(tname, type) {
         var myTeam = mkws.teams[tname];
         if (!myTeam) {
@@ -436,61 +441,20 @@ mkws.pagerNext = function(tname) {
         }
       });
     });
+    return true;
   }
 
 
-  function init(rootsel) {
-    mkws.autoHasAuto = false;
-    if (!rootsel) var rootsel = ':root';
-    var saved_config;
-    if (typeof mkws_config === 'undefined') {
-      log("setting empty config");
-      saved_config = {};
-    } else {
-      log("using config: " + $.toJSON(mkws_config));
-      saved_config = mkws_config;
-    }
-    mkws.setMkwsConfig(saved_config);
-
-    for (var key in mkws.config) {
-      if (mkws.config.hasOwnProperty(key)) {
-        if (key.match(/^language_/)) {
-          var lang = key.replace(/^language_/, "");
-          // Copy custom languages into list
-          mkws.locale_lang[lang] = mkws.config[key];
-          log("added locally configured language '" + lang + "'");
-        }
-      }
-    }
-
-    var lang = mkws.getParameterByName("lang") || mkws.config.lang;
-    if (!lang || !mkws.locale_lang[lang]) {
-      mkws.config.lang = ""
-    } else {
-      mkws.config.lang = lang;
-    }
-
-    log("using language: " + (mkws.config.lang ? mkws.config.lang : "none"));
-
-    if (mkws.config.query_width < 5 || mkws.config.query_width > 150) {
-      log("reset query width to " + mkws.config.query_width);
-      mkws.config.query_width = 50;
-    }
-
-    // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
-    if (mkws.config.pazpar2_url.match(/^\/\//)) {
-      mkws.config.pazpar2_url = document.location.protocol + mkws.config.pazpar2_url;
-      log("adjusted protocol independent link to " + 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);
-    }
+  // This function should have no side effects if run again on an operating session, even if 
+  // the element/selector passed causes existing widgets to be reparsed: 
+  //
+  // * configuration is not regenerated
+  // * authentication is not performed again
+  // * autosearches are not re-run
+  mkws.init = function(message, rootsel) {
+    if (message) mkws.log(message);
 
+    // TODO: Let's remove this soon
     // Backwards compatibility: set new magic class names on any
     // elements that have the old magic IDs.
     var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
@@ -505,8 +469,71 @@ mkws.pagerNext = function(tname) {
       }
     }
 
+    // MKWS is not active until init() has been run against an object with widget nodes.
+    // We only set initial configuration when MKWS is first activated.
+    if (!mkws.isActive) {
+      var widgetSelector = selectorForAllWidgets();
+      if ($(widgetSelector).length < 1) {
+        mkws.log("no widgets found");
+        return;
+      }
+
+      // Initial configuration
+      mkws.autoHasAuto = false;
+      var saved_config;
+      if (typeof mkws_config === 'undefined') {
+        log("setting empty config");
+        saved_config = {};
+      } else {
+        log("using config: " + $.toJSON(mkws_config));
+        saved_config = mkws_config;
+      }
+      mkws.setMkwsConfig(saved_config);
+
+      for (var key in mkws.config) {
+        if (mkws.config.hasOwnProperty(key)) {
+          if (key.match(/^language_/)) {
+            var lang = key.replace(/^language_/, "");
+            // Copy custom languages into list
+            mkws.locale_lang[lang] = mkws.config[key];
+            log("added locally configured language '" + lang + "'");
+          }
+        }
+      }
+
+      var lang = mkws.getParameterByName("lang") || mkws.config.lang;
+      if (!lang || !mkws.locale_lang[lang]) {
+        mkws.config.lang = ""
+      } else {
+        mkws.config.lang = lang;
+      }
+
+      log("using language: " + (mkws.config.lang ? mkws.config.lang : "none"));
+
+      if (mkws.config.query_width < 5 || mkws.config.query_width > 150) {
+        log("reset query width to " + mkws.config.query_width);
+        mkws.config.query_width = 50;
+      }
+
+      // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
+      if (mkws.config.pazpar2_url.match(/^\/\//)) {
+        mkws.config.pazpar2_url = document.location.protocol + mkws.config.pazpar2_url;
+        log("adjusted protocol independent link to " + 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);
+      }
+    }
+
     var then = $.now();
-    makeWidgetsWithin(1, $(rootsel));
+    // If we've made no widgets, return without starting an SP session
+    // or marking MKWS active.
+    if (makeWidgetsWithin(1, rootsel) === false) return false;
     var now = $.now();
 
     log("walking MKWS nodes took " + (now-then) + " ms");
@@ -521,17 +548,21 @@ mkws.pagerNext = function(tname) {
       }
     */
 
-    if (mkws.config.use_service_proxy) {
+    if (mkws.config.use_service_proxy && !mkws.authenticated) {
       authenticateSession(mkws.config.service_proxy_auth,
                           mkws.config.service_proxy_auth_domain,
                           mkws.config.pazpar2_url);
     } else {
-      // raw pp2
+      // raw pp2 or we have a session already open
       runAutoSearches();
     }
+    
+    mkws.isActive = true;
+    return true;
   };
+
   $(document).ready(function() {
-    var widgetSelector = selectorForAllWidgets();
-    if (widgetSelector && $(widgetSelector).length !== 0) init();
+    mkws.init();
   });
+
 })(mkws.$);
index b2bf974..4dccde4 100644 (file)
@@ -293,7 +293,7 @@ function team($, teamName) {
     if (maxrecs) params.maxrecs = maxrecs;
     if (torusquery) {
       if (!mkws.config.use_service_proxy)
-        alert("can't narrow search by torusquery when Service Proxy is not in use");
+        alert("can't narrow search by torusquery when not authenticated");
       params.torusquery = torusquery;
     }
 
index a11e522..339e28b 100644 (file)
@@ -1,8 +1,8 @@
 mkws.registerWidgetType('Categories', function() {
   var that = this;
 
-  if (!this.config.use_service_proxy) {
-    alert("can't use categories widget without Service Proxy");
+  if (!mkws.authenticated) {
+    alert("can't use categories widget when not authenticated");
     return;
   }
 
index 54d2f8c..6c90341 100755 (executable)
@@ -16,37 +16,39 @@ export APACHE_LOCK_FILE=$APACHE_LOG_DIR/accept.lock
 
 export MKWS_ROOT=$(pwd)/..
 
-MKWS_OS=debian 
+MKWS_OS=debian
 APACHE_VERSION=2.2
+apache2=$(env PATH=/bin:/usr/bin:/usr/sbin which apache2 httpd false 2>/dev/null | head -1)
+
 case $(uname) in
-  Darwin ) MKWS_OS=macos 
+  Darwin ) MKWS_OS=macos
           test -e libexec || ln -fs /usr/libexec .
           ;;
-  Linux )  MKWS_OS=debian 
+  Linux )  MKWS_OS=debian
           if [ -e /etc/debian_version ]; then
                MKWS_OS=debian
-               # Ubuntu with Apache 2.2 can continue using debian
-               if /usr/bin/dpkg -s apache2 | grep -q "Version: 2\.4\..*ubuntu"; then
-                       MKWS_OS=ubuntu
-                        APACHE_VERSION=2.4
+                if $apache2 -v | egrep -q 'Server version: Apache/2\.4\.'; then
+                    APACHE_VERSION=2.4
                fi
           fi
           if [ -e /etc/redhat-release ]; then
-               MKWS_OS=centos  
+               MKWS_OS=centos
           fi
           ;;
   * ) MKWS_OS=debian ;;
 esac
 
-export APACHE_MODULES="$MKWS_ROOT/tools/apache2/jasmine-dev.apache-modules.$MKWS_OS.conf"
 
 if [ "$APACHE_VERSION" = "2.4" ]; then
-       : ${MKWS_APACHE_TEMPLATE="$MKWS_ROOT/tools/apache2/jasmine-dev.template-2.4"}
+    : ${MKWS_APACHE_TEMPLATE="$MKWS_ROOT/tools/apache2/jasmine-dev.template-$APACHE_VERSION"}
+    APACHE_MODULES="$MKWS_ROOT/tools/apache2/jasmine-dev.apache-modules-$APACHE_VERSION.$MKWS_OS.conf"
 else
-       : ${MKWS_APACHE_TEMPLATE="$MKWS_ROOT/tools/apache2/jasmine-dev.template"}
+    : ${MKWS_APACHE_TEMPLATE="$MKWS_ROOT/tools/apache2/jasmine-dev.template"}
+    APACHE_MODULES="$MKWS_ROOT/tools/apache2/jasmine-dev.apache-modules.$MKWS_OS.conf"
 fi
-: ${MKWS_APACHE_FILE="$APACHE_LOG_DIR/jasmine-dev"}
 
+: ${MKWS_APACHE_FILE="$APACHE_LOG_DIR/jasmine-dev"}
+export APACHE_MODULES
 
 perl -npe 's,\${(.*?)},$ENV{$1},g; ' $MKWS_APACHE_TEMPLATE > $MKWS_APACHE_FILE.tmp
 mv -f $MKWS_APACHE_FILE.tmp $MKWS_APACHE_FILE
index d168fb2..59a0132 100644 (file)
@@ -18,6 +18,10 @@ describe("Check mkws.config object", function () {
         expect(mkws.locale_lang.da.Location).toMatch(/^Lokation$/);
     });
 
+    /*
+     * this is a test if the config value is a boolean JavaScript object: true or false
+     * and nothing else (0, '0', undefined, "false" etc.)
+     */
     it("mkws.config service proxy enabled/disabled", function () {
         if (mkws.config.use_service_proxy) {
             expect(mkws.config.use_service_proxy).toBe(true);
diff --git a/tools/apache2/jasmine-dev.apache-modules-2.4.debian.conf b/tools/apache2/jasmine-dev.apache-modules-2.4.debian.conf
new file mode 100644 (file)
index 0000000..ca48beb
--- /dev/null
@@ -0,0 +1,21 @@
+# apache 2.4
+
+Include /etc/apache2/mods-available/alias.load
+Include /etc/apache2/mods-available/authz*.load
+Include /etc/apache2/mods-available/proxy*.load
+Include /etc/apache2/mods-available/rewrite.load
+Include /etc/apache2/mods-available/headers.load
+Include /etc/apache2/mods-available/mime.load
+Include /etc/apache2/mods-available/deflate.load
+
+Include /etc/apache2/mods-available/alias*.conf
+Include /etc/apache2/mods-available/proxy*.conf
+Include /etc/apache2/mods-available/mime.conf
+Include /etc/apache2/mods-available/deflate.conf
+
+Include /etc/apache2/mods-enabled/mpm*conf
+Include /etc/apache2/mods-enabled/mpm*load
+Include /etc/apache2/mods-available/xml2enc.load
+Include /etc/apache2/mods-available/filter.load
+Include /etc/apache2/mods-available/slotmem_shm.load
+
diff --git a/tools/apache2/jasmine-dev.apache-modules.ubuntu.conf b/tools/apache2/jasmine-dev.apache-modules.ubuntu.conf
deleted file mode 100644 (file)
index 612d1c1..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-Include /etc/apache2/mods-available/alias.load
-Include /etc/apache2/mods-available/authz*.load
-Include /etc/apache2/mods-available/proxy*.load
-Include /etc/apache2/mods-available/rewrite.load
-Include /etc/apache2/mods-available/headers.load
-Include /etc/apache2/mods-available/mime.load
-Include /etc/apache2/mods-available/deflate.load
-
-Include /etc/apache2/mods-available/alias*.conf
-Include /etc/apache2/mods-available/proxy*.conf
-Include /etc/apache2/mods-available/mime.conf
-Include /etc/apache2/mods-available/deflate.conf
-
-Include /etc/apache2/mods-enabled/mpm*conf
-Include /etc/apache2/mods-enabled/mpm*load
-Include /etc/apache2/mods-available/xml2enc.load
-Include /etc/apache2/mods-available/filter.load
-Include /etc/apache2/mods-available/slotmem_shm.load
-
index 088b741..acf7cf4 100644 (file)
@@ -1,7 +1,7 @@
 # Configuration for the apache web server                 -*- apache -*-
 
 #####################################################################
-# global apache2 config
+# global apache 2.2 config
 #
 User ${APACHE_RUN_USER}
 Group ${APACHE_RUN_GROUP}
index 6d91adf..3c0f626 100644 (file)
@@ -1,7 +1,7 @@
 # Configuration for the apache web server                 -*- apache -*-
 
 #####################################################################
-# global apache2 config
+# global apache 2.4 config
 #
 User ${APACHE_RUN_USER}
 Group ${APACHE_RUN_GROUP}
diff --git a/tools/htdocs/robots.txt b/tools/htdocs/robots.txt
new file mode 100644 (file)
index 0000000..f94de5d
--- /dev/null
@@ -0,0 +1,5 @@
+# Copyright (c) 2014 IndexData ApS. http://indexdata.com
+
+User-agent: *
+Disallow: /service-proxy
+