/** * Jokuwiki - a tool for managing javascript widgets * * Jokuwiki is intended to provide a framework (initially for Dokuwiki) to * 1) isolate widgets from having to deal with dependencies (widget declared before dependencies available) * 2) handle a strict Content Security Policy (i.e. no inline scripts) * 3) non-standard content loading techniques (e.g. pjax) * * For simplicity the PJax page initializaton plugin is appended below */ var jokuwiki= { widgets: [], /* contains a list of [widgetname]=initFunction */ failcount: 0, /* limits frequent re-running after failures */ urls: [], /* maintains a list of script URLs loaded or about to be loaded */ iters: 0, /* track number of times worklist has been scanned */ pjaxloads: 0, /* count of times jokuwiki has been initialised */ attempts: 10, /* maximum number of attempts at runQueue per init invocation */ maxPjax: 200, /* max number of consecutive pjax loads before a full page load */ pjaxContainer: 'pjax_content', /* element ID used for pjax container (optional -see disablePjax below) */ /** * init should be called when the page is loaded or content injected */ init: function () { jokuwiki.iters=0; jokuwiki.failcount=0; jokuwiki.pjaxloads++; jokuwiki.attempts=10; jokuwiki.runQueue(); }, /** * private method * * scans the DOM for widgets to invoke * automatically reschedules itself for stuff which throws an exception */ runQueue: function () { if (jQuery.pjax && jokuwiki.pjaxloads>jokuwiki.maxPjax) { jokuwiki.disablePjax(); } jokuwiki.iters++; console.log(jokuwiki.iters + "(" + jokuwiki.pjaxloads + ") jokuwiki.runQueue iteration"); var els=jQuery("[data-jw]"); var success=false; for(var i=0; i