'\n}\n\nexport function capitalizePrint (obj) {\n return obj.charAt(0).toUpperCase() + obj.slice(1)\n}\n\nexport function collectStyles (element, params) {\n const win = document.defaultView || window\n\n // String variable to hold styling for each element\n let elementStyle = ''\n\n // Loop over computed styles\n const styles = win.getComputedStyle(element, '')\n\n for (let key = 0; key < styles.length; key++) {\n // Check if style should be processed\n if (params.targetStyles.indexOf('*') !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {\n if (styles.getPropertyValue(styles[key])) elementStyle += styles[key] + ':' + styles.getPropertyValue(styles[key]) + ';'\n }\n }\n\n // Print friendly defaults (deprecated)\n elementStyle += 'max-width: ' + params.maxWidth + 'px !important; font-size: ' + params.font_size + ' !important;'\n\n return elementStyle\n}\n\nfunction targetStylesMatch (styles, value) {\n for (let i = 0; i < styles.length; i++) {\n if (typeof value === 'object' && value.indexOf(styles[i]) !== -1) return true\n }\n return false\n}\n\nexport function addHeader (printElement, params) {\n // Create the header container div\n const headerContainer = document.createElement('div')\n\n // Check if the header is text or raw html\n if (isRawHTML(params.header)) {\n headerContainer.innerHTML = params.header\n } else {\n // Create header element\n const headerElement = document.createElement('h1')\n\n // Create header text node\n const headerNode = document.createTextNode(params.header)\n\n // Build and style\n headerElement.appendChild(headerNode)\n headerElement.setAttribute('style', params.headerStyle)\n headerContainer.appendChild(headerElement)\n }\n\n printElement.insertBefore(headerContainer, printElement.childNodes[0])\n}\n\nexport function cleanUp (params) {\n // If we are showing a feedback message to user, remove it\n if (params.showModal) Modal.close()\n\n // Check for a finished loading hook function\n if (params.onLoadingEnd) params.onLoadingEnd()\n\n // If preloading pdf files, clean blob url\n if (params.showModal || params.onLoadingStart) window.URL.revokeObjectURL(params.printable)\n\n // Run onPrintDialogClose callback\n let event = 'mouseover'\n\n if (Browser.isChrome() || Browser.isFirefox()) {\n // Ps.: Firefox will require an extra click in the document to fire the focus event.\n event = 'focus'\n }\n\n const handler = () => {\n // Make sure the event only happens once.\n window.removeEventListener(event, handler)\n\n params.onPrintDialogClose()\n\n // Remove iframe from the DOM\n const iframe = document.getElementById(params.frameId)\n\n if (iframe) {\n iframe.remove()\n }\n }\n\n window.addEventListener(event, handler)\n}\n\nexport function isRawHTML (raw) {\n const regexHtml = new RegExp('<([A-Za-z][A-Za-z0-9]*)\\\\b[^>]*>(.*?)\\\\1>')\n return regexHtml.test(raw)\n}\n", "import { collectStyles, addHeader } from './functions'\nimport Print from './print'\n\nexport default {\n print: (params, printFrame) => {\n // Get the DOM printable element\n const printElement = isHtmlElement(params.printable) ? params.printable : document.getElementById(params.printable)\n\n // Check if the element exists\n if (!printElement) {\n window.console.error('Invalid HTML element id: ' + params.printable)\n return\n }\n\n // Clone the target element including its children (if available)\n params.printableElement = cloneElement(printElement, params)\n\n // Add header\n if (params.header) {\n addHeader(params.printableElement, params)\n }\n\n // Print html element contents\n Print.send(params, printFrame)\n }\n}\n\nfunction cloneElement (element, params) {\n // Clone the main node (if not already inside the recursion process)\n const clone = element.cloneNode()\n\n // Loop over and process the children elements / nodes (including text nodes)\n const childNodesArray = Array.prototype.slice.call(element.childNodes)\n for (let i = 0; i < childNodesArray.length; i++) {\n // Check if we are skipping the current element\n if (params.ignoreElements.indexOf(childNodesArray[i].id) !== -1) {\n continue\n }\n\n // Clone the child element\n const clonedChild = cloneElement(childNodesArray[i], params)\n\n // Attach the cloned child to the cloned parent node\n clone.appendChild(clonedChild)\n }\n\n // Get all styling for print element (for nodes of type element only)\n if (params.scanStyles && element.nodeType === 1) {\n clone.setAttribute('style', collectStyles(element, params))\n }\n\n // Check if the element needs any state processing (copy user input data)\n switch (element.tagName) {\n case 'SELECT':\n // Copy the current selection value to its clone\n clone.value = element.value\n break\n case 'CANVAS':\n // Copy the canvas content to its clone\n clone.getContext('2d').drawImage(element, 0, 0)\n break\n }\n\n return clone\n}\n\nfunction isHtmlElement (printable) {\n // Check if element is instance of HTMLElement or has nodeType === 1 (for elements in iframe)\n return typeof printable === 'object' && printable && (printable instanceof HTMLElement || printable.nodeType === 1)\n}\n", "import { addHeader } from './functions'\nimport Print from './print'\nimport Browser from './browser'\n\nexport default {\n print: (params, printFrame) => {\n // Check if we are printing one image or multiple images\n if (params.printable.constructor !== Array) {\n // Create array with one image\n params.printable = [params.printable]\n }\n\n // Create printable element (container)\n params.printableElement = document.createElement('div')\n\n // Create all image elements and append them to the printable container\n params.printable.forEach(src => {\n // Create the image element\n const img = document.createElement('img')\n img.setAttribute('style', params.imageStyle)\n\n // Set image src with the file url\n img.src = src\n\n // The following block is for Firefox, which for some reason requires the image's src to be fully qualified in\n // order to print it\n if (Browser.isFirefox()) {\n const fullyQualifiedSrc = img.src\n img.src = fullyQualifiedSrc\n }\n\n // Create the image wrapper\n const imageWrapper = document.createElement('div')\n\n // Append image to the wrapper element\n imageWrapper.appendChild(img)\n\n // Append wrapper to the printable element\n params.printableElement.appendChild(imageWrapper)\n })\n\n // Check if we are adding a print header\n if (params.header) addHeader(params.printableElement, params)\n\n // Print image\n Print.send(params, printFrame)\n }\n}\n", "'use strict'\n\nimport Browser from './browser'\nimport Modal from './modal'\nimport Pdf from './pdf'\nimport Html from './html'\nimport RawHtml from './raw-html'\nimport Image from './image'\nimport Json from './json'\n\nconst printTypes = ['pdf', 'html', 'image', 'json', 'raw-html']\n\nexport default {\n init () {\n const params = {\n printable: null,\n fallbackPrintable: null,\n type: 'pdf',\n header: null,\n headerStyle: 'font-weight: 300;',\n maxWidth: 800,\n properties: null,\n gridHeaderStyle: 'font-weight: bold; padding: 5px; border: 1px solid #dddddd;',\n gridStyle: 'border: 1px solid lightgray; margin-bottom: -1px;',\n showModal: false,\n onError: (error) => { throw error },\n onLoadingStart: null,\n onLoadingEnd: null,\n onPrintDialogClose: () => {},\n onIncompatibleBrowser: () => {},\n modalMessage: 'Retrieving Document...',\n frameId: 'printJS',\n printableElement: null,\n documentTitle: 'Document',\n targetStyle: ['clear', 'display', 'width', 'min-width', 'height', 'min-height', 'max-height'],\n targetStyles: ['border', 'box', 'break', 'text-decoration'],\n ignoreElements: [],\n repeatTableHeader: true,\n css: null,\n style: null,\n scanStyles: true,\n base64: false,\n\n // Deprecated\n onPdfOpen: null,\n font: 'TimesNewRoman',\n font_size: '12pt',\n honorMarginPadding: true,\n honorColor: false,\n imageStyle: 'max-width: 100%;'\n }\n\n // Check if a printable document or object was supplied\n const args = arguments[0]\n if (args === undefined) {\n throw new Error('printJS expects at least 1 attribute.')\n }\n\n // Process parameters\n switch (typeof args) {\n case 'string':\n params.printable = encodeURI(args)\n params.fallbackPrintable = params.printable\n params.type = arguments[1] || params.type\n break\n case 'object':\n params.printable = args.printable\n params.fallbackPrintable = typeof args.fallbackPrintable !== 'undefined' ? args.fallbackPrintable : params.printable\n params.fallbackPrintable = params.base64 ? `data:application/pdf;base64,${params.fallbackPrintable}` : params.fallbackPrintable\n for (var k in params) {\n if (k === 'printable' || k === 'fallbackPrintable') continue\n\n params[k] = typeof args[k] !== 'undefined' ? args[k] : params[k]\n }\n break\n default:\n throw new Error('Unexpected argument type! Expected \"string\" or \"object\", got ' + typeof args)\n }\n\n // Validate printable\n if (!params.printable) throw new Error('Missing printable information.')\n\n // Validate type\n if (!params.type || typeof params.type !== 'string' || printTypes.indexOf(params.type.toLowerCase()) === -1) {\n throw new Error('Invalid print type. Available types are: pdf, html, image and json.')\n }\n\n // Check if we are showing a feedback message to the user (useful for large files)\n if (params.showModal) Modal.show(params)\n\n // Check for a print start hook function\n if (params.onLoadingStart) params.onLoadingStart()\n\n // To prevent duplication and issues, remove any used printFrame from the DOM\n const usedFrame = document.getElementById(params.frameId)\n\n if (usedFrame) usedFrame.parentNode.removeChild(usedFrame)\n\n // Create a new iframe for the print job\n const printFrame = document.createElement('iframe')\n\n if (Browser.isFirefox()) {\n // Set the iframe to be is visible on the page (guaranteed by fixed position) but hidden using opacity 0, because\n // this works in Firefox. The height needs to be sufficient for some part of the document other than the PDF\n // viewer's toolbar to be visible in the page\n printFrame.setAttribute('style', 'width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0')\n } else {\n // Hide the iframe in other browsers\n printFrame.setAttribute('style', 'visibility: hidden; height: 0; width: 0; position: absolute; border: 0')\n }\n\n // Set iframe element id\n printFrame.setAttribute('id', params.frameId)\n\n // For non pdf printing, pass an html document string to srcdoc (force onload callback)\n if (params.type !== 'pdf') {\n printFrame.srcdoc = '' + params.documentTitle + ''\n\n // Attach css files\n if (params.css) {\n // Add support for single file\n if (!Array.isArray(params.css)) params.css = [params.css]\n\n // Create link tags for each css file\n params.css.forEach(file => {\n printFrame.srcdoc += ''\n })\n }\n\n printFrame.srcdoc += ''\n }\n\n // Check printable type\n switch (params.type) {\n case 'pdf':\n // Check browser support for pdf and if not supported we will just open the pdf file instead\n if (Browser.isIE()) {\n try {\n console.info('Print.js doesn\\'t support PDF printing in Internet Explorer.')\n const win = window.open(params.fallbackPrintable, '_blank')\n win.focus()\n params.onIncompatibleBrowser()\n } catch (error) {\n params.onError(error)\n } finally {\n // Make sure there is no loading modal opened\n if (params.showModal) Modal.close()\n if (params.onLoadingEnd) params.onLoadingEnd()\n }\n } else {\n Pdf.print(params, printFrame)\n }\n break\n case 'image':\n Image.print(params, printFrame)\n break\n case 'html':\n Html.print(params, printFrame)\n break\n case 'raw-html':\n RawHtml.print(params, printFrame)\n break\n case 'json':\n Json.print(params, printFrame)\n break\n }\n }\n}\n", "import { capitalizePrint, addHeader } from './functions'\nimport Print from './print'\n\nexport default {\n print: (params, printFrame) => {\n // Check if we received proper data\n if (typeof params.printable !== 'object') {\n throw new Error('Invalid javascript data object (JSON).')\n }\n\n // Validate repeatTableHeader\n if (typeof params.repeatTableHeader !== 'boolean') {\n throw new Error('Invalid value for repeatTableHeader attribute (JSON).')\n }\n\n // Validate properties\n if (!params.properties || !Array.isArray(params.properties)) {\n throw new Error('Invalid properties array for your JSON data.')\n }\n\n // We will format the property objects to keep the JSON api compatible with older releases\n params.properties = params.properties.map(property => {\n return {\n field: typeof property === 'object' ? property.field : property,\n displayName: typeof property === 'object' ? property.displayName : property,\n columnSize: typeof property === 'object' && property.columnSize ? property.columnSize + ';' : 100 / params.properties.length + '%;'\n }\n })\n\n // Create a print container element\n params.printableElement = document.createElement('div')\n\n // Check if we are adding a print header\n if (params.header) {\n addHeader(params.printableElement, params)\n }\n\n // Build the printable html data\n params.printableElement.innerHTML += jsonToHTML(params)\n\n // Print the json data\n Print.send(params, printFrame)\n }\n}\n\nfunction jsonToHTML (params) {\n // Get the row and column data\n const data = params.printable\n const properties = params.properties\n\n // Create a html table\n let htmlData = '
'\n\n // Check if the header should be repeated\n if (params.repeatTableHeader) {\n htmlData += ''\n }\n\n // Add the table header row\n htmlData += '
'\n\n // Add the table header columns\n for (let a = 0; a < properties.length; a++) {\n htmlData += '
'\n }\n\n // Add the closing tag for the table header row\n htmlData += '
'\n\n // If the table header is marked as repeated, add the closing tag\n if (params.repeatTableHeader) {\n htmlData += ''\n }\n\n // Create the table body\n htmlData += ''\n\n // Add the table data rows\n for (let i = 0; i < data.length; i++) {\n // Add the row starting tag\n htmlData += '
'\n\n // Print selected properties only\n for (let n = 0; n < properties.length; n++) {\n let stringData = data[i]\n\n // Support nested objects\n const property = properties[n].field.split('.')\n if (property.length > 1) {\n for (let p = 0; p < property.length; p++) {\n stringData = stringData[property[p]]\n }\n } else {\n stringData = stringData[properties[n].field]\n }\n\n // Add the row contents and styles\n htmlData += '
\"\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", "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", "import { gt } from \"$json\";\n/* a11y-errors:\n *\n * Provide more accessible error texts\n *\n * Supported languages: nl, en (partially)\n *\n * Author: Niels Giesen\n * Copyright 2018 Berkeley Bridge\n *\n */\n(function ($) {\n var translations = {\n \"You may now safely close this window\": {\n nl: \"Je kunt het venster nu sluiten\"\n },\n \"Your models\": {\n nl: \"Jouw modellen\"\n },\n \"Your sessions\": {\n nl: \"Jouw sessies\"\n },\n \"Error: No response from server, server probably down\": {\n nl: \"Fout: Server is tijdelijk buiten gebruik. Je moet je opnieuw aanmelden.\"\n },\n \"Session has timed out. Please log in again.\": {\n nl: \"De sessie is afgelopen. Je moet je opnieuw aanmelden.\"\n },\n \"Input required\": {\n nl: \"Je hebt nog niets ingevuld in dit verplichte veld.\",\n en: \"You haven't yet filled in this required field.\"\n },\n \"Choice required\": {\n nl: \"Je hebt nog geen keuze gemaakt; dit is verplicht bij deze opties.\",\n en: \"You haven't yet selected any option; please make a choice (required).\"\n },\n \"Value has to lie between {minimum} and {maximum}\": {\n nl: \"Het getal in dit veld is kleiner dan {minimum} of groter dan {maximum}; dit is niet toegestaan. Voer een getal in tussen {minimum} en {maximum}.\",\n en: \"The Value has to lie between {minimum} and {maximum}.\"\n },\n \"Date has to lie between {minimum} and {maximum}\": {\n nl: \"De datum in dit veld valt voor of na {minimum} en {maximum}; dit is niet toegestaan. Voer een datum in tussen {minimum} en {maximum}.\",\n en: \"Date has to lie between {minimum} and {maximum}.\"\n },\n \"Negative number or zero expected\": {\n nl: \"Het getal in dit veld is niet 0 of lager dan 0; dit is niet toegestaan. Voer in: 0 of een getal lager dan 0 (voorbeelden: -4 of -55).\",\n en: \"Negative number or zero expected\"\n },\n \"Negative number expected\": {\n nl: \"Het getal in dit veld moet lager zijn dan 0, maar is het niet. Voer getal in onder 0 (voorbeelden: -4 of -55).\",\n en: \"Negative number expected\"\n },\n \"Value has to lie below {maximum}\": {\n nl: \"Het getal in dit veld moet lager zijn dan {maximum}, maar is dat niet. Voer een getal in lager dan {maximum+1}.\",\n en: \"Value has to lie below {maximum+1}\"\n },\n \"Positive number or zero expected\": {\n nl: \"Het getal in dit veld moet 0 zijn of hoger dan 0, maar is dat niet. Voer het getal 0 in of een hoger getal, bijvoorbeeld 3 of 222.\",\n en: \"Positive number or zero expected\"\n },\n \"Positive number expected\": {\n nl: \"Het getal in dit veld moet hoger dan 0 zijn, maar is dat niet. Voer een getal in hoger dan 0 (voorbeelden: 1 of 42).\",\n en: \"Positive number expected\"\n },\n \"Value has to lie above {minimum}\": {\n nl: \"Het getal in dit veld moet hoger zijn dan {minimum}, maar is dat niet. Voer een getal in hoger dan {minimum-1}.\",\n en: \"Value has to lie above {minimum-1}\"\n },\n \"A date after {maximum} is not allowed\": {\n nl: \"De datum die je hebt ingevoerd in dit veld ligt n\u00E1 {maximum}; dit is niet toegestaan.\",\n en: \"A date after {maximum} is not allowed\"\n },\n \"A date before {minimum} is not allowed\": {\n nl: \"De datum die je hebt ingevoerd in dit veld ligt v\u00F3\u00F3r {minimum}; dit is niet toegestaan.\",\n en: \"A date before {minimum} is not allowed\"\n },\n \"Invalid date\": {\n nl: \"Je hebt een ongeldige datum ingevoerd. Een geldige datum heeft het formaat dd-mm-jjjj.\",\n en: \"Invalid date\"\n },\n \"Text length exceeds the maximum of {maxlength} characters\": {\n nl: \"Deze tekst bevat meer dan het maximum aantal karakters {maxlength}.\",\n en: \"Text length exceeds the maximum of {maxlength} characters\"\n },\n \"Maximum allowed characters: {0}\": {\n nl: \"Deze tekst bevat meer dan het maximum aantal karakters {0}.\",\n en: \"Maximum allowed characters: {0}\"\n }\n };\n\n $(function () {\n gt.addTranslations(translations);\n });\n})(jQuery);\n", "/*\n auto-scroll.js\n \n A plugin to scroll the window to either a\n specified selector, or #bb-q with a possible\n offset.\n \n e.g. config:\n\n conf.template: {\n \"auto-scroll\": {\n \"offset\": \"-30\", (This is a px value)\n \"custom-selector\": \"#bb-q\",\n \"scroller-selector\": \"#some-parent\" (If not provided, 'html' is considered the parent to scroll)\n }\n }\n\n If no directive is given, default is:\n\n conf.template: {\n \"auto-scroll\": {\n \"offset\": \"-30\"\n \"custom-selector\": \"#bb-q\",\n \"scroller-selector\": \"html\"\n }\n }\n \n If scroller-selector is html (default), then the\n position of the custom selector is determined\n relative to the document. Otherwise it will be\n determined reletive to the scroller-selector.\n\n NB: This probably won't work without:\n\n conf.core: {\n \"scrollToSelectedGroup\": false\n }\n\n auto-scroll also exports it's CONFIG object.\n The object has a setter for props, which will\n fall back to the default if set to \"default\"\n or if your config fails the sanitycheck.\n You may need this for e.g. if a plugin \n changes the layout and makes the auto scroll \n position no longer valid etc...\n\n Usage example:\n\n import { CONFIG as scrollconfig } from \"[relative path]/plugins/auto-scroll/auto-scroll\";\n ...\n if (window.innerWidth <= 943) {\n scrollconfig.props = { selector: \".l-content--left\" };\n } else {\n scrollconfig.props = \"default\";\n }\n\n Please don't skirt the sanitycheck:\n scrollconfig.props.selector = ...\n\n Author: Tim Bauwens\n Copyright xxllnc 2023\n*/\n\nimport { bb } from \"$json\";\nimport { has, allPass } from \"$json/lib/functional\";\n\nconst scrollNow = (delay = 500) => {\n window.setTimeout(_e => {\n let config = CONFIG.props;\n let offsetHeight =\n config[\"scroller-selector\"] === \"html\"\n ? $(config.selector).offset().top\n : $(config.selector).position().top;\n\n $(config[\"scroller-selector\"]).animate(\n {\n scrollTop: offsetHeight + config.offset\n },\n 200\n );\n }, delay);\n};\n\nconst CONFIG = {\n default: {},\n internal: {},\n get props() {\n return this.internal;\n },\n set props(provided) {\n this.internal =\n provided === \"default\"\n ? Object.assign({}, this.default)\n : this.sanitycheck(provided);\n // Act now, since the provider probably expects that, unless default reset.\n if (provided != \"default\") scrollNow(1000);\n },\n sanitycheck: provided => {\n if (typeof provided !== \"object\") return Object.assign({}, CONFIG.default);\n provided = Object.assign(CONFIG.internal, provided);\n let check = has(CONFIG.props);\n return allPass([\n check(\"offset\") && !isNaN(props.offset),\n check(\"selector\") && document.querySelectorAll(props.selector).length,\n check(\"scrollerSelector\") &&\n document.querySelectorAll(props[\"scroller-selector\"]).length\n ])\n ? provided\n : Object.assign({}, CONFIG.default);\n }\n};\n\nexport { CONFIG };\n\n((doc, $) => {\n const directives = bb.propFinder(bb.conf, \"template\")(\"auto-scroll\", {});\n let newprops = {\n \"offset\": directives.hasOwnProperty(\"offset\")\n ? Number(directives.offset)\n : -30,\n \"selector\": directives.hasOwnProperty(\"custom-selector\")\n ? directives[\"custom-selector\"]\n : \"#bb-q\",\n \"scroller-selector\": directives.hasOwnProperty(\"scroller-selector\")\n ? directives[\"scroller-selector\"]\n : \"html\"\n };\n\n CONFIG.default = newprops;\n CONFIG.props = \"default\";\n\n $(doc).on(\"bb:finalHandleData\", (_e, data) => {\n if (\n data &&\n data.groups &&\n data.groups[data.groups.length - 1].screenmode !== \"addbottom\"\n ) {\n if (data.hasprevious) {\n scrollNow();\n } else {\n window.scrollTo(0, 0);\n }\n }\n });\n})(document, jQuery);\n", "const getCurrentChapterID = (groups = []) => {\n return groups.reduce(\n (_acc, curr) => {\n return curr.current ? curr.chapterid : false;\n },\n { current: false, chapterid: 0 }\n );\n};\n\nexport { getCurrentChapterID };\n", "/*\n * This utility can be imported to ease the use\n * of metadata by pulling it from the data provided.\n * The function will return an object containing three\n * properties:\n *\n * props --> a Map() containing a single entry per metadata property with it's\n * respective value of that metadata. Accumulated from all controls and\n * groups. Later groups overriding earlier.\n *\n * groups --> a Map() containing a single property per group\n * which has metadata, and the value of that metadata.\n *\n * controls --> a Map() containing a single property per control\n * which has metadata, and the value of that metadata.\n */\n\nconst getmetadata = data => {\n let fromnode = {\n props: new Map(),\n groups: new Map(),\n controls: new Map()\n };\n\n try {\n data.groups.forEach(group => {\n if (group.metadata !== undefined) {\n fromnode.groups.set(group.groupid, group.metadata);\n Object.keys(group.metadata).forEach(metaprop => {\n fromnode.props.set(metaprop, group.metadata[metaprop]);\n });\n }\n group.controls !== undefined &&\n group.controls.forEach(control => {\n Object.keys(control).forEach(prop => {\n if (prop === \"metadata\") {\n fromnode.controls.set([control.id], control.metadata);\n Object.keys(control.metadata).forEach(metaprop => {\n fromnode.props.set(metaprop, control.metadata[metaprop]);\n });\n }\n });\n });\n });\n return fromnode;\n } catch (err) {\n window.console && window.console.warn(err);\n return fromnode;\n }\n};\n\nexport { getmetadata };\n", "(function(){function n(){function v(){return null}function l(a){return a?\"object\"===typeof a||\"function\"===typeof a:!1}function p(a){if(null!==a&&!l(a))throw new TypeError(\"Object prototype may only be an Object or null: \"+a);}var q=null,e=Object,w=!!e.create||!({__proto__:null}instanceof e),A=e.create||(w?function(a){p(a);return{__proto__:a}}:function(a){function c(){}p(a);if(null===a)throw new SyntaxError(\"Native Object.create is required to create objects with null prototype\");c.prototype=a;return new c}),\nB=e.getPrototypeOf||([].__proto__===Array.prototype?function(a){a=a.__proto__;return l(a)?a:null}:v);var m=function(a,c){function k(){}if(void 0===(this&&this instanceof m?this.constructor:void 0))throw new TypeError(\"Constructor Proxy requires 'new'\");if(!l(a)||!l(c))throw new TypeError(\"Cannot create proxy with a non-object as target or handler\");q=function(){a=null;k=function(b){throw new TypeError(\"Cannot perform '\"+b+\"' on a proxy that has been revoked\");}};setTimeout(function(){q=null},0);var g=\nc;c={get:null,set:null,apply:null,construct:null};for(var h in g){if(!(h in c))throw new TypeError(\"Proxy polyfill does not support trap '\"+h+\"'\");c[h]=g[h]}\"function\"===typeof g&&(c.apply=g.apply.bind(g));g=B(a);var r=!1,t=!1;if(\"function\"===typeof a){var f=function(){var b=this&&this.constructor===f,d=Array.prototype.slice.call(arguments);k(b?\"construct\":\"apply\");return b&&c.construct?c.construct.call(this,a,d):!b&&c.apply?c.apply(a,this,d):b?(d.unshift(a),new (a.bind.apply(a,d))):a.apply(this,\nd)};r=!0}else a instanceof Array?(f=[],t=!0):f=w||null!==g?A(g):{};var x=c.get?function(b){k(\"get\");return c.get(this,b,f)}:function(b){k(\"get\");return this[b]},C=c.set?function(b,d){k(\"set\");c.set(this,b,d,f)}:function(b,d){k(\"set\");this[b]=d},y={};e.getOwnPropertyNames(a).forEach(function(b){if(!((r||t)&&b in f)){var d=e.getOwnPropertyDescriptor(a,b);e.defineProperty(f,b,{enumerable:!!d.enumerable,get:x.bind(a,b),set:C.bind(a,b)});y[b]=!0}});h=!0;if(r||t){var D=e.setPrototypeOf||([].__proto__===\nArray.prototype?function(b,d){p(d);b.__proto__=d;return b}:v);g&&D(f,g)||(h=!1)}if(c.get||!h)for(var u in a)y[u]||e.defineProperty(f,u,{get:x.bind(a,u)});e.seal(a);e.seal(f);return f};m.revocable=function(a,c){return{proxy:new m(a,c),revoke:q}};return m};var z=\"undefined\"!==typeof process&&\"[object process]\"==={}.toString.call(process)||\"undefined\"!==typeof navigator&&\"ReactNative\"===navigator.product?global:self;z.Proxy||(z.Proxy=n(),z.Proxy.revocable=z.Proxy.revocable);})();\n", "/*\n\n 'Store' module can be used by any plugin\n which requires state retention that\n can not be derived from the data in the\n current data in any given JSON res.\n\n Import the Map() 'state' and use the state\n to record data as the user progresses\n through the model. The state map is recorded\n in the session data 'uistates' every time it changes.\n\n If the user refreshes the page, or opens\n the session on a new tab/browser or at another\n time, the store module will make sure that\n state is updated with the recorded one - and\n an event wil be triggered 'bb:stateChange'\n\n NB: The state is shared over all other\n plugins which require it, so please namespace\n your entries.\n\n NB: The state is stringified to be stored\n as JSON - so don't get too fancy with your\n properties or values.\n\n Author: Tim Bauwens 2021\n\n*/\n\nimport \"proxy-polyfill/proxy.min.js\";\nimport { bb } from \"$json\";\nimport { has } from \"$json/lib/functional\";\n\nvar innerState, state;\n\nconst store = {\n sessionid: \"\",\n fresh: true,\n pushing: false,\n push: function () {\n if (!this.fresh && !this.pushing) {\n this.pushing = true;\n // Wait for the innserState to finish setting.\n window.setTimeout(() => {\n var form = new URLSearchParams();\n form.set(\"fmt\", \"json\");\n form.set(\"dbname\", bb.getVar(\"dbname\"));\n form.set(\"uniqueid\", bb.getVar(\"uniqueid\"));\n form.set(\"sessionid\", bb.getVar(\"sessionid\"));\n form.set(\"uistates\", JSON.stringify(Object.fromEntries(state)));\n\n form.get(\"uniqueid\") &&\n fetch(\"uistates\", {\n method: \"post\",\n headers: {\n \"Accept\": \"application/json, text/plain, */*\",\n \"Content-Type\": \"application/x-www-form-urlencoded;charset=UTF-8\"\n },\n body: form\n });\n store.pushing = false;\n }, 100);\n }\n }\n};\n\n$(document).on(\"bb:preHandleData\", (e, data) => {\n if (data && data.sessionid) {\n if (store.sessionid !== data.sessionid) {\n store.fresh = true;\n store.sessionid = data.sessionid;\n state = null;\n }\n\n if (store.fresh) {\n // Page refreshed, or case opened.\n\n if (data && has(\"uistates\")(data)) {\n innerState = data.uistates\n ? new Map(Object.entries(JSON.parse(data.uistates)))\n : new Map();\n state = new Proxy(innerState, {\n get(target, prop, receiver) {\n var value = Reflect.get(target, prop, receiver);\n if (typeof value === \"function\") {\n const origSet = value;\n value = function (key, value) {\n if (prop === \"set\" || prop === \"clear\") {\n store.push();\n }\n return origSet.apply(innerState, arguments);\n };\n }\n return value;\n }\n });\n $(document).trigger(\"bb:stateChange\");\n } else {\n innerState = new Map();\n }\n store.fresh = false;\n }\n }\n});\n\nexport { state };\n", "/*\n actielijst.js\n\n A local helper to form the final \"Actielijst\"\n into the grid as per design.\n\n Author: Tim Bauwens\n Copyright: xxllnc 2022\n\n*/\n\nimport { CONFIG as scrollconfig } from \"../../../../plugins/auto-scroll/auto-scroll\";\nimport { getCurrentChapterID } from \"$json/lib/getcurrentchapterid\";\nimport { getmetadata } from \"$json/lib/getmetadata\";\nimport { state } from \"$json/lib/store\";\nimport { bb } from \"$json\";\n\n((win, doc, $) => {\n let continueLink;\n\n function uid() {\n return `id-${Date.now()}-${Math.floor(Math.random() * 1000)}`;\n }\n\n function newRow(original) {\n let saved = state.has(\"p-chapters-helper\")\n ? state.get(\"p-chapters-helper\")\n : {};\n\n let id = uid();\n let imageName = original.querySelector(\"td:nth-of-type(7)\").innerText;\n let chapterid =\n saved.chaptermap[\n original.querySelector(\"td:nth-of-type(8)\").innerText.trim()\n ];\n let ariaLabel =\n original.querySelector(\"td:nth-of-type(1)\").innerText.trim() === \"1\"\n ? `Uit uw antwoorden op ${\n original.querySelector(\"td:nth-of-type(2)\").innerText\n } blijkt dat er geen actie vereist is`\n : `Uit uw antwoorden op ${\n original.querySelector(\"td:nth-of-type(2)\").innerText\n } blijkt dat er actie nodig is`;\n let rowset = doc.createElement(\"tbody\");\n rowset.setAttribute(\"tabIndex\", \"0\");\n rowset.setAttribute(\"ariaLabel\", ariaLabel);\n rowset.className = \"p-actielijst-grid--rowset\";\n rowset.innerHTML = `\n \n
\n `;\n\n rowset\n .querySelector(\".p-actielijst-grid--check\")\n .addEventListener(\"click\", e =>\n e.target.parentNode.querySelector(\"button.edit\").click()\n );\n\n rowset\n .querySelector(\".accordion-toggle\")\n .addEventListener(\"click\", e =>\n e.target.setAttribute(\"aria-selected\", e.target.checked)\n );\n\n return rowset;\n }\n\n function dateString(date, withdashes = false) {\n let year = date.getFullYear();\n let month = date.getMonth() + 1;\n if (String(month).length === 1) month = \"0\" + month;\n let day = date.getDate();\n if (String(day).length === 1) day = \"0\" + day;\n\n return withdashes ? `${year}-${month}-${day}` : `${year}${month}${day}`;\n }\n\n function UTCStamp(h = 0) {\n let now = new Date();\n now.setHours(h, 0, 0);\n return `T${now.getUTCHours()}000000Z`;\n }\n\n function msUTCStamp(h = 0) {\n // T12:00:00+00:00\n let now = new Date();\n now.setHours(h, 0, 0);\n return encodeURIComponent(`T${now.getUTCHours()}:00:00+00:00`);\n }\n\n function gglDate() {\n let target = new Date();\n target.setDate(target.getDate() + 3);\n let string = `${dateString(target)}${UTCStamp(12)}`;\n string += `/${dateString(target)}${UTCStamp(13)}`;\n string = encodeURIComponent(string);\n return string;\n }\n\n function datesStrings() {\n let target = new Date();\n target.setDate(target.getDate() + 3);\n let strings = {\n normal: dateString(target),\n dashes: dateString(target, true)\n };\n return strings;\n }\n\n function createHref(e) {\n // Useful: https://parcel.io/tools/calendar\n\n let href;\n\n const msgText = encodeURIComponent(`\n Deze reminder in je agenda leidt je terug naar de CyberVeilig Check van het Digital Trust Center.\n Vink af wat je gedaan hebt en check welke maatregelen je nog moet nemen om je beter te beschermen tegen cyberaanvallen.\n\n De link naar je eigen actielijst is:\n ${decodeURIComponent(continueLink)}\n\n Heb je vragen? Neem contact met ons op:\n digitaltrust@minezk.nl\n\n Veel succes,\n\n Team Digital Trust Center\n\n www.digitaltrustcenter.nl\n `);\n\n const msgTextICS = encodeURIComponent(\n `Deze reminder in je agenda leidt je terug naar de CyberVeiligCheck van het Digital Trust Center. Vink af wat je gedaan hebt en check welke maatregelen je nog moet nemen om je beter te beschermen tegen cyberaanvallen. De link naar je eigen actielijst is: ${decodeURIComponent(\n continueLink\n )} Heb je vragen? Neem contact met ons op: mailto:digitaltrust@minezk.nl?subject=Vraag%20over%20CyberVeilig%20Check Veel succes, Team Digital Trust Center www.digitaltrustcenter.nl`\n );\n const titleText = encodeURIComponent(`Doorgaan met de CyberVeiligCheck`);\n let strings = datesStrings();\n\n e.target.parentNode.querySelector(\"a.agenda\").target = \"_blank\";\n\n switch (e.target.value) {\n case \"none\":\n href = \"\";\n break;\n\n case \"google\":\n //https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20230119T110000Z%2F20230120T120000Z&details=ddddd&location=llll&text=ttttt\n href = `https://calendar.google.com/calendar/render?action=TEMPLATE&dates=${gglDate()}&location=${continueLink}&details=${msgText}&text=${titleText}`;\n break;\n\n case \"outlook\":\n //https://outlook.live.com/calendar/0/deeplink/compose?body=ddddd&enddt=2023-01-20T12%3A00%3A00%2B00%3A00&location=llll&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=2023-01-20T11%3A00%3A00%2B00%3A00&subject=ttttt\n href = `https://outlook.live.com/calendar/0/deeplink/compose?body=${msgText}&enddt=${\n strings.dashes\n }${msUTCStamp(\n 13\n )}&location=${continueLink}&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=${\n strings.dashes\n }${msUTCStamp(12)}&subject=${titleText}`;\n break;\n\n case \"office\":\n //https://outlook.office.com/calendar/0/deeplink/compose?body=ddddd&enddt=2023-01-20T12%3A00%3A00%2B00%3A00&location=llll&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=2023-01-20T11%3A00%3A00%2B00%3A00&subject=ttttt\n href = `https://outlook.office.com/calendar/0/deeplink/compose?body=${msgText}&enddt=${\n strings.dashes\n }${msUTCStamp(\n 13\n )}&location=${continueLink}&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=${\n strings.dashes\n }${msUTCStamp(13)}&subject=${titleText}`;\n break;\n\n case \"yahoo\":\n //https://outlook.live.com/calendar/0/deeplink/compose?body=ddddd&enddt=2023-01-20T12%3A00%3A00%2B00%3A00&location=llll&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=2023-01-19T11%3A00%3A00%2B00%3A00&subject=ttttt\n href = `https://calendar.yahoo.com/?desc=${msgText}&et=${\n strings.dashes\n }${msUTCStamp(13)}&in_loc=${continueLink}&st=${\n strings.dashes\n }${msUTCStamp(12)}&title=${titleText}&v=60`;\n break;\n\n case \"ics\":\n //data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART:20230119T110000Z%0ADTEND:20230120T120000Z%0ASUMMARY:ttttt%0ADESCRIPTION:ddddd%0ALOCATION:llll%0AEND:VEVENT%0AEND:VCALENDAR%0A\n href = `data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART:${\n strings.normal\n }${UTCStamp(12)}%0ADTEND:${strings.normal}${UTCStamp(\n 13\n )}%0ASUMMARY:${titleText}%0ADESCRIPTION;ENCODING=QUOTED-PRINTABLE:${msgTextICS}%0ALOCATION:${continueLink}%0AEND:VEVENT%0AEND:VCALENDAR%0A`;\n e.target.parentNode.querySelector(\"a.agenda\").target = \"\";\n break;\n\n default:\n href = \"\";\n break;\n }\n\n // Now set the href\n e.target.parentNode.querySelector(\"a.agenda\").href = href;\n if (href !== \"\") {\n e.target.parentNode.querySelector(\"a.agenda\").removeAttribute(\"tabindex\");\n } else {\n e.target.parentNode\n .querySelector(\"a.agenda\")\n .setAttribute(\"tabindex\", \"-1\");\n }\n }\n\n function calanderInvites() {\n let html = `\n \n
\n `;\n return html;\n }\n\n $(doc).on(\"bb:finalHandleData\", (_e, data) => {\n if (data && data.groups && data.groups.length) {\n const props = getmetadata(data).props;\n if (props.has(\"p-actielijst-show\")) {\n bb.Mode.set(\"hasActielijst\");\n // Break into the auto-scroll if needed:\n if (doc.querySelector(\".bbm-deel-2\")) {\n scrollconfig.props = { selector: \".bbm-deel-2\" };\n } else {\n scrollconfig.props = \"default\";\n }\n // Store the chapterID for the jump back button\n let saved = state.has(\"p-chapters-helper\")\n ? state.get(\"p-chapters-helper\")\n : {};\n saved.actielijstID = getCurrentChapterID(data.groups);\n state.set(\"p-chapters-helper\", saved);\n\n // Grab some values for continue later link in agenda:\n const location = bb.propFinder(bb.conf)(\n \"arbitrary.savecase-email-link-popup.location\",\n window.location.href\n );\n const sessionid = data.sessionid;\n continueLink = encodeURIComponent(\n `${location}?modelid=${data.dbname}&sessionid=${sessionid}`\n );\n try {\n // Move some things arround in the DOM to support the design.\n let fieldset = doc.querySelector(\"#bb-q fieldset\");\n let legend = fieldset.querySelector(\"legend\");\n let text = fieldset.querySelector(\".bb-text\");\n let toggler = fieldset.querySelector(\n '[data-metadata-keys=\"expanderToggle\"]'\n );\n let togglerText = fieldset.querySelector(\n '[data-metadata-keys=\"expanderText\"]'\n );\n let download = fieldset.querySelector('a[type=\"application/pdf\"]');\n let newContainer = doc.createElement(\"div\");\n newContainer.className = \"p-actielijst-head\";\n newContainer.innerHTML = `\n
\n `;\n fieldset.removeChild(legend);\n fieldset.removeChild(text);\n fieldset.removeChild(toggler);\n fieldset.removeChild(togglerText);\n fieldset.removeChild(download);\n fieldset.prepend(newContainer);\n let clonebtns = doc.querySelector(\".btns\").cloneNode(true);\n clonebtns.classList.add(\"final\");\n clonebtns.querySelector('a[type=\"application/pdf\"]').id = \"\";\n fieldset.append(clonebtns);\n doc.querySelectorAll(\"select.href-selector\").forEach(select => {\n select.addEventListener(\"change\", createHref);\n });\n doc\n .querySelectorAll(\".btns:not(.final) .p-actielijst--agenda-header\")\n .forEach(agenda => {\n agenda.addEventListener(\"click\", _e => {\n bb.Mode.toggle(\"showAgendaAdd\");\n });\n });\n } catch (err) {\n win.console && win.console.warn(err);\n }\n try {\n // let originalGrid = doc.querySelector(\"table.bbm-actielijst\");\n // originalGrid.querySelectorAll(\"tr\").forEach(row => {\n // row.replaceWith(newRow(row));\n // });\n let originalGrid = doc.querySelectorAll(\"table.bbm-actielijst\");\n originalGrid.forEach(grid => {\n grid.querySelectorAll(\"tr\").forEach(row => {\n row.replaceWith(newRow(row));\n });\n });\n } catch (err) {\n win.console && win.console.warn(err);\n }\n // Add some mis recording for clicks on add to agenda...\n let recorder = doc.querySelector(\n 'input[data-metadata-keys^=\"p-mis-click-count-agenda-field\"]'\n );\n\n if (recorder) {\n recorder.closest(\".bb-questionlabelgroup\").style.display = \"none\";\n doc\n .querySelectorAll(\".p-actielijst--agenda-content a.agenda\")\n .forEach(btn => {\n btn.addEventListener(\"click\", _e => {\n try {\n recorder.value = \"true\";\n bb.updatemis();\n } catch (err) {\n window.console && window.console.warn(err);\n }\n });\n });\n }\n\n // In case this is \"deel 2\", scroll the user to the start of that chapter.\n // if (\n // doc.querySelector(\"body\").dataset[\"node\"] ===\n // \"gresultaat.resultaat\"\n // ) {\n // console.log(\"yes\");\n // let title = doc.querySelector('.bbm-foo');\n // // title.scrollIntoView({ behavior: \"smooth\", block: \"start\" })\n // }\n } else {\n bb.Mode.unset(\"hasActielijst\");\n }\n }\n });\n})(window, document, jQuery);\n", "/*\n A small plugin to annoy people into returning\n to a tab which lost focus.\n\n Author: Tim Bauwens 2023\n*/\n\nimport { bb } from \"$json\";\n\n(doc => {\n const change = e => {\n let title = e.type === \"blur\" ? newTitle : originalTitle;\n doc.querySelector(\"head title\").innerText = title;\n };\n const props = bb.propFinder(bb.conf.template, \"change-title-on-tab-blur\");\n const newTitle = props(\"new-title\", \"Come back!\");\n\n const originalTitle = props(\n \"original-title\",\n doc.querySelector(\"head title\").innerText\n );\n\n try {\n window.addEventListener(\"blur\", change);\n window.addEventListener(\"focus\", change);\n } catch (err) {\n window.console && window.console.error(err);\n }\n})(document);\n", "/*\n chapter-helper.js\n\n A local helper to set display props\n for chapter items.\n\n Author: Tim Bauwens\n Copyright: xxllnc 2022\n*/\n\nimport { getCurrentChapterID } from \"$json/lib/getcurrentchapterid\";\nimport { getmetadata } from \"$json/lib/getmetadata\";\nimport { state } from \"$json/lib/store\";\nimport { has } from \"$json/lib/functional\";\nimport { CONFIG as scrollconfig } from \"../../../../plugins/auto-scroll/auto-scroll\";\n\n((_win, doc, $) => {\n var lastKnownScrollPos = 0;\n\n const applystate = () => {\n if (state.has(\"p-chapters-helper\")) {\n let saved = state.get(\"p-chapters-helper\");\n let toshow = saved.toshow || [];\n bb.Mode.toggle(\"hasSpecialChapters\", Boolean(toshow.length));\n let currentChapter = saved.currentChapter || \"\";\n let jl = doc.querySelector(\".bb-jumplist ul\");\n if (jl !== null) {\n jl.querySelectorAll(\"li\").forEach(chapter => {\n let title = chapter\n .querySelector(\"button > span\")\n .innerText.replace(/\\s/g, \"\");\n\n let bgpath = has(\"finalScore\")(\n chapter.querySelector(\"button[data-groupid]\").dataset\n )\n ? `url('../../rijks-cyberscan/plugins/chapters-helper/live/chapter_icons/${title}Actief.svg?v=20230117')`\n : `url('../../rijks-cyberscan/plugins/chapters-helper/live/chapter_icons/${title}Normaal.svg?v=20230117')`;\n\n let ariaLabel = has(\"finalScore\")(\n chapter.querySelector(\"button[data-groupid]\").dataset\n )\n ? chapter.querySelector(\"button[data-groupid]\").dataset\n .finalScore == 1\n ? \"Voltooid\"\n : `Huidige stap`\n : `Nog niet voltooid`;\n\n let selected =\n chapter\n .querySelector(\"button[data-groupid]\")\n .getAttribute(\"data-groupid\") === currentChapter\n ? true\n : false;\n\n chapter.classList.toggle(\"show\", toshow.includes(title));\n chapter.setAttribute(\"aria-hidden\", !toshow.includes(title));\n chapter.setAttribute(\"aria-label\", ariaLabel);\n chapter.classList.toggle(\"selected\", selected);\n chapter.style.setProperty(\"--bg\", bgpath);\n });\n }\n let actielijstID = saved.actielijstID || false;\n let btn = doc.querySelector(\"nav button.actielijst\");\n if (actielijstID) {\n btn.setAttribute(\"value\", actielijstID);\n btn.dataset.groupid = actielijstID;\n } else {\n btn.setAttribute(\"value\", \"\");\n btn.dataset.groupid = \"\";\n }\n }\n };\n\n $(doc).on(\"bb:stateChange\", () => {\n applystate();\n });\n\n $(doc).on(\"bb:preHandleData\", (_e, data) => {\n if (data && data.groups && data.groups.length) {\n lastKnownScrollPos = doc.querySelector(\".column--chapters\").scrollTop;\n }\n });\n\n $(doc).on(\"bb:postHandleData\", (_e, data) => {\n if (data && data.groups && data.groups.length) {\n let saved = state.has(\"p-chapters-helper\")\n ? state.get(\"p-chapters-helper\")\n : {};\n saved.currentChapter = getCurrentChapterID(data.groups);\n if (!has(\"chaptermap\")(saved)) saved.chaptermap = {};\n const props = getmetadata(data).props;\n if (props.has(\"p-chapters-helper-show\")) {\n let toshow = props.get(\"p-chapters-helper-show\").split(\"|\");\n saved.toshow = toshow.map(title => title.replace(/\\s/g, \"\"));\n saved.toshow = saved.toshow.filter(title => title !== \"false\");\n }\n if (props.has(\"p-chapters-helper-chapterid\")) {\n saved.chaptermap[props.get(\"p-chapters-helper-chapterid\")] =\n saved.currentChapter;\n }\n\n state.set(\"p-chapters-helper\", saved);\n\n // A small helper for the auto-scroll in case of small window size:\n if (window.innerWidth <= 943) {\n scrollconfig.props = { selector: \".l-content--left\" };\n } else {\n scrollconfig.props = \"default\";\n }\n }\n });\n\n $(doc).on(\"bb:finalHandleData\", (_e, data) => {\n if (data && data.groups && data.groups.length) {\n applystate();\n // Finally, scroll the jumplist to the right place.\n //let currentChapter = doc.querySelector(\".bb-jumplist li.selected\");\n let scrollSection = doc.querySelector(\".column--chapters\");\n scrollSection.scrollTo(0, lastKnownScrollPos);\n\n /*\n The desired scroll Y pos is the half the\n height of the column minus the selected\n icons total height offset (plus half \n it's own height).\n */\n let height = scrollSection.offsetHeight;\n let middle = height / 2;\n let posInList = Array.from(doc.querySelectorAll(\".bb-jumplist li.show\"))\n .map(item => item.className.includes(\"selected\"))\n .indexOf(true);\n let avgIconHeight = 110; // Guestimate magic number.\n let currentChapterIconOffset =\n avgIconHeight * posInList + avgIconHeight / 2;\n let desiredY = -1 * (middle - currentChapterIconOffset);\n\n window.setTimeout(e => {\n // Scroll to the desiredY\n scrollSection.scrollTo({\n top: desiredY,\n left: 0,\n behavior: \"smooth\"\n });\n }, 100);\n }\n });\n})(window, document, jQuery);\n", "// custom-radios.js\n\n/*\n * A simple plugin to replace\n * radios with a custom design.\n * Cross-browser and working with all\n * forms of output: grids and radios\n *\n * Note you'll have to provide your own styling to the faux .p-custom-radios-label\n *\n * Author: Niels Giesen\n * Copyright Berkeley Bridge 2019\n *\n */\n\n((doc, $) => {\n $(doc).on(\"bb:postHandleData\", (e, data) => {\n // If there are any checkboxes, deal with them\n let checkboxes = $(\"#bb-q\").find(\n 'input[type=\"radio\"]:not(.p-custom-radios)'\n );\n checkboxes.each((i, checkbox) => {\n checkbox.className += \" a-offscreen p-custom-radios\";\n checkbox.insertAdjacentHTML(\n \"afterEnd\",\n `\n \n `\n );\n });\n });\n})(document, jQuery);\n", "/*\n * end-tools:\n *\n * Place up to four functions in the\n * top or bottom of bb-q on any node.\n *\n * 1) A download report button\n * 2) An email report widget\n * 3) A print option.\n * 4) A feedback widget.\n *\n * Author: Tim Bauwens\n * Copyright 2020 Berkeley Bridge\n *\n */\n\nimport print from \"print-js\";\nimport { gt, bb, _ } from \"$json\";\nimport { getmetadata } from \"../../js/lib/getmetadata\";\n\n(($, win, doc) => {\n var translations = {\n \"Rapport downloaden\": {\n nl: \"Rapport downloaden\",\n en: \"Download report\"\n },\n \"Verzend rapport via e-mail\": {\n nl: \"Verzend rapport via e-mail\",\n en: \"Send report via e-mail\"\n },\n \"Was dit nuttig?\": {\n nl: \"Was dit nuttig?\",\n en: \"Was this useful?\"\n },\n \"Verzend\": {\n nl: \"Verzend\",\n en: \"Send\"\n },\n \"vul hier uw e-mail in\": {\n nl: \"vul hier uw e-mail in\",\n en: \"provide your e-mail here\"\n },\n \"jouw@email.com\": {\n nl: \"jouw@email.com\",\n en: \"your@email.com\"\n },\n \"E-mail is verzonden...\": {\n nl: \"E-mail is verzonden.\",\n en: \"E-mail has been sent.\"\n },\n \"Bedankt voor uw feedback\": {\n nl: \"Bedankt voor uw feedback\",\n en: \"Thanks for your feedback\"\n },\n \"Ja\": {\n nl: \"Ja\",\n en: \"Yes\"\n },\n \"Nee\": {\n nl: \"Nee\",\n en: \"No\"\n },\n \"prepping\": {\n nl: \"voorbereiden...\",\n en: \"preparing...\"\n },\n \"impossible\": {\n nl: \"niet mogelijk.\",\n en: \"not posssible.\"\n }\n };\n\n gt.addTranslations(translations);\n\n var metadata,\n emailSent,\n REPORTDOC = \"\", // Because there could be multiple, but we only handle one.\n SHOWONTOP = \"true\",\n DESIRED_TOOLS = [];\n\n $(function () {\n $(doc).on(\"bb:preHandleData\", (event, data) => {\n if (data && data.groups && data.groups.length && data.sessionid) {\n // Check in case metadata has been added or changed\n metadata = getmetadata(data).props;\n\n if (\n metadata.has(\"reportdoc\") &&\n metadata.get(\"reportdoc\").split(\".\").pop() === \"pdf\"\n ) {\n REPORTDOC = metadata.get(\"reportdoc\");\n }\n if (metadata.has(\"desiredtools\")) {\n DESIRED_TOOLS.length = 0;\n metadata\n .get(\"desiredtools\")\n .split(\"|\")\n .forEach(entry => {\n DESIRED_TOOLS.push(entry);\n });\n }\n if (metadata.has(\"showontop\")) {\n SHOWONTOP = metadata.get(\"showontop\");\n } else {\n SHOWONTOP = \"true\";\n }\n\n emailSent = emailSent || false;\n }\n });\n });\n\n $(function () {\n $(doc).on(\"bb:postHandleData\", function (event, data) {\n // Unset mode for hooks\n bb.Mode.unset(\"hasThreeInOne\");\n if (data && data.groups && data.groups.length && data.sessionid) {\n if (metadata.has(\"end-tools\") && metadata.get(\"end-tools\")) {\n // Set mode for hooks\n bb.Mode.set(\"hasThreeInOne\");\n\n // Hide and reset the support inputs.\n $(\".bb-g-endtools-feedback-vote\").hide();\n $(\".bb-g-endtools-email\").hide();\n $(\".bbm-endtools-email\").val(\"\");\n\n // Create the container for the functions.\n var $container = $('');\n\n if (DESIRED_TOOLS.indexOf(\"download\") > -1 && REPORTDOC.length) {\n // Make a download report button\n var $download = $(\n ''\n );\n $download.append(`\n \n \n ${_(\"Rapport downloaden\")}\n \n `);\n $container.append($download);\n }\n\n if (DESIRED_TOOLS.indexOf(\"print\") > -1 && REPORTDOC.length) {\n // Make the print button.\n var $print = $(\n ''\n );\n var $printbtn = $(`\n \n `).on(\"click\", e => {\n printJS({\n printable: `${REPORTDOC}?guid=${data.uniqueid}:${data.dbname}:${data.sessionid}`,\n type: \"pdf\",\n showModal: false\n });\n });\n $print.append($printbtn);\n $container.append($print);\n }\n\n if (DESIRED_TOOLS.indexOf(\"email\") > -1) {\n // Make the email widget\n var $email = $('');\n\n if (emailSent) {\n $email.append(\n '\"\n );\n emailSent = false;\n } else {\n $email.append(\n ``\n ).append(`\n \n `);\n\n // Handler\n $(doc).off(\".end-tools-events\", \".opt-for-email\");\n $(doc).on(\n \"click.end-tools-events\",\n \".opt-for-email\",\n function (e) {\n $(\".opt-for-email\")\n .html(_(\"Verzend\") + ' ⇾ ')\n .attr(\"class\", \"email-send bb-next\")\n .prop(\"disabled\", \"disabled\");\n $(\".email-container\").addClass(\"set\");\n $(\".email-address\")\n .removeClass(\"ready\")\n .addClass(\"set\")\n .trigger(\"focus\");\n }\n );\n $(doc).off(\".end-tools-events\", \".email-address\");\n $(doc).on(\n \"\\\n propertychange.end-tools \\\n change.end-tools-events \\\n click.end-tools-events \\\n keyup.end-tools-events \\\n input.end-tools-events \\\n paste.end-tools-events\",\n \".email-address\",\n function () {\n var input = $(\"input.email-address\").val();\n var regex =\n /^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n if (regex.test(input)) {\n $(\"button.email-send\")\n .addClass(\"validated\")\n .removeAttr(\"disabled\");\n emailSent = true;\n $(\".bbm-endtools-email\").val(input);\n } else {\n $(\"button.email-send\")\n .removeClass(\"validated\")\n .prop(\"disabled\", \"disabled\");\n $(\".bbm-endtools-email\").val(\"\");\n }\n }\n );\n }\n $container.append($email);\n }\n\n if (DESIRED_TOOLS.indexOf(\"feedback\") > -1) {\n // Make the feedback buttons.\n var $feedback = $(\n ''\n );\n $feedback\n .append(\n `\n \n `\n )\n .append(\"\").append(`\n \n `);\n\n // Handler\n var group;\n if (data && data.userinfo)\n $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)\n $feedback.data(\"modelname\", data.modelname);\n if (data && data.modelversion)\n $feedback.data(\"modelversion\", data.modelversion);\n $(doc).off(\".end-tools-events\", \".feedback-button\");\n $(doc).one(\n \"click.end-tools-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\n // Add the vote to the hiddden interface.\n $(\"input.bbm-endtools-feedback-vote\").attr(\"value\", vote);\n $feedback.html(\n '\"\n );\n bb.updatemis();\n }\n );\n $container.append($feedback);\n }\n\n // Reveal top or bottom depending on conf.\n if (SHOWONTOP === \"false\") {\n $(\"fieldset.selected\").append($container);\n setTimeout(function () {\n $container.toggleClass(\"showing\");\n }, 800);\n } else {\n $(\"#bb-q\").prepend($container);\n $(\"html,body\").animate({ scrollTop: 0 });\n setTimeout(function () {\n $container.toggleClass(\"showing\");\n }, 800);\n }\n }\n }\n });\n });\n})(jQuery, window, document);\n", "/*\n has-no-next-meta:\n\n Toggle data.hasnext when metadata\n prop 'no-next' is present.\n\n Copyright: Berkeley Bridge 2021\n Author: Tim Bauwens\n\n */\n\nimport { getmetadata } from \"$json/lib/getmetadata\";\n\n((doc, $) => {\n $(doc).on(\"bb:preHandleData\", (e, data) => {\n if (data && data.groups) {\n const md = getmetadata(data).props;\n data.hasnext = data.hasnext ? !md.has(\"no-next\") : data.hasnext;\n }\n });\n})(document, jQuery);\n", "import { bb } from \"$json\";\n/* headings:\n *\n * Turn labels whose font class (as provided the JSON object) match the\n * regular expression /^Standard title$|^Heading[^1-6]*([1-6]?)/ into headings.\n *\n * If the class has no numbering (e.g. 'Standard Title' instead of\n * 'Heading 2'), level 1 will be presumed.\n *\n * Since a model can run anywhere, it is possible to set a base level\n * for headings in arbitrary.headings.baseLevel (in\n * conf.json).\n *\n * If you want to force titles in 'addtobottom' nodes to duck below\n * the top ('cleared') node, declare arbitrary.headings.duck = true in\n * conf.json\n *\n * Author: Niels Giesen\n * Copyright 2016, 2018 Berkeley Bridge\n *\n */\n(function ($, win, doc) {\n var duck = false,\n baseLevel,\n topLevel,\n re = /^Standard title$|^Heading[^1-6]*([1-6]?)/;\n\n $(function () {\n try {\n baseLevel = bb.conf.arbitrary.headings.baseLevel;\n if (baseLevel === undefined) throw \"baseLevel is not defined\";\n topLevel = baseLevel - 1;\n } catch (err) {\n topLevel = 0;\n }\n\n try {\n duck = bb.conf.arbitrary.headings.duck;\n } catch (err) {}\n\n $(doc).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.groups && data.groups.length) {\n $.each(data.groups, function (_, group) {\n $.each(group.controls, function (_, ctl) {\n var klass = ctl[\"font-class\"],\n _level,\n m;\n if (ctl.controltype === \"label\" && ((m = klass.match(re)), m)) {\n _level = Number(m[1]) || 1;\n ctl._subtype = \"heading\";\n ctl._level =\n duck && group.screenmode !== \"clear\"\n ? _level + 1 + topLevel\n : _level + topLevel;\n }\n });\n });\n }\n });\n });\n})(jQuery, window, document);\n", "/* history:\n *\n * Manage history using the html5 history api and sessionStorage\n *\n * Could have support for crunchbang ( #!modelname=thisandthat )\n *\n * Author: Niels Giesen\n * Copyright 2013, 2014, 2015 Berkeley Bridge\n *\n */\nimport { bb, _ } from \"$json\";\nimport { has } from \"$json/lib/functional\";\nimport { setSettled } from \"$json/lib/settled\";\n\n(function ($, win, history, location) {\n var crunchbang = false;\n\n if (history && history.pushState) {\n if (!location.origin) {\n location.origin =\n location.protocol +\n \"//\" +\n location.hostname +\n (location.port ? \":\" + location.port : \"\");\n }\n\n $(function () {\n var apinav,\n storage,\n params = $.parseQuery(location.hash.slice(2)),\n _title_sep = \" \",\n _title = document.title;\n\n try {\n storage = window.sessionStorage;\n } catch (err) {\n storage = null;\n }\n\n function directory(loc) {\n return loc.origin + loc.pathname.replace(/[^/]+$/, \"\");\n }\n\n function restoreState(state) {\n if (state.sessionid) {\n // restore case\n bb.ajax\n .post({\n url: \"action\",\n data: state\n })\n .then(setSettled);\n } else if (bb.getVar(\"sessionid\")) {\n // exit running case and restore model view\n bb.exit(() => bb.menu(state).then(setSettled));\n } else {\n // restore model view\n bb.menu(state).then(setSettled);\n }\n }\n\n function ditchState() {\n storage && storage.removeItem(\"state\");\n history.replaceState(null, null, null);\n setSettled();\n }\n\n if (location.search !== \"\") ditchState();\n\n var initial_state =\n history.state || (storage && JSON.parse(storage.getItem(\"state\")));\n\n if (initial_state) {\n // Detect explicit edit of the crunchbang - this should\n // override the dbname parameter and instead use the modelname\n if (params.modelname && params.modelname !== initial_state.modelname) {\n initial_state.modelname = params.modelname;\n delete initial_state.dbname;\n delete initial_state.sessionid;\n }\n\n if (initial_state.directory === directory(location)) {\n bb.Mode.set(\"isLoggedIn\"); // Yes, just an assumption it will go allright.\n restoreState(initial_state);\n } else {\n ditchState();\n }\n } else if (params.modelname) {\n // Bookmarked with crunchbang, but no state\n bb.Router(params);\n } else {\n setSettled();\n }\n\n $(document).on(\"bb:jsonError\", ditchState);\n\n $(document).on(\"bb:preHandleData\", function (event, data) {\n if (data && data.uniqueid) {\n var title,\n state = {\n fmt: \"json\",\n uniqueid: data.uniqueid,\n // Save the 'directory part'\n directory: directory(location)\n };\n if (has(\"dbname\", data) && data.sessionid) {\n state.dbname = data.dbname;\n state.sessionid = data.sessionid;\n state.modelname = data.modelname; // Needed to get interpret explicit change to location\n\n if (data.modeldescription) {\n title = [_title, data.modeldescription.replace(/_/g, \" \")].join(\n _title_sep\n );\n }\n } else if (data.models) {\n var model = $.grep(data.models, function (m) {\n return m.selected;\n })[0],\n dbname = model ? model.dbname : null;\n if (dbname !== null) {\n state.dbname = dbname;\n title = [_title, model.modelname, \"-\", _(\"overview\")].join(\n _title_sep\n );\n } else {\n title = [_title, _(\"Your models\")].join(_title_sep);\n }\n }\n if (!apinav) {\n try {\n storage && storage.setItem(\"state\", JSON.stringify(state));\n } catch (e) {\n // Guard against QuotaExceededError (which always happens on Safari Private Browsing on iOS)\n }\n if (history.state && history.state.sessionid && state.sessionid) {\n history.replaceState(\n state,\n null,\n location.origin +\n location.pathname +\n ((crunchbang && \"#!modelname=\" + data.modelname) || \"\")\n );\n } else {\n if (data.modelname && crunchbang) {\n history.pushState(\n state,\n null,\n location.origin +\n location.pathname +\n \"#!modelname=\" +\n data.modelname\n );\n } else {\n history.pushState(\n state,\n null,\n location.origin + location.pathname\n );\n }\n }\n }\n if (title && document.title !== title) {\n document.title = title;\n }\n }\n // Something went miserably wrong. Clear history to get out of this mess.\n if (\n data &&\n ((data.error && data.error.summary) ||\n (data.groups && !data.groups.length) ||\n data.status === \"logout successful\")\n ) {\n // Extra check - may be we are but updating\n if (\n data &&\n data.error &&\n data.error.code &&\n data.error.code === 14 && // Error loading case\n data.error.subcode === 1002\n )\n // Updating\n return;\n ditchState();\n }\n apinav = false;\n });\n\n win.addEventListener(\"popstate\", function (e) {\n apinav = true;\n if (e.state) {\n if (e.state.directory === directory(location)) restoreState(e.state);\n else ditchState();\n }\n });\n });\n }\n})(jQuery, window, window.history, window.location);\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, \"
\");\n str += \"
\";\n grafsOut.push(str);\n }\n }\n\n //\n // Unhashify HTML blocks\n //\n end = grafsOut.length;\n for (var i = 0; i < end; i++) {\n // if this is a marker for an html block...\n while (grafsOut[i].search(/~K(\\d+)K/) >= 0) {\n var blockText = g_html_blocks[RegExp.$1];\n blockText = blockText.replace(/\\$/g, \"$$$$\"); // Escape any dollar signs\n grafsOut[i] = grafsOut[i].replace(/~K\\d+K/, blockText);\n }\n }\n\n return grafsOut.join(\"\\n\\n\");\n };\n\n var _EncodeAmpsAndAngles = function (text) {\n // Smart processing for ampersands and angle brackets that need to be encoded.\n\n // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:\n // http://bumppo.net/projects/amputator/\n text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\\w+);)/g, \"&\");\n\n // Encode naked <'s\n text = text.replace(/<(?![a-z\\/?\\$!])/gi, \"<\");\n\n return text;\n };\n\n var _EncodeBackslashEscapes = function (text) {\n //\n // Parameter: String.\n // Returns:\tThe string, with after processing the following backslash\n // escape sequences.\n //\n\n // attacklab: The polite way to do this is with the new\n // escapeCharacters() function:\n //\n // text = escapeCharacters(text,\"\\\\\",true);\n // text = escapeCharacters(text,\"`*_{}[]()>#+-.!\",true);\n //\n // ...but we're sidestepping its use of the (slow) RegExp constructor\n // as an optimization for Firefox. This function gets called a LOT.\n\n text = text.replace(/\\\\(\\\\)/g, escapeCharacters_callback);\n text = text.replace(/\\\\([`*_{}\\[\\]()>#+-.!])/g, escapeCharacters_callback);\n return text;\n };\n\n var _DoAutoLinks = function (text) {\n text = text.replace(\n /<((https?|ftp|dict):[^'\">\\s]+)>/gi,\n '$1'\n );\n\n // Email addresses: \n\n /*\n text = text.replace(/\n <\n (?:mailto:)?\n (\n [-.\\w]+\n \\@\n [-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+\n )\n >\n /gi, _DoAutoLinks_callback());\n */\n text = text.replace(\n /<(?:mailto:)?([-.\\w]+\\@[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+)>/gi,\n function (wholeMatch, m1) {\n return _EncodeEmailAddress(_UnescapeSpecialChars(m1));\n }\n );\n\n return text;\n };\n\n var _EncodeEmailAddress = function (addr) {\n //\n // Input: an email address, e.g. \"foo@example.com\"\n //\n // Output: the email address as a mailto link, with each character\n //\tof the address encoded as either a decimal or hex entity, in\n //\tthe hopes of foiling most address harvesting spam bots. E.g.:\n //\n //\tfoo\n // @example.com\n //\n // Based on a filter by Matthew Wickline, posted to the BBEdit-Talk\n // mailing list: \n //\n\n // attacklab: why can't javascript speak hex?\n function char2hex(ch) {\n var hexDigits = \"0123456789ABCDEF\";\n var dec = ch.charCodeAt(0);\n return hexDigits.charAt(dec >> 4) + hexDigits.charAt(dec & 15);\n }\n\n var encode = [\n function (ch) {\n return \"\" + ch.charCodeAt(0) + \";\";\n },\n function (ch) {\n return \"\" + char2hex(ch) + \";\";\n },\n function (ch) {\n return ch;\n }\n ];\n\n addr = \"mailto:\" + addr;\n\n addr = addr.replace(/./g, function (ch) {\n if (ch == \"@\") {\n // this *must* be encoded. I insist.\n ch = encode[Math.floor(Math.random() * 2)](ch);\n } else if (ch != \":\") {\n // leave ':' alone (to spot mailto: later)\n var r = Math.random();\n // roughly 10% raw, 45% hex, 45% dec\n ch = r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch);\n }\n return ch;\n });\n\n addr = '' + addr + \"\";\n addr = addr.replace(/\">.+:/g, '\">'); // strip the mailto: from the visible part\n\n return addr;\n };\n\n var _UnescapeSpecialChars = function (text) {\n //\n // Swap back in all the special characters we've hidden.\n //\n text = text.replace(/~E(\\d+)E/g, function (wholeMatch, m1) {\n var charCodeToReplace = parseInt(m1);\n return String.fromCharCode(charCodeToReplace);\n });\n return text;\n };\n\n var _Outdent = function (text) {\n //\n // Remove one level of line-leading tabs or spaces\n //\n\n // attacklab: hack around Konqueror 3.5.4 bug:\n // \"----------bug\".replace(/^-/g,\"\") == \"bug\"\n\n text = text.replace(/^(\\t|[ ]{1,4})/gm, \"~0\"); // attacklab: g_tab_width\n\n // attacklab: clean up hack\n text = text.replace(/~0/g, \"\");\n\n return text;\n };\n\n var _Detab = function (text) {\n // attacklab: Detab's completely rewritten for speed.\n // In perl we could fix it by anchoring the regexp with \\G.\n // In javascript we're less fortunate.\n\n // expand first n-1 tabs\n text = text.replace(/\\t(?=\\t)/g, \" \"); // attacklab: g_tab_width\n\n // replace the nth with two sentinels\n text = text.replace(/\\t/g, \"~A~B\");\n\n // use the sentinel to anchor our regex so it doesn't explode\n text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1, m2) {\n var leadingText = m1;\n var numSpaces = 4 - (leadingText.length % 4); // attacklab: g_tab_width\n\n // there *must* be a better way to do this:\n for (var i = 0; i < numSpaces; i++) leadingText += \" \";\n\n return leadingText;\n });\n\n // clean up sentinels\n text = text.replace(/~A/g, \" \"); // attacklab: g_tab_width\n text = text.replace(/~B/g, \"\");\n\n return text;\n };\n\n //\n // attacklab: Utility functions\n //\n\n var escapeCharacters = function (text, charsToEscape, afterBackslash) {\n // First we have to escape the escape characters so that\n // we can build a character class out of them\n var regexString =\n \"([\" + charsToEscape.replace(/([\\[\\]\\\\])/g, \"\\\\$1\") + \"])\";\n\n if (afterBackslash) {\n regexString = \"\\\\\\\\\" + regexString;\n }\n\n var regex = new RegExp(regexString, \"g\");\n text = text.replace(regex, escapeCharacters_callback);\n\n return text;\n };\n\n var escapeCharacters_callback = function (wholeMatch, m1) {\n var charCodeToEscape = m1.charCodeAt(0);\n return \"~E\" + charCodeToEscape + \"E\";\n };\n}; // end of Showdown.converter\n\nexport default Showdown;\n", "import { default as Showdown } from \"$showdown\";\nexport { converter };\n\nconst converter = new Showdown.converter();\n\nconst orig = converter.makeHtml.bind(converter);\nconverter.makeHtml = (text, inline) =>\n orig(text, inline).replace(/ {\n const container = doc.querySelector(\".p-info-sources--content\");\n const infoButton = doc.createElement(\"span\");\n infoButton.className = \"p-info-sources--toggleSpan\";\n infoButton.innerHTML = `\n \n `;\n\n $(doc).on(\"bb:postHandleData\", (_e, data) => {\n toggleInfosource(null, false);\n if (data && data.informationsources && data.informationsources.length) {\n container.querySelectorAll(\".p-info-source--item\").forEach(old => {\n container.removeChild(old);\n });\n const info = data.informationsources.map(getInfo);\n info.forEach(item => {\n let template = `\n