From: Jason Skomorowski Date: Fri, 16 May 2014 03:46:33 +0000 (-0400) Subject: Only init if there are widgets MKWS-166 X-Git-Tag: 1.0.0~668 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=bceef3c33269bf49847672af0482f85cb14cecdb Only init if there are widgets MKWS-166 --- diff --git a/src/mkws-core.js b/src/mkws-core.js index 6eb53bd..c7c2863 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -429,7 +429,7 @@ mkws.pagerNext = function(tname) { function selectorForAllWidgets() { - if (mkws.config.scan_all_nodes) { + if (mkws.config && mkws.config.scan_all_nodes) { // This is the old version, which works by telling jQuery to // find every node that has a class beginning with "mkws". In // theory it should be slower than the class-based selector; but @@ -476,7 +476,8 @@ mkws.pagerNext = function(tname) { } - $(document).ready(function() { + function init(rootsel) { + if (!rootsel) var rootsel = ':root'; var saved_config; if (typeof mkws_config === 'undefined') { log("setting empty config"); @@ -541,7 +542,7 @@ mkws.pagerNext = function(tname) { } var then = $.now(); - makeWidgetsWithin(1, $(':root')); + makeWidgetsWithin(1, $(rootsel)); var now = $.now(); log("Walking MKWS nodes took " + (now-then) + " ms"); @@ -564,5 +565,9 @@ mkws.pagerNext = function(tname) { // raw pp2 runAutoSearches(); } + }; + $(document).ready(function() { + var widgetSelector = selectorForAllWidgets(); + if (widgetSelector && $(widgetSelector).length !== 0) init(); }); })(jQuery);