// ======= 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 Timeslot = function (_preact$Component4) { _inherits(Timeslot, _preact$Component4); function Timeslot() { _classCallCheck(this, Timeslot); var _this5 = _possibleConstructorReturn(this, (Timeslot.__proto__ || Object.getPrototypeOf(Timeslot)).call(this)); _this5.click = function (event) {}; _this5.state = {}; return _this5; } _createClass(Timeslot, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var _this6 = this; var classes = ['timeslot']; var dayData = {}; var slots = this.props.field.slots().map(function (slot) { // console.log(slot); slot.local = moment.utc(slot.date).local().clone(); // console.log(slot.local.format('l h:mm A')); if (!dayData[slot.local.format('YYYY-MM-DD')]) { dayData[slot.local.format('YYYY-MM-DD')] = { available: [] }; } dayData[slot.local.format('YYYY-MM-DD')].available.push(slot); return slot; }); var days = []; var curDate = moment().startOf('week'); var weeksNumbers = [1, 2]; var weekItems = weeksNumbers.map(function (week) { var days = []; var available = []; for (var i = 1; i <= 7; i++) { available = []; if (dayData[curDate.format('YYYY-MM-DD')]) { available = dayData[curDate.format('YYYY-MM-DD')].available; } available = available.sort(function (a, b) { if (a.date > b.date) return 1; if (a.date < b.date) return -1; return 0; }); days.push({ date: curDate.format('YYYY-MM-DD'), moment: curDate.clone(), available: available }); curDate.add(1, 'day'); } return { week: week, days: days }; }); var dateToday = moment().format('YYYY-MM-DD'); var dateTomorrow = moment().add(1, 'day').format('YYYY-MM-DD'); var weeks = weekItems.map(function (week) { var days = week.days.map(function (day) { var useDay = true; if (day.moment.format('dddd') == 'Sunday') useDay = false; if (day.moment.format('dddd') == 'Saturday') useDay = false; if (useDay) { var _slots = day.available.map(function (slot) { var slotValue = slot.local.format('YYYY-MM-DD HH:mm:ss'); var classes = ['timeslot-week-day-slots-slot']; if (_this6.props.dataform.data[_this6.props.field_name] == slotValue) { classes.push('active'); } return e('div', { onClick: function onClick() { // console.log(slotValue); // console.log(this.props); _this6.props.dataform.update(_defineProperty({}, _this6.props.field_name, slotValue)); }, class: classes.join(' ') }, e('div', { class: 'timeslot-week-day-slots-slot-time' }, slot.local.format('h:mm A'))); }); var dayHead = []; if (dateToday == day.moment.format('YYYY-MM-DD')) { dayHead.push(e('div', { class: 'timeslot-week-day-head-label' }, 'Today')); } else if (dateTomorrow == day.moment.format('YYYY-MM-DD')) { dayHead.push(e('div', { class: 'timeslot-week-day-head-label' }, 'Tomorrow')); } else { dayHead.push(e('div', { class: 'timeslot-week-day-head-weekday' }, day.moment.format('ddd'))); dayHead.push(e('div', { class: 'timeslot-week-day-head-month' }, day.moment.format('MMM'))); dayHead.push(e('div', { class: 'timeslot-week-day-head-date' }, day.moment.format('D'))); } return e('div', { class: 'timeslot-week-day' }, e('div', { class: 'timeslot-week-day-head' }, dayHead), e('div', { class: 'timeslot-week-day-slots' }, _slots)); } }); return e('div', { class: 'timeslot-week' }, days); }); var tz = Intl.DateTimeFormat().resolvedOptions().timeZone; tz = tz.replace('/', ' / '); tz = tz.replace(/_/g, ' '); return [e('div', { onClick: this.click, class: classes.join(' ') }, weeks),, e('div', { class: 'timeslot-tz' }, 'Available times are ' + tz + ' timezone.')]; } }]); return Timeslot; }(preact.Component); var Form = function (_preact$Component5) { _inherits(Form, _preact$Component5); function Form() { _classCallCheck(this, Form); var _this7 = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this)); _this7.inputKeyUp = function (ob) { if (ob.event.keyCode === 13) { if (_this7.props.dataform && _this7.props.dataform.options.form_enter) { _this7.props.dataform.options.form_enter(ob); } else if (_this7.props.dataform) { ob.event.target.blur(); _this7.props.dataform.submit(); setTimeout(function () { ob.event.target.focus(); }, 20); } } else { return _this7.inputChange(ob); } }; _this7.inputChange = function (ob) { if (_this7.props.dataform) { if (ob.value) { _this7.props.dataform.update(_defineProperty({}, ob.field, ob.value)); } else if (ob.event) { _this7.props.dataform.update(_defineProperty({}, ob.field, ob.event.target.value)); } } }; _this7.state = {}; return _this7; } _createClass(Form, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var _this8 = this; 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 placeholder; var prob; var optionKey; (function () { var fieldClasses = ['field']; var field = _this8.props.fields[fieldKey]; var inputType = field.input_type || 'text'; var input = null; var label = null; var value = ''; if (_this8.props.data && _this8.props.data[fieldKey]) { value = _this8.props.data[fieldKey]; } else if (_this8.props.dataform && _this8.props.dataform.data && _this8.props.dataform.data[fieldKey]) { value = _this8.props.dataform.data[fieldKey]; } if (field.input_type == 'togglebuttons') { if (!Array.isArray(value)) { value = []; } } placeholder = null; if (_this8.props.placeholder) { placeholder = field.title; } if (!placeholder) { label = e('div', { class: 'field-label' }, field.title); } prob = null; if (_this8.props.dataform && _this8.props.dataform.probs && _this8.props.dataform.probs[fieldKey]) { prob = e('div', { class: 'field-prob' }, _this8.props.dataform.probs[fieldKey]); } if (field.input_type == 'timeslot') { input = e(Timeslot, { field_name: fieldKey, field: field, dataform: _this8.props.dataform }); } else if (field.input_type === 'dropdown') { label = e('div', { class: 'field-label' }, field.title); input = e('select', { defaultValue: value, onChange: function onChange(fieldKey, event) { this.inputChange({ field: fieldKey, event: event }); } }, e('option', { disabled: true, selected: true }, 'Select'), Object.keys(field.options).map(function (optionKey) { var option = field.options[optionKey]; return e('option', { value: option.id }, option.title); })); } else if (field.input_type == 'togglebuttons') { var buttons = []; for (optionKey in field.options) { if (field.options.hasOwnProperty(optionKey)) { (function () { var option = optionKey; var optionItem = field.options[optionKey]; var classes = ['field-togglebuttons-button']; if (value.indexOf(optionKey) !== -1) { classes.push('active'); } buttons.push(e('div', { onClick: function onClick(event) { // console.log(event); if (value.indexOf(option) === -1) { value.push(option); } else { value = value.filter(function (item) { if (item == option) return false; return true; }); } _this8.inputChange({ field: fieldKey, value: value }); }, class: classes.join(' ') }, e('div', { class: 'field-togglebuttons-button-title' }, optionItem.title))); })(); } } input = e('div', { class: 'field-togglebuttons' }, buttons); } else if (field.input_type == 'textarea') { input = e('div', { class: 'field-input text' + (_this8.props.inline ? ' inline' : '') }, e('textarea', { tabIndex: 1, placeholder: placeholder, onKeyUp: function (fieldKey, event) { this.inputKeyUp({ event: event, field: fieldKey }); }.bind(_this8, fieldKey), type: inputType, value: value })); } else { if (_this8.props.hasOwnProperty('is_current') && _this8.props.is_current == false) { input = e('div', { class: 'field-not-current' }, value); } else { input = e('div', { class: 'field-input text' + (_this8.props.inline ? ' inline' : '') }, e('input', { tabIndex: 1, placeholder: placeholder, onKeyUp: function (fieldKey, event) { this.inputKeyUp({ event: event, field: fieldKey }); }.bind(_this8, fieldKey), type: inputType, value: value })); } } var inlineLabel = null; if (_this8.props.inline) { inlineLabel = e('div', { class: 'field-input-label' }, field.title, field.info ? e('p', { class: 'field-input-label-info' }, field.info) : ''); } if (_this8.props.inline) { fieldClasses.push('inline'); } fields.push(e('div', { class: fieldClasses.join(' ') }, label, inlineLabel, input, prob)); })(); } } } if (this.props.inline) { formClasses.push('inline'); } 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; this.layout = Ui_layout ? new Ui_layout(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.routerParts = function () { var pathname = window.location.pathname; return pathname.split('/'); }; 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 _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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_layout = function () { function Ui_layout(ui) { _classCallCheck(this, Ui_layout); this.ui = ui; } _createClass(Ui_layout, [{ key: "autoMatrix", value: function autoMatrix(options) { var width = options.width, height = options.height, items = options.items, padding = options.padding; var itemsUse = items.slice(0); var count = itemsUse.length; var grid = { x: 0, y: 0 }; while (grid.x * grid.y < count) { if (width > height) { if (count == 3) { grid.x = 2; grid.y = 1; } grid.x++; if (grid.x * grid.y >= count) break; grid.y++; if (grid.x * grid.y >= count) break; } else { grid.y++; if (grid.x * grid.y >= count) break; grid.x++; if (grid.x * grid.y >= count) break; } } var remainder = grid.x * grid.y - count; var remainderWas = remainder; // console.log(grid); // console.log(remainder); var matrix = { rows: [] }; for (var y = 0; y < grid.y; y++) { var xUse = grid.x; if (remainderWas >= grid.y - y) { if (remainder > 0) { xUse--; remainder--; } } // console.log('xUse', xUse); var newRow = { items: [] }; for (var x = 0; x < xUse; x++) { newRow.items.push(itemsUse.shift()); } matrix.rows.push(newRow); } var itemHeight = (height - padding * (matrix.rows.length + 1)) / matrix.rows.length; var itemWidth = (width - padding * (grid.x + 1)) / grid.x; matrix.rows = matrix.rows.map(function (row, rowKey) { var rowItemSpace = { width: itemWidth, height: itemHeight }; var rowExtraSpace = 0; if (grid.x > row.items.length) { var rowXDiff = grid.x - row.items.length; rowExtraSpace = rowXDiff * (itemWidth + padding) * .5; } row.items = row.items.map(function (item, itemKey) { var itemBox = { width: rowItemSpace.width, height: rowItemSpace.height }; itemBox.left = rowExtraSpace + itemWidth * itemKey + padding * (itemKey + 1); itemBox.top = itemHeight * rowKey + padding * (rowKey + 1); item.box = itemBox; return item; }); return row; }); // console.log(matrix); return matrix; } }]); return Ui_layout; }(); 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(); console.log(event); }; this.displayElmClick = function (event) { // console.log(event); event.preventDefault(); event.stopPropagation(); _this.focused = true; }; // 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'; }; 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); } _this.displayElm.addEventListener('mouseenter', _this.displayElmEnter); _this.displayElm.addEventListener('mouseleave', _this.displayElmLeave); } }; this.render = function () { console.log(_this.c); console.log('render ' + _this.c.state.id); }; }