From 96ff13c77214b76cb54dbaa6b9fae081a856738f Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 28 Apr 2014 17:08:12 +0100 Subject: [PATCH] Main iteration to create widgets moved to new function makeWidgetsWithin. This now recursively calls itself to re-parse new content generated within a widget during its creation. The upshot is the widgets can now hold other widgets, and we're going to be able to move a shedload of code out of mkws-team.js into the individual widgets. Yay us! Fixes MKWS-180. --- src/mkws-core.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/mkws-core.js b/src/mkws-core.js index 11a4889..0bfc174 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -322,6 +322,24 @@ mkws.pagerNext = function(tname) { } } + + function makeWidgetsWithin(level, node) { + node.find('[class^="mkws"],[class*=" mkws"]').each(function() { + handleNodeWithTeam(this, function(tname, type) { + var oldHTML = this.innerHTML; + var myTeam = mkws.teams[tname]; + var myWidget = widget(j, myTeam, type, this); + myTeam.addWidget(myWidget); + var newHTML = this.innerHTML; + if (newHTML !== oldHTML) { + log("widget " + tname + ":" + type + " HTML changed from '" + oldHTML + "' to '" + newHTML + "': reparse!"); + makeWidgetsWithin(level+1, $(this)); + } + }); + }); + } + + $(document).ready(function() { var saved_config; if (typeof mkws_config === 'undefined') { @@ -388,17 +406,9 @@ mkws.pagerNext = function(tname) { } }); }); - // Second pass: make the individual widget objects. This has - // to be done separately, and after the team-creation, since - // that sometimes makes new widget nodes (e.g. creating - // mkwsTermlists inside mkwsResults. - $('[class^="mkws"],[class*=" mkws"]').each(function() { - handleNodeWithTeam(this, function(tname, type) { - var myTeam = mkws.teams[tname]; - var myWidget = widget(j, myTeam, type, this); - myTeam.addWidget(myWidget); - }); - }); + + makeWidgetsWithin(1, $(':root')); + var now = $.now(); log("Walking MKWS nodes took " + (now-then) + " ms"); -- 1.7.10.4