Unique teams for subsequent autosearch widgets on team AUTO
authorJason Skomorowski <jason@indexdata.com>
Fri, 1 Aug 2014 15:27:32 +0000 (11:27 -0400)
committerJason Skomorowski <jason@indexdata.com>
Fri, 1 Aug 2014 15:27:32 +0000 (11:27 -0400)
examples/htdocs/surlyauto.html [new file with mode: 0644]
src/mkws-core.js

diff --git a/examples/htdocs/surlyauto.html b/examples/htdocs/surlyauto.html
new file mode 100644 (file)
index 0000000..ef9c436
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <title>MKWS demo: Multiple autosearching widgets get their own teams</title>
+    <link rel="stylesheet" type="text/css" href="mkws-widget-reference.css" />
+    <script type="text/javascript">
+      var mkws_config = { service_proxy_auth: "//mkws.indexdata.com/service-proxy-testauth" };
+    </script>
+    <!-- <script type="text/javascript" src="//mkws.local/mkws&#45;complete.js"></script> -->
+    <script type="text/javascript" src="//mkws.indexdata.com/mkws-complete.js"></script>
+  </head>
+  <body>
+    <div class='mkwsReference' autosearch='one' sentences='1'>result will appear here</div>
+    <div class='mkwsReference' autosearch='two' sentences='1'>result will appear here</div>
+    <div class='mkwsReference' autosearch='three' sentences='1'>result will appear here</div>
+    <div class='mkwsReference' sentences='1'>result will appear here</div>
+  </body>
+</html>
index 04accc8..b8b06b4 100644 (file)
@@ -379,7 +379,26 @@ mkws.pagerNext = function(tname) {
       }
     }
 
-    if (!teamName) teamName = "AUTO";
+    // Widgets without a team are on team "AUTO"
+    if (!teamName) {
+      teamName = "AUTO";
+      // Autosearch widgets don't join team AUTO if there is already an
+      // autosearch on the team or the team has otherwise gotten a query
+      if (node.hasAttribute("autosearch")) {
+        if (mkws.autoHasAuto ||
+            mkws.teams["AUTO"] && mkws.teams["AUTO"].config()["query"]) {
+          log("AUTO team already has a query, using unique team");
+          teamName = "UNIQUE";
+        }
+        mkws.autoHasAuto = true;
+      }
+    }
+
+    // Widgets on team "UNIQUE" get a random team
+    if (teamName === "UNIQUE") {
+      teamName = Math.floor(Math.random() * 100000000).toString();
+    }
+
     callback.call(node, teamName, type);
   }
 
@@ -523,6 +542,7 @@ mkws.pagerNext = function(tname) {
 
 
   function init(rootsel) {
+    mkws.autoHasAuto = false;
     if (!rootsel) var rootsel = ':root';
     var saved_config;
     if (typeof mkws_config === 'undefined') {