From ed9584cc29f7be0e35b94faf2e9800d9400598e6 Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Fri, 1 Aug 2014 11:27:32 -0400 Subject: [PATCH] Unique teams for subsequent autosearch widgets on team AUTO --- examples/htdocs/surlyauto.html | 18 ++++++++++++++++++ src/mkws-core.js | 22 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 examples/htdocs/surlyauto.html diff --git a/examples/htdocs/surlyauto.html b/examples/htdocs/surlyauto.html new file mode 100644 index 0000000..ef9c436 --- /dev/null +++ b/examples/htdocs/surlyauto.html @@ -0,0 +1,18 @@ + + + + MKWS demo: Multiple autosearching widgets get their own teams + + + + + + +
result will appear here
+
result will appear here
+
result will appear here
+
result will appear here
+ + diff --git a/src/mkws-core.js b/src/mkws-core.js index 04accc8..b8b06b4 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -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') { -- 1.7.10.4