From 6f363ac39f7a3239156ca2562d21fc5a3477af88 Mon Sep 17 00:00:00 2001 From: Jeroen Versteege Date: Tue, 16 Mar 2021 09:28:06 +0100 Subject: [PATCH 1/2] bootstrap-> set initial value on first load of external data --- .gitignore | 2 +- dist/legalform.css | 458 --- dist/legalform.js | 3290 ----------------- .../bootstrap/init-external-fields-trait.js | 22 +- package-lock.json | 806 ++++ 5 files changed, 820 insertions(+), 3758 deletions(-) delete mode 100644 dist/legalform.css delete mode 100644 dist/legalform.js create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 413ff5b..cf0c1c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules - +dist /vendor/ diff --git a/dist/legalform.css b/dist/legalform.css deleted file mode 100644 index dc5caa9..0000000 --- a/dist/legalform.css +++ /dev/null @@ -1,458 +0,0 @@ -.wizard { - overflow: visible; -} - -.wizard { - padding-right: 25px; -} - -.wizard:not(.material) { - padding: 32px; -} - -.wizard .option label { - font-weight: 200; -} - -.wizard .form-group.has-error .option label { - color: #a94442; -} - -.wizard .form-group { - position: relative; -} - -.wizard .form-group > .help { - display: block; - margin-right: 4px; - position: absolute; - right: -25px; - top: 45%; - font-size: 20px; - opacity: 0.5; - cursor: pointer; -} - -.has-error .selectize-input { - border-color: rgb(169, 68, 66) !important; -} - -.selectize-control .selectize-input { - vertical-align: top; -} - -.wizard .datepicker table { - width: 100%; -} - -.wizards-actions.template { - display: none; -} - -/* fix selectize min-height for material & bootstrap */ -.selectize-dropdown.form-control { - min-height: auto !important; -} - -#doc-wizard .form-group .option label .required { - font-weight: bold; -} -.likert tr:first-child{ - height: 6em; -} - -.likert td { - position: relative; - width: 25px; -} - -.likert td:first-child { - width: auto; -} - -.likert td .likert-option { - max-width: 7em; - overflow: hidden; - white-space: pre; - text-overflow: ellipsis; - position: absolute; - bottom: 0; - left: 3px; - -webkit-transform: rotate(-50deg) translateX(10px, 10px); - -ms-transform: rotate(-50deg) translate(10px, 10px); - transform: rotate(-50deg) translate(10px, 10px); - -webkit-transform-origin: bottom left; - -ms-transform-origin: bottom left; - transform-origin: bottom left; -} - -.likert td:last-child .likert-option { - max-width:5em -} - -.likert-question { - padding-right: 1em; -}.material .form-group input, -.material .form-group textarea, -.material .form-group select, -.material .selectize-input { - font-family: "Proxima Nova", Montserrat, sans-serif; - font-weight: 300; -} - -.material .form-control { - color: rgba(0, 0, 0, 0.8); - font-size: 15px; -} - -.material .form-group { - margin: 0; -} - -.material .form-group .form-control:focus, -.material .form-group .selectize-control { - box-shadow: none; -} - - -.material .form-group:not(.has-error) .form-control:not(.selectize-dropdown):not(.selectize-control) { - background-image: linear-gradient(to top, rgba(0, 0, 0, 0.6) 2px, - rgba(0, 150, 136, 0) 2px), - linear-gradient(to top, - rgba(0, 0, 0, 0.26) 1px, transparent 1px); -} - - -.material .has-error .check { - border-color: rgb(244, 67, 54) !important; -} - -.material .has-error .checkbox label { - color: rgb(244, 67, 54) !important; -} - -.material .has-error input, -.material .has-danger input { - color: rgb(244, 67, 54) !important; - background-image: linear-gradient(to top, rgba(244, 67, 54, 0.6) 2px, - rgba(0, 150, 136, 0) 2px), - linear-gradient(to top, - rgb(244, 67, 54) 1px, transparent 1px) !important; -} - -.material .has-error .input-group-addon, -.material .has-danger .input-group-addon { - border: none; - background: transparent; -} - -.material .is-focused .input-group-addon, .is-focused .input-group-addon { - color: rgba(0, 0, 0, 0.8); -} - -.material .has-error label, -.material .has-danger label { - color: rgb(244, 67, 54); -} - -.material .form-group.is-focused:not(.has-error) label.form-control-label { - color: rgba(0, 0, 0, 0.8); -} - -.material .form-group:hover:not(.is-focused) label.form-control-label { - color: rgba(0, 0, 0, 0.6); -} - -.material .form-group .selectize-control .selectize-input { - padding: 6px 0px; - border: none; - border-radius: 0px; - box-shadow: none; - background: transparent; - background-image: linear-gradient(to top, rgba(0, 0, 0, 0.1) 1px, - rgba(0, 150, 136, 0) 1px), - linear-gradient(to top, - rgba(0, 0, 0, 0.26) 1px, transparent 1px); -} - -.material .form-group .bmd-label-floating { - z-index: 2; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - max-height: 16px; -} - -.material .form-group.is-focused .bmd-label-floating { - max-height: 12px; -} - -.material .form-group .selectize-control .selectize-dropdown { - box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24); - border: none; - color: rgba(0, 0, 0, 0.87); -} - -.material .dropdown-item.active, -.material .dropdown-item.active:focus, -.material .dropdown-item.active:hover { - background-color: rgb(238, 238, 238); - color: rgb(33, 33, 33); -} - -/* Change form to material design */ -.material { - counter-reset: step; - margin-top: 51px; - width: 100%; - padding-bottom: 15px; - background: #fff; -} - -.material label + .option { - padding-top: 5px; -} - -.material .progress { - margin-bottom: 0; - border-radius: 0; -} - -.material .wizard-step { - display: block; - position: relative; - padding: 10px 0 10px 0; - min-height: 70px; - counter-increment: step; -} - -.material .wizard-step h3 { - display: block; - font-size: 20px; - line-height: 30px; - width: 100%; - padding: 10px 50px; - line-heigt: 30px; - margin: 0; - cursor: pointer; -} - -.material .wizard-step:before { - content: '\f00c'; - font-family: FontAwesome; - font-weight: bold; - display: inline-block; - width: 34px; - height: 34px; - background: #8EC640; - background: radial-gradient(circle, #65d26a 0px, #65d26a 14px, #ffffff 15px, #65d26a 16px); - line-height: 34px; - text-align: center; - border-radius: 50%; - color: #fff; - font-size: 16px; - vertical-align: 3px; - - position: absolute; - z-index: 2; - left: 8px; - top: 18px; -} - -.material .wizard-step.active:before { - content: counter(step); - font-family: inherit; - line-height: 35px; - background: radial-gradient(circle, #0082FE 0px, #0082FE 13px, #fff 15px, #0082FE 16px); -} - -.material .wizard-step.active ~.wizard-step:before { - content: counter(step); - font-family: inherit; - line-height: 35px; - background: radial-gradient(circle, #c2baba 0px, #c2baba 14px, #fff 15px, #c2baba 16px); -} - -.material .wizard-step:after { - content: ''; - display: block; - position: absolute; - z-index: 5; - width: 2px; - height: 100%; - left: 24px; - top: 0; - background: linear-gradient(to bottom, #f0eded 0, #f0eded 14px, transparent 15px, transparent 59px, #f0eded 60px, #f0eded 100%); -} - -.material .wizard-step .wizzard-form { - margin: 5px 1px 10px 25px; - position: relative; - margin-bottom: 0px; - display: block; - padding: 0 30px 20px 20px; - height: auto; - border-radius: 4px; - display: none; -} -.material .wizard-step.active .wizzard-form { - display: block; -} - -.material .wizzard-form .form-group label .required { - color: red; -} - -.material .wizard-step .wizards-actions { - display: none; -} - -.material .wizard-step .wizards-actions { - min-height: 60px; - padding: 10px 10px 10px 0; - width: 100%; -} -.material .wizard-step.active .wizards-actions { - display: block; - min-height: 65px; -} - -.material .btn.btn-rounded { - border-radius: 22px; -} - -.material .btn.empty-background { - background: none; -} - -.material .btn-success.btn-outline { - border: 2px solid #4caf50; - color: #4caf50; - background: rgba(76, 175, 80, 0.1); -} - -.material .btn-primary.btn-outline, -.material .btn-primary.btn-outline:focus { - border: 2px solid rgba(0, 0, 0, 0.87) !important; - color: rgba(0, 0, 0, 0.87) !important; - background: rgba(0, 0, 0, 0) !important; -} -.material .btn-primary.btn-outline:active, -.material .btn-primary.btn-outline:hover { - border-color: rgba(0,0,0, 0.95) !important; - color: rgba(0,0,0, 0.95) !important; - background: rgba(0, 0, 0, 0.1) !important; -} - -.material .btn-primary.btn-outline:active, -.material .btn-primary.btn-outline.active { - border-color: #b87430; - color: #b87430; - box-shadow: none; - background: rgba(235, 162, 90, 0.4); -} - -.material .selectize-control.multi .selectize-input.input-active:after, -.material .selectize-control.multi .selectize-input:after, -.material .selectize-control.single .selectize-input.input-active:after, -.material .selectize-control.single .selectize-input:after { - content: ""; -} - -.material .bootstrap-datetimepicker-widget.dropdown-menu { - opacity: initial; - transform: none; - transform-origin: none; - transition: none; -} - -.material label { - font-weight: 300; -} - -.material .form-group > label { - position: relative; - top: 0px; - left: 0px; - font-size: 13px; - text-overflow: ellipsis; - width: 100%; - overflow: hidden; - max-width: 100%; - margin: 0px; - color: rgba(0, 0, 0, 0.6); - line-height: 2; -} - -.material .form-group.has-danger .form-control, -.material .form-group.has-error .form-control { - box-shadow: none; -} - -.material .radio label, -.material .checkbox label { - padding-left: 2.5rem; - color: rgba(0, 0, 0, 0.7); - line-height: 1.5; -} - -.material .radio label input[type="radio"] ~ .bmd-radio-inner-circle, -.material .radio label input[type="radio"]:checked ~ .bmd-radio-inner-circle { - background-color: #757575; - border-color: #757575; -} - -.material .radio label input[type="radio"]:checked ~ .bmd-radio-outer-circle{ - border-color: #757575; -} - -.material .checkbox label input[type="checkbox"]:checked + .checkbox-decorator .check, -.material .checkbox label input[type="checkbox"]:checked + .checkbox-decorator .check:before { - color: #757575; - border-color: #757575; -} - -.material .checkbox label .checkbox-decorator { - top: 6px; -} - -.material .selectize-dropdown { - padding: 0px; -} - -.material .selectize-dropdown [data-selectable] { - padding: 16px; - white-space: normal; -} - -.material .selectize-dropdown-content { - max-height: unset !important; -} - -.material .selectize-input { - min-height: 32px; - height: 32px; -} - -.material .selectize-input .item { - padding-top: 7px; - margin-bottom: 0px; - max-width: 95%; - width: 95%; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.material .label-addon { - margin-left: calc(0.75rem + 1%); -} - -.material .form-group textarea { - line-height: 1.8; -} - -.material .form-control + .input-group-addon:not(:first-child), -.material .form-control + .input-group-btn:not(:first-child) { - width: auto; -} diff --git a/dist/legalform.js b/dist/legalform.js deleted file mode 100644 index d34b7e9..0000000 --- a/dist/legalform.js +++ /dev/null @@ -1,3290 +0,0 @@ - -var calculationVars = { - globals: [ - 'Array', 'Date', 'JSON', 'Math', 'NaN', 'RegExp', 'decodeURI', 'decodeURIComponent', 'true', 'false', - 'encodeURI', 'encodeURIComponent', 'isFinite', 'isNaN', 'null', 'parseFloat', 'parseInt', 'undefined' - ], - computedRegexp: /("(?:[^"\\]+|\\.)*"|'(?:[^'\\]+|\\.)*')|(^|[^\w\.\)\]\"\'])(\.?)(\w*[a-zA-z]\w*(?:[\.\w\[\]]+(?=[^\w(]|$))?)/g -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = calculationVars; -} - -/** - * We use this lib in LT for deep cloning, in order to preserve getter methods, like toString. - * Method $.extend() does not preserve such methods. - */ - -/*! -Copyright (C) 2015 by Andrea Giammarchi - @WebReflection - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ -var cloner = (function (O) {'use strict'; - - // (C) Andrea Giammarchi - Mit Style - - var - - // constants - VALUE = 'value', - PROTO = '__proto__', // to avoid jshint complains - - // shortcuts - isArray = Array.isArray, - create = O.create, - dP = O.defineProperty, - dPs = O.defineProperties, - gOPD = O.getOwnPropertyDescriptor, - gOPN = O.getOwnPropertyNames, - gOPS = O.getOwnPropertySymbols || - function (o) { return Array.prototype; }, - gPO = O.getPrototypeOf || - function (o) { return o[PROTO]; }, - hOP = O.prototype.hasOwnProperty, - oKs = (typeof Reflect !== typeof oK) && - Reflect.ownKeys || - function (o) { return gOPS(o).concat(gOPN(o)); }, - set = function (descriptors, key, descriptor) { - if (key in descriptors) dP(descriptors, key, { - configurable: true, - enumerable: true, - value: descriptor - }); - else descriptors[key] = descriptor; - }, - - // used to avoid recursions in deep copy - index = -1, - known = null, - blown = null, - clean = function () { known = blown = null; }, - - // utilities - New = function (source, descriptors) { - var out = isArray(source) ? [] : create(gPO(source)); - return descriptors ? Object.defineProperties(out, descriptors) : out; - }, - - // deep copy and merge - deepCopy = function deepCopy(source) { - var result = New(source); - known = [source]; - blown = [result]; - deepDefine(result, source); - clean(); - return result; - }, - deepMerge = function (target) { - known = []; - blown = []; - for (var i = 1; i < arguments.length; i++) { - known[i - 1] = arguments[i]; - blown[i - 1] = target; - } - merge.apply(true, arguments); - clean(); - return target; - }, - - // shallow copy and merge - shallowCopy = function shallowCopy(source) { - clean(); - for (var - key, - descriptors = {}, - keys = oKs(source), - i = keys.length; i--; - set(descriptors, key, gOPD(source, key)) - ) key = keys[i]; - return New(source, descriptors); - }, - shallowMerge = function () { - clean(); - return merge.apply(false, arguments); - }, - - // internal methods - isObject = function isObject(value) { - /*jshint eqnull: true */ - return value != null && typeof value === 'object'; - }, - shouldCopy = function shouldCopy(value) { - /*jshint eqnull: true */ - index = -1; - if (isObject(value)) { - if (known == null) return true; - index = known.indexOf(value); - if (index < 0) return 0 < known.push(value); - } - return false; - }, - deepDefine = function deepDefine(target, source) { - for (var - key, descriptor, - descriptors = {}, - keys = oKs(source), - i = keys.length; i--; - ) { - key = keys[i]; - descriptor = gOPD(source, key); - if (VALUE in descriptor) deepValue(descriptor); - set(descriptors, key, descriptor); - } - dPs(target, descriptors); - }, - deepValue = function deepValue(descriptor) { - var value = descriptor[VALUE]; - if (shouldCopy(value)) { - descriptor[VALUE] = New(value); - deepDefine(descriptor[VALUE], value); - blown[known.indexOf(value)] = descriptor[VALUE]; - } else if (-1 < index && index in blown) { - descriptor[VALUE] = blown[index]; - } - }, - merge = function merge(target) { - for (var - source, - keys, key, - value, tvalue, - descriptor, - deep = this.valueOf(), - descriptors = {}, - i, a = 1; - a < arguments.length; a++ - ) { - source = arguments[a]; - keys = oKs(source); - for (i = 0; i < keys.length; i++) { - key = keys[i]; - descriptor = gOPD(source, key); - if (hOP.call(target, key)) { - if (VALUE in descriptor) { - value = descriptor[VALUE]; - if (shouldCopy(value)) { - descriptor = gOPD(target, key); - if (VALUE in descriptor) { - tvalue = descriptor[VALUE]; - if (isObject(tvalue)) { - merge.call(deep, tvalue, value); - } - } - } - } - } else { - if (deep && VALUE in descriptor) { - deepValue(descriptor); - } - } - set(descriptors, key, descriptor); - } - } - return dPs(target, descriptors); - } - ; - - return { - deep: { - copy: deepCopy, - merge: deepMerge - }, - shallow: { - copy: shallowCopy, - merge: shallowMerge - } - }; - -}(Object)); - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = cloner; -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = defineProperty; -} - -/** - * Define non-enumarable getter property on object - * - * @param {object} object - * @param {string} name - * @param {function} method - */ -function defineProperty(object, name, method) { - Object.defineProperty(object, name, { - enumerable: false, - configurable: false, - get: function() { - return method; - } - }); -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = { setByKeyPath, getByKeyPath }; -} - -/** - * Set (nested) property of object using dot notation - * - * @param {object} target - * @param {string} key - * @param value - */ -function setByKeyPath(target, key, value) { - var parts = key.split('.'); - - for (var i = 0; i < parts.length; i++) { - var part = parts[i]; - - if (i < parts.length -1) { - if (typeof target[part] !== 'object') { - target[part] = {}; - } - - target = target[part]; - } else { - target[part] = value; - } - } -} - -/** - * Get (nested) property of object using dot notation - * - * @param {object} target - * @param {string} key - * @param defaultValue - */ -function getByKeyPath(target, key, defaultValue) { - if (!target || !key) return false; - - key = key.split('.'); - var l = key.length, - i = 0, - p = ''; - - for (; i < l; ++i) { - p = key[i]; - - if (target.hasOwnProperty(p)) target = target[p]; - else return defaultValue; - } - - return target; -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = escapeDots; -} - -/** - * Escape dots in computed keypath name - * @param {string} keypath - * @return {string} - */ -function escapeDots(keypath) { - return typeof keypath === 'string' ? keypath.replace(/\./g, '\\.') : keypath; -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = expandCondition; - var calculationVars = require('./calculation-vars'); -} - -/** - * Normalize ractive condition - * @param {string} condition - * @param {string} group Group name - * @param {Boolean} isCalculated If condition should have syntax of calculated expressions - * @return {string} - */ -function expandCondition(condition, group, isCalculated) { - var computedRegexp = calculationVars.computedRegexp; - var globals = calculationVars.globals; - - // Convert expression to computed - return condition.replace(computedRegexp, function(match, str, prefix, scoped, keypath) { - if (str) return match; // Just a string - if (!scoped && globals.indexOf(keypath) !== -1) return match; // A global, not a keypath - - //Keypath - var name = (scoped && group ? group + '.' : '') + keypath; - if (isCalculated) name = '${' + name + '}'; - - return prefix + ' ' + name; - }); -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = formatLocale; -} - -/** - * Format locale of template or document - * @param {string} locale - * @param {string} format - * @return {string} - */ -function formatLocale(locale, format) { - var delimiter = '_'; - var pos = locale.indexOf(delimiter); - - if (format === 'short') { - if (pos !== -1) locale = locale.substr(0, pos); - } else if (format === 'momentjs') { - locale = locale.toLowerCase(); - if (pos !== -1) { - parts = locale.split(delimiter); - locale = parts[0] === parts[1] ? parts[0] : parts.join('-'); - } - } else if (format) { - throw 'Unknown format "' + format + '" for getting document locale'; - } - - return locale; -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = ltriToUrl; -} - -/** - * Translate an LTRI to a URL - * - * @param {string} url LTRI or URL - * @return {string} - */ -function ltriToUrl(url) { - if (url.match(/^https?:\/\//)) return url; - - var baseElement = document.querySelector('head base'); - var base = baseElement ? baseElement.getAttribute('href') : null; - base = base || '/'; - - var scheme = window.location.protocol + '//'; - var host = window.location.host; - - base = base.replace(/service\/[a-z]+\//, 'service/'); - - if (!base.match(/^(https?:)?\/\//)) { - base = host + '/' + base.replace(/^\//, ''); - } - - if (url.match('lt:')) { - url = url.replace('lt:', ''); - - if (typeof legalforms !== 'undefined') { - host = legalforms.base_url.replace(/https?:\/\//, ''); - } - } - - var auth = url.match(/^[^:\/@]+:[^:\/@]+@/); - if (auth) { - url = url.replace(auth[0], ''); - base = auth[0] + base; - } - - url = url.replace(/^([a-z]+):(\/)?/, function(match, resource) { - var start = resource === 'external' ? host : base.replace(/\/$/, ''); - - return scheme + start + '/' + resource + '/'; - }); - - return url; -} -// Use default date for moment -moment.fn.toString = function() { - if (typeof this.defaultFormat === 'undefined') return this.toDate().toString(); - return this.format(this.defaultFormat); -}; - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = parseNumber; -} - -var numberRegexp = new RegExp('^(?:((?:\\d{1,3}(?:\\.\\d{3})+|\\d+)(,\\d{1,})?)|((?:\\d{1,3}(?:,\\d{3})+|\\d+)(\\.\\d{1,})?))$'); -var dotRegexp = /\./g; -var commaRegexp = /,/g; - -/** - * Create float number from number, given by string with decimal comma/dot - * @param {string} number - * @return {float|null} - */ -function parseNumber(number) { - if (typeof number === 'undefined' || number === null) return null; - - if (typeof number.amount !== 'undefined') { - number = number.amount; - } - - number = number.toString(); - var match = number.match(numberRegexp); - if (!match) return null; - - var isDecimalComma = - typeof match[2] !== 'undefined' || - (typeof match[3] !== 'undefined' && typeof match[4] === 'undefined'); - - number = isDecimalComma ? - number.replace(dotRegexp, '').replace(',', '.') : - number.replace(commaRegexp, ''); - - return parseFloat(number); -} -/** - * Dynamic addition and removing of computed properties in current used version of Ractive (0.9.13) is not supported out of the box. - * So we use this object for that purpose. It uses code, extracted from ractive, and simplified to only cover our needs - * (that is only support computed properties, given as strings). - */ - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = RactiveDynamicComputed; -} - -function RactiveDynamicComputed() { - var self = this; - - this.dotRegExp = /\./g; - this.computedVarRegExp = /\$\{([^\}]+)\}/g; - - /** - * Remove computed property from existing rative instance - * @param {object} ractive - * @param {string} key - */ - this.remove = function(ractive, key) { - var escapedKey = key.replace(dotRegExp, '\\.'); - - delete ractive.computed[key]; - delete ractive.viewmodel.computations[escapedKey]; - } - - /** - * Add computed expression to existing ractive instance - * @param {object} ractive - * @param {string} key - * @param {string} value - */ - this.add = function(ractive, key, value) { - var signature = getComputationSignature(ractive, key, value); - - ractive.computed[key] = value; - ractive.viewmodel.compute(key, signature); - } - - function getComputationSignature(ractive, key, signature) { - if (typeof signature !== 'string') { - throw 'Unable to dynamically add computed property with value of type ' + (typeof signature); - } - - var getter = createFunctionFromString(signature, ractive); - var getterString = signature; - - return { - getter: getter, - setter: undefined, - getterString: getterString, - setterString: undefined, - getterUseStack: undefined - }; - } - - function createFunctionFromString(str, bindTo) { - var hasThis; - - var functionBody = 'return (' + str.replace(self.computedVarRegExp, function (match, keypath) { - hasThis = true; - return ("__ractive.get(\"" + keypath + "\")"); - }) + ');'; - - if (hasThis) { functionBody = "var __ractive = this; " + functionBody; } - var fn = new Function( functionBody ); - return hasThis ? fn.bind( bindTo ) : fn; - } -} - -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = tmplToExpression; -} - -var dotRegExp = /\./g; - -/** - * Insert repeated step index into expression - * @param {object} step - * @param {string} expression - * @return {string} - */ -function tmplToExpression(expressionTmpl, group, idx) { - var prefix = group + '.'; - prefix = prefix.replace(dotRegExp, '\\.'); - - var prefixRegExp = new RegExp('\\$\\{' + prefix, 'g'); - var replacement = '${' + group + '[' + idx + '].'; - - return expressionTmpl.replace(prefixRegExp, replacement); -} -/** - * Change the HTML to Bootstrap Material. - * - * @param $docWizard - */ -(function($) { - $.fn.toMaterial = function() { - if (!$.fn.bootstrapMaterialDesign) { - return; - } - - var $docWizard = $(this); - - // Add class to the material design to prevent another styles for it. - - if (typeof $docWizard.attr('class') !== 'undefined' && $docWizard.attr('class').indexOf('wizard-step') === -1) { - $docWizard.addClass('material'); - } - - // Do all labels floating for nice view - $docWizard.find('.form-group').addClass('bmd-form-group'); - $docWizard.find('.form-group > label').addClass('form-control-label bmd-label-static'); - - // Make all inputs a form control - $docWizard.find('.form-group > input').addClass('form-control'); - $docWizard.find('.selectize-input > input').addClass('form-control'); - - // Added prev-next button to the each step - var $wizardSteps = $docWizard.find('.wizard-step'); - - $wizardSteps.each(function(index, value) { - if (!$(this).children('.wizzard-form').length) { - var $wizardForm = $('
').appendTo(this); - $wizardForm.addClass('wizzard-form'); - $wizardForm.append($(this).find('form')); - $wizardForm.append($(this).find('.wizards-actions')); - } - }); - - // Change checkboxes to the bootstrap material - $docWizard.find('.form-group .option').each(function() { - var $div = $(this); - var type = 'radio'; - $div.addClass($div.find('input').attr('type')); - $div.find('input').prependTo($div.find('label')); - }); - - // Change likert-view on bootstrap material - $docWizard.find('.likert-answer').each(function(){ - if (!$(this).children('.radio').length) { - var $div = $('
').appendTo(this).addClass('radio'); - var $label = $('