// ======= amplib js main ======= !function(n,l){"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l(n.preact={})}(this,function(n){var l,u,t,i,o,f,r,e={},c=[],s=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord/i;function a(n,l){for(var u in l)n[u]=l[u];return n}function h(n){var l=n.parentNode;l&&l.removeChild(n)}function p(n,l,u){var t,i=arguments,o={};for(t in l)"key"!==t&&"ref"!==t&&(o[t]=l[t]);if(arguments.length>3)for(u=[u],t=3;t2&&(l.children=c.slice.call(arguments,2)),v(n.type,l,l.key||n.key,l.ref||n.ref)},n.createContext=function(n){var l={},u={__c:"__cC"+r++,__:n,Consumer:function(n,l){return n.children(l)},Provider:function(n){var t,i=this;return this.getChildContext||(t=[],this.getChildContext=function(){return l[u.__c]=i,l},this.shouldComponentUpdate=function(l){n.value!==l.value&&t.some(function(n){n.context=l.value,g(n)})},this.sub=function(n){t.push(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){t.splice(t.indexOf(n),1),l&&l.call(n)}}),n.children}};return u.Consumer.contextType=u,u},n.toChildArray=b,n._e=A,n.options=l}); //# sourceMappingURL=preact.umd.js.map let e = preact.createElement; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var dataform = function () { function dataform(options) { var _this = this; _classCallCheck(this, dataform); this.submit = function (options) { if (_this.options.path) { _this.submit_state = 'submitting'; _this.render(); var postOptions = { on_success: function on_success(ob) { if (ob.response && ob.response.valid == true) { _this.probs = false; if (_this.options.on_submit_complete) { _this.options.on_submit_complete({ response: ob.response }); } _this.submit_state = false; _this.submitted_count++; _this.render(); } else { // console.log(ob); _this.submit_state = false; if (ob.response && ob.response.probs) { _this.probs = ob.response.probs; if (_this.options.on_submit_fail) { _this.options.on_submit_fail({ response: ob.response }); } } _this.render(); } } }; if (_this.options.path_format) { postOptions.path_format = _this.options.path_format; } ui.controller.formPost(_this.options.path, _this.data, postOptions); } else { console.error('No form path.'); } }; this.render = function () { if (_this.context) { _this.context.setState({ version: Date.now() }); } }; this.options = options; this.data = this.options.data || {}; this.context = this.options.context || false; this.probs = false; this.submitted_count = 0; this.submit_state = false; } _createClass(dataform, [{ key: 'update', value: function update(updates) { for (var dataKey in updates) { if (updates.hasOwnProperty(dataKey)) { if (this.data[dataKey] != updates[dataKey]) { this.data[dataKey] = updates[dataKey]; delete this.probs[dataKey]; } } } this.render(); } }]); return dataform; }(); var Controls = function (_preact$Component) { _inherits(Controls, _preact$Component); function Controls() { _classCallCheck(this, Controls); var _this2 = _possibleConstructorReturn(this, (Controls.__proto__ || Object.getPrototypeOf(Controls)).call(this)); _this2.state = {}; return _this2; } _createClass(Controls, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var controls = []; if (this.props.items) { for (var itemKey in this.props.items) { if (this.props.items.hasOwnProperty(itemKey)) { var item = this.props.items[itemKey]; controls.push(e('div', { id: itemKey, class: 'controls-item' }, e(Button, item))); } } } return e('div', { class: 'controls' }, controls); } }]); return Controls; }(preact.Component); var Probs = function (_preact$Component2) { _inherits(Probs, _preact$Component2); function Probs() { _classCallCheck(this, Probs); var _this3 = _possibleConstructorReturn(this, (Probs.__proto__ || Object.getPrototypeOf(Probs)).call(this)); _this3.state = {}; return _this3; } _createClass(Probs, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var probs = []; if (this.props.items) { for (var itemKey in this.props.items) { if (this.props.items.hasOwnProperty(itemKey)) { var item = this.props.items[itemKey]; probs.push(e('div', { id: itemKey, class: 'probs-item' }, this.props.items[itemKey])); } } } return e('div', { class: 'probs' }, probs); } }]); return Probs; }(preact.Component); var Button = function (_preact$Component3) { _inherits(Button, _preact$Component3); function Button() { _classCallCheck(this, Button); var _this4 = _possibleConstructorReturn(this, (Button.__proto__ || Object.getPrototypeOf(Button)).call(this)); _this4.click = function (event) { if (_this4.props.onClick) { event.preventDefault(); event.stopPropagation(); _this4.props.onClick({ event: event }); } }; _this4.state = {}; return _this4; } _createClass(Button, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var classes = ['button']; if (this.props.color) { classes.push('color-' + this.props.color); } return e('button', { onClick: this.click, class: classes.join(' ') }, this.props.title); } }]); return Button; }(preact.Component); var Form = function (_preact$Component4) { _inherits(Form, _preact$Component4); function Form() { _classCallCheck(this, Form); var _this5 = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this)); _this5.inputKeyUp = function (ob) { if (ob.event.keyCode === 13) { if (_this5.props.dataform) { ob.event.target.blur(); _this5.props.dataform.submit(); setTimeout(function () { ob.event.target.focus(); }, 20); } } else { return _this5.inputChange(ob); } }; _this5.inputChange = function (ob) { if (_this5.props.dataform) { _this5.props.dataform.update(_defineProperty({}, ob.field, ob.event.target.value)); } }; _this5.state = {}; return _this5; } _createClass(Form, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var fields = []; var formClasses = ['form']; if (this.props.dataform && this.props.dataform.submit_state == 'submitting') { formClasses.push('submitting'); } if (this.props.dataform && this.props.dataform.submitted_count > 0) { formClasses.push('submitted'); } if (this.props.fields) { for (var fieldKey in this.props.fields) { if (this.props.fields.hasOwnProperty(fieldKey)) { var fieldClasses = ['field']; var field = this.props.fields[fieldKey]; var inputType = field.input_type || 'text'; var input = null; var label = null; var value = ''; if (this.props.data && this.props.data[fieldKey]) { value = this.props.data[fieldKey]; } else if (this.props.dataform && this.props.dataform.data && this.props.dataform.data[fieldKey]) { value = this.props.dataform.data[fieldKey]; } var placeholder = null; if (this.props.placeholder) { placeholder = field.title; } if (!placeholder) { label = e('div', { class: 'field-label' }, field.title); } var prob = null; if (this.props.dataform && this.props.dataform.probs && this.props.dataform.probs[fieldKey]) { prob = e('div', { class: 'field-prob' }, this.props.dataform.probs[fieldKey]); } input = e('input', { // onChange: event => { // this.inputChange({ // event, // field: fieldKey // }); // }, placeholder: placeholder, onKeyUp: function (fieldKey, event) { this.inputKeyUp({ event: event, field: fieldKey }); }.bind(this, fieldKey), type: inputType, value: value }); fields.push(e('div', { class: fieldClasses.join(' ') }, label, e('div', { class: 'field-input text' }, input), prob)); } } } return e('div', { class: formClasses.join(' ') }, fields); } }]); return Form; }(preact.Component); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui = function Ui(options) { _classCallCheck(this, Ui); // console.log(options); this.options = options; this.tab = Math.floor(Date.now() / 1000); this.controller = Ui_controller ? new Ui_controller(this) : false; this.dom = Ui_dom ? new Ui_dom(this) : false; }; function Component(options) { var _this = this; this.options = options; this.id = options.id; this.data = options.data || {}; this.root = document.getElementById('component_' + this.id); this.state = options.state || {}; this.element = new window[options.component](this); this.setState = function (state, callback) { Object.assign(_this.state, state); _this.render(callback); }; this.before = function () { if (_this.element.before) { _this.element.before(); } }; this.render = function (callback) { if (_this.element.render) { _this.element.render(); } if (callback) { callback(); } }; this.before(); this.render(); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_controller = function Ui_controller(ui) { var _this = this; _classCallCheck(this, Ui_controller); this.formPost = function (path, data, options) { options = options || {}; var pathFormat = options.path_format || 'form_view'; var url = void 0; if (pathFormat == 'direct') { url = _this.appUrl(path, false, { direct: true }); } else { url = _this.appUrl('controller/form_view/' + path + '.htp', { recupdate_action: 'update' }); } fetch(url, { method: 'POST', // or 'PUT' headers: { 'Content-Type': 'text/plain' }, body: JSON.stringify({ data: data }) }).then(function (response) { return response.json(); }).then(function (data) { if (options.on_success) { options.on_success({ response: data }); } }).catch(function (error) { if (options.on_error) { options.on_error({ response: data }); } }); }; this.appUrl = function (path, addParams, options) { var url = []; var qs = []; options = options || {}; if (!options.direct) { url.push(_this.ui.options.app_url_root); } url.push(path); var params = { s: _this.ui.options.site, p: _this.ui.options.page, ul_client_date: new Date().toISOString(), ul_client_key: _this.ui.options.ul_client_key, ul_app_id: _this.ui.options.app, uslapp_session: _this.ui.options.uslapp_session, ul_client_tab: _this.ui.tab }; if (addParams) { for (var paramKey in addParams) { if (addParams.hasOwnProperty(paramKey)) { params[paramKey] = addParams[paramKey]; } } } for (var paramKey in params) { if (params.hasOwnProperty(paramKey)) { qs.push(paramKey + '=' + encodeURIComponent(params[paramKey])); } } if (path.indexOf('?') !== -1) { url.push('&' + qs.join('&')); } else { url.push('?' + qs.join('&')); } return url.join(''); }; this.ui = ui; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_dom = function Ui_dom(ui) { var _this = this; _classCallCheck(this, Ui_dom); this.ini = function () { _this.iniResize(); _this.iniScroll(); _this.iniFeatures(); _this.iniIntersect(); }; this.uid = function () { return _this.uidcur++; }; this.checkAll = function () { _this.checkScroll(); _this.checkMobile(); }; this.iniIntersect = function () { var options = { root: document.querySelector('#scrollArea'), rootMargin: '0px', threshold: .4 }; _this.observer = new IntersectionObserver(_this.intersectCallback, options); }; this.intersectCallback = function (entries, observer) { // console.log(entries); entries.forEach(function (entry) { // console.log(entry); if (entry.isIntersecting) { entry.target.classList.remove('ui-dom-intersect-below'); entry.target.classList.remove('ui-dom-intersect-above'); entry.target.classList.add('ui-dom-intersect-in'); entry.target.classList.remove('ui-dom-intersect-out'); } else { var windowHeightHalf = window.outerHeight / 2; if (entry.boundingClientRect.bottom > windowHeightHalf) { entry.target.classList.add('ui-dom-intersect-below'); entry.target.classList.remove('ui-dom-intersect-above'); } else { entry.target.classList.remove('ui-dom-intersect-below'); entry.target.classList.add('ui-dom-intersect-above'); } entry.target.classList.remove('ui-dom-intersect-in'); entry.target.classList.add('ui-dom-intersect-out'); } // Each entry describes an intersection change for one observed // target element: // entry.boundingClientRect // entry.intersectionRatio // entry.intersectionRect // entry.isIntersecting // entry.rootBounds // entry.target // entry.time }); }; this.iniScroll = function () { _this.checkScrollLastTop = 0; window.addEventListener('scroll', _this.checkScroll); }; this.iniResize = function () { window.addEventListener('resize', _this.checkAll); }; this.iniFeatures = function () { _this.featureWebP(); }; this.featureWebP = function () { var webP = false; var elem = document.createElement('canvas'); if (!!(elem.getContext && elem.getContext('2d'))) { webP = elem.toDataURL('image/webp').indexOf('data:image/webp') == 0; } if (webP) { document.documentElement.classList.add('f-webp'); _this.sup.webp = true; } else { document.documentElement.classList.add('f-webp-0'); _this.sup.webp = false; } }; this.checkScroll = function () { var top = (window.pageYOffset || document.scrollTop) - (document.clientTop || 0); var scrollDiff = top - _this.checkScrollLastTop; // console.log(scrollDiff); if (top > _this.checkScrollLastTop) { document.body.classList.add('scrolling-last-down'); document.body.classList.remove('scrolling-last-up'); } else if (top < _this.checkScrollLastTop) { document.body.classList.remove('scrolling-last-down'); document.body.classList.add('scrolling-last-up'); } _this.checkScrollLastTop = top; if (top >= 10) { document.body.classList.add('scrolled-down'); document.body.classList.remove('scrolled-up'); } else { document.body.classList.remove('scrolled-down'); document.body.classList.add('scrolled-up'); } }; this.checkMobile = function () { if (document.body.clientWidth > 800) { _this.screen = 'desktop'; document.body.classList.add('desktop'); document.body.classList.remove('mobile'); } else { _this.screen = 'mobile'; document.body.classList.remove('desktop'); document.body.classList.add('mobile'); } }; this.ui = ui; this.screen = false; this.sup = { webp: false }; this.checkAll(); this.ini(); this.uidcur = 1; }; var headMenusOpen = {}; function headMenu(component) { var _this = this; this.c = component; this.select = function (selected) { _this.c.setState({ selected: selected }); }; this.menuOpen = false; this.timers = {}; this.overNav = false; this.overDisplay = false; this.focused = false; this.timing = { enter: 200, leave: 200, duration: 200 }; this.showStarting = false; this.displayElmEnter = function () { _this.overDisplay = true; if (_this.timers.leaving) { clearTimeout(_this.timers.leaving); } }; this.displayElmLeave = function () { if (_this.focused) return false; _this.overDisplay = false; _this.timers.leaving = setTimeout(function () { _this.hideNow(); }, _this.timing.leave); }; this.menuElmEnter = function () { _this.overNav = true; if (_this.timers.leaving) { clearTimeout(_this.timers.leaving); } _this.timers.showing = setTimeout(function () { // console.log(this.overNav); // console.log(this.overDisplay); if (_this.overNav == true || _this.overDisplay == true) { // console.log('showing'); _this.showNow(); } }, _this.timing.enter); }; this.menuElmLeave = function () { _this.overNav = false; _this.timers.leaving = setTimeout(function () { _this.hideNow(); }, _this.timing.leave); }; this.menuElmClick = function (event) { event.target.blur(); event.preventDefault(); event.stopPropagation(); }; this.displayElmClick = function (event) { // console.log(event); event.preventDefault(); event.stopPropagation(); _this.focused = true; }; this.closeDisplayOnClick = function (event) { _this.hideNow(); }; // this.leaveStart = () =>{ // if (this.leaveStarting) { // clearTimeout(this.leaveStarting) // } // this.leaveStarting = setTimeout(()=>{ // this.hideNow(); // }, this.timing.leave) // } // this.showStart = () =>{ // // headMenusOpen[this.c.state.id] = true; // if (this.showStarting) { // clearTimeout(this.showStarting) // } // this.showStarting = setTimeout(()=>{ // this.showNow(); // }, this.timing.enter) // } this.showNow = function () { // console.log(Object.keys(headMenusOpen).length); _this.displayElmPosition(); _this.displayElm.classList.add('active'); if (Object.keys(headMenusOpen).length < 2) { _this.displayElm.classList.add('entering'); setTimeout(function () { _this.displayElm.classList.remove('entering'); }, _this.timing.duration); } _this.displayElm.classList.remove('leaving'); }; this.displayElmPosition = function () { var menuBox = _this.menuElm.getBoundingClientRect(); _this.displayElm.style.display = 'block'; var displayBox = _this.displayElm.getBoundingClientRect(); _this.displayElm.style.display = null; var menuBoxCenter = (menuBox.left + menuBox.right) / 2; var newLeft = menuBoxCenter - displayBox.width / 2; if (newLeft < 100) newLeft = 100; _this.displayElm.style.left = newLeft + 'px'; var pointerLeft = menuBoxCenter - newLeft - 8; _this.displayPointerElm.style.marginLeft = pointerLeft + 'px'; if (ui.dom.screen == 'mobile') { _this.displayPointerElm.style.marginLeft = '85%'; _this.displayElm.style.right = '5px'; _this.displayElm.style.left = newLeft / 2 + 'px'; } }; this.hideNow = function () { delete headMenusOpen[_this.c.state.id]; _this.displayElm.classList.remove('active'); // if (Object.keys(headMenusOpen).length<1) { // this.displayElm.classList.add('leaving'); // setTimeout(()=>{ // this.displayElm.classList.remove('leaving'); // }, this.timing.duration) // } }; this.bodyClick = function (event) { if (_this.focused) { // event.preventDefault(); // event.stopPropagation(); _this.focused = false; _this.hideNow(); } }; this.before = function () { _this.menuElm = document.getElementById('head_menu_' + _this.c.state.id); _this.displayElm = document.getElementById('menu_' + _this.c.state.id); _this.displayPointerElm = document.getElementById('menu_pointer_' + _this.c.state.id); // window.addEventListener('scroll', this.scroll); if (_this.menuElm && _this.displayElm && _this.displayPointerElm) { document.body.addEventListener('click', _this.bodyClick); _this.menuElm.addEventListener('click', _this.menuElmClick); _this.menuElm.addEventListener('mouseenter', _this.menuElmEnter); _this.menuElm.addEventListener('mouseleave', _this.menuElmLeave); if (_this.displayElm.classList.contains('focusable')) { _this.displayElm.addEventListener('click', _this.displayElmClick); } if (_this.displayElm.classList.contains('closeDisplayOnClick')) { _this.displayElm.addEventListener('click', _this.closeDisplayOnClick); } _this.displayElm.addEventListener('mouseenter', _this.displayElmEnter); _this.displayElm.addEventListener('mouseleave', _this.displayElmLeave); } }; this.render = function () { // console.log('render ' + this.c.state.id); }; }