/*~/Script/Lanta/Util.js*/ function getChildrenWithSelf(root) { var result = []; if (!!root) { result.push(root); var children = root.getElementsByTagName("*"); for (var i = 0; i < children.length; i++) { result.push(children[i]); } } return result; } /*------------------------------------------------------*/ /*~/Script/Lanta/FuncUtil.js*/ var lanta = lanta || {}; lanta.FuncUtil = lanta.FuncUtil || {}; lanta.FuncUtil.getArgumentNames = lanta.FuncUtil.getArgumentNames || function(func) { const stripComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; const argumentNames = /([^\s,]+)/g; var fnStr = func.toString().replace(stripComments, ''); var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(argumentNames); if (result === null) result = []; return result; }; lanta.FuncUtil.invoke = lanta.FuncUtil.invoke || function(fn, context, argumentValueFactory) { var argary = []; var argNames = lanta.FuncUtil.getArgumentNames(fn); for (var i = 0; i < argNames.length; i++) { var argName = argNames[i]; argary.push(argumentValueFactory(context, argName)); } return fn.apply(context, argary); }; /*------------------------------------------------------*/ /*~/Script/Lanta/AttributeBinding.js*/ var lanta = lanta || {}; lanta.AttributeBinding = lanta.AttributeBinding || function(owner, handler) { var arg = lanta.FuncUtil.getArgumentNames(handler); if (arg.length !== 1) { throw new Error("Attribute bound function must have one argument: " + handler.toString()); } var attributeName = arg[0]; var find = function() { var element = owner; while (!!element) { var value = null; if (element.getAttribute && (!!(value = element.getAttribute(attributeName)))) { if (value === "null") { value = null; } if (owner["lastAttributeBindingValueFor_" + attributeName] === value) { return; } handler(value); owner["lastAttributeBindingValueFor_" + attributeName] = value; return; } element = element.parentElement; } setTimeout(find, Math.floor(Math.random() * 100) + 1); }; setTimeout(find, 0); lanta.BindingCore.subscribeNotificationsCallback(owner, find); }; /*------------------------------------------------------*/ /*~/Script/Lanta/CoreOps.js*/ var lt = lt || {}; lanta.CoreOps = lanta.CoreOps || {}; lanta.Extensions = lanta.Extensions || {}; lanta.Extensions.defaultErrorHandler = lanta.Extensions.defaultErrorHandler || function(error) { console.error(error); alert(error.message || error); }; window.onbeforeunload = function () { //lanta.Extensions.defaultErrorHandler = function(e) {}; }; lanta.CoreOps.defaultCustomArgumentFactory = function (element, argumentName) { throw new Error("Cannot find element by \"" + argumentName + "\" inside of " + element); }; lanta.Extensions.customArgumentFactory = lanta.Extensions.customArgumentFactory || lanta.CoreOps.defaultCustomArgumentFactory; if (!lanta.CoreOps.elementSeekers) { var tagSeeker = function (target, tag, value) { var result = []; var childrenByTagName = getChildrenWithSelf(target); for (var i = 0; i < childrenByTagName.length; i++) { var child = childrenByTagName[i]; var name = child.getAttribute(tag); if (name === value) { result.push(child); } } if (result.length === 0) { return null; } return result; }; var seekers = []; seekers.push(function (target, id) { return tagSeeker(target, "id", id); }); seekers.push(function (target, className) { return target.getElementsByClassName(className); }); seekers.push(function (target, name) { return tagSeeker(target, "name", name); }); seekers.push(function (target, ltName) { return tagSeeker(target, "lt-name", ltName); }); seekers.push(lanta.Extensions.customArgumentFactory); lanta.CoreOps.elementSeekers = seekers; } lanta.CoreOps.seekElement = lanta.CoreOps.seekElement || function (root, elementName, doNotThrow) { var result = null; for (var i = 0; i < seekers.length; i++) { var seeker = seekers[i]; if ((!!doNotThrow) && seeker === lanta.CoreOps.defaultCustomArgumentFactory) { continue; } result = seeker(root, elementName); if ((!result) || (result.length === 0)) { continue; } break; } if (!result) { return null; } if (result.length === 0) { return null; } if (result.length === 1) { result = result[0]; } return result; }; lanta.CoreOps.seekClosestElement = lanta.CoreOps.seekClosestElement || function (refElement, name) { for (; !!refElement; refElement = refElement.parentElement) { var result = lanta.CoreOps.seekElement(refElement, name, true); if (!!result) { if (Array.isArray(result) && (result.length > 0)) { return result[0]; } return result; } } return null; }; lanta.CoreOps.attachController = lanta.CoreOps.attachController || function (element, controllerFunction, viewModel) { try { controllerFunction = controllerFunction || function() {}; element["lt_element_controllers"] = element["lt_element_controllers"] || []; element["lt_element_controllers"].push(controllerFunction); element.bind = function(handler) { var builder = new lanta.BindingCore.BindingBuilder(this, handler); builder.bind(); return builder; }; element.attribute = function (handler) { this["lt_attribute_bindings"] = element["lt_attribute_bindings"] || []; this["lt_attribute_bindings"].push(new lanta.AttributeBinding(this, handler)); }; element.bind.bind(element); lanta.Markup.process(element); lanta.FuncUtil.invoke(controllerFunction, element, lanta.CoreOps.seekElement); var bindingProcessor = element["lt_element_binding_processor"]; if (!!bindingProcessor) { if (viewModel) { lt.setViewModel(element, viewModel); } bindingProcessor.activate(); } } catch (e) { lanta.Extensions.defaultErrorHandler(e); } }; lt.getViewModel = lt.getViewModel || function(element) { if (!element) { return null; } if (!!element["lt_view_model"]) { return element["lt_view_model"]; } return lt.getViewModel(element.parentElement); }; lt.setViewModel = lt.setViewModel || function(element, vm) { lanta.BindingCore.setViewModel(element, vm); lt.notify(element); }; /*------------------------------------------------------*/ /*~/Script/Lanta/BindingCore.js*/ var lanta = lanta || {}; lanta.BindingCore = lanta.BindingCore || {}; lanta.BindingCore.subscribeNotificationsCallback = lanta.BindingCore.subscribeNotificationsCallback || function(owner, callback) { if (!owner.ltNotificationListeners) { owner.ltNotificationListeners = []; } owner.ltNotificationListeners.push(callback); }; lanta.BindingCore.NotificationManager = lanta.BindingCore.NotificationManager || function() { var self = this; var queue = []; var timer = null; var tickTimeout = 30; var tick = function() { var timeoutProlonged = false; if (queue.length > 500) { tickTimeout = 100; timeoutProlonged = true; } else { tickTimeout = 30; } var startTime = new Date(); while (queue.length > 0) { if ((new Date() - startTime) > tickTimeout) { if (!timeoutProlonged) { tickTimeout = 100; timeoutProlonged = true; } else { return; } } var current = queue.shift(); if (!!current.element.notifyModelChange) { current.element.notifyModelChange(current.notificationName); } if (!!current.element.ltNotificationListeners) { var ary = current.element.ltNotificationListeners; for (var x = 0; x < ary.length; x++) { var callback = ary[x]; callback(current.notificationName); } } var children = current.element.children || current.element.childNodes; for (var i = 0; i < children.length; i++) { queue.push({ element: children[i], notificationName: current.notificationName }); } } window.clearInterval(timer); timer = null; }; var thresholdUp = 1000; var thresholdDn = 0; var enqueue = function (owner, name) { if (queue.length > thresholdUp) { console.log("Upper threshold reached - " + queue.length); thresholdUp = thresholdUp * 2; thresholdDn = thresholdUp / 2; } if (queue.length < thresholdDn) { console.log("Bottom threshold reached - " + queue.length); thresholdUp = thresholdUp / 2; thresholdDn = thresholdUp / 2; if (thresholdUp < 1000) { thresholdUp = 1000; } } if (queue.length > 100 && (!!owner)) { for (var i = 0; i < queue.length; i++) { if (queue[i].element === owner) { return; } } } queue.push({ element: owner, notificationName: name }); if (queue.length === 1) { if (timer !== null) { window.clearInterval(timer); timer = null; } timer = window.setInterval(tick, 50); } }; self.enqueueNotification = function (name) { if (queue.length > 0) { queue.splice(0, queue.length); } enqueue(window.document, name); }; self.notifyElement = function(element) { enqueue(element, ""); }; }; lanta.BindingCore.NotificationManager.instance = lanta.BindingCore.NotificationManager.instance || new lanta.BindingCore.NotificationManager(); lanta.BindingCore.notify = lanta.BindingCore.notify || function (target) { try { if (target instanceof HTMLElement) { lanta.BindingCore.NotificationManager.instance.notifyElement(target); return; } } catch (ee) { console.error(ee); } lanta.BindingCore.NotificationManager.instance.enqueueNotification(target); }; lanta.BindingCore.setViewModel = lanta.BindingCore.setViewModel || function(element, viewModel) { var processor = element["lt_element_binding_processor"]; if (!processor) { return; } processor.setViewModel(viewModel); }; lanta.BindingCore.ComparerResult = lanta.BindingCore.ComparerResult || { FORBIDDEN:2, CHANGED:1, UNCHANGED:0 }; lanta.BindingCore.defaultRelativeSourceFactory = lanta.BindingCore.defaultRelativeSourceFactory || function(owner, expression) { //return owner["lt_view_model"]; // EXPERIMENT: return lt.getViewModel(owner); }; lanta.BindingCore.defaultExpressionEvaluator = lanta.BindingCore.defaultExpressionEvaluator || function (owner, expression, relativeSourceFactory) { if (expression === null || expression === undefined) { expression = ""; } var parts = expression.split("."); var parentExp = relativeSourceFactory(owner, expression); for (var i = 0; i < parts.length; i++) { if (parts[i] === null || parts[i] === undefined || parts[i].length === 0) { continue; } if (parentExp === null || parentExp === undefined) { return parentExp; } parentExp = parentExp[parts[i]]; } return parentExp; }; lanta.BindingCore.defaultComparer = lanta.BindingCore.defaultComparer || function(oldValue, newValue) { if (oldValue === undefined) oldValue = null; if (newValue === undefined) newValue = null; if (newValue == null && oldValue == null) { return lanta.BindingCore.ComparerResult.FORBIDDEN; } if (newValue === oldValue) { return lanta.BindingCore.ComparerResult.UNCHANGED; } return lanta.BindingCore.ComparerResult.CHANGED; }; lanta.BindingCore.createParameter = lanta.BindingCore.createParameter || function(expression, relativeSourceFactory, comparer, expressionEvaluator) { relativeSourceFactory = relativeSourceFactory || lanta.BindingCore.defaultRelativeSourceFactory; comparer = comparer || lanta.BindingCore.defaultComparer; expressionEvaluator = expressionEvaluator || lanta.BindingCore.defaultExpressionEvaluator; return { expression: expression, comparer: comparer, evaluator: expressionEvaluator, sourceFactory: relativeSourceFactory }; }; lanta.BindingCore.bind = lanta.BindingCore.bind || function(element, func, parameters) { if (!parameters.length) { throw new Error("Array required"); } var processor = element["lt_element_binding_processor"]; if (!processor) { processor = new lanta.BindingCore.ElementBindingProcessor(element); element["lt_element_binding_processor"] = processor; } processor.addBinding(func, parameters); }; lanta.BindingCore.ElementBindingProcessor = lanta.BindingCore.ElementBindingProcessor || function(owner) { var bindings = []; var active = false; this.addBinding = function (func, parameters) { var newBinding = new lanta.BindingCore.ElementBinding(owner, func, parameters); bindings.push(newBinding); }; var notifyModelChange = function (expression) { if (!active) { return; } for (var i = 0; i < bindings.length; i++) { bindings[i].notify(expression); } }; this.setViewModel = function(viewModel) { for (var i = 0; i < bindings.length; i++) { bindings[i].notify(null, viewModel); } }; this.activate = function() { active = true; notifyModelChange(""); }; this.notify = this.activate; owner.notifyModelChange = notifyModelChange; }; lanta.BindingCore.ElementBinding = lanta.BindingCore.ElementBinding || function(owner, handler, parameters) { var oldValues = []; var oldValuesSerialized = []; var serialize = function(x) { if (x === undefined) x = null; if (x === null) return null; return JSON.stringify(x); }; this.notify = function(expression, viewModel) { try { if (expression === undefined) expression = null; if (viewModel === undefined) viewModel = null; if ((expression !== null) && (viewModel !== null)) { throw new Error("Cannot notify by expression and either ViewModel"); } if (viewModel !== null) { owner["lt_view_model"] = viewModel; } var result = lanta.BindingCore.ComparerResult.UNCHANGED; for (var j = 0; j < parameters.length; j++) { var param = parameters[j]; var newValue = param.evaluator(owner, param.expression, param.sourceFactory); var serializedOldValue = oldValuesSerialized[j]; var serializedNewValue = serialize(newValue); var comparationResult = param.comparer(serializedOldValue, serializedNewValue); oldValuesSerialized[j] = serializedNewValue; if (comparationResult > result) { result = comparationResult; } oldValues[j] = newValue; } if (result !== lanta.BindingCore.ComparerResult.CHANGED) { return; } handler.apply(owner, oldValues); } catch (e) { lanta.Extensions.defaultErrorHandler(e); } }; }; var lt = lt || {}; lt.notify = lanta.notify || function(target) { try { target = target || ""; lanta.BindingCore.notify(target); } catch (e) { lanta.Extensions.defaultErrorHandler(e); } }; lt.updateBindings = lt.updateBindings || function (element) { var processor = element["lt_element_binding_processor"]; if (!!processor) { processor.notify(""); } }; /*------------------------------------------------------*/ /*~/Script/Lanta/ItemGeneration.js*/ var lt = lt || {}; lanta.itemsGeneration = lanta.itemsGeneration || {}; lanta.itemsGeneration.Generator = lanta.itemsGeneration.Generator || function() { var getChildByKey = function(container, key) { var children = container.children || container.childNodes; for (var i = 0; i < children.length; i++) { var child = children[i]; if (child["lt-item-key"] === key) { return child; } } return null; }; var createChild = function(itemTemplate, key) { var clone = itemTemplate.cloneNode(true); clone["lt-item-key"] = key; clone.className = clone.className.replace(/\blt-template\b/g, ""); return clone; }; var placeTo = function(container, element, position) { var children = container.children || container.childNodes; if (children.length > position && children[position] === element) { return; } if (position >= children.length - 1) { container.appendChild(element); return; } var nextChild = children[position]; if (nextChild === element) { return; } container.insertBefore(element, nextChild); }; this.generate = function(container, itemTemplate, collection, keyGenerator, controller) { try { var templateControllers = itemTemplate["lt_element_controllers"] || []; if ((collection === null) || (collection === undefined)) { container.innerHTML = ""; return; } var keyIndex = {}; for (var keyItemIndex in collection) { if (!collection.hasOwnProperty(keyItemIndex)) continue; var keyDataItem = collection[keyItemIndex]; var keykey = (!keyGenerator) ? keyItemIndex : keyGenerator(keyDataItem); keyIndex[keykey] = 1; } var children = container.children || container.childNodes; for (var i = children.length - 1; i >= 0; i--) { var ch = children[i]; var childKey = ch["lt-item-key"]; if (!keyIndex[childKey]) { container.removeChild(ch); } } var position = 0; for (var itemIndex in collection) { if (!collection.hasOwnProperty(itemIndex)) continue; var dataItem = collection[itemIndex]; var key = (!keyGenerator) ? position : keyGenerator(dataItem); var attach = false; var child = getChildByKey(container, key); if (!child) { attach = true; child = createChild(itemTemplate, key); } placeTo(container, child, position); if (attach) { for (var tcindex = 0; tcindex < templateControllers.length; tcindex++) { var templateController = templateControllers[tcindex]; lanta.CoreOps.attachController(child, templateController, dataItem); } lanta.CoreOps.attachController(child, controller, dataItem); } lanta.BindingCore.setViewModel(child, dataItem); position++; } } catch (e) { lanta.Extensions.defaultErrorHandler(e); } }; }; lanta.itemsGeneration.Generator.instance = lanta.itemsGeneration.Generator.instance || new lanta.itemsGeneration.Generator(); lanta.itemsGeneration.generate = lanta.itemsGeneration.generate || function(container, itemTemplate, collection, keyGenerator, controller) { lanta.itemsGeneration.Generator.instance.generate(container, itemTemplate, collection, keyGenerator, controller); }; var lt = lt || {}; lt.generate = lt.generate || function(container, itemTemplate, collection, keyGenerator, controller) { lanta.itemsGeneration.Generator.instance.generate(container, itemTemplate, collection, keyGenerator, controller); }; /*------------------------------------------------------*/ /*~/Script/Lanta/Lt.Bind.js*/ var lt = lt || {}; lanta.BindingCore = lanta.BindingCore || {}; lanta.BindingCore.BindingBuilder = lanta.BindingCore.BindingBuilder || function(owner, handler) { var self = this; var bindingParams = []; var windowSourceFactory = function (owner, expression) { return window; }; var findVmSourceFactory = function(owner, expression) { if (!owner) { return null; } if (!!owner["lt_view_model"]) { return owner["lt_view_model"]; } return findVmSourceFactory(owner.parentElement, expression); }; var canBeNullComparer = function(oldValue, newValue) { if (oldValue !== newValue) { return lanta.BindingCore.ComparerResult.CHANGED; } return lanta.BindingCore.ComparerResult.UNCHANGED; }; this.canBeNullFunction = function(argument) { var param = this.getParamByArgument(argument); param.comparer = canBeNullComparer; this.updateBinding(); return this; }; this.relativeToVmFunction = function(expression, argument) { var param = this.getParamByArgument(argument); param.sourceFactory = findVmSourceFactory; param.expression = expression || param.expression; this.updateBinding(); return this; }; this.toGlobalFunction = function (expression, argument) { var param = this.getParamByArgument(argument); if (!!expression) { param.expression = expression; } else { param.expression = argument; } param.hasGlobalSource = true; param.sourceFactory = windowSourceFactory; return this; }; this.relativeToGlobalFunction = function(expression, argument) { return this.toGlobalFunction(expression + "." + argument, argument); }; this.getParamByArgument = function(argumentName) { for (var i = 0; i < bindingParams.length; i++) { var bp = bindingParams[i]; if (bp.originalArgumentName === argumentName) { return bp; } } throw new Error("Argument " + argumentName + " does not exist"); }; this.relativeToGlobal = function(modelName) { for (var i = 0; i < bindingParams.length; i++) { var bp = bindingParams[i]; if (bp.hasGlobalSource) { continue; } bp.expression = modelName + "." + bp.expression; bp.hasGlobalSource = true; bp.sourceFactory = windowSourceFactory; } return this; }; this.updateBinding = function() { }; this.bind = function() { var builder = self; var argumentNames = lanta.FuncUtil.getArgumentNames(handler); var rootPath = owner["lt-view-model-base"]; for (var i = 0; i < argumentNames.length; i++) { var argumentName = argumentNames[i]; var expression = (!!rootPath) ? rootPath + "." + argumentName : argumentName; var parameter = lanta.BindingCore.createParameter(expression); parameter.originalArgumentName = argumentName; bindingParams.push(parameter); builder[argumentName + "CanBeNull"] = (new Function(" return this.canBeNullFunction('" + argumentName + "'); ")).bind(builder); builder[argumentName + "ToGlobal"] = (new Function("expression", " return this.toGlobalFunction(expression, '" + argumentName + "'); ")).bind(builder); builder[argumentName + "RelativeToGlobal"] = (new Function("expression", " return this.relativeToGlobalFunction(expression, '" + argumentName + "'); ")).bind(builder); builder[argumentName + "RelativeToVm"] = (new Function("expression", " return this.relativeToVmFunction(expression, '" + argumentName + "'); ")).bind(builder); } lanta.BindingCore.bind(owner, handler, bindingParams); return builder; }; }; /*------------------------------------------------------*/ /*~/Script/Lanta/Lt.Attach.js*/ lanta.ControlBuilder = function() { var self = this; var elements = []; this.element = function (e) { if ((typeof e) === "string") { var ebid = document.getElementById(e); if (!ebid) { ebid = document.querySelector(e); if (!ebid) { throw new Error("Element '" + e + "' not found"); } } elements.push(ebid); return self; } if (e.nodeType > 0) { elements.push(e); return self; } if (e.length !== undefined) { if (e.length !== 1) { throw new Error("Passed array has length=" + e.length); } return self.element(e[0]); } throw new Error("lt.element expects an element, elementId, css selector or element[], elementId[], selector[]. Invalid value passed:" + e); }; this.elements = function (e) { if ((typeof e) === "string") { var ebid = document.querySelectorAll(e); if ((!ebid) || (ebid.length === 0)) { throw new Error("No elements returned by selector '" + e + "'"); } for (var i = 0; i < ebid.length; i++) { self.element(ebid[i]); } return self; } if (e.length !== undefined) { if (e.length === 0) { throw new Error("Passed array is empty"); } for (var j = 0; j < e.length; j++) { self.element(e[j]); } return self; } throw new Error("lt.elements expects a selector, element[], elementId[], selector[]. Invalid value passed:" + e); }; this.withModel = function (m) { var modelParam = lanta.BindingCore.createParameter(m, function(owner, expression) { return window; }); for (var i = 0; i < elements.length; i++) { var element = elements[i]; lanta.BindingCore.bind(element, function(value) { this["lt_view_model"] = value; lt.updateBindings(this); }, [modelParam]); } return this; }; this.attach = function(controller) { controller = controller || function() {}; var model = null; for (var i = 0; i < elements.length; i++) { var element = elements[i]; var eModel = element.getAttribute("data-model") || null; if (i > 0 && model !== eModel) { throw new Error("Mismatch data-model values of attaching elements"); } model = eModel; if (model !== null) { this.withModel(model); } lanta.CoreOps.attachController(elements[i], controller); } return { attach: self.attach }; }; }; lt.element = function(e) { var builder = new lanta.ControlBuilder(); return builder.element(e); }; lt.elements = function(e) { var builder = new lanta.ControlBuilder(); return builder.elements(e); }; /*------------------------------------------------------*/ /*~/Script/Lanta/Lanta.Markup.js*/ var lanta = lanta || {}; lanta.Markup = lanta.Markup || {}; lanta.Markup.attributeSetters = lanta.Markup.attributeSetters || []; lanta.Markup.elementMarkerCounter = lanta.Markup.elementMarkerCounter || 0; if (lanta.Markup.attributeSetters.length === 0) { // set attribute lanta.Markup.attributeSetters.push(function (target, propertyName, value) { target.setAttribute(propertyName, value); target[propertyName] = value; return true; }); //style setter lanta.Markup.attributeSetters.push(function (target, propertyName, value) { if (propertyName.indexOf("style.") !== 0) { return false; } var props = propertyName.split('.'); var currP = target["style"]; if (!currP) { target["style"] = currP = {}; } for (var i = 1; i < props.length - 1; i++) { currP = currP[props[i]]; } currP[props[props.length - 1]] = value; return true; }); //class lanta.Markup.attributeSetters.push(function (target, propertyName, value) { if (propertyName.indexOf("class.") !== 0) { return false; } var className = propertyName.substring(6); var currentClasses = target.className.split(" "); var newClasses = []; for (var i = 0; i < currentClasses.length; i++) { if (currentClasses[i] !== className) { newClasses.push(currentClasses[i]); } } if (value) { newClasses.push(className); } target.setAttribute("class", newClasses.join(" ")); return true; }); //not_class lanta.Markup.attributeSetters.push(function (target, propertyName, value) { if (propertyName.indexOf("class!.") !== 0) { return false; } var className = propertyName.substring(7); var currentClasses = target.className.split(" "); var newClasses = []; for (var i = 0; i < currentClasses.length; i++) { if (currentClasses[i] !== className) { newClasses.push(currentClasses[i]); } } if (!value) { newClasses.push(className); } target.setAttribute("class", newClasses.join(" ")); return true; }); //checked, selected, disabled lanta.Markup.attributeSetters.push(function (target, propertyName, value) { if (propertyName !== "checked" && propertyName !== "selected" && propertyName !== "disabled") { return false; } if (!!value) { target.setAttribute(propertyName, value); } else { target.removeAttribute(propertyName); } target[propertyName] = value; return true; }); //text setter lanta.Markup.attributeSetters.push(function (target, propertyName, value) { if (propertyName !== "text") { return false; } var text = document.createTextNode(value); var p = document.createElement('p'); p.appendChild(text); target.innerHTML = p.innerHTML; return true; }); //itemsSource lanta.Markup.attributeSetters.push(function(target, propertyName, value) { if (propertyName.toLowerCase() !== "itemssource") { return false; } if ((!value) || (!value.length) || (value.length === 0)) { if (!target["__ltItemTemplate"]) { return true; } } var doGeneration = function (container, collection, itemTemplate) { container["__ltItemTemplate"] = itemTemplate; var keySelector = null; if (!(keySelector = container["__ltItemKeySelector"])) { var keyPropertyName = container.getAttribute("data-key"); if (!keyPropertyName) { container.innerHTML = "ATTRIBUTE DATA-KEY NOT FOUND"; return true; } keySelector = new Function("__itemVm", "return __itemVm['" + keyPropertyName + "']"); container["__ltItemKeySelector"] = keySelector; } lt.generate(container, itemTemplate, collection, keySelector); }; var template = null; if (!(template = target["__ltItemTemplate"])) { var templateUrl = target.getAttribute("template-url"); if (templateUrl) { var templateContainerId = "templateContainerId_" + templateUrl; var templateContainer = document.getElementById(templateContainerId); if (templateContainer) { doGeneration(target, value, templateContainer.firstChild); return true; } var templatarium = document.getElementById("lt-templatarium"); if (!templatarium) { templatarium = document.createElement("div"); templatarium.setAttribute("id", "lt-templatarium"); document.body.appendChild(templatarium); templatarium.setAttribute("style", "display:none"); } templateContainer = document.createElement("div"); templateContainer.setAttribute("id", templateContainerId); templatarium.appendChild(templateContainer); lt.fillBy(templateContainer, templateUrl, function (placeHolder) { doGeneration(target, value, placeHolder.firstChild); }); return true; } var templates = []; // target.querySelectorAll(".lt-template"); for (var i = 0; i < target.children.length; i++) { var child = target.children[i]; var childClass = child.getAttribute("class") || ""; if (childClass.indexOf("lt-template") > -1) { templates.push(child); } } if (templates.length === 0) { target.innerHTML = "NO TEMPLATE"; return true; } if (templates.length > 1) { target.innerHTML = "REDUNDANT TEMPLATE DEFINITION"; return true; } template = templates[0]; } doGeneration(target, value, template); return true; }); }; lanta.Markup.createElementUid = lanta.Markup.createElementUid || function () { return ("mrk_"+[1e7]+[1e3]+[4e3]+[8e3]+[1e11]).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); }; lanta.Markup.getElementMarker = lanta.Markup.getElementMarker || function(element) { var marker = element["lt-autobind-marker"]; if (!!marker) { return marker; } marker = "mrk_" + lanta.Markup.createElementUid(); element["lt-autobind-marker"] = marker; return marker; }; lanta.Markup.getChildByMarker = lanta.Markup.getChildByMarker || function(root, marker) { var allChildren = getChildrenWithSelf(root); for (var i = 0; i < allChildren.length; i++) { var e = allChildren[i]; if (e["lt-autobind-marker"] === marker) { return e; } } return null; }; lanta.Markup.setValue = lanta.Markup.setValue || function(target, propertyName, value) { for (var i = lanta.Markup.attributeSetters.length - 1; i >= 0; i--) { var setter = lanta.Markup.attributeSetters[i]; if (setter(target, propertyName, value)) { return; } } }; lanta.Markup.bindExpression = lanta.Markup.bindExpression || function(owner, element, expression) { var expressions = expression.split(";"); for (var expIndex = 0; expIndex < expressions.length; expIndex ++) { var exp = expressions[expIndex]; if (exp.trim().length === 0) { continue; } var parts = exp.split(":"); if (parts.length !== 2) { throw new Error("Invalid expression '" + exp + "'"); } var to = parts[0].trim(); var from = parts[1].trim(); var param = lanta.BindingCore.createParameter(from); var marker = lanta.Markup.getElementMarker(element); var fn = new Function(["_value"], " var target = lanta.Markup.getChildByMarker(this, '" + marker + "'); if (!!target) { lanta.Markup.setValue(target, '" + to + "', _value); }\r\n//# sourceURL="+to+"_"+from+".js"); lanta.BindingCore.bind(owner, fn, [param]); } }; lanta.Markup.bindItemsSourceExpression = lanta.Markup.bindItemsSourceExpression || function (owner, element, expression) { var param = lanta.BindingCore.createParameter(expression); var marker = lanta.Markup.getElementMarker(element); var children = element.children || element.childNodes; var itemTemplate = children[0]; if (!itemTemplate) { throw new Error("Element " + element.toString() + " has items-source, but doesn't have any child element, which is required to be an item template"); } var keyGeneratorLambda = element.getAttribute("item-key"); if (!keyGeneratorLambda) { keyGeneratorLambda = "null"; } else { keyGeneratorLambda = "function(VM){ return " + keyGeneratorLambda + "; }"; } element["lt-item-template"] = itemTemplate; var fn = new Function(["_value"], " var container = lanta.Markup.getChildByMarker(this, '" + marker + "');\r\n" + "var template = container['lt-item-template']; \r\n if(!template) { throw new Error('No item template found'); } \r\n" + "lanta.itemsGeneration.Generator.instance.generate(container, template, _value, " + keyGeneratorLambda + ");\r\n" + "\r\n//# sourceURL=" + element.toString() + "_itemsGeneration.js"); lanta.BindingCore.bind(owner, fn, [param]); }; lanta.Markup.multieventMacros = { "userinput:":"keyup:change:mouseup:" }; lanta.Markup.bindEventExpression = lanta.Markup.bindEventExpression || function(owner, element, expression) { var expressions = []; var rawExpressions = expression.split(";"); for (var ri = 0; ri < rawExpressions.length; ri++) { var rawExpression = rawExpressions[ri].trim(); if (rawExpression.length < 0) { continue; } for (var macro in lanta.Markup.multieventMacros) { if (lanta.Markup.multieventMacros.hasOwnProperty(macro)) { rawExpression = rawExpression.replace(macro, lanta.Markup.multieventMacros[macro]); } } var reparts = rawExpression.split(':'); if (reparts.length < 3) { expressions.push(rawExpression); continue; } for (var evtinx = 0; evtinx < (reparts.length - 1); evtinx++) { expressions.push(reparts[evtinx] + ':' + reparts[reparts.length - 1]); } } for (var expIndex = 0; expIndex < expressions.length; expIndex++) { var exp = expressions[expIndex]; if (exp === null || exp.length === 0) { continue; } var parts = exp.split(":"); if (parts.length !== 2) { console.warn("Invalid expression '" + exp + "'"); continue; } var eventType = parts[0].trim(); var handler = parts[1].trim(); var handlerParts = handler.split("(").join(",").split(")").join(",").split(","); for (var i = 0; i < handlerParts.length; i++) { handlerParts[i] = handlerParts[i].trim(); } if (handlerParts.length < 1) { continue; } var eMarker = lanta.Markup.getElementMarker(element); var method = handlerParts.shift(); var params = []; for (var j = 0; j < handlerParts.length; j++) { var expr = handlerParts[j].trim(); if ((!expr) || (expr.length < 1)) { continue; } params.push(expr); } var eventInfo = JSON.stringify({ source: eMarker, method: method, arguments: params }); eventInfo = eventInfo.split("'").join("\\'"); var fnCode = "lanta.Markup.fireEvent(event, JSON.parse('" + eventInfo + "'))"; element.addEventListener(eventType, new Function(["event"], fnCode)); } }; lanta.Markup.fireEvent = lanta.Markup.fireEvent || function(event, eventInfo) { try { var handler = null; var elementOwner = event.srcElement; var vm = null; var viewModelOwner = event.srcElement; for (; !!viewModelOwner; viewModelOwner = viewModelOwner.parentElement) { vm = viewModelOwner["lt_view_model"]; if (!!vm) { break; } } var args = []; for (var argumentIndex = 0; argumentIndex < eventInfo.arguments.length; argumentIndex++) { var argumentVm = vm; var argumentExpression = eventInfo.arguments[argumentIndex]; if (argumentExpression === "true") { args.push(true); continue; } else if (argumentExpression === "VM") { args.push(argumentVm); continue; } else if (argumentExpression === "false") { args.push(false); continue; } else if (argumentExpression === "this") { args.push(event.srcElement); continue; } else if (argumentExpression === "event") { args.push(event); continue; } else if (argumentExpression.indexOf("'") === 0 || argumentExpression.indexOf('"') === 0) { argumentExpression = argumentExpression.substring(1); if (argumentExpression[argumentExpression.length - 1] === '"' || argumentExpression[argumentExpression.length - 1] === "'") { argumentExpression = argumentExpression.substring(0, argumentExpression.length - 1); } args.push(argumentExpression); continue; } else if (!isNaN(argumentExpression)) { args.push(Number.parseFloat(argumentExpression)); continue; } else if (argumentExpression === "null") { args.push(null); continue; } else if (argumentExpression.indexOf("this.") === 0) { argumentExpression = argumentExpression.substring(5); argumentVm = event.srcElement; } else if (argumentExpression.indexOf("$") === 0) { var elmName = argumentExpression.substring(1); var argParts = elmName.split("."); if (!viewModelOwner) { console.error("Cannot locate $" + argParts[0] + "because the root element was not found"); } var element = lanta.CoreOps.seekClosestElement(event.srcElement, argParts[0]); if (!element) { console.error("Cannot locate $" + argParts[0]); } argumentVm = element; argParts.shift(); argumentExpression = argParts.join("."); } if (argumentVm === null || argumentVm === undefined) { args.push(null); continue; } var obtained = lanta.BindingCore.defaultExpressionEvaluator(viewModelOwner, argumentExpression, function() { return argumentVm; }); args.push(obtained); } if (eventInfo.method.indexOf("VM.") === 0) { if (vm === null || vm === undefined) { console.warn("Cannot invoke " + eventInfo.method + " because VM is null"); return; } var methodExpression = eventInfo.method.substring(3); handler = lanta.BindingCore.defaultExpressionEvaluator(null, methodExpression, function() { return vm; }); if (!handler) { console.error("Cannot invoke " + eventInfo.method + " because the method was not found"); return; } elementOwner = vm; } else if (eventInfo.method.indexOf("window.") === 0) { var methodExpression = eventInfo.method.substring(7); handler = lanta.BindingCore .defaultExpressionEvaluator(null, methodExpression, function() { return window; }); if (!handler) { console.error("Cannot invoke " + eventInfo.method + " because the method was not found"); return; } } else { for (; !!elementOwner; elementOwner = elementOwner.parentElement) { handler = elementOwner[eventInfo.method]; if (!handler || !handler.apply || !handler.call) { continue; } break; } } if (!handler) { throw new Error("Event handler '" + eventInfo.method + "' not found"); } handler.apply(elementOwner, args); } catch (e) { lanta.Extensions.defaultErrorHandler(e); } }; lanta.Markup.process = lanta.Markup.process || function(owner) { try { var allChildren = getChildrenWithSelf(owner); for (var i = 0; i < allChildren.length; i++) { var child = allChildren[i]; var dataBindExp = child.getAttribute("data-bind"); if (!!dataBindExp) { lanta.Markup.bindExpression(owner, child, dataBindExp); } var eventExp = child.getAttribute("event-bind"); if (!!eventExp) { lanta.Markup.bindEventExpression(owner, child, eventExp); } var itemsSourceExp = child.getAttribute("items-source"); if (!!itemsSourceExp) { lanta.Markup.bindItemsSourceExpression(owner, child, itemsSourceExp); } } } catch (e) { lanta.Extensions.defaultErrorHandler(e); } }; /*------------------------------------------------------*/ /*~/Script/Lanta/Lt.Call.js*/ var lanta = lanta || {}; lanta.ApiCallBuilder = lanta.ApiCallBuilder || function (url) { var self = this; var queryString = ""; var bodyJson = null; var useCache = false; var noJson = false; var throughDisabled = false; var httpMethod = "GET"; var silent = false; var formData = null; var responseHandler = function (resp) { console.log("No response handler. Request=" + url + " response:" + resp); lt.notify(); }; var errorHandler = function (err) { lanta.Extensions.defaultErrorHandler(new Error(err)); }; var call = function(method, handler) { httpMethod = method || httpMethod; responseHandler = handler || responseHandler; if (!lanta.ApiCallBuilder.isEnabled && !throughDisabled) { var selfUrl = self.getUrl(); for (let i = 0; i < lanta.ApiCallBuilder.postponedCalls.length; i++) { var call = lanta.ApiCallBuilder.postponedCalls[i]; if (call.getUrl() === selfUrl) { return; } } lanta.ApiCallBuilder.postponedCalls.push(self); return; } if (!useCache) { self.query({ "_nocache": new Date().getTime() }); } else { self.query({ "_build": (window["__release"] || "?") }); } var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState !== 4) { return; } if (xmlHttp.status !== 200) { if (!silent) { lt.api.usageManager.notifyOperationEnd(); } if (xmlHttp.status === 0) { errorHandler("Nepodařilo se spojit se serverem, opakujte akci později..."); return; } errorHandler(xmlHttp.status + ": " + xmlHttp.responseText); return; } var parsedResponse = xmlHttp.responseText; if (parsedResponse.indexOf("ExecutionError") > -1) { try { var errorObj = JSON.parse(parsedResponse); if (errorObj.ExecutionError && errorObj.StatusCode > 499) { try { errorHandler(errorObj.StatusCode + ": " + errorObj.ExecutionError); return; } finally { if (!silent) { lt.api.usageManager.notifyOperationEnd(); } } } } catch (e) { try { console.error("Parsing of error response failed:" + e.toString()); return; } finally { if (!silent) { lt.api.usageManager.notifyOperationEnd(); } } } } if (!noJson) { try { parsedResponse = JSON.parse(parsedResponse); } catch (e) { console.warn("JSON expected - use .nojson modifier in call builder (" + url + ")"); } } try { responseHandler(parsedResponse); lt.notify(); } finally { if (!silent) { lt.api.usageManager.notifyOperationEnd(); } } }; try { if (!!queryString) { url = url + "?" + queryString; } xmlHttp.open(httpMethod, url, true); if (!silent) { lt.api.usageManager.notifyOperationStart(); } if (formData) { xmlHttp.send(formData); } else { xmlHttp.setRequestHeader('Content-type', '*/*; charset=utf-8'); xmlHttp.send(bodyJson); } } catch (error) { if (!silent) { lt.api.usageManager.notifyOperationEnd(); } console.error(error); errorHandler(error.message); } }; this.query = function (qry) { if (!qry) { return self; } for (var key in qry) { if (qry.hasOwnProperty(key)) { var value = qry[key]; if (value === null || value === undefined) { continue; } if (queryString.length > 0) { queryString = queryString + "&"; } queryString = queryString + encodeURIComponent(key) + "=" + encodeURIComponent(value.toString()); } } return self; }; this.body = function (obj) { bodyJson = JSON.stringify(obj); return self; }; this.formData = function(name, value) { formData = formData || new FormData(); formData.append(name, value); return self; }; this.onerror = function (handler) { errorHandler = handler || errorHandler; return self; }; this.get = function (handler) { call("GET", handler); }; this.post = function (handler) { call("POST", handler); }; this.useCache = function () { useCache = true; return self; }; this.noJson = function () { noJson = true; return self; }; this.ignoreDisabledApi = function () { throughDisabled = true; return self; }; this.getUrl = function () { var result = url; if (!!queryString) { result = result + "?" + queryString; } return result; }; this.call = function() { call(); }; this.silent = function() { silent = true; return self; }; this.downloadFile = function() { var lnk = document.createElement("a"); lnk.setAttribute("hidden", true); lnk.setAttribute("download", true); lnk.setAttribute("href", self.getUrl()); document.body.appendChild(lnk); lnk.click(); }; }; lanta.ApiCallBuilder.isEnabled = lanta.ApiCallBuilder.isEnabled || true; lanta.ApiCallBuilder.postponedCalls = lanta.ApiCallBuilder.postponedCalls || []; var lt = lt || {}; lt.api = lt.api || function (url) { return new lanta.ApiCallBuilder(url); }; lt.api.disable = lt.api.disable || function () { lanta.ApiCallBuilder.isEnabled = false; }; lt.api.enable = lt.api.enable = function () { lanta.ApiCallBuilder.isEnabled = true; while (lanta.ApiCallBuilder.postponedCalls.length > 0) { var postponedCall = lanta.ApiCallBuilder.postponedCalls.pop(); postponedCall.call(); } }; lt.api.UsageManager = lt.api.UsageManager || function() { var self = this; var pendingOpsCounter = 0; var handlers = []; var notifyHandlers = function(busy) { for (var i = 0; i < handlers.length; i++) { var h = handlers[i]; h(busy); } }; self.notifyOperationStart = function() { pendingOpsCounter++; if (pendingOpsCounter === 1) { notifyHandlers(true); } }; self.notifyOperationEnd = function() { pendingOpsCounter--; if (pendingOpsCounter === 0) { notifyHandlers(false); } if (pendingOpsCounter < 0) { pendingOpsCounter = 0; } }; self.subscribeBusyHandler = function(handler) { handlers.push(handler); handler(pendingOpsCounter > 0); }; }; lt.api.usageManager = lt.api.usageManager || new lt.api.UsageManager(); /*------------------------------------------------------*/ /*~/Script/Lanta/Lt.CustomAttributes.js*/ var lanta = lanta || {}; lanta.CustomAttributes = lanta.CustomAttributes || {}; lanta.CustomAttributes.Watcher = lanta.CustomAttributes.Watcher || function() { const oldValueStorePrefix = "__lt_attribute_old_value_"; //handler = function(element, newValue, attributeName, oldValue) var handlers = {}; var initialized = false; var visitElement = function (element, attributes) { if (!element.hasAttributes()) { return; } var elementAttributes = element.attributes; attributes = attributes || []; if (attributes.length === 0) { for (var atrId = 0; atrId < elementAttributes.length; atrId++) { attributes.push(elementAttributes[atrId].name); } } else { var filteredAttributes = []; for (var eai = 0; eai < attributes.length; eai++) { if (element.hasAttribute(attributes[eai])) { filteredAttributes.push(attributes[eai]); } } if (filteredAttributes.length === 0) { return; } attributes = filteredAttributes; } for (var i = 0; i < attributes.length; i++) { var handlerList = handlers[attributes[i]]; if (!handlerList) { continue; } var oldValueMarker = oldValueStorePrefix + attributes[i]; var value = element.getAttribute(attributes[i]); if (value === element[oldValueMarker]) { continue; } for (var handlerIndex = 0; handlerIndex < handlerList.length; handlerIndex++) { var handler = handlerList[handlerIndex]; try { handler(element, value, attributes[i], element[oldValueMarker] || null); } catch (e) { console.error("Attribute handler " + handler + " failed"); console.error(e); } } element[oldValueMarker] = value; } }; var visitAll = function () { if (!document.body) { setTimeout(visitAll, 50); return; } var allElements = document.body.getElementsByTagName("*"); for (var i = 0; i < allElements.length; i++) { var e = allElements[i]; visitElement(e); } }; var watch = function () { if ((!document) || (!document.body)) { setTimeout(watch, 50); return; } document.addEventListener('DOMContentLoaded', function () { visitAll(); }, false); if (!initialized) { visitAll(); } initialized = true; var config = { attributes: true, childList: true, subtree: true }; var callback = function (mutationsList) { for (var i = 0; i < mutationsList.length; i++) { var mutation = mutationsList[i]; if (mutation.type === 'attributes') { visitElement(mutation.target, [mutation.attributeName]); } } }; var observer = new MutationObserver(callback); observer.observe(document.body, config); }; this.registerHandler = function(attributeName, handler) { var handlerList = handlers[attributeName] || (handlers[attributeName] = []); handlerList.push(handler); if (handlerList.length === 1) { watch(); } if (!document || !document.body) { return; } var allElements = document.body.getElementsByTagName("*"); for (var i = 0; i < allElements.length; i++) { var e = allElements[i]; visitElement(e, [attributeName]); } }; setInterval(visitAll, 500); }; lanta.CustomAttributes.Watcher.instance = lanta.CustomAttributes.Watcher.instance || new lanta.CustomAttributes.Watcher(); var lt = lt || {}; lt.watchCustomAttribute = lt.watchCustomAttribute || function(attributeName, handler) { lanta.CustomAttributes.Watcher.instance.registerHandler(attributeName, handler); }; /*------------------------------------------------------*/ /*~/Script/Lanta/ViewsLoader.js*/ var lanta = lanta || {}; lanta.ViewLoading = lanta.ViewLoading || {}; lanta.ViewLoading.cache = lanta.ViewLoading.cache || {}; lanta.ViewLoading.makeScriptsLive = lanta.ViewLoading.makeScriptsLive || function (div, sourceUrl) { var allScripts = div.getElementsByTagName("script"); for (var i = 0; i < allScripts.length; i++) { var sourceTag = allScripts[i]; var newTag = document.createElement("script"); var sourceAttributes = sourceTag.attributes; if (!!sourceAttributes) { for (var j = 0; j < sourceAttributes.length; j++) { var sourceAttribute = sourceAttributes[j]; newTag.setAttribute(sourceAttribute.name, sourceAttribute.value); } } newTag.innerHTML = sourceTag.innerHTML + "\r\n//# sourceURL=" + sourceUrl; sourceTag.parentElement.insertBefore(newTag, sourceTag); sourceTag.parentElement.removeChild(sourceTag); } }; lanta.ViewLoading.inheritAttributes = lanta.ViewLoading.inheritAttributes || function(element, html) { var matches = html.match(/{attr\.[^}]+}/gim) || []; for (let i = 0; i < matches.length; i++) { var attributeName = matches[i].match(/\.[^}]+/gim)[0].substring(1); var sourceValue = element.getAttribute(attributeName) || ""; html = html.split(matches[i]).join(sourceValue); } var binding = element.getAttribute("data-bind"); if ((!binding) || (binding.length === 0)) { return html; } var expressions = binding.split(";"); for (var expIndex = 0; expIndex < expressions.length; expIndex++) { var exp = expressions[expIndex]; if (exp.trim().length === 0) { continue; } var parts = exp.split(":"); if (parts.length !== 2) { throw new Error("Invalid expression '" + exp + "'"); } var to = parts[0].trim(); var from = parts[1].trim(); html = html.split("$" + to + "$").join(from); } return html; }; lanta.ViewLoading.loader = function (target, value, attribute, callback) { lt.api(value).useCache().ignoreDisabledApi().noJson().get(function (html) { if (html.indexOf("{%GENERATE%}") > -1) { var dynamicValue = new Date().getUTCMilliseconds() + "_" + Math.random(); while (html.indexOf("{%GENERATE%}") > -1) { html = html.replace("{%GENERATE%}", dynamicValue); } } html = lanta.ViewLoading.inheritAttributes(target, html); var content = target.innerHTML; html = html.split("{content}").join(content); if (attribute === "fill-by") { target.innerHTML = html; lanta.ViewLoading.makeScriptsLive(target, value); if (!!callback) { callback(target); } return; } if (attribute === "replace-by") { var xdiv = document.createElement("DIV"); xdiv.innerHTML = html; lanta.ViewLoading.makeScriptsLive(xdiv, value); var parent = target.parentElement; if (parent == null) { return; } var els = []; for (var nid = 0; nid < xdiv.childNodes.length; nid++) { els.push(xdiv.childNodes[nid]); } xdiv.innerHTML = ''; for (var i = 0; i < els.length; i++) { try { target.parentNode.insertBefore(els[i], target); }catch (ieieie){} } parent.removeChild(target); if (!!callback) { callback(els[0]); } } }); }; lt.watchCustomAttribute("fill-by", lanta.ViewLoading.loader); lt.watchCustomAttribute("replace-by", lanta.ViewLoading.loader); lt.replaceBy = lt.replaceBy || function (placeholder, src, callback) { lanta.ViewLoading.loader(placeholder, src, "replace-by", callback); }; lt.fillBy = lt.fillBy || function (placeholder, src, callback) { lanta.ViewLoading.loader(placeholder, src, "fill-by", callback); }; /*------------------------------------------------------*/ /*~/Script/Lanta/UpdateModelByForm.js*/ var lt = lt || {}; lt.updateModelByForm = lt.updateModelByForm || function(model, formRoot) { model = model || {}; const children = getChildrenWithSelf(formRoot); for (let i = 0; i < children.length; i++) { const element = children[i]; const attribute = element.getAttribute("update-model"); if (!attribute) { continue; } var updater = element.updateModel || lt.updateModelByForm.defaultUpdater; const parts = attribute.split(";"); for (let j = 0; j < parts.length; j++) { var expression = parts[j].trim(); if (expression.length < 1) { continue; } var targetAndSource = expression.split(":"); if (targetAndSource.length !== 2) { if (targetAndSource.length === 1) { targetAndSource.push("value"); } else { throw new Error("Invalid update-model expression '" + expression + "'. Target:Source expected"); } } updater.call(element, model, targetAndSource[0].trim(), targetAndSource[1].trim()); } } return model; }; lt.updateModelByForm.defaultUpdater = lt.updateModelByForm.defaultUpdater || function(model, targetPropertyName, sourcePropertyName) { model[targetPropertyName] = this[sourcePropertyName]; }; /*------------------------------------------------------*/ /*~/Script/Common/UrlBus.js*/ var app = app || {}; app.UrlBus = app.UrlBus || function() { var currentJsonValues = {}; var currentObjValues = {}; var callbacks = {}; var self = this; var changeHandler = function() { const srch = new URLSearchParams(window.location.search); var htext = window.location.hash; if (htext.indexOf("#") === 0) { htext = htext.substr(1); } const hash = new URLSearchParams(htext); const all = {}; for (let key of srch.keys()) { all[key] = srch.get(key); } for (let key of hash.keys()) { var trgKey = key; if (trgKey.indexOf("#") === 0) { trgKey = trgKey.substr(1); } all[trgKey] = hash.get(key); } var acknowledgeds = []; for (let key in all) { const old = currentJsonValues[key]; const nw = all[key]; if (old === nw) { continue; } currentJsonValues[key] = nw; if (nw == null) { currentObjValues[key] = null; continue; } try { currentObjValues[key] = JSON.parse(nw); } catch (e) { currentObjValues[key] = currentJsonValues[key]; } let gotAck = false; const cbks = callbacks[key]; if (cbks != null) { for (var cbkid = 0; cbkid < cbks.length; cbkid++) { var cbk = cbks[cbkid]; gotAck = cbk(currentObjValues[key]) | gotAck; } } if (gotAck) { acknowledgeds.push(key); } } for (var acix = 0; acix < acknowledgeds.length; acix++) { self.clear(acknowledgeds[acix]); } }; var init = function () { if ((!document) || (!document.body)) { setTimeout(init, 100); return; } changeHandler(); window.addEventListener("hashchange", changeHandler, false); }; init(); self.watch = function(param, callback) { var current = currentObjValues[param]; if (current != null) { if (callback(current) === true) { self.clear(param); } } (callbacks[param] = callbacks[param] || []).push(callback); }; self.set = function(param, value, keepThisTab) { var setter = new URLSearchParams(window.location.hash); if (value == null) { delete currentJsonValues[param]; delete currentObjValues[param]; } if (setter.has("#" + param)) { param = "#" + param; } if (value == null) { delete currentJsonValues[param]; delete currentObjValues[param]; setter.delete(param); } else { setter.set(param, JSON.stringify(value)); } try { history.replaceState(null, null, ' '); } catch(e){} if (keepThisTab) { window.location.hash = setter.toString(); } else { setter.set("elNewTab", "yes"); window.open(window.location.href + "#" + setter.toString(), "_blank"); } }; self.clear = function (param) { if (window.location.href.indexOf("elNewTab=yes") > -1) { try { window.close(); return; } catch (e) { console.error(e); } } self.set(param, null); }; self.get = function(param) { return currentObjValues[param]; }; }; app.urlBus = app.urlBus || new app.UrlBus(); /*------------------------------------------------------*/ /*~/Script/Common/ContextMenu.js*/ var app = app || {}; app.contextMenu = app.contextMenu || {}; app.contextMenu.shownMenus = app.contextMenu.shownMenus || []; var setupContextMenu = function () { if ((!document) || (!document.body)) { setTimeout(setupContextMenu, 100); return; } if (document.body.showContextMenu) { return; } var closer = function () { if (window.event.isMenuOpen) { return; } while (app.contextMenu.shownMenus.length > 0) { var mnu = app.contextMenu.shownMenus.pop(); mnu.style.display = 'none'; } window.removeEventListener("click", closer); }; document.body.showContextMenu = function(menu, caller) { closer(); menu.style.display = 'block'; app.contextMenu.shownMenus.push(menu); window.addEventListener("click", closer); window.event.isMenuOpen = true; var viewportOffset = caller.getBoundingClientRect(); menu.style.left = viewportOffset.left + 'px'; menu.style.top = viewportOffset.top + 'px'; }; }; setupContextMenu(); /*------------------------------------------------------*/ /*~/Script/Common/GlobalEventHandlers.js*/ var app = app || {}; app.globalEventHandlers = app.globalEventHandlers || {}; app.globalEventHandlers.init = app.globalEventHandlers.init || function() { if ((!document) || (!document.body)) { setTimeout(app.globalEventHandlers.init, 100); return; } document.body.enterTo = document.body.enterTo || function(target) { if (window.event.key === "Enter") { target.click(); } }; }; app.globalEventHandlers.init(); /*------------------------------------------------------*/ /*~/Script/Common/TextMatcher.js*/ var TextMatcher = TextMatcher || function(pattern) { pattern = TextMatcher.natcharmap.denat(pattern || "").trim().toLowerCase(); var words = pattern.split(" "); this.match = function (text, emptyQueryResult) { if (pattern.length === 0) { return !!emptyQueryResult; } text = TextMatcher.natcharmap.denat(text || "").trim().toLowerCase(); for (var i = 0; i < words.length; i++) { var word = words[i]; if (word.trim().length < 1) { continue; } if (text.indexOf(word) < 0) { return false; } } return true; }; }; TextMatcher.natcharmap = TextMatcher.natcharmap || { "Á": "A", "Č": "C", "Ď": "D", "Ě": "E", "É": "E", "Í": "I", "Ň": "N", "Ó": "O", "Ř": "R", "Š": "S", "Ť": "T", "Ú": "U", "Ů": "U", "Ý": "Y", "Ž": "Z", "á": "a", "č": "c", "ď": "d", "ě": "e", "é": "e", "í": "i", "ň": "n", "ó": "o", "ř": "r", "š": "s", "ť": "t", "ú": "u", "ů": "u", "ý": "y", "ž": "z", "denat": function (inp) { var rb = []; for (var i = 0; i < inp.length; i++) { var orichar = inp.charAt(i); rb.push(natcharmap[orichar] || orichar); } return rb.join(""); } }; /*------------------------------------------------------*/