\" + times(`${Jumplist.type}>`, level);\n return (\n bakeInnerList(\n jumplist[0],\n level,\n hasselectedbelow(jumplist, jumplist[0].level)\n ) + bakeInnerList(jumplist.slice(1), jumplist[0].level)\n );\n}\nexport const bakeAsListitems = jumplist => {\n let html = bakeInnerList(jumplist);\n // Odd case of indentation sans parent:\n if ([\"u\", \"o\"].includes(html.charAt(1)))\n return '
' + html + \"
\";\n return html;\n};\nfunction bakeAsDropDown(jumplist, level = 0, containsselection) {\n // Implemented recursively so we can make the 'chapter' selected\n if (!(jumplist instanceof Array)) {\n return (\n \"\"\n );\n }\n if (jumplist.length == 0) return \"\";\n return (\n bakeAsDropDown(\n jumplist[0],\n level,\n hasselectedbelow(jumplist, jumplist[0].level)\n ) + bakeAsDropDown(jumplist.slice(1), jumplist[0].level)\n );\n}\n\nconst findCurrentIndex = compose(\n i => (i === -1 ? Infinity : i),\n findIndex(({ status }) => status === \"future\")\n);\n\nexport var Jumplist = new (function () {\n var _jumplist = []; //Save last jumplist\n this.type = \"ul\";\n this.draw = function draw(jumplist) {\n jumplist = jumplist || _jumplist;\n if (jumplist) _jumplist = jumplist;\n $(\n `.bb-jumplist ${Jumplist.type}, .bb-jumplist li, .bb-jumplist-dropdown select`\n ).remove();\n if (jumplist.length) {\n if (\n $(\".bb-jumplist:visible, .bb-jumplist-dropdown:visible\").length === 0\n ) {\n // If we can't rely on CSS to decide the appropriate type\n // of jumplist (happens sometimes onload), draw them both\n drawAsList(jumplist);\n drawAsDropDown(jumplist);\n } else {\n // Draw our standard list:\n if ($(\".bb-jumplist\").is(\":visible\")) drawAsList(jumplist);\n // Also draw the dropdown:\n if ($(\".bb-jumplist-dropdown\").is(\":visible\")) drawAsDropDown(jumplist);\n }\n }\n };\n\n function drawAsList(jumplist) {\n const currentIndex = findCurrentIndex(jumplist);\n $(\".bb-jumplist\").map((i, l) => {\n const slicetype = l.dataset[\"slice\"];\n const itemizer = choose([\n [equals(\"before\"), slice(0, currentIndex)],\n [equals(\"after\"), slice(currentIndex, Infinity)],\n [T, identity]\n ])(slicetype);\n\n const html = bakeAsListitems(itemizer(jumplist));\n $(l).append(\n `<${Jumplist.type} aria-describedby=\"a-jumplist-title\">${html}${Jumplist.type}>`\n );\n });\n $(\".bb-jumplist a:last\").addClass(\"last\");\n $(\".bb-jumplist li:last-child\").addClass(\"last-child\"); // aid older browsers\n }\n function drawAsDropDown(jumplist) {\n if (jumplist.length) {\n var html = bakeAsDropDown(jumplist, 0);\n $(\".bb-jumplist-dropdown\").append(\"\");\n }\n }\n\n return this;\n})();\n","import { getVar } from \"./vars.js\";\n\nexport const userinfo = () => getVar(\"userinfo\") || {};\n","import { userinfo } from \"./user-info.js\";\nimport {\n compose,\n either,\n includes,\n prop,\n strictDifference\n} from \"./functional.js\";\n\nexport const PERM_ACCESSALLMODELS = \"accessallmodels\",\n // Allow to access all models\n PERM_ALLOWACCESSCASES = \"allowaccesscases\",\n // Allow to access to all the cases on the server\n PERM_ALLOWACCESSCASESFROMDOMAIN = \"allowaccesscasesfromdomain\",\n // Allow to access all the cases in the same domain on the server\n PERM_ALLOWALLCASEOVERVIEWDOMAIN = \"allowallcaseoverviewdomain\",\n // Allow to see all the cases in same domain on the server\n PERM_ALLOWALLCASESOVERVIEW = \"allowallcasesoverview\",\n // Allow to see all the cases made on the server\n PERM_ALLOWCASEOVERVIEW = \"allowcaseoverview\",\n // Allow to see the cases made by the user on the server\n PERM_ALLOWDOWNLOADCASE = \"allowdownloadcase\",\n // Allow user to download a case from the server\n PERM_ALLOWIPLOGTOUSER = \"allowiplogtouser\",\n // Allow the IP log to be send to the user\n PERM_ALLOWLOGTOUSER = \"allowlogtouser\",\n // Allow the WHOLE log of the server to be send to the user\n\n PERM_ALLOWMISALL = \"allowmisall\",\n // Allow all the MIS data to be shown\n PERM_ALLOWMISDOCUMENTS = \"allowmisdocuments\",\n // Allow the documents of the case to be opened\n PERM_ALLOWMISDOMAIN = \"allowmisdomain\",\n // Allow the MIS data within the same domain to be shown\n PERM_ALLOWMISOWNCASES = \"allowmisowncases\",\n // Allow the MIS data of the own cases to be shown\n\n PERM_ALLOWSAVECASE = \"allowsavecase\",\n // Allow to save a case on the server\n PERM_ALLOWSESSIONLOGTOUSER = \"allowsessionlogtouser\",\n // Allow the log concerning a case to be send to the user\n\n PERM_ALLOWSTARTCASES = \"allowstartcases\",\n // Allow to create a new case on the server\n PERM_PUBLISHMODEL = \"publishmodel\",\n // Allow to publish models to the server\n PERM_SAASCLIENTLOGICWRITABLE = \"saasclientlogicwritable\",\n // Allow users to change texts and logic in SAAS\tNeeds either updatemodels or updateownmodel to have effect\n PERM_SAASCLIENTWRITABLE = \"saasclientwritable\",\n // Allow users to change texts of the model in SAAS\tNeeds either updatemodels or updateownmodel to have effect\n PERM_SAASMANAGEPUBLISHINGSERVERS = \"saasmanagepublishingservers\",\n // Allow management of the publishing servers in server\n PERM_UPDATEDOMAINS = \"updatedomains\",\n // Allow to update or delete all the domains on the server (needs update users and models)\n PERM_UPDATEMODELS = \"updatemodels\",\n // Allow to update or delete all the models on the server\n PERM_UPDATEOWNMODEL = \"updateownmodel\",\n // Allow update or delete the models owned by user\n PERM_UPDATEOWNUSER = \"updateownuser\",\n // Allow to update the own user on the server, need this for webadmin access\n PERM_UPDATEROLES = \"updateroles\",\n // Allow to update or delete all the roles on the server\n PERM_UPDATESETTINGS = \"updatesettings\",\n // Allow to update the settings of the server\n PERM_UPDATEUSERS = \"updateusers\",\n // Allow to update or delete all the users on the server\n PERM_GETDATASOURCELIST = \"getdatasourcelist\",\n // Allow retrieving a sparse list of datasources\n PERM_MANAGEDATASOURCES = \"managedatasources\";\n// Allow retrieving, posting, updating, and deleting datasource specs and file\n\n// 4.12 equivalents\nconst oldperms = {\n guest: [PERM_ALLOWSTARTCASES],\n user: [\n PERM_PUBLISHMODEL,\n PERM_UPDATEOWNMODEL,\n PERM_UPDATEOWNUSER,\n PERM_ALLOWCASEOVERVIEW,\n PERM_ALLOWSTARTCASES,\n PERM_ALLOWSAVECASE,\n PERM_ALLOWMISOWNCASES // ,\n // PERM_SAASCLIENTWRITABLE,\n // PERM_SAASCLIENTLOGICWRITABLE\n ],\n administrator: [\n PERM_PUBLISHMODEL,\n PERM_ACCESSALLMODELS,\n PERM_UPDATEOWNMODEL,\n PERM_UPDATEDOMAINS,\n PERM_UPDATESETTINGS,\n PERM_UPDATEMODELS,\n PERM_UPDATEUSERS,\n // PERM_UPDATEROLES,\n PERM_UPDATEOWNUSER,\n PERM_ALLOWCASEOVERVIEW,\n PERM_ALLOWACCESSCASESFROMDOMAIN,\n PERM_ALLOWACCESSCASES,\n PERM_ALLOWSTARTCASES,\n PERM_ALLOWSAVECASE,\n PERM_ALLOWMISOWNCASES,\n PERM_ALLOWMISDOCUMENTS,\n // PERM_SAASCLIENTWRITABLE,\n // PERM_SAASCLIENTLOGICWRITABLE,\n // PERM_SAASMANAGEPUBLISHINGSERVERS,\n // PERM_SAASCLIENTWRITABLE,\n PERM_ALLOWDOWNLOADCASE // ,\n // PERM_MANAGEDATASOURCES\n ],\n viewer: [PERM_ALLOWMISDOMAIN],\n manager: [\n PERM_UPDATEOWNUSER,\n PERM_ALLOWCASEOVERVIEW,\n PERM_ALLOWACCESSCASESFROMDOMAIN,\n PERM_ALLOWACCESSCASES,\n PERM_ALLOWSAVECASE,\n PERM_ALLOWMISOWNCASES // ,\n // PERM_SAASCLIENTWRITABLE\n ],\n vieweradmin: [PERM_ALLOWMISALL, PERM_ALLOWMISDOMAIN, PERM_ALLOWMISDOCUMENTS],\n any: []\n};\n\nexport const permissions = () =>\n compose(\n either(\n prop(\"permissions\"),\n compose(role => oldperms[role] || oldperms[\"any\"], prop(\"role\"))\n ),\n userinfo\n )(null);\n\nexport const hasPermission = perm =>\n perm instanceof Array\n ? strictDifference(perm, permissions()).length === 0\n : includes(perm, permissions());\n\nexport const webadminMakesSense = permissions =>\n permissions.some(perm => perm.startsWith(\"update\"));\n","/* global $ */\nif (\"bb\" in window) {\n throw \"bb was already loaded\";\n}\nimport \"./lib/polyfills/url-search-params.js\";\nimport * as Errors from \"./lib/errors.js\";\nimport { token } from \"./lib/tokens.js\";\nimport { shouldExit } from \"./lib/case-exit.js\";\nimport { A11y } from \"./lib/a11y\";\nimport { Ajax, checkJSON } from \"./lib/ajax.js\";\nimport { BBI } from \"./lib/bbi.js\";\nimport { collectWithin, serializeQuestions } from \"./lib/collect-values.js\";\nimport { conf, propFinder } from \"./lib/conf\";\nimport { wControl, getControl } from \"./lib/control.js\";\nimport { validateInput } from \"./lib/control-validation.js\";\nimport { parseDate, humanDate } from \"./lib/dates\";\nimport { escapeHTML } from \"./lib/escape.js\";\nimport {\n editPolicy,\n mustUpdate,\n canEditEarlier\n} from \"./lib/feature-queries.js\";\nimport { createFormGroup } from \"./lib/form-groups.js\";\nimport \"./lib/form-widgets-definitions.js\";\nimport { setSettled } from \"./lib/settled.js\";\nimport { collectAttributes } from \"./lib/utils\";\nimport {\n any,\n both,\n complement,\n compose,\n either,\n find,\n has,\n ifElse,\n includes,\n map,\n path,\n pathEq,\n prop,\n propEq,\n propOr,\n tap,\n when\n} from \"./lib/functional\";\nimport { doGrouping, groupOuter } from \"./lib/groupings\";\nimport { Jumplist } from \"./lib/jumplist\";\nimport { fromApiServer } from \"./lib/location.js\";\nimport { Mode } from \"./lib/mode.js\";\nimport { Numerals } from \"./lib/numerals.js\";\nimport { notify } from \"./lib/notify.js\";\nimport { permissions, webadminMakesSense } from \"./lib/permissions.js\";\nimport { _ } from \"./lib/gettext.js\";\nimport { positionalFormat } from \"./lib/text-utils\";\nimport { urlutils } from \"./lib/url-utils.js\";\nimport Vars from \"./lib/vars.js\";\nimport \"./lib/$.scrollTo.js\";\n\n$(\"html\").removeClass(\"no-js\");\n\nconst arbitraryCoreProp = propFinder(conf, \"arbitrary.core\");\n/**\n * Copyright (c) 2010 Conrad Irwin MIT license.\n * Based loosely on original: Copyright (c) 2008 mkmanning MIT license.\n *\n * Parses CGI query strings into javascript objects.\n *\n * See the README for details.\n **/\n$.parseQuery = function (options) {\n var config = { query: window.location.search || \"\" },\n params = {};\n\n if (typeof options === \"string\") {\n options = { query: options };\n }\n $.extend(config, $.parseQuery, options);\n config.query = config.query.replace(/^\\?/, \"\");\n\n $.each(config.query.split(config.separator), function (i, param) {\n var pair = param.split(\"=\"),\n key = config.decode(pair.shift(), null).toString(),\n value = config.decode(pair.length ? pair.join(\"=\") : null, key);\n\n if (\n config.array_keys.test\n ? config.array_keys.test(key)\n : config.array_keys(key)\n ) {\n params[key] = params[key] || [];\n params[key].push(value);\n } else {\n params[key] = value;\n }\n });\n delete params[\"\"];\n return params;\n};\n$.parseQuery.decode = $.parseQuery.default_decode = function (string) {\n return decodeURIComponent((string || \"\").replace(/\\+/g, \" \"));\n};\n$.parseQuery.array_keys = function () {\n return false;\n};\n$.parseQuery.separator = \"&\";\n\n// thanks http://web.enavu.com/daily-tip/maxlength-for-textarea-with-jquery/\n$(document).on(\"keyup\", \"textarea[maxlength]\", function () {\n var $this = $(this);\n //get the limit from maxlength attribute\n var limit = parseInt($this.prop(\"maxlength\"));\n //get the current text inside the textarea\n var text = $this.val();\n //count the number of characters in the text\n var chars = text.length;\n\n //check if there are more characters then allowed\n if (chars > limit) {\n //and if there are use substr to get the text before the limit\n var new_text = text.substr(0, limit);\n\n //and change the current text with the new text\n $this.val(new_text);\n $this.addClass(\"bb-programmatically-changed\");\n window.setTimeout(function () {\n $this.removeClass(\"bb-programmatically-changed\");\n }, 1000);\n }\n});\n\nlet bb = { Mode, conf };\n\n/*** TEXT UTILITIES BEGIN ***/\n\n/******* compareVersions ******/\nfunction compareVersions(a, b) {\n var i, l, d;\n\n a = a.toLowerCase().split(/(\\d+)/);\n b = b.toLowerCase().split(/(\\d+)/);\n l = Math.min(a.length, b.length);\n\n for (i = 0; i < l; i++) {\n d = a[i] - b[i];\n if (isNaN(d)) {\n if (a[i] === b[i]) d = 0;\n else if (a[i] < b[i]) {\n d = -1;\n } else d = 1;\n }\n if (d !== 0) return d;\n }\n\n return a.length - b.length;\n}\n\nfunction compareVersionsOn(prop, a, b) {\n return compareVersions(String(a[prop]), String(b[prop]));\n}\n/*** TEXT UTILITIES END ***/\n\n/*** DATEPICKER BEGIN ***/\n\n// Defaults jQuery datepicker BEGIN\n$(function () {\n $.datepicker.setDefaults(\n $.extend(\n true,\n $.datepicker._defaults,\n {\n showAnim: \"\",\n changeYear: true,\n changeMonth: true,\n yearRange: \"c-150:c+150\"\n }, // RFC\n arbitraryCoreProp(\"datepicker.defaults\") || {},\n { altFormat: \"yy-mm-dd\" }\n )\n );\n});\n// Defaults jQuery datepicker END\n\n/*** DATEPICKER END ***/\n\n/*** MISC jQUERY UTILITIES BEGIN ***/\n\n// thanks http://jqueryfordesigners.com/video.php?f=queue.flv\n$.fn.pause = function (n) {\n return this.queue(function () {\n var el = this;\n window.setTimeout(function () {\n return $(el).dequeue();\n }, n);\n });\n};\n\n$.fn.sort = function () {\n return this.pushStack($.makeArray([].sort.apply(this, arguments)));\n};\n\n$.fn.extend({\n insertAtCaret: function (myValue) {\n return this.each(function () {\n if (document.selection) {\n //For browsers like Internet Explorer\n this.focus();\n var sel = document.selection.createRange();\n sel.text = myValue;\n this.focus();\n } else if (this.selectionStart || this.selectionStart == \"0\") {\n //For browsers like Firefox and Webkit based\n var startPos = this.selectionStart;\n var endPos = this.selectionEnd;\n var scrollTop = this.scrollTop;\n this.value =\n this.value.substring(0, startPos) +\n myValue +\n this.value.substring(endPos, this.value.length);\n this.focus();\n this.selectionStart = startPos + myValue.length;\n this.selectionEnd = startPos + myValue.length;\n this.scrollTop = scrollTop;\n } else {\n this.value += myValue;\n this.focus();\n }\n return this;\n });\n },\n selectAllText: function () {\n var el = this.get(0);\n if (el) {\n if (typeof el.selectionStart === \"number\") {\n (el.selectionStart = 0), (el.selectionEnd = el.value.length);\n } else if (typeof el.createTextRange !== \"undefined\") {\n el.focus();\n var range = el.createTextRange();\n range.select();\n }\n }\n return this;\n }\n});\n\n/** Add resizeEnd event.\n *\n * Thanks Carlos Martinez on\n * http://stackoverflow.com/questions/2854407/\n * javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed\n *\n * I did put this in a closure so as not to pollute the global\n * namespace.\n */\n(function () {\n var _to = null,\n _delay = 500;\n $(window).on(\"resize\", function () {\n if (_to) window.clearTimeout(_to);\n _to = window.setTimeout(function () {\n $(this).trigger(\"resizeEnd\");\n }, _delay);\n });\n})();\n/*** MISC jQUERY UTILITIES END ***/\n\n/*** KEYMAP BEGIN ***/\nvar KEYS = {\n BACKSPACE: 8,\n TAB: 9,\n ENTER: 13,\n SPACE: 32,\n ESC: 27,\n UP: 38,\n DOWN: 40,\n KP_RADIX: 110\n};\n\n// Navigation\nvar maps = {\n questions: function (ev) {\n if (!Mode.get(\"hasModel\")) return undefined;\n if (ev.originalEvent.target && ev.originalEvent.target.tagName === \"TR\") {\n if (!gridKeys(ev)) return false;\n }\n var $target = $(ev.target);\n switch (ev.keyCode) {\n case KEYS.ENTER:\n if ($target.hasClass(\"bb-prior\")) {\n step(\"prior\");\n return false;\n }\n if ($target.hasClass(\"bb-skip\")) {\n step(\"skip\");\n return false;\n }\n if (!Mode.get(\"hasNoNext\")) {\n if (\n ev.shiftKey ||\n $target.hasClass(\"bb-next\") ||\n $target.is('input[type=\"text\"]') ||\n $target.is('input[type=\"radio\"]') ||\n $target.is('input[type=\"checkbox\"]') ||\n $target.is('input[type=\"checkbox\"]') ||\n $target.is('select[data-type=\"listbox\"]') ||\n $target.is(\"fieldset\")\n ) {\n step(\"next\");\n return false;\n }\n if (ev.target.tagName === \"TEXTAREA\") {\n ev.stopImmediatePropagation();\n break;\n }\n }\n if (ev.target.tagName === \"A\") {\n if (ev.target.href.substr(-1) !== \"#\")\n // A true link\n break;\n }\n break;\n case KEYS.SPACE:\n if ($target.is('[role=\"button\"]')) {\n $target.trigger(\"click\");\n return false;\n }\n break;\n case KEYS.BACKSPACE:\n return dispatchBackspace(ev);\n // Escape from modal window\n case KEYS.ESC:\n $(\".closable\").hide();\n break;\n case KEYS.KP_RADIX:\n if ($target.data(\"type\") === \"numedit\") {\n $target.insertAtCaret(_(\"__radixpoint__\", \".\"));\n return false;\n }\n }\n return undefined;\n }\n};\n\nfunction gridKeys(ev) {\n var target = ev.originalEvent.target,\n $target = $(target);\n switch (ev.keyCode) {\n case KEYS.UP:\n $(ev.target).prev().trigger(\"focus\");\n return false;\n case KEYS.DOWN:\n case KEYS.TAB:\n if ($target.find(\":input, a\").length !== 1) {\n return true;\n }\n if (\n $target.find(\n \"a, :input\" + ':not([type=\"checkbox\"])' + ':not([type=\"radio\"])'\n ).length\n ) {\n return true;\n }\n if (ev.shiftKey) $target.prev().trigger(\"focus\");\n else $target.next().trigger(\"focus\");\n return false;\n case KEYS.SPACE:\n var $inputs = $target.find(\n 'input[type=\"checkbox\"], ' + 'input[type=\"radio\"]'\n ),\n $input = $inputs.filter(\":nth(0)\");\n if ($inputs.length > 2) return true;\n else $input.prop(\"checked\", !$input.is(\":checked\"));\n return false;\n }\n return true;\n}\n\nfunction aintTheEnterKey(ev) {\n return ev.type === \"keydown\" && ev.keyCode !== KEYS.ENTER;\n}\n\nfunction dispatchBackspace(ev) {\n if (!ev.shiftKey) return true;\n if (Mode.get(\"hasNoPrior\")) return false;\n step(\"prior\");\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n}\n\n$(document).on(\"keydown\", maps.questions);\n\n$(document).on(\"keydown\", \".bb-btn\", function (ev) {\n if (ev.keyCode === 13) {\n // Dispatch to click handler on ENTER.\n $(this).trigger(\"click\");\n return false;\n }\n return true;\n});\n/*** KEYMAP END ***/\n\n/*** ROLES BEGIN ***/\n\nfunction setRole() {\n var userinfo = Vars.getVar(\"userinfo\") || {};\n\n Mode.toggle(\"isAdmin\", userinfo.role === \"administrator\");\n Mode.toggle(\"isUser\", userinfo.role === \"user\");\n Mode.toggle(\"isViewer\", userinfo.role === \"viewer\");\n Mode.toggle(\"isVieweradmin\", userinfo.role === \"vieweradmin\");\n Mode.toggle(\"isGuest\", userinfo.role === \"guest\");\n Mode.toggle(\"isAnonymous\", userinfo.fullname === \"anonymous\");\n const perms = permissions();\n perms.forEach(p => {\n Mode.toggle(p, true, false);\n });\n Mode.toggle(\"webadminMakesSense\", webadminMakesSense(perms), false);\n}\n\n/*** ROLES END ***/\n\n/*** INITIALIZATION BEGIN ***/\n\n$(function () {\n $(\"body\").attr(\"data-modus\", \"none\");\n\n document.addEventListener(\"submit\", function (ev) {\n var action = ev.target.getAttribute(\"action\");\n if (!action) {\n ev.preventDefault();\n return false;\n }\n return undefined;\n });\n\n $(document).on(\"submit\", \"form#bb-login\", function () {\n // Serialize form as array\n var params = $(this).serializeArray(),\n action = this.getAttribute(\"action\");\n // Trim values and set the desired format\n $.each(params, function (_, val) {\n if (val.name === \"fmt\") val.value = \"json\";\n else val.value = (val.value || \"\").trim();\n });\n $.postJSON(\n action,\n [$.param(params), window.location.search.substring(1)].join(\"&\")\n );\n return false;\n });\n\n var formfocus = window.setTimeout(function () {\n $(\"form#bb-login input[name=username]\").trigger(\"focus\");\n }, 0);\n\n bb.Router = function router(params) {\n if (\n (typeof params.username !== \"undefined\" &&\n typeof params.password !== \"undefined\") ||\n params.uniqueid ||\n params.modelid ||\n params.modelname ||\n params.dbname ||\n params.state ||\n params.request ||\n params.bsid\n ) {\n Mode.set(\"isDeepLinked\");\n hideLogin();\n if (params.bsid) new BBI().authenticate();\n else if (!bb.autologinrewritten) {\n var action;\n if (\n typeof params.username !== \"undefined\" &&\n typeof params.password !== \"undefined\"\n )\n action = \"login\";\n if (params.uniqueid) action = \"menu\";\n // Studio deeplink\n if (typeof params.uniqueid === \"undefined\" && params.modelid)\n action = \"open\";\n if (params.uniqueid && (params.modelid || params.dbname))\n action = \"action\";\n if (params.modelname) action = \"open\";\n if (params.request) {\n action = params.request;\n delete params.request;\n }\n $.postJSON(action, $.param(params) + \"&fmt=json\").then(setSettled);\n }\n window.clearTimeout(formfocus);\n }\n };\n\n if (window.location.search.length > 1) {\n bb.Router($.parseQuery());\n } else setSettled();\n\n $(document).on(\"bb:renderQuestions\", renderGroups);\n});\n\n/**\n * Set the effect to be used when re-showing login form.\n *\n * @param {String} effect One of 'show', 'fadeIn' or 'slideDown'\n */\nfunction safeResetEffect(effect = \"slideDown\") {\n if (typeof effect !== \"string\") {\n console.warn(\"Argument effect should be a string\");\n return \"slideDown\";\n }\n if (!/^(show|fadeIn|slideDown)$/.test(effect)) {\n console.warn(\"Invalid effect: \" + effect);\n return \"slideDown\";\n }\n return effect;\n}\n\nfunction resetLogin() {\n $(\"#bb-login\")[resetLogin.effect]();\n}\n\nresetLogin.effect = safeResetEffect(\n arbitraryCoreProp(\"loginResetEffect\", \"slideDown\")\n);\n\n/*** INITIALIZATION END ***/\n/*** JUMPLIST BEGIN ***/\n$(document).on(\"change\", \".bb-jumplist-dropdown select\", function () {\n bb.gotonode($(this).val());\n});\n\n$(document).on(\n \"click\",\n \"[data-groupid]:not([data-chapterstatus='forbidden'])\",\n function () {\n var $this = $(this),\n groupid = $this.attr(\"data-groupid\");\n bb.gotonode(groupid);\n }\n);\n\n/*** JUMPLIST END ***/\n\n/*** CASES BEGIN ***/\n$.fn.deleteme = function () {\n if (\n confirm(\n _(\"Delete\") + \" \" + (this.length == 1 ? _(\"case\") : _(\"cases\")) + \"?\"\n )\n ) {\n return this.each(function () {\n var me = $(this);\n if (me.hasClass(\"bb-case\")) {\n var casus = {\n dbname: me.data(\"dbname\"),\n sessionid: me.data(\"sessionid\")\n };\n deleteCase(casus.dbname, casus.sessionid, Vars.getVar(\"uniqueid\"));\n if (isCaseCurrent(casus)) {\n $(\"#bb-q\").empty();\n Mode.unset(\"hasModel\");\n }\n }\n });\n }\n return this;\n};\n\nvar Cases = (function () {\n var _cases = [];\n var _unfilteredcases = [];\n var _MAX = 10;\n var _idx = 0;\n var _filtertext = _(\"filter cases by name\");\n\n function update(cases) {\n _unfilteredcases = cases || [];\n _cases = cases || [];\n if (cases && cases.length > 0) {\n cases.sort(function (a, b) {\n return a.dateenter > b.dateenter ? -1 : 1;\n });\n var $controls = $(\"#bb-cases-controls\");\n if ($controls.is(\":empty\")) {\n $controls.html(\n ' ' +\n ' ' +\n ' 1-10' +\n ' ' +\n ' ' +\n ''\n );\n $controls.attr(\"data-unbound\", true);\n }\n if ($controls.attr(\"data-unbound\")) {\n $controls.removeAttr(\"data-unbound\");\n $(\"#bb-cases-prev\").click(prevSlice);\n $(\"#bb-cases-next\").click(nextSlice);\n $(\"#bb-cases-first\").click(showSlice.bind(null, 0));\n $(\"#bb-cases-last\").click(\n showSlice.bind(null, Math.floor((_cases.length - 1) / _MAX))\n );\n\n $(\"#bb-cases-filter\", $controls).keyup(function (ev) {\n if (ev.keyCode === KEYS.TAB) return true;\n var $this = $(this),\n val = ($this.val() || \"\").trim();\n if (val != \"\") {\n var re = new RegExp(val, \"i\");\n _cases = _unfilteredcases.filter(function (e) {\n return re.test(e.name);\n });\n } else _cases = _unfilteredcases;\n showSlice(0);\n return false;\n });\n }\n showSlice(0);\n } else {\n empty();\n }\n }\n function showSlice(idx) {\n _idx = idx;\n var caselen = _cases.length;\n\n $(\"#bb-cases .bb-case\").remove();\n\n $(_cases.slice(_idx * _MAX, (_idx + 1) * _MAX)).each(function (i) {\n wCasus(_cases[i + _idx * _MAX]).appendTo(\"#bb-cases-table\");\n });\n if (_cases.length) {\n $(\n '
' +\n '
\" +\n \"
\" +\n \"
\" +\n (bb.Plugins.newname\n ? '
' +\n '
' +\n '' +\n \"
\" +\n \"
\"\n : \"\") +\n \"\"\n ).prependTo(\"#bb-cases-table\");\n\n // Some browsers do leave thead and tbody in place, even when\n // $().empty-ing the table, so:\n $(\"#bb-cases-table thead~thead\").remove();\n }\n\n $(\"#bb-cases-currentslice\")\n .text(\n _idx * _MAX +\n 1 +\n \"-\" +\n Math.min(caselen, (_idx + 1) * _MAX) +\n \"/\" +\n caselen\n )\n .attr(\n \"aria-label\",\n positionalFormat(\n _(\"results {0} to {1} from {2}\"),\n _idx * _MAX + 1,\n Math.min(caselen, (_idx + 1) * _MAX),\n caselen\n )\n );\n\n $(\"#bb-cases-prev, #bb-cases-first\").prop(\"disabled\", _idx == 0);\n var hasNoNext = _idx == Math.floor((caselen - 1) / _MAX);\n $(\"#bb-cases-next, #bb-cases-last\").prop(\"disabled\", hasNoNext);\n\n $(\"#bb-cases\").trigger(\"bb:rendered\");\n }\n function nextSlice() {\n var divident = Math.floor(_cases.length / _MAX);\n showSlice(Math.min(_idx + 1, divident));\n }\n function prevSlice() {\n showSlice(Math.max(_idx - 1, 0));\n }\n function empty() {\n $(\"#bb-cases-table\").empty();\n }\n return {\n empty: empty,\n update: update\n };\n})();\n\nfunction howManyColumns() {\n var base = 2;\n return (\n $.grep([\"showreport\", \"showdeleteinmenu\", \"showcopycase\"], Vars.getVar)\n .length + base\n );\n}\n\nfunction wCasus(casus) {\n var cas = $.extend(\n {},\n casus,\n // Turn into JavaScript dates, and normalize as good as we can:\n {\n dateenter: casus.dateenter && parseDate(casus.dateenter),\n datecreate:\n Vars.getVar(\"showdatecreated\") &&\n casus.datecreate &&\n parseDate(casus.datecreate)\n },\n {\n showcopycase: Vars.getVar(\"showcopycase\"),\n showdeleteinmenu: Vars.getVar(\"showdeleteinmenu\")\n }\n );\n if (Vars.getVar(\"showreport\")) cas.reporturl = urlutils.caseReport(casus);\n // Turn into JavaScript dates, and normalize as good as we can:\n if (cas.datecreate) cas.firstrun = humanDate(cas.datecreate);\n if (cas.dateenter) cas.lastaccess = humanDate(cas.dateenter);\n var html = bb.createCaseItem(cas);\n\n var $case = $(html);\n\n $case.find(\".bb-case-name\").bind(\"click keydown\", function (ev) {\n if (aintTheEnterKey(ev)) return;\n Ajax.replace({\n url: \"action\",\n data: {\n dbname: casus.dbname,\n sessionid: casus.sessionid,\n uniqueid: Vars.getVar(\"uniqueid\"),\n fmt: \"json\"\n }\n });\n });\n $case.find(\".bb-case-copy\").bind(\"click keydown\", function (ev) {\n if (aintTheEnterKey(ev)) return;\n Ajax.replace({\n url: \"action\",\n data: {\n dbname: casus.dbname,\n templateindex: casus.sessionid,\n uniqueid: Vars.getVar(\"uniqueid\"),\n fmt: \"json\"\n }\n });\n });\n $case.data(\"sessionid\", casus.sessionid);\n $case.data(\"dbname\", casus.dbname);\n return $case;\n}\n\nbb.createCaseItem =\n bb.createCaseItem ||\n function (casus) {\n var dateTitle,\n dateSpan = \"\",\n copySpan = \"\",\n reportSpan = \"\",\n deleteSpan = \"\",\n classes = [\"bb-case\"];\n dateTitle = _(\"Last opened\") + \": \" + casus.lastaccess;\n if (Vars.getVar(\"showdatecreated\")) {\n dateTitle += \", \" + _(\"created\") + \": \" + casus.firstrun;\n }\n dateSpan =\n '
' +\n casus.lastaccess +\n \"
\";\n if (Vars.getVar(\"showreport\")) {\n reportSpan =\n '
\"\n );\n })(model)\n );\n },\n // Enhance Model with extra computed properties:\n enhanceModel: function (model) {\n model._selectedclass = model.selected ? \"selected\" : \"\";\n model._nicename = model.modelname.replace(/_/g, \" \");\n if (model.lastupdate) {\n model._date = parseDate(model.lastupdate);\n model._humandate = humanDate(model._date);\n }\n if (model.modelinfo) {\n model._liner_notes = model.modelinfo.split(/(?:\\r?\\n|\\\\r\\\\n|\\\\n)/);\n }\n if (model.authorinfo) {\n model._author_notes = model.authorinfo.split(/(?:\\r?\\n|\\\\r\\\\n|\\\\n)/);\n }\n return model;\n },\n update: function (data) {\n var models = data.models;\n models.sort(compareVersionsOn.bind(null, \"modelname\"));\n\n var explicit = models.filter(function (m) {\n return typeof m[\"order\"] === \"number\";\n });\n if (explicit[0]) {\n explicit.sort(function (a, b) {\n return (\n a[\"order\"] - b[\"order\"] ||\n compareVersions(String(a[\"order\"]), String(b[\"order\"]))\n );\n });\n models = models.filter(function (m) {\n // absent (undefined) or the empty string\n return typeof m[\"order\"] !== \"number\";\n });\n models = explicit.concat(models);\n }\n\n this.empty();\n var self = this;\n $(this.selector).append(\n $.map(models, function (model) {\n return self.modelitem(self.enhanceModel(model));\n })\n );\n },\n empty: function () {\n $(this.selector).empty();\n }\n};\n\n$(document).on(\"click keydown\", \".bb-model-cases\", function (ev) {\n if (aintTheEnterKey(ev)) return;\n var $this = $(this),\n dbname =\n this.getAttribute(\"data-bb:dbname\") ||\n $this.parents(\".bb-model\").attr(\"data-bb:dbname\");\n Ajax.replace({\n url: \"menu\",\n data: {\n dbname: dbname,\n uniqueid: Vars.getVar(\"uniqueid\"),\n fmt: \"json\"\n },\n dataType: \"json\"\n });\n});\n/*** MODELS END ***/\n\n/*** NAVIGATION, REQUESTS BEGIN ***/\n\n/**\n * Request 'action'\n *\n * @param {String} direction One of 'prior', 'next', 'exit', 'runtonode', 'gotonode', 'update' or 'updatemis'\n * @param {Function} cb Callback function to run on succes, defaults to checkJSON()\n * @param {Object} options Object, with possible keys: 'fullnodename' : 'graph.node',\n * 'groupid' : 'groupid-iteration',\n * 'sync' : Boolean\n */\nfunction step(direction, cb, options = {}) {\n Validation.reset();\n if (Ajax.busy) return;\n\n Ajax.last && Ajax.last.abort();\n Ajax.direction = direction;\n Ajax.row = Ajax.direction === \"update\" && options && options.update;\n\n try {\n const container = either(prop(\"groupElt\"), () =>\n document.querySelector(\".group.selected\")\n )(options);\n if (container === null) {\n throw new Error(\"There does not seem to be an open session.\");\n }\n\n if (\n [\"next\", \"skip\"].includes(direction) &&\n $(\"#bb-q .group:not([disabled]) .validatable:visible\")\n .validate({\n silent: false,\n justhide: false,\n requestUpdate: false,\n batched: true\n })\n .filter(\"[aria-invalid=true]\").length > 0\n )\n throw new Error(\"There are errors, please double check your answers.\");\n\n const screenid = Vars.getVar(\"screenid\");\n const groupid = $.data(container).groupid;\n Ajax.groupid = groupid;\n\n // todo: voeg nieuwe waarden toe aan object.\n if (!(direction === \"prior\" && Mode.get(\"hasNoPrior\"))) {\n const ajaxOptions = {\n async: !options || !options.sync, //See noted render() as a reason for this.\n data: [\n \"step=\" + direction,\n direction === \"update\" && options && options.update\n ? \"update=\" + encodeURIComponent(options.update)\n : \"\",\n direction === \"runtonode\"\n ? \"fullnodename=\" + options.fullnodename\n : \"\",\n direction === \"gotonode\" ? \"groupid=\" + options.groupid : \"\",\n Vars.querify(Vars.SESSION_KEYS),\n \"screenid=\" + groupid,\n \"fmt=json\",\n collectWithin({\n container,\n params: new URLSearchParams(options.extraparams)\n })\n .toString()\n .replace(/\\r?\\n/g, \"%0D%0A\")\n ]\n .filter(Boolean)\n .join(\"&\"),\n success: function (data, status, req) {\n data._direction = direction;\n data._passed = options && options.pass;\n data._isUpdate = propEq(\"isUpdate\", true, options);\n // if (direction === \"update\" && groupid !== screenid && editPolicy(conf) === \"stay\") {\n // container.classList.remove(\"unselected\");\n // container.classList.add(\"selected\");\n\n // // Do not render, just update\n // Ajax.release();\n // Vars.setVars(data);\n // updateDynProps(data);\n // } else\n\n if (groupid !== screenid && editPolicy(conf) === \"return\") {\n // Do not render, we're going back again. This would be\n // nice, but we do need some values to be rerendered -\n // warranting redraw of nodes after the edited one.\n\n Ajax.release();\n Vars.setVars(data);\n } else if (options && options.cbIsAdditional) {\n options.cbIsAdditional === \"before\" && cb && cb(data, status, req);\n checkJSON(data, status, req);\n options.cbIsAdditional !== \"before\" && cb && cb(data, status, req);\n } else {\n (cb || checkJSON)(data, status, req);\n }\n if (\n Ajax.row &&\n groupid === screenid &&\n compose(\n when(Boolean, any(propEq(\"dynamic\", true))),\n prop(\"groups\")\n )(data)\n ) {\n console.info(\n \"Requesting an extra update for dynprops. Should be handled by server instead\"\n );\n window.setTimeout(bb.update, 0);\n }\n }\n };\n\n if (\n screenid !== undefined &&\n direction !== \"update\" &&\n groupid !== screenid\n ) {\n console.warn(\n `groupid ${groupid} is not the current screenid ${screenid}, but no update was requested`\n );\n }\n if (direction === \"update\" && groupid !== screenid) {\n // Hold your breath, first go back, so as to put server pointer at the right node.\n bb.gotonode(\n // Will get the .selected\n groupid,\n data => {\n Ajax.release();\n Vars.setVars(data); // Sets screenid\n Ajax.direction = direction;\n // Is always \"update\", actually;\n Ajax.row = direction === \"update\" && options && options.update;\n Ajax.groupid = groupid;\n const req = Ajax.post(ajaxOptions); // Gets the original callback, if any.\n if (editPolicy(conf) === \"return\")\n req.then(data => {\n Ajax.release();\n Vars.setVars(data);\n\n bb.gotonode(\n screenid,\n () => {\n // The gotonode invocation just overwrote the direction and row.\n Ajax.direction = direction;\n Ajax.row =\n direction === \"update\" && options && options.update;\n if (!Ajax.row) cb && cb();\n },\n {\n cbIsAdditional: \"before\",\n groupElt: container,\n isUpdate: true\n }\n );\n });\n },\n { sync: false, cbIsAdditional: false }\n );\n } else {\n Ajax.post(ajaxOptions);\n }\n }\n } catch (e) {\n $(document).trigger(\"bb:userError\", e.message);\n A11y.log(_(e.message));\n }\n}\n\nlet lastUpdateRequest;\n\nfunction requestDynProps(input) {\n if (Ajax.busy) return;\n\n var thisUpdateRequest;\n\n Ajax.last && Ajax.last.abort();\n Ajax.direction = \"update\";\n // Ajax.row = Ajax.direction === 'update' && options && options.update;\n\n const ajaxOptions = {\n async: true,\n data: [\n \"step=update\",\n Vars.querify(Vars.NAV_KEYS),\n \"fmt=json\",\n serializeQuestions()\n ]\n .filter(Boolean)\n .join(\"&\"),\n success: (...args) => {\n if (thisUpdateRequest === lastUpdateRequest) {\n $(document).trigger(\"bb:preHandleData\", ...args);\n updateDynProps(args[0], input);\n }\n }\n };\n lastUpdateRequest = thisUpdateRequest = Ajax.post(ajaxOptions);\n}\n\n// bb:prePost handler always goes off on bb.ajax.post.\n$(document).on(\"bb:prePost\", function (event, options) {\n if (includes(options.url, [\"action\", \"open\", \"bbisreturns\"]))\n if (!includes(Ajax.direction, [\"update\", \"updatemis\"]))\n $(document).trigger(\"bb:preStep\", options);\n});\n\n// bb:preStep handler goes off after user-initiated, possibly\n// expensive, actions.\n$(document).on(\"bb:preStep\", function () {\n Ajax.busy = true;\n // Hide lingering calendars\n $(\".group.selected .hasDatepicker\").datepicker(\"hide\");\n});\n\n// Save\n$(document).on(\"click\", \".bb-save\", function () {\n step(\"save\", null);\n});\n\n// Update - from grids (+/- a row), or from dynamically added buttons (e.g. plugin\n// metadata-add-update-button)\n$(document).on(\"click\", \"[name=update]\", function (ev) {\n step(\"update\", null, {\n update: $(this).val(),\n groupElt: ev.target.closest(\".group\")\n });\n});\n\n// Prior\n$(document).on(\"click\", \".bb-prior\", function () {\n step(\"prior\");\n});\n\n// Next\n$(document).on(\"click\", \".bb-next\", function (ev) {\n bb.next();\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n});\n\n// Skip\n$(document).on(\"click\", \".bb-skip\", function (ev) {\n bb.skip();\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n});\n\n$(document).on(\"keydown\", \".group a\", function (ev) {\n if (\n ev.shiftKey &&\n ev.keyCode === KEYS.ENTER &&\n ev.target.href.substr(-1) !== \"#\"\n ) {\n // true link BUT SHIFT + ENTER\n bb.next();\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n }\n return true;\n});\n\n// Close\n$(document).on(\"click\", \".bb-close\", function () {\n logout();\n self.close();\n $(\"body\").html(_(\"You may now safely close this window\"));\n});\n\n// Restart\n$(document).on(\"click\", \".bb-restart\", function (event) {\n if (\n \"noconfirm\" in event.currentTarget.dataset ||\n confirm(_(\"Are you sure? This will reset all values.\"))\n )\n bb.restart();\n return false;\n});\n\n$(document).on(\"click\", 'input[aria-disabled=\"true\"]', function (event) {\n event.preventDefault();\n});\n\n/**\n * Log out\n *\n * @param {Boolean} ev Either a jQuery event or not\n * @param {Function} cb Callback function to be run after logout.\n * Supercedes default action on Ajax request. @see Ajax.post.\n */\n\nconst timedOutResponse = () => ({\n error: {\n code: 9 //Errors.CODES.cWebSessionTimeOut\n }\n});\n\nfunction logout(ev, cb) {\n if (Vars.getVar(\"uniqueid\")) {\n exit(function () {\n const options = {\n url: \"logout\",\n data: \"fmt=json&\" + Vars.querify(\"uniqueid\"),\n async: false\n };\n // When called directly, which\n if (cb instanceof Function) {\n options.success = options.error = cb;\n }\n Ajax.post(options);\n });\n } else {\n console && console.info && console.info(\"Fake logging out, ID is missing\");\n const mockResponse = timedOutResponse();\n ((cb instanceof Function && cb) || checkJSON)(mockResponse, 200, {\n responseJSON: mockResponse,\n responseText: JSON.stringify(mockResponse)\n });\n }\n return false;\n}\n\n$(document).on(\"click\", \".bb-logout\", logout);\n$(document).on(\"keydown\", \".bb-logout\", function (ev) {\n if (ev.keyCode !== KEYS.ENTER && ev.keyCode !== KEYS.SPACE) return true;\n logout(ev);\n return false;\n});\n\n/** Exit\n *\n * Exit the current case;\n * @param {Function} fun Function to execute after having exited.\n * If exiting isn't necessary, still execute fun.\n */\nfunction exit(fun, sync = true) {\n if (typeof fun !== \"function\")\n // Could be an event object on .bb-stop\n fun = undefined;\n if (shouldExit()) {\n step(\"exit\", fun, { sync });\n } else fun && fun();\n}\n\n$(document).on(\"click\", \".bb-stop\", exit);\n\n// Request 'getuserinfo'\nfunction getUserInfo() {\n $.postJSON(\"getuserinfo\", Vars.querify(\"uniqueid\") + \"&fmt=json\");\n}\n\n/*** NAVIGATION, REQUESTS END ***/\n\n/*** MENU BEGIN ***/\n\nfunction setupMenu() {\n $(\".bb-settings\").attr({ target: \"blank\" });\n}\n\n// Open WebAdmin (in new page)\nfunction openSettings() {\n var href = fromApiServer(\"webadmin\" + \"?\" + Vars.querify(\"uniqueid\"));\n window.open(href);\n return false;\n}\n\n$(document).on(\"click\", \".bb-settings\", openSettings);\n$(document).on(\"keydown\", \".bb-settings\", function (ev) {\n if (ev.keyCode !== KEYS.ENTER && ev.keyCode !== KEYS.SPACE) return true;\n openSettings(ev);\n return false;\n});\n\n/** menu\n *\n * Open menu (model overview)\n * @param {String|Object|undefined} creds Optional credentials,\n * defaults to fmt:json and uniqueid\n */\nfunction menu(creds) {\n return $.postJSON(\n \"menu\",\n creds || {\n fmt: \"json\",\n uniqueid: Vars.getVar(\"uniqueid\")\n }\n );\n}\n\n/** exitthenmenu\n *\n * Exit a case, then open a menu\n * @param {Event} ev Optional event whose propagation will be stopped\n */\nfunction exitthenmenu(ev) {\n exit(function () {\n menu();\n });\n ev && ev.stopPropagation && ev.stopPropagation();\n}\n\n$(document).on(\"click\", \".bb-openmodels\", exitthenmenu);\n$(document).on(\"keydown\", \".bb-openmodels\", function (ev) {\n if (ev.keyCode !== KEYS.ENTER) return;\n exitthenmenu(ev);\n});\n\n/*** MENU END ***/\n\n/*** MISC UI BEGIN ***/\n\nfunction hideLogin() {\n $(\"form#bb-login\").hide();\n}\n\n/**\n * Simple class toggling to implement collapsing/expanding widgets.\n *\n * Needs CSS styling and / or Event handler registered on custom\n * jQuery 'bb:collapsing' Event.\n */\n$(document).on(\"click keydown\", \".bb-collapsable .bb-collapser\", function (ev) {\n if (aintTheEnterKey(ev) || ev.shiftKey) return true;\n $(this)\n .closest(\".bb-collapsable\")\n .toggleClass(\"bb-collapsed\")\n .trigger(\"bb:collapsing\");\n return false;\n});\n\n/*** MISC UI END ***/\n\n/*** DATA HANDLERS BEGIN ***/\n\n/**\n * Default handlers for JSON object.\n *\n * Order in which these handlers are executed are:\n *\n * bb:preHandleData\n * bb:handleData\n * bb:postHandleData\n * bb:finalHandleData\n */\n\n$(document).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups) {\n data.groups.forEach(function (group) {\n const groupid = group.groupid;\n group.controls.forEach(function (control) {\n control._originalid = control.id;\n control.id = groupid + \"-\" + control.id;\n if (control.isfor) {\n control._originalisfor = control.isfor;\n control.isfor = groupid + \"-\" + control.isfor;\n }\n if (control.controltype === \"label\") {\n control.value = control.value.trim();\n if (control.isfor && control.value)\n control.value = control.value + \" \";\n }\n if (\n control.controltype === \"memo\" &&\n control.maxlength > 0 &&\n !control.placeholder\n ) {\n control.placeholder = positionalFormat(\n _(\"Maximum allowed characters: {0}\"),\n control.maxlength\n );\n }\n });\n });\n }\n});\n/**\n * Default handler for JSON object.\n *\n * Sets mode, variables, calls functions to update UI.\n *\n */\nfunction onHandleData(event, data) {\n // Save previous modus - it will be the next modus if unset.\n var modus = $(\"body\").attr(\"data-modus\"); // Either 'model', 'menu', or 'none'\n\n Mode.unset(\"hasMessage\");\n if (typeof data == \"undefined\") return;\n if (typeof document.selection != \"undefined\")\n try {\n document.selection.removeAllRanges();\n // eslint-disable-next-line no-empty, no-unused-vars -- tryCatch was there for IE's sake. probably because we were using Selection.empty()\n } catch (e) {}\n\n // Fix error objects - they are a mess\n if (data.error) {\n data.error = Errors.translate(data.error);\n // Do not throw the error just yet - we may need it to\n // get in the right mode\n }\n\n Vars.setVars(data);\n\n if (data.userinfo) {\n Mode.set(\"isLoggedIn\");\n setRole();\n setupMenu();\n return;\n }\n\n if (\n data.error &&\n ([\n Errors.CODES.cWebPleaseLogin,\n Errors.CODES.cUMWrongUserNamePassword,\n Errors.CODES.cWebSessionTimeOut\n ].indexOf(data.error.code) > -1 ||\n data.error.code === \"UNAUTHORIZED\")\n ) {\n // Do nothing\n } else if (has(\"bbis\", data)) {\n // Authenticate through BBI\n new BBI(data).authenticate();\n return;\n } else if (Vars.getVar(\"uniqueid\")) {\n // We are apparently logged in\n hideLogin();\n if (!Vars.getVar(\"userinfo\")) {\n // Get user information\n getUserInfo();\n }\n }\n\n // \"DrawScreen: end\"\n /* Only set modus if this is possibly mode-changing data (e.g.\n * DON'T even go here when data.userinfo is true).\n */\n if (data.status || data.groups || data.cases || data.models || data.error) {\n if (data.groups) modus = \"model\";\n else if (\n data.models ||\n data.cases ||\n (data.status && data.status == \"Ready\")\n ) {\n modus = \"menu\";\n } else if (data.status && data.status == \"logout successful\") {\n modus = \"none\";\n } else if (data.error && data.error.code === Errors.CODES.cWebPleaseLogin) {\n modus = \"none\";\n } else if (\n data.error &&\n data.error.code === Errors.CODES.cUMWrongUserNamePassword\n ) {\n modus = \"none\";\n } else if (\n data.error &&\n data.error.code === Errors.CODES.cWebSessionTimeOut\n ) {\n modus = \"none\";\n } else if (data.error && data.error.code === \"READY\") {\n modus = \"menu\";\n }\n $(\"body\").attr(\"data-modus\", modus);\n // Set current modus\n\n // Clean up state vars that were left over\n if (modus === \"menu\") {\n Vars.unsetVars([\"sessionid\", \"screenid\"]); // Session specific data\n }\n if (modus === \"none\") {\n const perms = permissions();\n Vars.unsetVars();\n perms.forEach(p => {\n Mode.toggle(p, false, false);\n });\n }\n\n // Will need to be seen with every control\n Mode.unset(\"hasHints\");\n\n if (!data.error)\n Mode.toggle(\"hasNoModelsShown\", modus !== \"menu\")\n\n .toggle(\"hasModel\", modus === \"model\")\n\n .toggle(\"hasMenu\", modus === \"menu\")\n\n .toggle(\n \"hasModels\",\n modus === \"menu\" && !!data.models && !!data.models.length\n )\n\n .toggle(\n \"hasCases\",\n modus === \"menu\" && !!data.cases && !!data.cases.length\n )\n\n .toggle(\n \"hasJumplist\",\n modus === \"model\" && !!data.jumplist && !!data.jumplist.length\n )\n\n .toggle(\n \"hasInformationsources\",\n modus === \"model\" &&\n data.informationsources &&\n !!data.informationsources.length\n )\n\n .toggle(\"hasNoPrior\", modus === \"model\" && !data.hasprevious)\n\n .toggle(\"hasNoNext\", modus === \"model\" && !data.hasnext);\n\n // When going from logged out to logged in:\n if (\n // Mode.get(\"isLoggedIn\") &&\n modus === \"none\"\n ) {\n bb.onBeforeLogout();\n } else Mode.toggle(\"isLoggedIn\", modus !== \"none\");\n\n if (modus === \"none\") {\n Mode.unset(\"isDeepLinked\");\n setRole(); // Sets Mode\n }\n if (modus !== \"model\") {\n Mode.unset(\"isValidated\");\n }\n }\n\n if (\n data.error &&\n !includes(data.error.code, propOr([], \"ignoredErrorCodes\", conf))\n ) {\n notify(\n {\n keepalive: path([\"arbitrary\", \"core\", \"notify\", \"keepalive\"], conf),\n html: false\n },\n data.error\n );\n }\n\n // View updates\n if (data.modeldescription) {\n $(\".bb-modelname\")\n .text(data.modeldescription.replace(/_/g, \" \"))\n .attr(\"lang\", data.modellanguage);\n } else if (modus !== \"model\") {\n $(\".bb-modelname\").text(\"\");\n }\n\n if (modus !== \"model\") {\n $(\"#bb-q\").empty();\n }\n\n if (modus !== \"menu\") {\n Cases.empty();\n Models.empty();\n }\n\n if (modus === \"menu\") {\n if (data.models && !!data.models.length) {\n Models.update(data);\n }\n if (data.cases && !!data.cases.length) {\n Cases.update(data.cases);\n }\n }\n\n if (modus === \"model\") {\n if (data.groups) {\n Validation.reset();\n $(document).trigger(\"bb:renderQuestions\", data);\n }\n Validation.setMode(); // Sets Mode\n\n $(\".bb-openattachments\").attr(\"href\", urlutils.getFiles());\n\n // if (data.informationsources){\n // runHook(\"informationsources\")(data.informationsources);\n // }\n if (data.jumplist) {\n Jumplist.type = arbitraryCoreProp(\"jumplist.type\") || \"ul\";\n Jumplist.draw(data.jumplist);\n }\n }\n}\n\n$(document).on(\"bb:handleData\", onHandleData);\n\n/**\n * Default final handler for JSON object.\n *\n * Runs after any DOM updates. Should only be used for focusing or non-UI stuff.\n *\n * Do not override (unless you know exactly what you are doing) --\n * just augment it if need be.\n *\n */\n$(document).on(\"bb:finalHandleData\", function () {\n bb.ajax.release();\n});\n\nlet returnfocusto, returnSelection;\n\nconst $document = $(document);\n\n$document.on(\"focus\", \":input\", ev => {\n const activeElement = ev.target;\n returnfocusto = activeElement.getAttribute(\"id\");\n if (activeElement.value)\n returnSelection = {\n selectionStart: 0,\n selectionEnd: activeElement.value.length,\n selectionDirection: \"forward\"\n };\n});\n\n$document.on(\"keydown\", \":input\", ev => {\n const activeElement = ev.target;\n const { selectionStart, selectionEnd, selectionDirection } = activeElement;\n returnSelection = { selectionStart, selectionEnd, selectionDirection };\n});\n\nfunction returnfocus() {\n try {\n let elt = document.querySelector(`[id=\"${returnfocusto}\"]`);\n if (elt) {\n elt.focus();\n if (elt.classList.contains(\"hasDatepicker\")) {\n $(elt).datepicker(\"widget\").hide();\n }\n let { selectionStart, selectionEnd, selectionDirection } =\n returnSelection;\n elt.setSelectionRange(selectionStart, selectionEnd, selectionDirection);\n }\n } catch (e) {\n // Checkbox throw an error that some object is not or no\n // longer usable. But how may we check?\n\n // Number inputs and such\n e.select && e.select();\n return true;\n }\n return false;\n}\n\nfunction focusHandler(event, data) {\n if (data.groups) {\n window.setTimeout(function () {\n const [grid, row] = (Ajax.row || \"\").split(\".\");\n var $input,\n focusstring = \":input:visible:enabled:not([readonly]):last\";\n if (row) {\n if (row === \"+\") {\n // Addbutton for entire grid\n $input = $(`.group [name=\"update\"][value=\"${grid}.+\"]`);\n } else {\n $input = $(\n '.group [name=\"' +\n grid +\n '\"] tbody tr:nth(' +\n row +\n \") \" +\n focusstring\n );\n // Might've been the last row - then focus the butlast one\n if (!$input.length)\n $input = $(\n '.group [name=\"' +\n grid +\n '\"] tbody tr:nth(' +\n (parseInt(row) - 1) +\n \") \" +\n focusstring\n );\n // Empty table? Focus addbutton\n if (!$input.length)\n $input = $(`.group [name=\"update\"][value=\"${grid}.+\"]`);\n }\n if ($input.length) {\n $input.trigger(\"focus\");\n }\n } else {\n // focus was lost\n if (\n both(\n complement(propEq(\"_isUpdate\", true)),\n complement(propEq(\"_direction\", \"update\"))\n )(data) ||\n (Mode.get(\"a-keyboard-user\") &&\n document.activeElement === document.body &&\n !returnfocus())\n ) {\n $(\".group.selected\").trigger(\"focus\");\n const e_group = document.querySelector(\".group.selected\");\n if (e_group === null) return;\n e_group.focus();\n if (doScrollToSelected(conf)) {\n if (e_group.previousElementSibling) {\n e_group.scrollIntoView({\n behavior: window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n .matches\n ? \"auto\"\n : \"smooth\"\n });\n }\n }\n }\n }\n }, 0);\n return;\n }\n if (data.models && (!data.cases || !data.cases.length)) {\n $(\".bb-model-name:first\").trigger(\"focus\");\n $(\".bb-model.selected .bb-model-name:first\").trigger(\"focus\");\n return;\n }\n if (data.cases) {\n $(\"#bb-cases tbody .bb-case .bb-case-name:first\").trigger(\"focus\");\n return;\n }\n $(\"form#bb-login input[name=username]\").trigger(\"focus\");\n}\n\nfunction setupFocusHandler(event, data) {\n if (data.uniqueid) {\n $(document).on(\"bb:finalHandleData\", focusHandler);\n $(document).off(\"bb:finalHandleData\", setupFocusHandler);\n }\n}\n\n$(document).on(\"bb:finalHandleData\", setupFocusHandler);\n\nfunction updateDynProps(fulldata, input) {\n var data = {\n groups: fulldata.groups\n };\n $(document).trigger(\"bb:willUpdate\", fulldata);\n if (data && data.groups) {\n var group = data.groups.filter(function (group) {\n return group.current;\n })[0];\n let controls = sortControls(group.controls.slice(0), []);\n $(\n '.group [data-datatype^=\"datades:\"], .group [data-type=\"label\"]'\n ).updateControl(controls, input);\n Validation.setMode();\n }\n $(document).trigger(\"bb:hasUpdated\", fulldata);\n}\n\n$(document).on(\"bb:updated\", function (event, $widget, control, updates) {\n if (updates.indexOf(\"visible\") > -1 && control.identifier) {\n var $parent = $widget.parents(\".bb-questionlabelgroup\");\n if (control.visible) {\n $parent.attr(\"data-visible\", control.visible);\n window.setTimeout(function () {\n $parent.removeAttr(\"hidden\").attr(\"data-visible\", control.visible);\n }, 80);\n } else {\n $parent.attr(\"data-visible\", control.visible);\n window.setTimeout(function () {\n $parent.attr(\"hidden\", true);\n }, 80);\n }\n }\n});\n\n/*** DATA HANDLERS END ***/\n\n/*** VALIDATION BEGIN ***/\n\n/**\n * @Class Validation object.\n *\n */\nvar Validation = {\n /**\n * @member @private {Array} Stack of to-be-validated elemenents\n */\n _stack: [],\n /**\n * @member {Function}\n * @return undefined\n */\n reset: function () {\n this._stack = [];\n },\n /**\n * @member {Function}\n * @return {Element} Next Element eligible for validation\n */\n next: function () {\n return this._stack.pop();\n },\n /**\n * @member {Function}\n * @param {Element} el Element we want to be validated in due time\n */\n add: function (el) {\n this._stack.push(el);\n }\n};\n\n/**\n * Are all inputs valid?\n * @return {Boolean} Whether all inputs pass the test\n */\nValidation.allValid = function () {\n return (\n $.grep(\n $(\n '.group:not([disabled]) .validatable, .group:not([disabled]) [data-datatype^=\"datades:\"]'\n )\n .validate({ silent: true })\n .map(function () {\n return $(this).data(\"validated\");\n }),\n function (val) {\n return val === false;\n }\n ).length === 0\n );\n};\n\n/**\n * Update isValidated Mode\n * @return undefined\n */\nValidation.setMode = function () {\n Mode.toggle(\"isValidated\", Validation.allValid());\n};\n\n/**\n * Live Validation instructions\n */\n$(document).on(\"keyup change\", \"body.hasModel\", Validation.setMode);\n\n$(document).on(\"bb:errorOn\", (_event, message, _input, _error, options) => {\n if (!options.batched) A11y.log(message);\n});\n\n// Push the input just left onto the validation stack\n$(document).on(\"focusout\", \"#bb-q .group .validatable\", function () {\n var me = $(this);\n Validation.add(me[0]);\n});\n\n$.fn.extend({\n geterrorelt: function () {\n var $this = $(this);\n return $this.data(\"$error\") || $();\n },\n showValidation: function (options, ok, error) {\n var $this = $(this),\n node = $this.get(0);\n\n var errortext;\n if (error instanceof Error) errortext = error.message;\n else errortext = error;\n\n if (!document.body.contains(node)) {\n // console.log('Trying to validate unconnected', this)\n return;\n }\n $this.data(\"validated\", ok);\n\n if (!ok) {\n var $error = $this.geterrorelt(),\n $anchor = $this.is(\"input[type=checkbox]\")\n ? $this.next()\n : $this.data(\"anchor\");\n\n $this.attr(\"aria-invalid\", true);\n\n if ($error.length === 0) {\n if (!options.silent && !options.justhide) {\n $error = $(\n ``\n );\n $this.data(\"$error\", $error);\n }\n }\n // If there was already an error element, and the input is\n // still invalid but (reason and therefore) the errortext\n // has changed, change the error text shown to the user.\n if ($error.length > 0) {\n if ($error.data(\"lasterrortext\") !== errortext) {\n $error.data(\"lasterrortext\", errortext);\n $error.text(errortext);\n }\n }\n if (!options.silent && !options.justhide) {\n $this.addClass(\"error invalid\");\n // (re-)attach $error.\n $anchor.after($error);\n // This may be necessary:\n $(\"#bb-wrapmodel\").scrollTo($error);\n // Allow complicated widgets to fix stuff afterwards\n $this.trigger(\"bb:errorOn\", [errortext, $anchor, $error, options]);\n }\n } else {\n $this.attr(\"aria-invalid\", false);\n $this.geterrorelt().remove();\n $this.removeClass(\"error invalid\");\n $this.addClass(\"validated\");\n // Allow complicated widgets to fix stuff afterwards\n $this.trigger(\"bb:errorOff\", [options]);\n\n if (!options.silent && options.requestUpdate) {\n if (Mode.get(\"hasDynamicInterfaces\")) {\n requestDynProps(node);\n }\n }\n }\n },\n // Validate input\n // OPTIONS: silent, justhide\n validate: function (options) {\n if (!options) {\n options = {};\n }\n if (options.silent === undefined) {\n options.silent = false;\n }\n if (options.justhide === undefined) {\n options.justhide = false;\n }\n // requestUpdate needs to be false whenever validation is done\n // upon node navigation (next, skip), in order to avoid useless\n // server requests. Also, on validating for just showing errors\n // on tabbing away, we want not to request an update - that is\n // already taken care of by the onChange event\n if (options.requestUpdate === undefined) {\n options.requestUpdate = true;\n }\n\n // Argument noui says: do not update the ui (i.e. do not show nor hide any errors).\n return $(this).each(function () {\n var $this = $(this),\n ok = true,\n errortext;\n\n try {\n // Let actual validation be performed by other method.\n ok = validateInput($this);\n } catch (err) {\n ok = false;\n errortext = err;\n }\n\n return $this.showValidation(options, ok, errortext);\n });\n }\n});\n\n// Check when tabbing / clicking to new input - we want to show\n// validation while tabbing through, but not tabbing. onChange we want\n// to hide validation errors, but not show them immediately.\n$(document).on(\"focusin\", \":input, a\", function () {\n let validatable;\n while ((validatable = Validation.next())) {\n validatable = $(validatable);\n if ($(this).is(\":radio\")) {\n //Only validate when really outside of the radiogroup\n if (!$(this).parent(\".radiogroup\").has(validatable))\n validatable.validate({ requestUpdate: false });\n } else {\n if (validatable.get(0) != $(this).get(0))\n validatable.validate({ requestUpdate: false });\n }\n }\n});\n\n$(document).on(\n \"change\",\n \"#bb-q .group.selected :input:not(button)\",\n function () {\n var $this = $(this),\n options = { silent: false, justhide: true };\n if ($this.is(\":radio\")) {\n // validating radio???\n $this.parents(\".radiogroup\").validate(options);\n } else {\n $this.validate(options);\n }\n }\n);\n\n// Always check checkboxes onchange\n$(document).on(\"change\", \"#bb-q .group :checkbox\", function () {\n $(this).parents(\".checklist\").validate();\n});\n\nfunction debounce(func, wait, immediate) {\n var timeout;\n return function () {\n var context = this,\n args = arguments;\n var later = function () {\n timeout = null;\n if (!immediate) func.apply(context, args);\n };\n var callNow = immediate && !timeout;\n window.clearTimeout(timeout);\n timeout = window.setTimeout(later, wait);\n if (callNow) func.apply(context, args);\n };\n}\n\nconst eltControltype = compose(prop(\"controltype\"), getControl);\n\nconst doChangeOnKeyDown = elt => {\n const setting = path([\"arbitrary\", \"core\", \"update-on-typing\"])(conf);\n return (\n setting === \"always\" ||\n (setting instanceof Array && includes(eltControltype(elt), setting))\n );\n};\n\nfunction keyDown() {\n if (doChangeOnKeyDown(this)) $(this).data(\"valBefore\", $(this).val());\n}\n\n$(document).on(\n \"keydown\",\n \"#bb-q .group.selected :input:not(button)\",\n debounce(keyDown, 32, true)\n);\n\n$(document).on(\n \"keyup\",\n \"#bb-q .group.selected :input:not(button)\",\n function () {\n if (doChangeOnKeyDown(this)) {\n var $this = $(this),\n before = $this.data(\"valBefore\"),\n val = $this.val();\n if (before !== undefined && before !== val) {\n $this.trigger(\"change\");\n $this.removeData(\"valBefore\");\n }\n }\n }\n);\n/*** VALIDATION END ***/\n\n/*** HINTS, TOOLTIPS BEGIN ***/\n// Move to plugin core:tooltips\n/*** HINTS, TOOLTIPS END ***/\n\n/*** RENDERING 'ENGINE' BEGIN ***/\nconst doScrollToSelected = compose(\n val => val !== false,\n path([\"arbitrary\", \"core\", \"scrollToSelectedGroup\"])\n);\nconst setDynamicMode = tap(\n group =>\n group.current && Mode.toggle(\"hasDynamicInterfaces\", Boolean(group.dynamic))\n);\n\n/**\n * Render questions / labels (i.o.w. the main interaction\n * interface) This function is only called when there are actually\n * screens in need of rendering. Therefore, it need not check the JSON\n * object\n *\n * @param ev {Event} The event that triggered this function\n * @param data {Object} 'JSON'-object conforming to BB JSON API.\n */\nfunction renderGroups(ev, data) {\n // Save previous id\n var previd = $(\"#bb-q\" + \" .group.selected\").data(\"groupid\"),\n groups = data.groups,\n $bbq = $(\"#bb-q\");\n\n // Begin -- Only update what is new or was .selected before! There\n // is a problem with $.ajax calls when fast-clicking => therefore\n // step has {async: false}\n //\n // FIXME: when user press next, while\n // there is no next, a node too many is inserted. This can be\n // fixed now the server passes along the node id of a group.\n\n groups.forEach(setGroupTitle);\n if (![\"open\", \"exit\"].includes(Ajax.direction) && mustUpdate(conf)) {\n // Prepare DOM -- remove unneeded or to be re-rendered .groups\n for (let group of document.querySelectorAll(\".group\")) {\n if (complement(any(propEq(\"groupid\", group.dataset[\"gid\"])))(groups)) {\n // Remove a group if not in response\n group.parentNode.removeChild(group);\n } else if (Ajax.row && group.dataset[\"gid\"] === Ajax.groupid) {\n // When adding/deleting rows, safe the space where the group\n // was (entire group will be re-rendered)\n const gob = find(propEq(\"groupid\", group.dataset[\"gid\"]))(groups);\n const tempNode = document.createComment(\"group\");\n group.parentNode.replaceChild(tempNode, group);\n gob._tempNode = tempNode;\n }\n }\n compose(\n map(\n compose(\n ifElse(\n ({ groupid }) =>\n document.querySelector(`.group[data-gid=\"${groupid}\"]`),\n group => {\n updateDynProps({\n groups: [{ current: true, controls: group.controls }]\n });\n const elt = document.querySelector(\n `.group[data-gid=\"${group.groupid}\"]`\n );\n setSelectedStateAttributes(elt, group);\n },\n renderGroup\n ),\n setDynamicMode\n )\n ),\n sortGroups\n )(groups);\n } else {\n // Always remove .selected:\n $(\".group.selected\", $bbq).remove();\n if (Ajax.direction == \"next\" && groups.length > 1) {\n // Re-render only previous group and current group\n groups = groups.filter(function (group) {\n return group.current || group.groupid === previd;\n });\n } else if (\n Ajax.direction == \"prior\" &&\n $(\"#bb-q .group\").length > 0 &&\n groups.length > 1\n ) {\n // Re-render only current group\n groups = groups.filter(function (group) {\n return group.current;\n });\n } else $bbq.empty();\n // End -- Only update what is new!\n\n $bbq.hide();\n compose(map(compose(renderGroup, setDynamicMode)), sortGroups)(groups);\n }\n $bbq.attr(\"lang\", data.modellanguage).show();\n\n // Old questionlabelgroup plugin:\n if (!doGrouping(conf)) {\n (bb.questionlabelgroup || questionlabelgroup)();\n\n $('.bb-questionlabelgroup:has([data-datatype][data-visible=\"false\"])').attr(\n {\n \"data-visible\": false,\n \"hidden\": true\n }\n );\n }\n}\n\nfunction sortGroups(groups) {\n // Fix insertion order\n return groups.sort(function (a, b) {\n return a.order - b.order;\n });\n}\n\nfunction sortControls(a, b) {\n if (!a[0]) return b.reverse();\n var ac = a.shift(),\n bc = b[0];\n if (\n bc &&\n ac.controltype === \"label\" &&\n !ac.datatype && // Label with a datatype is a text interface\n bc._sorted === undefined &&\n bc.controltype !== \"label\" &&\n (bc.controltype !== \"linklabel\" || bc.isreport) &&\n bc.controltype !== \"checkbox\"\n ) {\n // Reverse input with label\n b.shift();\n bc._sorted = true; // Instruct next recursion not to touch the control\n if (has(\"notnull\", bc)) ac.isForNotNull = bc.notnull;\n if (has(\"readonly\", bc)) ac.readonly = bc.readonly;\n ac.dynamic = bc.dynamic = /^datades:/.test(bc.datatype);\n ac.metadata = Object.assign({}, bc.metadata, ac.metadata);\n bc.meta = bc.meta || {}; // Associate input with label\n bc.meta.label = (ac.value || \"\").trim();\n bc.aria = bc.aria || {}; // Associate input with label\n if (bc.notnull) bc.aria.required = true;\n if (ac.notnull) ac.aria.required = true;\n // Associate input (group) with label.\n if (\n [\"radio\", \"checkmultilist\", \"listbox\", \"multilist\"].includes(\n bc.controltype\n )\n ) {\n if (bb.conf.a11y.optionfieldsets) {\n ac.controltype = \"legend\";\n ac.className = \"bb-label\";\n } else {\n bc.aria.labelledby = ac.id;\n }\n } else if (bc.controltype === \"grid\") {\n if (bb.conf.a11y.captions) {\n ac.controltype = \"caption\";\n bc.caption = ac;\n } else {\n bc.aria.labelledby = ac.id;\n }\n } else {\n ac.isFor = bc.id;\n }\n return sortControls(a, [bc, ac].concat(b));\n } else {\n if (\n bc &&\n ac.controltype === \"label\" &&\n !ac.datatype && // Label with a datatype is a text interface\n bc.controltype === \"checkbox\"\n ) {\n ac.isFor = bc.id; // Associate label with checkbox (that comes before)\n if (has(\"notnull\", bc)) ac.isForNotNull = bc.notnull;\n if (has(\"readonly\", bc)) ac.readonly = bc.readonly;\n ac.dynamic = /^datades:/.test(bc.datatype);\n ac.metadata = Object.assign({}, bc.metadata, ac.metadata);\n bc.meta = bc.meta || {}; // Associate input with label\n bc.meta.label = (ac.value || \"\").trim();\n bc.aria = bc.aria || {};\n if (bc.notnull) bc.aria.required = true;\n if (ac.notnull) ac.aria.required = true;\n }\n return sortControls(a, [ac].concat(b));\n }\n}\n\nfunction setGroupTitle(group) {\n var controls = group.controls;\n // It's a title, if:\n // there are two 1st is label Not a 'text' interface 1st doesnt control any\n if (\n controls[1] &&\n controls[0].controltype === \"label\" &&\n !controls[0].datatype &&\n !controls[0].isfor\n ) {\n controls[0].controltype = \"legend\";\n group.screentitle = controls[0].value;\n }\n}\n\nconst setSelectedStateAttributes = (elt, group) => {\n elt.classList.toggle(\"selected\", group.current);\n elt.classList.toggle(\"unselected\", !group.current);\n if (group.current || canEditEarlier(conf)) {\n elt.removeAttribute(\"aria-hidden\");\n elt.removeAttribute(\"disabled\");\n } else {\n elt.setAttribute(\"aria-hidden\", true);\n elt.setAttribute(\"disabled\", \"disabled\");\n }\n};\n\nconst hasStatusRole = pathEq([\"metadata\", \"role\"], \"status\");\n\nfunction renderGroup(group) {\n var controls = group.controls,\n wGroup = $(\n '\"\n );\n\n // If this has a dupe, first remove the old one:\n $(\".group\").each(function () {\n if ($(this).data(\"groupid\") === group.groupid) $(this).remove();\n });\n\n const elt = wGroup.get(0);\n elt.dataset[\"gid\"] = group[\"groupid\"];\n wGroup.data(\"groupid\", group[\"groupid\"]);\n\n controls = sortControls(controls.slice(0), []);\n\n if (doGrouping(conf)) controls = groupOuter(controls);\n\n $(controls).each(function (i, c) {\n if (doGrouping(conf)) {\n elt.appendChild(createFormGroup(wControl, group, 1)(c));\n } else wControl(c, group, elt);\n });\n\n elt.classList.add(\"bb-screenmode-\" + group.screenmode);\n elt.setAttribute(\"data-node\", group.name);\n if (!bb.getVar(\"wrongOrder\")) elt.setAttribute(\"data-bb:order\", group.order);\n\n setSelectedStateAttributes(elt, group);\n\n if (group._tempNode) {\n group._tempNode.parentNode.replaceChild(elt, group._tempNode);\n delete group._tempNode;\n } else {\n if (group.screenmode == \"addtop\") $(\"#bb-q\").prepend(elt);\n else $(\"#bb-q\").append(elt);\n }\n}\n\n/**\n * Wrap questions + accompanying labels in a single group\n *\n * This function may be overriden by assigning a function to bb.questionlabelgroup\n * @see Plugin questionlabelgroup-ng\n *\n * @return undefined\n */\nfunction questionlabelgroup() {\n $(\".group:not(:has(.bb-questionlabelgroup))>.bb-label\").each(function () {\n var $this = $(this);\n var input = $this.next(\n \":not(label):not(a):not([type=checkbox]):not(img):not(.clearfix)\"\n );\n var itype = input.data(\"type\");\n var questionandlabel = $this.add(input);\n\n if (questionandlabel.length > 1)\n questionandlabel.wrapAll(\n ''\n );\n else {\n questionandlabel = $this.prev(\"[type=checkbox]\").add(this);\n if (questionandlabel.length > 1)\n questionandlabel.wrapAll(\n ''\n );\n }\n questionandlabel\n .parent(\".bb-questionlabelgroup\")\n .append('');\n $.each(\n questionandlabel.parent(\".bb-questionlabelgroup\").find(\"[data-type]\"),\n function () {\n var $this = $(this);\n if ($this.attr(\"class\")) {\n var classname = $this.attr(\"class\").match(/\\bbbm-[a-z0-9-]+\\b/);\n if (classname) {\n classname = classname[0].replace(/\\bbbm-/, \"bb-g-\");\n $this.parents(\".bb-questionlabelgroup\").addClass(classname);\n }\n }\n }\n );\n });\n}\n\n/*** RENDERING 'ENGINE' END ***/\n\n/*** 'COMPLEX' WIDGET BEHAVIOUR BEGIN ***/\n\n/**\n * Radiogroup and checklist enhancements\n */\n\n$(document)\n .on(\"change programmatically-changed\", \".bb-option\", function (ev) {\n var $this = $(this);\n $this.toggleClass(\"checked\", ev.target.checked);\n if (ev.target.type === \"radio\" && ev.target.checked) {\n $this.siblings().removeClass(\"checked\");\n }\n })\n .on(\"focus\", \".bb-option\", function (ev) {\n $(this).addClass(\"focus\");\n if (ev.target.type === \"radio\") {\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n }\n return true;\n })\n .on(\"blur\", \".bb-option\", function () {\n $(this).removeClass(\"focus\");\n })\n .on(\n \"keydown\",\n \".radiogroup .bb-option\",\n // Fix the odd default behaviour of selecting upon focus\n function (ev) {\n var $other,\n chars = [37, 38, 39, 40],\n // left, up, right, down\n idx = chars.indexOf(ev.keyCode);\n if (idx === -1) return true;\n\n $other =\n idx < 2 // 'prev' chars\n ? $(this).prev().find('input[type=\"radio\"]')\n : $(this).next().find('input[type=\"radio\"]');\n\n // At beginning or end... go around (Edge selects otherwise...).\n if (!$other.length) {\n $other =\n idx < 2 // 'prev' chars\n ? $(this).siblings().last().find('input[type=\"radio\"]')\n : $(this).siblings().first().find('input[type=\"radio\"]');\n }\n if ($other.length) {\n $other.trigger(\"focus\");\n ev.preventDefault();\n ev.stopImmediatePropagation();\n return false;\n }\n return true;\n }\n );\n\n/*** 'COMPLEX' WIDGET BEHAVIOUR END ***/\n\n/*** LINKS BEGIN ***/\n\n/**\n * Original code moved to plugin rewrite-links\n *\n */\n\n/*** LINKS END ***/\n\n/*** TOKENCHANNEL BEGIN ***/\n\n$(document).on(\"bb:preHandleData\", (_, data) => {\n if (has(\"uniqueid\", data)) {\n token.setToken(prop(\"uniqueid\", data));\n }\n});\n\n$(document).on(\"bb:preHandleData\", (_, data) => {\n // document.body.dispatchEvent(new customEvent(\"bb:storeToken\", { bubbles: true, })\n if (has(\"uniqueid\", data)) {\n token.setToken(prop(\"uniqueid\", data));\n }\n});\n\n$(document).on(\"bb:mode:isLoggedIn\", (_event, bool) => {\n if (!bool) {\n resetLogin();\n Mode.unset(\"hasModel\")\n .unset(\"hasNoModelsShown\")\n .unset(\"hasMenu\")\n .unset(\"hasModels\")\n .unset(\"hasCases\")\n .unset(\"hasJumplist\")\n .unset(\"hasInformationsources\")\n .unset(\"hasNoPrior\")\n .unset(\"hasNoNext\");\n token\n .getHash()\n .then(tokenHash => token.postMessage({ tokenHash, type: \"loggedOut\" }));\n }\n});\n\ntoken.addEventListener(\"message\", message => {\n token.getHash().then(hash => {\n if (message.data.tokenHash === hash) {\n if (message.data.type === \"loggedOut\") window.close() || logout();\n }\n });\n});\n\n/*** TOKENCHANNEL END ***/\n\n/*** EXPORTS BEGIN ***/\n\nbb.escapeHTML = escapeHTML;\nbb.exit = exit;\nbb.deleteCase = deleteCase;\nbb.logout = logout;\nbb.menu = menu;\n\nbb.authenticate = token => Vars.setVars({ uniqueid: token });\nbb.newcase = newcase;\nbb.step = step;\nbb.restart = function restart() {\n newcase(Vars.getVar(\"dbname\"));\n};\nbb.rewind = function rewind(cb, options) {\n step(\"rewind\", cb, options);\n};\nbb.update = function update(cb, options) {\n step(\"update\", cb, options);\n};\nbb.updatemis = function updatemis(options) {\n step(\"updatemis\", $.noop, options);\n};\nbb.next = function next(cb, options) {\n step(\"next\", cb, options);\n};\nbb.prior = function prior(cb, options) {\n step(\"prior\", cb, options);\n};\nbb.skip = function skip(cb, options) {\n step(\"skip\", cb, options);\n};\nbb.gotonode = function gotonode(groupid, cb, options = null) {\n step(\"gotonode\", cb, Object.assign({}, { groupid }, options));\n};\nbb.runtonode = function runtonode(nodename, cb) {\n step(\"runtonode\", cb, { fullnodename: nodename });\n};\nbb.getVar = Vars.getVar;\nbb.notify = notify.bind(null, {});\nbb.ajax = {\n replace: Ajax.replace,\n busy: function () {\n return Ajax.busy;\n },\n release: Ajax.release,\n post: Ajax.post,\n direction: function () {\n return Ajax.direction;\n }\n};\nbb.URL = urlutils;\nbb.Numerals = Numerals;\nbb.Plugins = bb.Plugins || {};\nbb.Validation = Validation;\nbb.positionalFormat = positionalFormat;\nbb.humanDate = humanDate;\nbb.propFinder = propFinder;\nbb.requestDynProps = requestDynProps;\nbb.onBeforeLogout = () => {\n Mode.unset(\"isLoggedIn\");\n};\n// Window-export some stuff used in bookmarklets.\nwindow.bb = {\n restart: bb.restart,\n getVar: bb.getVar,\n requestDynProps: bb.requestDynProps,\n Mode,\n menu\n};\n\n/*** EXPORTS END ***/\n\nexport { bb, _, _ as gt };\n","/**\n * https://github.com/flesler/jquery.scrollTo\n * Copyright (c) 2007-2013 Ariel Flesler - afleslergmailcom | http://flesler.blogspot.com\n * Dual licensed under MIT and GPL.\n * @author Ariel Flesler\n * @version 1.4.6\n */\n(function ($) {\n var h = ($.scrollTo = function (a, b, c) {\n $(window).scrollTo(a, b, c);\n });\n h.defaults = {\n axis: \"xy\",\n duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1,\n limit: true\n };\n h.window = function (a) {\n return $(window)._scrollable();\n };\n $.fn._scrollable = function () {\n return this.map(function () {\n var a = this,\n isWin =\n !a.nodeName ||\n $.inArray(a.nodeName.toLowerCase(), [\n \"iframe\",\n \"#document\",\n \"html\",\n \"body\"\n ]) != -1;\n if (!isWin) return a;\n var b = (a.contentWindow || a).document || a.ownerDocument || a;\n return /webkit/i.test(navigator.userAgent) || b.compatMode == \"BackCompat\"\n ? b.body\n : b.documentElement;\n });\n };\n $.fn.scrollTo = function (e, f, g) {\n if (typeof f == \"object\") {\n g = f;\n f = 0;\n }\n if (typeof g == \"function\") g = { onAfter: g };\n if (e == \"max\") e = 9e9;\n g = $.extend({}, h.defaults, g);\n f = f || g.duration;\n g.queue = g.queue && g.axis.length > 1;\n if (g.queue) f /= 2;\n g.offset = both(g.offset);\n g.over = both(g.over);\n return this._scrollable()\n .each(function () {\n if (e == null) return;\n var d = this,\n $elem = $(d),\n targ = e,\n toff,\n attr = {},\n win = $elem.is(\"html,body\");\n switch (typeof targ) {\n case \"number\":\n case \"string\":\n if (/^([+-]=?)?\\d+(\\.\\d+)?(px|%)?$/.test(targ)) {\n targ = both(targ);\n break;\n }\n targ = $(targ, this);\n if (!targ.length) return;\n case \"object\":\n if (targ.is || targ.style) toff = (targ = $(targ)).offset();\n }\n $.each(g.axis.split(\"\"), function (i, a) {\n var b = a == \"x\" ? \"Left\" : \"Top\",\n pos = b.toLowerCase(),\n key = \"scroll\" + b,\n old = d[key],\n max = h.max(d, a);\n if (toff) {\n attr[key] = toff[pos] + (win ? 0 : old - $elem.offset()[pos]);\n if (g.margin) {\n attr[key] -= parseInt(targ.css(\"margin\" + b)) || 0;\n attr[key] -= parseInt(targ.css(\"border\" + b + \"Width\")) || 0;\n }\n attr[key] += g.offset[pos] || 0;\n if (g.over[pos])\n attr[key] += targ[a == \"x\" ? \"width\" : \"height\"]() * g.over[pos];\n } else {\n var c = targ[pos];\n attr[key] =\n c.slice && c.slice(-1) == \"%\" ? (parseFloat(c) / 100) * max : c;\n }\n if (g.limit && /^\\d+$/.test(attr[key]))\n attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max);\n if (!i && g.queue) {\n if (old != attr[key]) animate(g.onAfterFirst);\n delete attr[key];\n }\n });\n animate(g.onAfter);\n function animate(a) {\n $elem.animate(\n attr,\n f,\n g.easing,\n a &&\n function () {\n a.call(this, targ, g);\n }\n );\n }\n })\n .end();\n };\n h.max = function (a, b) {\n var c = b == \"x\" ? \"Width\" : \"Height\",\n scroll = \"scroll\" + c;\n if (!$(a).is(\"html,body\")) return a[scroll] - $(a)[c.toLowerCase()]();\n var d = \"client\" + c,\n html = a.ownerDocument.documentElement,\n body = a.ownerDocument.body;\n return Math.max(html[scroll], body[scroll]) - Math.min(html[d], body[d]);\n };\n function both(a) {\n return typeof a == \"object\" ? a : { top: a, left: a };\n }\n})(jQuery);\n","import { _ } from \"$json\";\n\nconst DICTIONARY = {\n \"close this infomation box\": {\n \"en\": \"close this infomation box\",\n \"nl\": \"sluit dit informatievak\",\n \"en-GB\": \"close this infomation box\"\n },\n \"Send link popup\": {\n \"en\": \"Send link popup\",\n \"nl\": \"Pop-up voor koppeling verzenden\",\n \"en-GB\": \"Send link popup\"\n }\n};\n\n_.addTranslations(DICTIONARY);\n\nclass Listener {\n constructor(id) {\n this[id] = event => {\n if (event.isComposing || event.keyCode !== 27) {\n return;\n } else {\n // No need to be specific, just destroy the most recent one.\n Array.from(document.querySelectorAll(\".p-dialogue-container\"))\n .pop()\n .click();\n }\n };\n }\n}\n\nexport default class Dialogue {\n constructor(props = {}, parent) {\n this.id = `dialogue-${Date.now()}-${Math.floor(Math.random() * 10000)}`;\n this.parent =\n parent !== undefined && typeof parent === \"object\" && \"nodeType\" in parent\n ? parent\n : document.getElementsByTagName(\"body\")[0];\n this.elemprops = props;\n this.rtnfocus = document.children[0];\n }\n\n destroy(human = true) {\n let me = document.getElementById(this.id);\n if (me) this.parent.removeChild(me);\n\n // Remove keyup listener\n this.handler &&\n document.removeEventListener(`keyup`, this.handler[this.id], false);\n\n // Untrap focus\n document.querySelectorAll(\"[data-hushed-by-dialogue]\").forEach(elem => {\n let prev = elem.getAttribute(\"data-previous-tabindex\");\n elem.removeAttribute(\"tabindex\");\n if (prev !== \"none\") {\n elem.setAttribute(\"tabindex\", prev);\n }\n elem.removeAttribute(\"data-previous-tabindex\");\n elem.removeAttribute(\"data-hushed-by-tabindex\");\n });\n\n // Unhide ARIA\n document\n .querySelectorAll(\"[data-aria-hidden-by-dialogue]\")\n .forEach(elem => {\n let prev = elem.getAttribute(\"data-previous-aria\");\n elem.removeAttribute(\"aria-hidden\");\n if (prev !== \"none\") {\n elem.setAttribute(\"aria-hidden\", prev);\n }\n elem.removeAttribute(\"data-previous-aria\");\n elem.removeAttribute(\"data-aria-hidden-by-dialogue\");\n });\n\n // Return focus, but not if this was called by the render method,\n // otherwise we will override the activeElement with the initial\n // rtnfocus value (document.children[0])\n human && this.rtnfocus.focus();\n }\n\n render(elem) {\n // Remove dialogue if it already exists.\n this.destroy(false);\n\n // Remove all other focusable elements from tabindex on the DOM,\n // so we can truly trap the focus for all users w/o trapping\n // keyboard user out of the browser controls.\n document\n .querySelectorAll(\n \"a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]\"\n )\n .forEach(elem => {\n elem.setAttribute(\"data-hushed-by-dialogue\", true);\n elem.setAttribute(\n \"data-previous-tabindex\",\n elem.getAttribute(\"tabindex\") || \"none\"\n );\n elem.setAttribute(\"tabindex\", \"-1\");\n });\n\n // ARIA hide everything to avoid screen readers keyboard\n // shortcuts gaining access outside of the dialogue.\n document.querySelectorAll(\"*:not(body):not(html)\").forEach(elem => {\n elem.setAttribute(\"data-aria-hidden-by-dialogue\", true);\n elem.setAttribute(\n \"data-previous-aria\",\n elem.getAttribute(\"aria-hidden\") || \"none\"\n );\n elem.setAttribute(\"aria-hidden\", \"true\");\n });\n\n // Create elements.\n let container = document.createElement(\"div\");\n container.className = \"p-dialogue-container\";\n container.style.cssText = `\n background-color: rgba(0,0,0,.5);\n height: 100%;\n left: 0;\n position: fixed;\n text-align: center;\n top: 0;\n width: 100%;\n z-index: 100;\n `;\n container.id = this.id;\n container.setAttribute(\"role\", \"dialog\");\n // container.setAttribute(\"aria-label\", \"dialog\"); // BAD A11Y - more accessible label should be given by class caller.\n Object.keys(this.elemprops).forEach(prop => {\n prop === \"class\"\n ? (container.className += \" \" + this.elemprops[prop])\n : container.setAttribute(prop, this.elemprops[prop]);\n });\n container.addEventListener(\"click\", e => {\n this.destroy();\n });\n\n let inner = document.createElement(\"div\");\n inner.className = \"inner\";\n inner.style.cssText = `\n display: inline-block;\n margin: 10vh 25px auto 25px;\n overflow: auto;\n `;\n inner.addEventListener(\"click\", e => {\n e.stopPropagation();\n });\n\n let closer = document.createElement(\"button\");\n let x = document.createTextNode(\"+\");\n closer.append(x);\n closer.className = \"dialogue-close\";\n closer.style.cssText = `\n font-size: 2.2rem;\n line-height: 1.2rem;\n padding: 5px;\n position: absolute;\n right: 5px;\n top: 5px;\n transform-origin: top;\n transform: rotate(45deg);\n `;\n closer.addEventListener(\"click\", e => this.destroy());\n closer.setAttribute(\"aria-label\", _(\"close this infomation box\"));\n\n // Add to DOM\n inner.appendChild(closer);\n inner.appendChild(elem);\n container.appendChild(inner);\n this.parent.appendChild(container);\n\n // Set the rtnfocus, then focus inside dialogue.\n this.rtnfocus = document.activeElement;\n inner.focus();\n\n this.handler = new Listener(this.id);\n\n document.addEventListener(`keyup`, this.handler[this.id], false);\n }\n}\n","/* a11y-describedby:\n *\n * - Describe group with all its standard remarks\n * - Describe input by any non-standard remark labels directly\n * preceding it\n *\n * Author: Niels Giesen\n * Copyright 2016 Berkeley Bridge\n *\n */\nimport { tap, when, compose, prop, path, find } from \"$json/lib/functional\";\n\n$(document).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups) {\n $.each(data.groups, function (_, group) {\n var remarks = [],\n pretexts = [];\n $.each(group.controls, function (idx, control) {\n if (control[\"font-class\"].toLowerCase() === \"standard remark\") {\n remarks.push(control.id);\n } else if (control.datatype && control.controltype === \"label\") {\n pretexts.push(control.id);\n }\n const explicitId = path([\"metadata\", \"describedby\"], control);\n if (explicitId) {\n compose(\n when(\n Boolean,\n compose(id => pretexts.push(id), prop(\"id\"))\n ),\n find(c => c.identifier && c.identifier.endsWith(`.${explicitId}`)),\n prop(\"controls\")\n )(group);\n }\n if (control.datatype && control.controltype !== \"label\") {\n maybeSetDescription(control, pretexts);\n pretexts = [];\n }\n });\n maybeSetDescription(group, remarks);\n });\n }\n});\n\nfunction maybeSetDescription(thing, description_ids) {\n if (description_ids.length) {\n thing.aria = thing.aria || {};\n thing.aria.describedby = description_ids.join(\" \");\n }\n}\n","/* asterisk:\n *\n * Add asterisk to labels for required fields\n *\n * Author: Niels Giesen\n * Copyright 2015 Berkeley Bridge\n *\n */\n(function ($, win, doc) {\n function appendAsterisk(child) {\n if (child.nodeType === 3 /* Node.TEXT_NODE */) {\n var val = child.nodeValue,\n space = \"\",\n words = val.split(\" \"),\n lastword = words.pop();\n // json.js adds a space for visual purposes\n if (lastword === \"\") {\n space = \" \";\n lastword = words.pop();\n }\n child.nodeValue = words.join(\" \");\n child.parentNode.insertAdjacentHTML(\n \"beforeEnd\",\n ' ' +\n lastword +\n ` *` +\n \"\" +\n space\n );\n } else if (child.nodeType === 1 /* Node.ELEMENT_NODE */) {\n if (child.lastChild) appendAsterisk(child.lastChild);\n }\n }\n\n $(doc).on(\"bb:updated\", function (event, $widget, control, updates) {\n if (updates.indexOf(\"isForNotNull\") > -1) {\n if (control.isForNotNull) {\n appendAsterisk($widget.get(0).lastChild);\n } else {\n const $stick = $widget.find(\".bb-p-asterisk-stick\");\n if (!$stick.get(0)) return;\n $stick.find(\"sup\").remove();\n const textnode = $stick.get(0).childNodes[0];\n if (textnode) $(textnode).unwrap();\n }\n }\n });\n})(jQuery, window, document);\n","(function ($) {\n $(document).on(\"bb:errorOn\", \".bb-input-wrap\", adderrorclass);\n $(document).on(\"bb:errorOff\", \".bb-input-wrap\", rmerrorclass);\n\n function adderrorclass(ev) {\n $(ev.currentTarget).addClass(\"bb-input-wrap--error\");\n }\n\n function rmerrorclass(ev) {\n $(ev.currentTarget).removeClass(\"bb-input-wrap--error\");\n }\n\n $(document).on(\"click\", \".selected .bb-input-wrap\", focus);\n\n function notAnInput(node) {\n return node.form === undefined; // With form inputs, this will\n // be either the form or null\n }\n function focus(ev) {\n if (notAnInput(ev.target)) {\n ev.currentTarget.querySelector(\"input, select, textarea\").focus();\n }\n }\n})(jQuery);\n","/* global jQuery */\n// custom-checkboxes.js\n\n/*\n * A simple plugin to replace\n * checkboxes with a custom design.\n * Cross-browser and working with all\n * forms of output; grids, checklists\n * and mutli-checklists\n *\n * Author: Tim Bauwens\n * Copyright Berkeley Bridge 2019\n *\n */\n\n((doc, $) => {\n const addCustomCheckbox = checkbox => {\n checkbox.className += \" a-offscreen p-custom-checkboxes\";\n checkbox.insertAdjacentHTML(\n \"afterEnd\",\n `\n \n `\n );\n };\n\n const addCheckBoxes = () => {\n // If there are any checkboxes, deal with them\n const checkboxes = $(\"#bb-q\").find(\n 'input[type=\"checkbox\"]:not(.p-custom-checkboxes)'\n );\n checkboxes.each((_, checkbox) => {\n addCustomCheckbox(checkbox);\n });\n };\n\n $(doc).on(\"bb:postHandleData\", (_, data) => {\n if (!data || !data.groups) return;\n addCheckBoxes();\n });\n\n $(doc).on(\"bb:updated\", (_, $widget, { controltype }) => {\n if (controltype === \"grid\" || controltype === \"checkmultilist\") {\n const checkboxes = $widget.find(\n 'input[type=\"checkbox\"]:not(.p-custom-checkboxes)'\n );\n checkboxes.each((_, checkbox) => {\n addCustomCheckbox(checkbox);\n });\n }\n });\n})(document, jQuery);\n","// final-node.js\n\n/*\n A plugin to target the final node and\n make a report and feedback buttons, similar\n to nta:three-in-one.\n*/\n\n((doc, $) => {\n var reportURL;\n $(doc).on(\"bb:preHandleData\", (e, data) => {\n if (data && data.groups && data.groups.length > 0) {\n if (data.groups[0].name === \"main.document\") {\n // Grab the doc url, and remove it from the controls.\n data.groups[0].controls.forEach((control, i) => {\n if (control.controltype === \"linklabel\") {\n reportURL = control.url;\n data.groups[0].controls.splice(i, 1);\n }\n });\n }\n }\n });\n $(doc).on(\"bb:postHandleData\", (e, data) => {\n if (data && data.groups && data.groups.length > 0) {\n if (data.groups[0].name === \"main.document\") {\n // Create the container for the functions.\n var $container = $('');\n\n // Make a download report button\n var $download = $('');\n $download.append(`\n \n Samenvatting als PDF downloaden\n `);\n $container.append($download);\n\n // Make the feedback buttons.\n var $feedback = $(\n ''\n );\n $feedback\n .append(\"\")\n .append(\n ''\n )\n .append(\n ''\n );\n\n // Handler\n var group;\n if (data && data.userinfo) $feedback.data(\"userinfo\", data.userinfo);\n group = data.groups.filter(function (g) {\n return g.current;\n })[0];\n $feedback.data(\"nodename\", group.name);\n if (data && data.modelname) $feedback.data(\"modelname\", data.modelname);\n if (data && data.modelversion)\n $feedback.data(\"modelversion\", data.modelversion);\n $(doc).off(\".three-in-one-events\", \".feedback-button\");\n $(doc).one(\n \"click.three-in-one-events\",\n \".feedback-button\",\n function (e) {\n var vote =\n $(e.target).data(\"value\") !== undefined\n ? $(e.target).data(\"value\")\n : $(e.target).parents(\"button\").data(\"value\");\n // Send the vote to the feedback model and update the inner text\n $.getJSON(\"open?\", {\n \"modelname\": \"Feedback\",\n \"username\": \"feedback\",\n \"password\": \"feedback\",\n \"fmt\": \"json\",\n \"fdbk:f\": vote,\n \"fdbk:n\": $feedback.data(\"nodename\"),\n \"fdbk:u\": $feedback.data(\"userinfo\")\n ? $feedback.data(\"userinfo\")[\"fullname\"]\n : \"\",\n \"fdbk:m\": $feedback.data(\"modelname\"),\n \"fdbk:v\": bb.getVar(\"version\") && bb.getVar(\"version\").join(\".\"),\n \"fdbk:a\":\n [\n bb.getVar(\"replyserveraddress\"),\n bb.getVar(\"replyserverport\")\n ].join(\":\") +\n \"/\" +\n bb.getVar(\"proxyredirect\"),\n \"fdbk:s\": bb.getVar(\"sessionid\"),\n \"fdbk:d\": location.href.replace(/(password=)(?:[^&]+)/, \"$1***\"),\n \"fdbk:b\": navigator.userAgent\n });\n\n // Add the vote to the hiddden interface.\n $(\"input.bbm-feedback-vote\").attr(\"value\", vote);\n $feedback.html(\"\");\n }\n );\n\n $container.append($feedback);\n\n // Reveal\n\n $(\"#bb-q\").prepend($container);\n $(\"html,body\").animate({ scrollTop: 0 });\n setTimeout(function () {\n $container.toggleClass(\"showing\");\n }, 800);\n }\n }\n });\n})(document, jQuery);\n","/*!\n * mustache.js - Logic-less {{mustache}} templates with JavaScript\n * http://github.com/janl/mustache.js\n */\n\n/*global define: false Mustache: true*/\n\nfunction mustacheFactory(mustache) {\n var objectToString = Object.prototype.toString;\n var isArray =\n Array.isArray ||\n function isArrayPolyfill(object) {\n return objectToString.call(object) === \"[object Array]\";\n };\n\n function isFunction(object) {\n return typeof object === \"function\";\n }\n\n /**\n * More correct typeof string handling array\n * which normally returns typeof 'object'\n */\n function typeStr(obj) {\n return isArray(obj) ? \"array\" : typeof obj;\n }\n\n function escapeRegExp(string) {\n return string.replace(/[\\-\\[\\]{}()*+?.,\\\\\\^$|#\\s]/g, \"\\\\$&\");\n }\n\n /**\n * Null safe way of checking whether or not an object,\n * including its prototype, has a given property\n */\n function hasProperty(obj, propName) {\n return obj != null && typeof obj === \"object\" && propName in obj;\n }\n\n // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577\n // See https://github.com/janl/mustache.js/issues/189\n var regExpTest = RegExp.prototype.test;\n function testRegExp(re, string) {\n return regExpTest.call(re, string);\n }\n\n var nonSpaceRe = /\\S/;\n function isWhitespace(string) {\n return !testRegExp(nonSpaceRe, string);\n }\n\n var entityMap = {\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n \"/\": \"/\",\n \"`\": \"`\",\n \"=\": \"=\"\n };\n\n function escapeHtml(string) {\n return String(string).replace(/[&<>\"'`=\\/]/g, function fromEntityMap(s) {\n return entityMap[s];\n });\n }\n\n var whiteRe = /\\s*/;\n var spaceRe = /\\s+/;\n var equalsRe = /\\s*=/;\n var curlyRe = /\\s*\\}/;\n var tagRe = /#|\\^|\\/|>|\\{|&|=|!/;\n\n /**\n * Breaks up the given `template` string into a tree of tokens. If the `tags`\n * argument is given here it must be an array with two string values: the\n * opening and closing tags used in the template (e.g. [ \"<%\", \"%>\" ]). Of\n * course, the default is to use mustaches (i.e. mustache.tags).\n *\n * A token is an array with at least 4 elements. The first element is the\n * mustache symbol that was used inside the tag, e.g. \"#\" or \"&\". If the tag\n * did not contain a symbol (i.e. {{myValue}}) this element is \"name\". For\n * all text that appears outside a symbol this element is \"text\".\n *\n * The second element of a token is its \"value\". For mustache tags this is\n * whatever else was inside the tag besides the opening symbol. For text tokens\n * this is the text itself.\n *\n * The third and fourth elements of the token are the start and end indices,\n * respectively, of the token in the original template.\n *\n * Tokens that are the root node of a subtree contain two more elements: 1) an\n * array of tokens in the subtree and 2) the index in the original template at\n * which the closing tag for that section begins.\n */\n function parseTemplate(template, tags) {\n if (!template) return [];\n\n var sections = []; // Stack to hold section tokens\n var tokens = []; // Buffer to hold the tokens\n var spaces = []; // Indices of whitespace tokens on the current line\n var hasTag = false; // Is there a {{tag}} on the current line?\n var nonSpace = false; // Is there a non-space char on the current line?\n\n // Strips all whitespace tokens array for the current line\n // if there was a {{#tag}} on it and otherwise only space.\n function stripSpace() {\n if (hasTag && !nonSpace) {\n while (spaces.length) delete tokens[spaces.pop()];\n } else {\n spaces = [];\n }\n\n hasTag = false;\n nonSpace = false;\n }\n\n var openingTagRe, closingTagRe, closingCurlyRe;\n function compileTags(tagsToCompile) {\n if (typeof tagsToCompile === \"string\")\n tagsToCompile = tagsToCompile.split(spaceRe, 2);\n\n if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)\n throw new Error(\"Invalid tags: \" + tagsToCompile);\n\n openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + \"\\\\s*\");\n closingTagRe = new RegExp(\"\\\\s*\" + escapeRegExp(tagsToCompile[1]));\n closingCurlyRe = new RegExp(\n \"\\\\s*\" + escapeRegExp(\"}\" + tagsToCompile[1])\n );\n }\n\n compileTags(tags || mustache.tags);\n\n var scanner = new Scanner(template);\n\n var start, type, value, chr, token, openSection;\n while (!scanner.eos()) {\n start = scanner.pos;\n\n // Match any text between tags.\n value = scanner.scanUntil(openingTagRe);\n\n if (value) {\n for (var i = 0, valueLength = value.length; i < valueLength; ++i) {\n chr = value.charAt(i);\n\n if (isWhitespace(chr)) {\n spaces.push(tokens.length);\n } else {\n nonSpace = true;\n }\n\n tokens.push([\"text\", chr, start, start + 1]);\n start += 1;\n\n // Check for whitespace on the current line.\n if (chr === \"\\n\") stripSpace();\n }\n }\n\n // Match the opening tag.\n if (!scanner.scan(openingTagRe)) break;\n\n hasTag = true;\n\n // Get the tag type.\n type = scanner.scan(tagRe) || \"name\";\n scanner.scan(whiteRe);\n\n // Get the tag value.\n if (type === \"=\") {\n value = scanner.scanUntil(equalsRe);\n scanner.scan(equalsRe);\n scanner.scanUntil(closingTagRe);\n } else if (type === \"{\") {\n value = scanner.scanUntil(closingCurlyRe);\n scanner.scan(curlyRe);\n scanner.scanUntil(closingTagRe);\n type = \"&\";\n } else {\n value = scanner.scanUntil(closingTagRe);\n }\n\n // Match the closing tag.\n if (!scanner.scan(closingTagRe))\n throw new Error(\"Unclosed tag at \" + scanner.pos);\n\n token = [type, value, start, scanner.pos];\n tokens.push(token);\n\n if (type === \"#\" || type === \"^\") {\n sections.push(token);\n } else if (type === \"/\") {\n // Check section nesting.\n openSection = sections.pop();\n\n if (!openSection)\n throw new Error('Unopened section \"' + value + '\" at ' + start);\n\n if (openSection[1] !== value)\n throw new Error(\n 'Unclosed section \"' + openSection[1] + '\" at ' + start\n );\n } else if (type === \"name\" || type === \"{\" || type === \"&\") {\n nonSpace = true;\n } else if (type === \"=\") {\n // Set the tags for the next time around.\n compileTags(value);\n }\n }\n\n // Make sure there are no open sections when we're done.\n openSection = sections.pop();\n\n if (openSection)\n throw new Error(\n 'Unclosed section \"' + openSection[1] + '\" at ' + scanner.pos\n );\n\n return nestTokens(squashTokens(tokens));\n }\n\n /**\n * Combines the values of consecutive text tokens in the given `tokens` array\n * to a single token.\n */\n function squashTokens(tokens) {\n var squashedTokens = [];\n\n var token, lastToken;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n token = tokens[i];\n\n if (token) {\n if (token[0] === \"text\" && lastToken && lastToken[0] === \"text\") {\n lastToken[1] += token[1];\n lastToken[3] = token[3];\n } else {\n squashedTokens.push(token);\n lastToken = token;\n }\n }\n }\n\n return squashedTokens;\n }\n\n /**\n * Forms the given array of `tokens` into a nested tree structure where\n * tokens that represent a section have two additional items: 1) an array of\n * all tokens that appear in that section and 2) the index in the original\n * template that represents the end of that section.\n */\n function nestTokens(tokens) {\n var nestedTokens = [];\n var collector = nestedTokens;\n var sections = [];\n\n var token, section;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n token = tokens[i];\n\n switch (token[0]) {\n case \"#\":\n case \"^\":\n collector.push(token);\n sections.push(token);\n collector = token[4] = [];\n break;\n case \"/\":\n section = sections.pop();\n section[5] = token[2];\n collector =\n sections.length > 0\n ? sections[sections.length - 1][4]\n : nestedTokens;\n break;\n default:\n collector.push(token);\n }\n }\n\n return nestedTokens;\n }\n\n /**\n * A simple string scanner that is used by the template parser to find\n * tokens in template strings.\n */\n function Scanner(string) {\n this.string = string;\n this.tail = string;\n this.pos = 0;\n }\n\n /**\n * Returns `true` if the tail is empty (end of string).\n */\n Scanner.prototype.eos = function eos() {\n return this.tail === \"\";\n };\n\n /**\n * Tries to match the given regular expression at the current position.\n * Returns the matched text if it can match, the empty string otherwise.\n */\n Scanner.prototype.scan = function scan(re) {\n var match = this.tail.match(re);\n\n if (!match || match.index !== 0) return \"\";\n\n var string = match[0];\n\n this.tail = this.tail.substring(string.length);\n this.pos += string.length;\n\n return string;\n };\n\n /**\n * Skips all text until the given regular expression can be matched. Returns\n * the skipped string, which is the entire tail if no match can be made.\n */\n Scanner.prototype.scanUntil = function scanUntil(re) {\n var index = this.tail.search(re),\n match;\n\n switch (index) {\n case -1:\n match = this.tail;\n this.tail = \"\";\n break;\n case 0:\n match = \"\";\n break;\n default:\n match = this.tail.substring(0, index);\n this.tail = this.tail.substring(index);\n }\n\n this.pos += match.length;\n\n return match;\n };\n\n /**\n * Represents a rendering context by wrapping a view object and\n * maintaining a reference to the parent context.\n */\n function Context(view, parentContext) {\n this.view = view;\n this.cache = { \".\": this.view };\n this.parent = parentContext;\n }\n\n /**\n * Creates a new context using the given view with this context\n * as the parent.\n */\n Context.prototype.push = function push(view) {\n return new Context(view, this);\n };\n\n /**\n * Returns the value of the given name in this context, traversing\n * up the context hierarchy if the value is absent in this context's view.\n */\n Context.prototype.lookup = function lookup(name) {\n var cache = this.cache;\n\n var value;\n if (cache.hasOwnProperty(name)) {\n value = cache[name];\n } else {\n var context = this,\n names,\n index,\n lookupHit = false;\n\n while (context) {\n if (name.indexOf(\".\") > 0) {\n value = context.view;\n names = name.split(\".\");\n index = 0;\n\n /**\n * Using the dot notion path in `name`, we descend through the\n * nested objects.\n *\n * To be certain that the lookup has been successful, we have to\n * check if the last object in the path actually has the property\n * we are looking for. We store the result in `lookupHit`.\n *\n * This is specially necessary for when the value has been set to\n * `undefined` and we want to avoid looking up parent contexts.\n **/\n while (value != null && index < names.length) {\n if (index === names.length - 1)\n lookupHit = hasProperty(value, names[index]);\n\n value = value[names[index++]];\n }\n } else {\n value = context.view[name];\n lookupHit = hasProperty(context.view, name);\n }\n\n if (lookupHit) break;\n\n context = context.parent;\n }\n\n cache[name] = value;\n }\n\n if (isFunction(value)) value = value.call(this.view);\n\n return value;\n };\n\n /**\n * A Writer knows how to take a stream of tokens and render them to a\n * string, given a context. It also maintains a cache of templates to\n * avoid the need to parse the same template twice.\n */\n function Writer() {\n this.cache = {};\n }\n\n /**\n * Clears all cached templates in this writer.\n */\n Writer.prototype.clearCache = function clearCache() {\n this.cache = {};\n };\n\n /**\n * Parses and caches the given `template` and returns the array of tokens\n * that is generated from the parse.\n */\n Writer.prototype.parse = function parse(template, tags) {\n var cache = this.cache;\n var tokens = cache[template];\n\n if (tokens == null)\n tokens = cache[template] = parseTemplate(template, tags);\n\n return tokens;\n };\n\n /**\n * High-level method that is used to render the given `template` with\n * the given `view`.\n *\n * The optional `partials` argument may be an object that contains the\n * names and templates of partials that are used in the template. It may\n * also be a function that is used to load partial templates on the fly\n * that takes a single argument: the name of the partial.\n */\n Writer.prototype.render = function render(template, view, partials) {\n var tokens = this.parse(template);\n var context = view instanceof Context ? view : new Context(view);\n return this.renderTokens(tokens, context, partials, template);\n };\n\n /**\n * Low-level method that renders the given array of `tokens` using\n * the given `context` and `partials`.\n *\n * Note: The `originalTemplate` is only ever used to extract the portion\n * of the original template that was contained in a higher-order section.\n * If the template doesn't use higher-order sections, this argument may\n * be omitted.\n */\n Writer.prototype.renderTokens = function renderTokens(\n tokens,\n context,\n partials,\n originalTemplate\n ) {\n var buffer = \"\";\n\n var token, symbol, value;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n value = undefined;\n token = tokens[i];\n symbol = token[0];\n\n if (symbol === \"#\")\n value = this.renderSection(token, context, partials, originalTemplate);\n else if (symbol === \"^\")\n value = this.renderInverted(token, context, partials, originalTemplate);\n else if (symbol === \">\")\n value = this.renderPartial(token, context, partials, originalTemplate);\n else if (symbol === \"&\") value = this.unescapedValue(token, context);\n else if (symbol === \"name\") value = this.escapedValue(token, context);\n else if (symbol === \"text\") value = this.rawValue(token);\n\n if (value !== undefined) buffer += value;\n }\n\n return buffer;\n };\n\n Writer.prototype.renderSection = function renderSection(\n token,\n context,\n partials,\n originalTemplate\n ) {\n var self = this;\n var buffer = \"\";\n var value = context.lookup(token[1]);\n\n // This function is used to render an arbitrary template\n // in the current context by higher-order sections.\n function subRender(template) {\n return self.render(template, context, partials);\n }\n\n if (!value) return;\n\n if (isArray(value)) {\n for (var j = 0, valueLength = value.length; j < valueLength; ++j) {\n buffer += this.renderTokens(\n token[4],\n context.push(value[j]),\n partials,\n originalTemplate\n );\n }\n } else if (\n typeof value === \"object\" ||\n typeof value === \"string\" ||\n typeof value === \"number\"\n ) {\n buffer += this.renderTokens(\n token[4],\n context.push(value),\n partials,\n originalTemplate\n );\n } else if (isFunction(value)) {\n if (typeof originalTemplate !== \"string\")\n throw new Error(\n \"Cannot use higher-order sections without the original template\"\n );\n\n // Extract the portion of the original template that the section contains.\n value = value.call(\n context.view,\n originalTemplate.slice(token[3], token[5]),\n subRender\n );\n\n if (value != null) buffer += value;\n } else {\n buffer += this.renderTokens(\n token[4],\n context,\n partials,\n originalTemplate\n );\n }\n return buffer;\n };\n\n Writer.prototype.renderInverted = function renderInverted(\n token,\n context,\n partials,\n originalTemplate\n ) {\n var value = context.lookup(token[1]);\n\n // Use JavaScript's definition of falsy. Include empty arrays.\n // See https://github.com/janl/mustache.js/issues/186\n if (!value || (isArray(value) && value.length === 0))\n return this.renderTokens(token[4], context, partials, originalTemplate);\n };\n\n Writer.prototype.renderPartial = function renderPartial(\n token,\n context,\n partials\n ) {\n if (!partials) return;\n\n var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];\n if (value != null)\n return this.renderTokens(this.parse(value), context, partials, value);\n };\n\n Writer.prototype.unescapedValue = function unescapedValue(token, context) {\n var value = context.lookup(token[1]);\n if (value != null) return value;\n };\n\n Writer.prototype.escapedValue = function escapedValue(token, context) {\n var value = context.lookup(token[1]);\n if (value != null) return mustache.escape(value);\n };\n\n Writer.prototype.rawValue = function rawValue(token) {\n return token[1];\n };\n\n mustache.name = \"mustache.js\";\n mustache.version = \"2.2.1\";\n mustache.tags = [\"{{\", \"}}\"];\n\n // All high-level mustache.* functions use this writer.\n var defaultWriter = new Writer();\n\n /**\n * Clears all cached templates in the default writer.\n */\n mustache.clearCache = function clearCache() {\n return defaultWriter.clearCache();\n };\n\n /**\n * Parses and caches the given template in the default writer and returns the\n * array of tokens it contains. Doing this ahead of time avoids the need to\n * parse templates on the fly as they are rendered.\n */\n mustache.parse = function parse(template, tags) {\n return defaultWriter.parse(template, tags);\n };\n\n /**\n * Renders the `template` with the given `view` and `partials` using the\n * default writer.\n */\n mustache.render = function render(template, view, partials) {\n if (typeof template !== \"string\") {\n throw new TypeError(\n 'Invalid template! Template should be a \"string\" ' +\n 'but \"' +\n typeStr(template) +\n '\" was given as the first ' +\n \"argument for mustache#render(template, view, partials)\"\n );\n }\n\n return defaultWriter.render(template, view, partials);\n };\n\n // This is here for backwards compatibility with 0.4.x.,\n /*eslint-disable */ // eslint wants camel cased function name\n mustache.to_html = function to_html(template, view, partials, send) {\n /*eslint-enable*/\n\n var result = mustache.render(template, view, partials);\n\n if (isFunction(send)) {\n send(result);\n } else {\n return result;\n }\n };\n\n // Export the escaping function so that the user may override it.\n // See https://github.com/janl/mustache.js/issues/244\n mustache.escape = escapeHtml;\n\n // Export these mainly for testing, but also for advanced usage.\n mustache.Scanner = Scanner;\n mustache.Context = Context;\n mustache.Writer = Writer;\n}\n\nlet Mustache = {};\n\nmustacheFactory(Mustache);\n\nexport default Mustache;\nexport { Mustache };\n","/*\n * Show preview documents\n *\n * See readme.md in this directory.\n *\n * Author: Niels Giesen\n * Copyright (C) 2014-2019 by Berkeley Bridge\n *\n */\nimport { fromApiServer } from \"$json/lib/location\";\nimport { gt, _, bb } from \"$json\";\nimport Mustache from \"$mustache\";\nlet $ = jQuery;\nconst config = bb.propFinder(bb.conf, \"arbitrary.previews\");\n\n// Text that may be shown when there is no default preview available.\nconst fallBackText = config(\"fallbacktext\");\nlet _snips = [];\n\nconst styleElt = config => {\n let s = document.createElement(\"style\");\n s.textContent = `\nhtml {\n height: 100%;\n}\n${config(\n \"iframe.style\",\n `\nhtml {\n background-color: transparent;\n}\n.bb-path {\n box-shadow: none;\n padding: 0;\n max-width: 100%;\n}\n.bb-p-preview-new {\n border-left: 10px solid #189bd8;\n padding-left: 10px;\n}`\n)}\n`;\n return s;\n};\n\nlet iframeStyle = styleElt(config);\n\nlet uncached = url => url + \"&_nocache=\" + new Date().getTime();\n\ngt.addTranslations({\n // Actually means no preview could be loaded (not in the correct format or some other error).\n \"no preview available\": {\n nl: \"geen preview beschikbaar\",\n fr: \"aucune prévisualisation disponible\",\n de: \"keine Vorschau verfügbar\",\n ru: \"предварительный просмотр недоступен\"\n },\n \"open this preview in a new window\": {\n nl: \"open deze preview in een apart venster\",\n fr: \"ouvrir cette prévisualisation dans une autre fenêtre\",\n de: \"öffne diese Vorschau in einem neuem Fenster\",\n ru: \"откройте предварительный просмотр в новом окне\"\n }\n});\n\nfunction compareSnippets($container, _snips) {\n const snippets = $container.find(\"h1,h2,h3,h4,h5,h6,p,ul\");\n let num = 0;\n const tmpsnips = [];\n $.each(snippets, function () {\n let snip = this.innerHTML;\n if (_snips.indexOf(snip) === -1) {\n this.classList.add(\"bb-p-preview-new\");\n if (++num == 1) $container.scrollTo(this);\n }\n tmpsnips.push(snip);\n });\n return tmpsnips;\n}\n\nconst removeEmptyItems = node => {\n let items = node.querySelectorAll(\"li, p\");\n for (let i = items.length; i > 0; --i) {\n let item = items[i - 1];\n if ($.trim(item.textContent) === \"\") {\n if (!item.nextElementSibling && !item.previousElementSibling)\n item.parentNode.parentNode.removeChild(item.parentNode);\n else item.parentNode.removeChild(item);\n }\n }\n};\n\nconst onLoadHandler = (iframe, portion, config) => () => {\n const doc = iframe.contentDocument;\n if (!doc.querySelector(portion)) {\n bb.Mode.unset(\"hasTextInside\");\n } else {\n bb.Mode.set(\"hasText\");\n bb.Mode.set(\"hasTextInside\");\n removeEmptyItems(doc.body);\n doc.head.appendChild(iframeStyle);\n if (config(\"showChanges\")) {\n _snips = compareSnippets($(doc), _snips);\n }\n if (config(\"iframe.resize\") && \"IntersectionObserver\" in window) {\n let options = {\n root: doc.body.parentElement,\n rootMargin: \"0px\",\n threshold: 1.0\n };\n var callback = function (entries, observer) {\n entries.forEach(entry => {\n if (entry.isIntersecting && entry.intersectionRatio == 1) {\n } else {\n let rect = doc.body.getBoundingClientRect();\n if (rect.height) iframe.style.height = `${rect.height + 200}px`;\n }\n });\n };\n let observer = new IntersectionObserver(callback, options);\n observer.observe(doc.body);\n }\n // Previews.trigger('reloaded', [ doc, iframe ]);\n }\n};\n\n(function (win, doc) {\n $(function () {\n var _document; // which document?\n var _textURL; // which url?\n var _outside = false;\n var $container = $(\"#bb-p-preview\");\n let iframe;\n\n if (config(\"iframe.on\")) {\n iframe = document.createElement(\"iframe\");\n iframe.setAttribute(\"class\", \"p-previews-frame\");\n }\n\n /* Remove all notion of current preview\n */\n function cleanUp(all) {\n bb.Mode.unset(\"hasText\");\n bb.Mode.unset(\"hasTextInside\");\n // Following line seems to have been too blunt:\n all && bb.Mode.unset(\"hasPreviews\");\n $container.empty();\n _textURL = undefined;\n _document = undefined;\n }\n\n /* reload\n * @param (String) href: (optional) URL, Will use cached URL if omitted.\n * @param (Srting) document: (optional) Template name. Cache it so\n * we can check its validity later on.\n */\n function reload(url, document, portion) {\n if (url) _textURL = url;\n if (document) _document = document;\n if (_textURL) loadDoc(_textURL, portion);\n }\n\n let loadInside = config(\"iframe.on\")\n ? (url, portion) => {\n bb.Mode.set(\"hasTextInside\");\n $container.empty();\n $container.append(iframe);\n iframe.src = uncached(url);\n var handler = onLoadHandler(iframe, portion, config);\n iframe.onload = handler;\n }\n : (url, portion) => {\n $container.load(\n url + \"&_nocache=\" + new Date().getTime() + ` ${portion}`,\n function (responseText) {\n // If container is empty, loading has apparently failed.\n if ($container.find(portion).length === 0) {\n // cleanUp()\n $container.text(_(\"no preview available\"));\n bb.Mode.unset(\"hasTextInside\");\n } else {\n bb.Mode.set(\"hasTextInside\");\n var btn = $(outsidebutton);\n $container.prepend(btn);\n btn.on(\"click\", function () {\n loadOutside(url);\n });\n if (config(\"showChanges\")) {\n _snips = compareSnippets($container, _snips);\n }\n removeEmptyItems($container.get(0));\n $(doc).trigger(\"bb-p:previews-rendered\", {\n $container,\n responseText\n });\n }\n }\n );\n };\n\n function loadDoc(url, portion) {\n if (!url) return;\n if (!portion) portion = \"#preview\";\n bb.Mode.set(\"hasText\");\n\n $('#bb-p-previews a[href=\"' + url + '\"]')\n .addClass(\"selected\")\n .siblings()\n .removeClass(\"selected\");\n\n if (!_outside) {\n loadInside(fromApiServer(url), portion);\n }\n if (_outside) {\n loadOutside(fromApiServer(url));\n }\n }\n\n function loadOutside(url) {\n _outside = true;\n bb.Mode.unset(\"hasTextInside\");\n $container.empty();\n\n var w = win.open(\n url + \"&_nocache=\" + new Date().getTime(),\n \"Preview\",\n \"resizable=yes,scrollbars=yes\",\n true\n );\n if (!w.closed)\n var watchClose = win.setInterval(function () {\n try {\n if (w.closed) {\n win.clearTimeout(watchClose);\n //Do something here...\n _outside = false;\n bb.Mode.set(\"hasTextInside\");\n reload();\n }\n } catch (e) {}\n }, 200);\n }\n\n $(document).on(\"click\", \"#bb-p-previews a\", function () {\n if (!$container.length) return true;\n reload(this.getAttribute(\"href\"), this.getAttribute(\"data-document\"));\n return false;\n });\n\n var tmpl = $(\"#bb-p-previews-template\").html() || \"\";\n var outsidetmpl = $(\"#bb-p-preview-outside-template\").html();\n if (!outsidetmpl) {\n outsidetmpl =\n '\";\n }\n Mustache.tags = [\"[[\", \"]]\"];\n var outsidebutton = Mustache.render(outsidetmpl, {\n title: _(\"open this preview in a new window\")\n });\n\n // Each navigatory action w/ documents re-renders links and fetches the document.\n $(document).on(\"bb:postHandleData\", function (event, data) {\n if (!data.documents) {\n if (\n (data && data.status && data.status === \"logout successful\") ||\n (data.models && data.models.length > 0)\n ) {\n cleanUp(true);\n }\n return;\n } else {\n if (data.documents.length > 0) {\n bb.Mode.set(\"hasPreviews\");\n // Some plugins used to remove all but the first document => config option 'singular'.\n if (config(\"singular\") === true) {\n data.documents = [data.documents[0]];\n }\n }\n var gHD = getHref(data);\n var selected = data.documents.find(function (doc) {\n return _document === doc.document;\n // The following is more expensive:\n // return (_textURL === (doc.href && doc.href() || gHD.bind(doc)()))\n });\n // autoload: true: load first model-level document.\n // autoload: 'any': load first document, period (could be audit trail).\n if (!selected && config(\"autoload\")) {\n selected = data.documents.find(function (doc) {\n if (config(\"autoload\") === \"any\") return true;\n if (config(\"autoload\") === true) return !doc.href; // Set by previews-include-audit-trail.\n });\n }\n if (selected) {\n selected.selected = true;\n _document = selected.document;\n _textURL = (selected.href && selected.href()) || gHD.bind(selected)();\n } else {\n cleanUp();\n if (fallBackText) $container.text(fallBackText);\n }\n\n var templatedata = {\n documents: data.documents,\n name: function () {\n return this.document.replace(/_/g, \" \");\n },\n breakablename: function () {\n return this.document.replace(/_/g, \" \");\n },\n href: getHref(data)\n };\n $(\"#bb-p-previews\").html(Mustache.render(tmpl, templatedata));\n\n if (selected) {\n reload();\n }\n }\n });\n\n function getHref(data) {\n return function () {\n return (\n \"preview?\" +\n \"dbname=\" +\n data.dbname +\n \"&sessionid=\" +\n data.sessionid +\n \"&uniqueid=\" +\n data.uniqueid +\n \"&template=\" +\n this.document\n );\n };\n }\n\n /**\n * Export loadDoc function\n */\n bb.Plugins = $.extend({}, bb.Plugins, {\n previews: {\n loadDoc: loadDoc,\n reload: reload\n }\n });\n });\n})(window, document);\n","//\n// showdown.js -- A javascript port of Markdown.\n//\n// Copyright (c) 2007 John Fraser.\n//\n// Original Markdown Copyright (c) 2004-2005 John Gruber\n// \n//\n// Redistributable under a BSD-style open source license.\n// See license.txt for more information.\n//\n// The full source distribution is at:\n//\n//\t\t\t\tA A L\n//\t\t\t\tT C A\n//\t\t\t\tT K B\n//\n// \n//\n\n//\n// Wherever possible, Showdown is a straight, line-by-line port\n// of the Perl version of Markdown.\n//\n// This is not a normal parser design; it's basically just a\n// series of string substitutions. It's hard to read and\n// maintain this way, but keeping Showdown close to the original\n// design makes it easier to port new features.\n//\n// More importantly, Showdown behaves like markdown.pl in most\n// edge cases. So web applications can do client-side preview\n// in Javascript, and then build identical HTML on the server.\n//\n// This port needs the new RegExp functionality of ECMA 262,\n// 3rd Edition (i.e. Javascript 1.5). Most modern web browsers\n// should do fine. Even with the new regular expression features,\n// We do a lot of work to emulate Perl's regex functionality.\n// The tricky changes in this file mostly have the \"attacklab:\"\n// label. Major or self-explanatory changes don't.\n//\n// Smart diff tools like Araxis Merge will be able to match up\n// this file with markdown.pl in a useful way. A little tweaking\n// helps: in a copy of markdown.pl, replace \"#\" with \"//\" and\n// replace \"$text\" with \"text\". Be sure to ignore whitespace\n// and line endings.\n//\n\n//\n// Showdown usage:\n//\n// var text = \"Markdown *rocks*.\";\n//\n// var converter = new Showdown.converter();\n// var html = converter.makeHtml(text);\n//\n// alert(html);\n//\n// Note: move the sample code to the bottom of this\n// file before uncommenting it.\n//\n\n//\n// Showdown namespace\n//\nvar Showdown = {};\n\n//\n// converter\n//\n// Wraps all \"globals\" so that the only thing\n// exposed is makeHtml().\n//\nShowdown.converter = function () {\n //\n // Globals:\n //\n\n // Global hashes, used by various utility routines\n var g_urls;\n var g_titles;\n var g_html_blocks;\n\n // Used to track when we're inside an ordered or unordered list\n // (see _ProcessListItems() for details):\n var g_list_level = 0;\n\n this.makeHtml = function (text, inline_only) {\n //\n // Main function. The order in which other subs are called here is\n // essential. Link and image substitutions need to happen before\n // _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the \n // and tags get encoded.\n //\n\n // Clear the global hashes. If we don't clear these, you get conflicts\n // from other articles when generating a page which contains more than\n // one article (e.g. an index page that shows the N most recent\n // articles):\n g_urls = new Array();\n g_titles = new Array();\n g_html_blocks = new Array();\n\n // attacklab: Replace ~ with ~T\n // This lets us use tilde as an escape char to avoid md5 hashes\n // The choice of character is arbitray; anything that isn't\n // magic in Markdown will work.\n text = text.replace(/~/g, \"~T\");\n\n // attacklab: Replace $ with ~D\n // RegExp interprets $ as a special character\n // when it's in a replacement string\n text = text.replace(/\\$/g, \"~D\");\n\n // Standardize line endings\n text = text.replace(/\\r\\n/g, \"\\n\"); // DOS to Unix\n text = text.replace(/\\r/g, \"\\n\"); // Mac to Unix\n\n // Make sure text begins and ends with a couple of newlines:\n text = \"\\n\\n\" + text + \"\\n\\n\";\n\n // Convert all tabs to spaces.\n text = _Detab(text);\n\n // Strip any lines consisting only of spaces and tabs.\n // This makes subsequent regexen easier to write, because we can\n // match consecutive blank lines with /\\n+/ instead of something\n // contorted like /[ \\t]*\\n+/ .\n text = text.replace(/^[ \\t]+$/gm, \"\");\n\n // Turn block-level HTML blocks into hash entries\n text = _HashHTMLBlocks(text);\n\n // Strip link definitions, store in hashes.\n text = _StripLinkDefinitions(text);\n\n if (inline_only) text = _RunSpanGamut(text);\n else text = _RunBlockGamut(text);\n\n text = _UnescapeSpecialChars(text);\n\n // attacklab: Restore dollar signs\n text = text.replace(/~D/g, \"$$\");\n\n // attacklab: Restore tildes\n text = text.replace(/~T/g, \"~\");\n\n return text;\n };\n\n var _StripLinkDefinitions = function (text) {\n //\n // Strips link definitions from text, stores the URLs and titles in\n // hash references.\n //\n\n // Link defs are in the form: ^[id]: url \"optional title\"\n\n /*\n var text = text.replace(/\n ^[ ]{0,3}\\[(.+)\\]: // id = $1 attacklab: g_tab_width - 1\n [ \\t]*\n \\n?\t\t\t\t// maybe *one* newline\n [ \\t]*\n (\\S+?)>?\t\t\t// url = $2\n [ \\t]*\n \\n?\t\t\t\t// maybe one newline\n [ \\t]*\n (?:\n (\\n*)\t\t\t\t// any lines skipped = $3 attacklab: lookbehind removed\n [\"(]\n (.+?)\t\t\t\t// title = $4\n [\")]\n [ \\t]*\n )?\t\t\t\t\t// title is optional\n (?:\\n+|$)\n /gm,\n function(){...});\n */\n var text = text.replace(\n /^[ ]{0,3}\\[(.+)\\]:[ \\t]*\\n?[ \\t]*(\\S+?)>?[ \\t]*\\n?[ \\t]*(?:(\\n*)[\"(](.+?)[\")][ \\t]*)?(?:\\n+|\\Z)/gm,\n function (wholeMatch, m1, m2, m3, m4) {\n m1 = m1.toLowerCase();\n g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive\n if (m3) {\n // Oops, found blank lines, so it's not a title.\n // Put back the parenthetical statement we stole.\n return m3 + m4;\n } else if (m4) {\n g_titles[m1] = m4.replace(/\"/g, \""\");\n }\n\n // Completely remove the definition from the text\n return \"\";\n }\n );\n\n return text;\n };\n\n var _HashHTMLBlocks = function (text) {\n // attacklab: Double up blank lines to reduce lookaround\n text = text.replace(/\\n/g, \"\\n\\n\");\n\n // Hashify HTML blocks:\n // We only want to do this for block-level HTML tags, such as headers,\n // lists, and tables. That's because we still want to wrap
\");\n }\n );\n\n text = text.replace(\n /^(.+)[ \\t]*\\n-+[ \\t]*\\n+/gm,\n function (matchFound, m1) {\n return hashBlock(\"
\" + _RunSpanGamut(m1) + \"
\");\n }\n );\n\n // atx-style headers:\n // # Header 1\n // ## Header 2\n // ## Header 2 with closing hashes ##\n // ...\n // ###### Header 6\n //\n\n /*\n text = text.replace(/\n ^(\\#{1,6})\t\t\t\t// $1 = string of #'s\n [ \\t]*\n (.+?)\t\t\t\t\t// $2 = Header text\n [ \\t]*\n \\#*\t\t\t\t\t\t// optional closing #'s (not counted)\n \\n+\n /gm, function() {...});\n */\n\n text = text.replace(\n /^(\\#{1,6})[ \\t]*(.+?)[ \\t]*\\#*\\n+/gm,\n function (wholeMatch, m1, m2) {\n var h_level = m1.length;\n return hashBlock(\n \"\" + _RunSpanGamut(m2) + \"\"\n );\n }\n );\n\n return text;\n };\n\n // This declaration keeps Dojo compressor from outputting garbage:\n var _ProcessListItems;\n\n var _DoLists = function (text) {\n //\n // Form HTML ordered (numbered) and unordered (bulleted) lists.\n //\n\n // attacklab: add sentinel to hack around khtml/safari bug:\n // http://bugs.webkit.org/show_bug.cgi?id=11231\n text += \"~0\";\n\n // Re-usable pattern to match any entirel ul or ol list:\n\n /*\n var whole_list = /\n (\t\t\t\t\t\t\t\t\t// $1 = whole list\n (\t\t\t\t\t\t\t\t// $2\n [ ]{0,3}\t\t\t\t\t// attacklab: g_tab_width - 1\n ([*+-]|\\d+[.])\t\t\t\t// $3 = first list item marker\n [ \\t]+\n )\n [^\\r]+?\n (\t\t\t\t\t\t\t\t// $4\n ~0\t\t\t\t\t\t\t// sentinel for workaround; should be $\n |\n \\n{2,}\n (?=\\S)\n (?!\t\t\t\t\t\t\t// Negative lookahead for another list item marker\n [ \\t]*\n (?:[*+-]|\\d+[.])[ \\t]+\n )\n )\n )/g\n */\n var whole_list =\n /^(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/gm;\n\n if (g_list_level) {\n text = text.replace(whole_list, function (wholeMatch, m1, m2) {\n var list = m1;\n var list_type = m2.search(/[*+-]/g) > -1 ? \"ul\" : \"ol\";\n\n // Turn double returns into triple returns, so that we can make a\n // paragraph for the last item in a list, if necessary:\n list = list.replace(/\\n{2,}/g, \"\\n\\n\\n\");\n var result = _ProcessListItems(list);\n\n // Trim any trailing whitespace, to put the closing `$list_type>`\n // up on the preceding line, to get it past the current stupid\n // HTML block parser. This is a hack to work around the terrible\n // hack that is the HTML block parser.\n result = result.replace(/\\s+$/, \"\");\n result = \"<\" + list_type + \">\" + result + \"\" + list_type + \">\\n\";\n return result;\n });\n } else {\n whole_list =\n /(\\n\\n|^\\n?)(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/g;\n text = text.replace(whole_list, function (wholeMatch, m1, m2, m3) {\n var runup = m1;\n var list = m2;\n\n var list_type = m3.search(/[*+-]/g) > -1 ? \"ul\" : \"ol\";\n // Turn double returns into triple returns, so that we can make a\n // paragraph for the last item in a list, if necessary:\n var list = list.replace(/\\n{2,}/g, \"\\n\\n\\n\");\n var result = _ProcessListItems(list);\n result =\n runup + \"<\" + list_type + \">\\n\" + result + \"\" + list_type + \">\\n\";\n return result;\n });\n }\n\n // attacklab: strip sentinel\n text = text.replace(/~0/, \"\");\n\n return text;\n };\n\n _ProcessListItems = function (list_str) {\n //\n // Process the contents of a single ordered or unordered list, splitting it\n // into individual list items.\n //\n // The $g_list_level global keeps track of when we're inside a list.\n // Each time we enter a list, we increment it; when we leave a list,\n // we decrement. If it's zero, we're not in a list anymore.\n //\n // We do this because when we're not inside a list, we want to treat\n // something like this:\n //\n // I recommend upgrading to version\n // 8. Oops, now this line is treated\n // as a sub-list.\n //\n // As a single paragraph, despite the fact that the second line starts\n // with a digit-period-space sequence.\n //\n // Whereas when we're inside a list (or sub-list), that line will be\n // treated as the start of a sub-list. What a kludge, huh? This is\n // an aspect of Markdown's syntax that's hard to parse perfectly\n // without resorting to mind-reading. Perhaps the solution is to\n // change the syntax rules such that sub-lists must start with a\n // starting cardinal number; e.g. \"1.\" or \"a.\".\n\n g_list_level++;\n\n // trim trailing blank lines:\n list_str = list_str.replace(/\\n{2,}$/, \"\\n\");\n\n // attacklab: add sentinel to emulate \\z\n list_str += \"~0\";\n\n /*\n list_str = list_str.replace(/\n (\\n)?\t\t\t\t\t\t\t// leading line = $1\n (^[ \\t]*)\t\t\t\t\t\t// leading whitespace = $2\n ([*+-]|\\d+[.]) [ \\t]+\t\t\t// list marker = $3\n ([^\\r]+?\t\t\t\t\t\t// list item text = $4\n (\\n{1,2}))\n (?= \\n* (~0 | \\2 ([*+-]|\\d+[.]) [ \\t]+))\n /gm, function(){...});\n */\n list_str = list_str.replace(\n /(\\n)?(^[ \\t]*)([*+-]|\\d+[.])[ \\t]+([^\\r]+?(\\n{1,2}))(?=\\n*(~0|\\2([*+-]|\\d+[.])[ \\t]+))/gm,\n function (wholeMatch, m1, m2, m3, m4) {\n var item = m4;\n var leading_line = m1;\n var leading_space = m2;\n\n if (leading_line || item.search(/\\n{2,}/) > -1) {\n item = _RunBlockGamut(_Outdent(item));\n } else {\n // Recursion for sub-lists:\n item = _DoLists(_Outdent(item));\n item = item.replace(/\\n$/, \"\"); // chomp(item)\n item = _RunSpanGamut(item);\n }\n\n return \"
\" + item + \"
\\n\";\n }\n );\n\n // attacklab: strip sentinel\n list_str = list_str.replace(/~0/g, \"\");\n\n g_list_level--;\n return list_str;\n };\n\n var _DoCodeBlocks = function (text) {\n //\n // Process Markdown `
` blocks.\n //\n\n /*\n text = text.replace(text,\n /(?:\\n\\n|^)\n (\t\t\t\t\t\t\t\t// $1 = the code block -- one or more lines, starting with a space/tab\n (?:\n (?:[ ]{4}|\\t)\t\t\t// Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width\n .*\\n+\n )+\n )\n (\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))\t// attacklab: g_tab_width\n /g,function(){...});\n */\n\n // attacklab: sentinel workarounds for lack of \\A and \\Z, safari\\khtml bug\n text += \"~0\";\n\n text = text.replace(\n /(?:\\n\\n|^)((?:(?:[ ]{4}|\\t).*\\n+)+)(\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))/g,\n function (wholeMatch, m1, m2) {\n var codeblock = m1;\n var nextChar = m2;\n\n codeblock = _EncodeCode(_Outdent(codeblock));\n codeblock = _Detab(codeblock);\n codeblock = codeblock.replace(/^\\n+/g, \"\"); // trim leading newlines\n codeblock = codeblock.replace(/\\n+$/g, \"\"); // trim trailing whitespace\n\n codeblock = \"
\" + codeblock + \"\\n
\";\n\n return hashBlock(codeblock) + nextChar;\n }\n );\n\n // attacklab: strip sentinel\n text = text.replace(/~0/, \"\");\n\n return text;\n };\n\n var hashBlock = function (text) {\n text = text.replace(/(^\\n+|\\n+$)/g, \"\");\n return \"\\n\\n~K\" + (g_html_blocks.push(text) - 1) + \"K\\n\\n\";\n };\n\n var _DoCodeSpans = function (text) {\n //\n // * Backtick quotes are used for spans.\n //\n // * You can use multiple backticks as the delimiters if you want to\n // include literal backticks in the code span. So, this input:\n //\n // Just type ``foo `bar` baz`` at the prompt.\n //\n // Will translate to:\n //\n //
Just type foo `bar` baz at the prompt.
\n //\n //\tThere's no arbitrary limit to the number of backticks you\n //\tcan use as delimters. If you need three consecutive backticks\n //\tin your code, use four for delimiters, etc.\n //\n // * You can use spaces to get literal backticks at the edges:\n //\n // ... type `` `bar` `` ...\n //\n // Turns to:\n //\n // ... type `bar` ...\n //\n\n /*\n text = text.replace(/\n (^|[^\\\\])\t\t\t\t\t// Character before opening ` can't be a backslash\n (`+)\t\t\t\t\t\t// $2 = Opening run of `\n (\t\t\t\t\t\t\t// $3 = The code block\n [^\\r]*?\n [^`]\t\t\t\t\t// attacklab: work around lack of lookbehind\n )\n \\2\t\t\t\t\t\t\t// Matching closer\n (?!`)\n /gm, function(){...});\n */\n\n text = text.replace(\n /(^|[^\\\\])(`+)([^\\r]*?[^`])\\2(?!`)/gm,\n function (wholeMatch, m1, m2, m3, m4) {\n var c = m3;\n c = c.replace(/^([ \\t]*)/g, \"\"); // leading whitespace\n c = c.replace(/[ \\t]*$/g, \"\"); // trailing whitespace\n c = _EncodeCode(c);\n return m1 + \"\" + c + \"\";\n }\n );\n\n return text;\n };\n\n var _EncodeCode = function (text) {\n //\n // Encode/escape certain characters inside Markdown code runs.\n // The point is that in code, these characters are literals,\n // and lose their special Markdown meanings.\n //\n // Encode all ampersands; HTML entities are not\n // entities within a Markdown code span.\n text = text.replace(/&/g, \"&\");\n\n // Do the angle bracket song and dance:\n text = text.replace(//g, \">\");\n\n // Now, escape characters that are magic in Markdown:\n text = escapeCharacters(text, \"*_{}[]\\\\\", false);\n\n // jj the line above breaks this:\n //---\n\n //* Item\n\n // 1. Subitem\n\n // special char: *\n //---\n\n return text;\n };\n\n var _DoItalicsAndBold = function (text) {\n // must go first:\n text = text.replace(\n /(\\*\\*|__)(?=\\S)([^\\r]*?\\S[*_]*)\\1/g,\n \"$2\"\n );\n\n text = text.replace(/(\\*|_)(?=\\S)([^\\r]*?\\S)\\1/g, \"$2\");\n\n return text;\n };\n\n var _DoBlockQuotes = function (text) {\n /*\n text = text.replace(/\n (\t\t\t\t\t\t\t\t// Wrap whole match in $1\n (\n ^[ \\t]*>[ \\t]?\t\t\t// '>' at the start of a line\n .+\\n\t\t\t\t\t// rest of the first line\n (.+\\n)*\t\t\t\t\t// subsequent consecutive lines\n \\n*\t\t\t\t\t\t// blanks\n )+\n )\n /gm, function(){...});\n */\n\n text = text.replace(\n /((^[ \\t]*>[ \\t]?.+\\n(.+\\n)*\\n*)+)/gm,\n function (wholeMatch, m1) {\n var bq = m1;\n\n // attacklab: hack around Konqueror 3.5.4 bug:\n // \"----------bug\".replace(/^-/g,\"\") == \"bug\"\n\n bq = bq.replace(/^[ \\t]*>[ \\t]?/gm, \"~0\"); // trim one level of quoting\n\n // attacklab: clean up hack\n bq = bq.replace(/~0/g, \"\");\n\n bq = bq.replace(/^[ \\t]+$/gm, \"\"); // trim whitespace-only lines\n bq = _RunBlockGamut(bq); // recurse\n\n bq = bq.replace(/(^|\\n)/g, \"$1 \");\n // These leading spaces screw with
content, so we need to fix that:\n bq = bq.replace(\n /(\\s*
[^\\r]+?<\\/pre>)/gm,\n function (wholeMatch, m1) {\n var pre = m1;\n // attacklab: hack around Konqueror 3.5.4 bug:\n pre = pre.replace(/^ /gm, \"~0\");\n pre = pre.replace(/~0/g, \"\");\n return pre;\n }\n );\n\n return hashBlock(\"
\\n\" + bq + \"\\n
\");\n }\n );\n return text;\n };\n\n var _FormParagraphs = function (text) {\n //\n // Params:\n // $text - string to process with html
tags\n //\n\n // Strip leading and trailing lines:\n text = text.replace(/^\\n+/g, \"\");\n text = text.replace(/\\n+$/g, \"\");\n\n var grafs = text.split(/\\n{2,}/g);\n var grafsOut = new Array();\n\n //\n // Wrap
tags.\n //\n var end = grafs.length;\n for (var i = 0; i < end; i++) {\n var str = grafs[i];\n\n // if this is an HTML marker, copy it\n if (str.search(/~K(\\d+)K/g) >= 0) {\n grafsOut.push(str);\n } else if (str.search(/\\S/) >= 0) {\n str = _RunSpanGamut(str);\n str = str.replace(/^([ \\t]*)/g, \"