// https://stackoverflow.com/questions/27078285/simple-throttle-in-js // Returns a function, that, when invoked, will only be triggered at most once // during a given window of time. Normally, the throttled function will run // as much as it can, without ever going more than once per `wait` duration; // but if you'd like to disable the execution on the leading edge, pass // `{leading: false}`. To disable execution on the trailing edge, ditto. function throttle(func, wait, options) { var context, args, result; var timeout = null; var previous = 0; if (!options) options = {}; var later = function() { previous = options.leading === false ? 0 : Date.now(); timeout = null; result = func.apply(context, args); if (!timeout) context = args = null; }; return function() { var now = Date.now(); if (!previous && options.leading === false) previous = now; var remaining = wait - (now - previous); context = this; args = arguments; if (remaining <= 0 || remaining > wait) { if (timeout) { clearTimeout(timeout); timeout = null; } previous = now; result = func.apply(context, args); if (!timeout) context = args = null; } else if (!timeout && options.trailing !== false) { timeout = setTimeout(later, remaining); } return result; }; }; class Grip { constructor(opt) { if(opt.element === undefined) { throw new Error("Grip: no element provided.") } this.element = opt.element; this.color = opt.color || "primary"; this.offsetX = opt.offsetX || opt.offset || 0; this.offsetY = opt.offsetY || opt.offset || 0; this.spreadX = opt.spreadX || opt.spread || 24; this.spreadY = opt.spreadY || opt.spread || 24; this.animating = false; } trigger() { if(this.animating) return; this.animating = true; const top = this.element.offsetTop - 3 - this.offsetY; const left = this.element.offsetLeft - 3 - this.offsetX; const width = this.element.offsetWidth + 2 * (3 + this.offsetX); const height = this.element.offsetHeight + 2 * (3 + this.offsetY); const i = Grip.iterator++; const animName = `anim--grip--i_${i}`; const style = document.createElement("style"); style.textContent = ` @keyframes ${animName} { from { top: ${top}px; left: ${left}px; width: ${width}px; height: ${height}px; opacity: 1; } to { top: ${top - this.spreadY}px; left: ${left - this.spreadX}px; width: ${width + 2 * this.spreadX}px; height: ${height + 2 * this.spreadY}px; opacity: 0; } } `; document.body.appendChild(style) const grip = document.createElement("div"); grip.className = `grip grip--color-${this.color}`; grip.style.animationName = animName; document.body.appendChild(grip) setTimeout(() => { document.body.removeChild(style) document.body.removeChild(grip) this.animating = false; }, 1010) } } Grip.iterator = 0; function scrollElementIntoView(element, opt, thr = 100) { element.scrollIntoView(opt) return new Promise((resolve, reject) => { if(resolve !== undefined) { let prevScroll = -1; const f = () => { const nextScroll = document.scrollingElement.scrollTop; if(prevScroll == nextScroll) { clearInterval(interval) resolve() } else { prevScroll = nextScroll; } }; const interval = setInterval(f, 100); f() } }) } const $NAV = { el: { parent: document.getElementById("navbar"), bars: document.getElementById("navbar-bars"), times: document.getElementById("navbar-times"), slide: document.getElementById("navbar-slide"), }, opened: false, open() { if(this.opened) return; this.opened = true; this.el.slide.dataset.opened = true; window.history.pushState({ navbar: true, }, null) }, close() { if(!this.opened) return; this.opened = false; this.el.slide.dataset.opened = false; }, onScroll() { this.el.parent.dataset.scrolled = document.scrollingElement.scrollTop != 0; }, scrollToContact() { this.close() scrollElementIntoView(this.c.element, { behavior: "smooth", block: "center", }) .then(() => { this.c.grip.trigger() }) }, ini() { this.el.bars.addEventListener("click", this.open.bind(this)) this.el.times.addEventListener("click", () => { window.history.back() }) window.addEventListener("scroll", throttle(this.onScroll.bind(this), 500)) const fc = document.getElementById("footer-contact"); this.c = { element: fc, grip: new Grip({ element: fc, color: "white", offsetX: 4, }), }; document.querySelectorAll("[data-contact]").forEach(el => { el.addEventListener("click", this.scrollToContact.bind(this)) }) window.history.replaceState({ ...window.history.state, navbar: false, }, null) window.addEventListener("popstate", () => { if(window.history.state !== null) { if(!window.history.state.navbar) { this.close() } } }) }, }; $NAV.ini() class ScrollHighlight { constructor(offset, thr) { this.offset = offset || 60; this.thr = thr || 500; this.items = []; document.querySelectorAll("[data-sh]").forEach(el => { this.items.push({ grip: new Grip({ element: el, }), top: el.offsetTop, height: el.offsetHeight, highlighted: false, timeout: null, }) }) this._onScroll = throttle(this.onScroll.bind(this), this.thr); if(this.items.length != 0) { window.addEventListener("scroll", this._onScroll) this._onScroll() } } onScroll() { const s = document.scrollingElement.scrollTop; const h = window.innerHeight; const from = s + this.offset; const to = s + h - this.offset; this.items.forEach((item, i) => { if(item.grip.animating) return; if(from <= item.top && to - item.height >= item.top) { if(item.highlighted) return; item.highlighted = true; item.grip.trigger(from, to) } else { item.highlighted = false; } }) } } new ScrollHighlight() const ajax = { post(url, postData, opt) { let fd = new FormData(); this.parseData(fd, postData) return this.composeRequest(url, "POST", opt, fd); }, get(url, opt) { return this.composeRequest(url, "GET", opt); }, composeRequest(url, method, opt, sentData) { opt = opt || {}; url = url.split("?"); url[0] = url[0].replace(/^\/+|\/+$/, ""); // trims slashes url[0] += url[0] ? "/" : ""; // url = (url[1] ? url.join("?")+"&" : url[0]+"?")+"appv="+globals.appVersion; url = url[1] ? url.join("?") : url[0]; return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); if(typeof opt.progress == "function") { xhr.upload.addEventListener("progress", e => { e.percent = e.lengthComputable ? Math.round(10000*e.loaded/e.total)/100 : 0; opt.progress(e) }) } if(typeof opt.getInstance == "function") { opt.getInstance(xhr) } xhr.addEventListener("load", () => { try { let data = JSON.parse(xhr.response); if(typeof data.v != "undefined") { console.error(data.v) reject(data) } else { resolve(data) } } catch(e) { console.log(e) reject(e); } }) xhr.addEventListener("error", e => { console.log(e) reject(xhr); }) xhr.open(method, `${__vars.httpprefix}fetch/${url}`) xhr.send(sentData) }) }, identifyVariableType(v) { return Object.prototype.toString.call(v); }, composeObjectKey(prevKey, key) { return typeof prevKey == "undefined" ? key : prevKey+"["+key+"]"; }, parsingFunctions: { "[object Object]": (formData, data, prevKey) => { let objKeys = Object.keys(data); objKeys.forEach(key => { ajax.parseData(formData, data[key], ajax.composeObjectKey(prevKey, key)) }) }, "[object Array]": (formData, data, prevKey) => { data.forEach((value, key) => { ajax.parseData(formData, value, ajax.composeObjectKey(prevKey, key)) }) }, "[object Number]": (formData, data, prevKey) => { if([NaN, Infinity, -Infinity].indexOf(data) == -1 && data >= Number.MIN_SAFE_INTEGER && data <= Number.MAX_SAFE_INTEGER) formData.append(prevKey, data) }, "[object Boolean]": (formData, data, prevKey) => { formData.append(prevKey, data ? 1 : 0) }, "[object String]": (formData, data, prevKey) => { formData.append(prevKey, data) }, "[object File]": (formData, data, prevKey) => { formData.append(prevKey, data) }, "[object FileList]": (formData, data, prevKey) => { for(let i=0; i { let r = Math.random() * 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8); return v.toString(16); }); } const AreaSearchHeader = () => { return

Je Bynaps ve vašem městě?

Zjistěte, zda jsou ve vašem měste aktivní podniky v aplikaci Bynaps.

}; const AreaSearchInputAutocomplete = ({ value, onChange }) => { const handleChange = e => { onChange(e.target.value, false) }; const locateMe = () => { navigator.geolocation.getCurrentPosition( r => { ajax.post("ibiyc/coords-to-city", { lng: r.coords.longitude, lat: r.coords.latitude, }) .then(e => { if(e.status == "OK") { onChange(e.payload.city, true) } else { alert(e.message) } }) .catch(e => { alert("Nastala chyba. Zkuste akci opakovat později.") }) }, r => { console.error(r) } ) }; return
}; const AreaSearchResult = ({ city, onClick }) => { const handleClick = () => { onClick(city) }; return
{city.title}
{city.subtitle}
}; const AreaSearchResultList = ({ cities, onSelect }) => { return
{cities.map(city => { return })}
}; const AreaSearchMessage = ({ text, type }) => { return type !== null &&

{text}

}; const AreaSearchLoading = ({ loading }) => { return loading &&
}; const AreaSearchPageSearch = ({ savedCities, savedValue, token, onCity }) => { const [cities, setCities] = React.useState(savedCities); const [value, setValue] = React.useState(savedValue); const [loading, setLoading] = React.useState(false); const [message, setMessage] = React.useState({ text: "", type: null, }); const firstUpdate = React.useRef(true); const instantSearch = React.useRef(false); const timeout = React.useRef(null); const handleChange = (v, instant) => { instantSearch.current = instant; setValue(v) }; React.useEffect(() => { if(firstUpdate.current) { firstUpdate.current = false; return; } clearTimeout(timeout.current) const hasValue = value != ""; setLoading(hasValue) setMessage({ text: "", type: null, }) const nextMessage = {...message}; if(hasValue) { timeout.current = setTimeout(() => { ajax.post("ibiyc/search-places", { search: value, token: token, }) .then(e => { if(e.status == "OK") { setCities(e.payload.places) if(e.payload.places.length == 0) { setMessage({ text: "Nebyla nalezena žádná města.", type: "info", }) } } else { setMessage({ text: e.message, type: "danger", }) } }) .catch(e => { setMessage({ text: "Nastala chyba. Zkuste akci opakovat později.", type: "danger", }) }) .finally(() => { setLoading(false) }) }, instantSearch.current ? 1 : 1000) } }, [value]) const handleSelect = city => { onCity({ city, cities, value, }) }; return
Powered by Google
Czech republic
}; const AreaSearchBusiness = ({ business, onClick }) => { return
{business.title}
{business.title}
}; const AreaSearchBusinessPopup = ({ opened, onClose }) => { const prevOpened = React.useRef(opened); const counter = React.useRef(0); React.useEffect(() => { if(opened != prevOpened.current) { prevOpened.current = opened; counter.current++; } }) const isOpened = counter.current == 0 && !opened ? "x" : opened; return

Zajímá Vás detail podniku?
Zaregistrujte se!

Registrovat
}; const AreaSearchBusinessList = ({ businesses }) => { const [opened, setOpened] = React.useState(false); const [popupOpened, setPopupOpened] = React.useState(false); const max = 12; const handleButtonClick = () => { setOpened(true) }; const handleBusinessClick = () => { setPopupOpened(true) }; const handlePopupClose = () => { setPopupOpened(false) }; let list = []; for(let i=0; i ) } else { break; } } return
{list}
{!opened && businesses.length > max &&
}
}; const AreaSearchEmailCollect = ({ city }) => { const [email, setEmail] = React.useState(""); const [loading, setLoading] = React.useState(false); const [message, setMessage] = React.useState({ text: "", type: null, }); const nextMessage = React.useRef({...message}); const handleChange = e => { setEmail(e.target.value) }; const handleSubmit = e => { e.preventDefault() setLoading(true) ajax.post("ibiyc/create-watchdog", { email: email, place_id: city.place_id, area: city.id, }) .then(e => { if(e.status == "OK") { setEmail("") nextMessage.current.type = "success"; } else { nextMessage.current.type = "danger"; } nextMessage.current.text = e.message; }) .catch(e => { nextMessage.current = { text: "Nastala chyba. Zkuste akci opakovat později.", type: "danger", }; }) .finally(() => { setMessage(nextMessage.current) setLoading(false) }) }; return

Budeme vás kontaktovat

Napište svůj e-mail a my vás upozorníme, až bude Bynaps ve měste {city.title} aktivní.

Žádná reklamní sdělení nečekejte, pouze jeden e-mail s upozorněním.

}; function copyToClipboard(textToCopy, event) { const top = event === undefined ? 0 : event.currentTarget.getBoundingClientRect().top; let b = document.createElement('textarea'); b.style.position = "fixed"; b.style.top = top+"px"; b.style.left = "-100px"; b.style.width = "50px"; b.style.height = "50px"; b.style.fontSize = "20px"; let v = new DOMParser().parseFromString(textToCopy, "text/html"); b.value = v.documentElement.textContent; document.body.appendChild(b) if(!!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform)) { b.contentEditable = true; let range = document.createRange(); let s = window.getSelection(); s.removeAllRanges() s.addRange(range) b.setSelectionRange(0, textToCopy.length) } else { b.select() } let copied = false; try { document.execCommand("copy") copied = true; } catch (d) { copied = window.prompt("Zkopírujte si odkaz do schránky a stiskněte \"OK\".", textToCopy) !== null; } document.body.removeChild(b); return copied; } class ShareDialog extends React.Component { constructor(props) { super(props) this.state = { openedOnce: false, opened: false, copied: false, }; this._close = this.close.bind(this); // this._shareOnFacebook = this.shareOnFacebook.bind(this); this._copy = this.copy.bind(this); this._shareMore = this.shareMore.bind(this); } open() { this.setState({ openedOnce: true, opened: true, copied: false, }) } close() { this.setState({ opened: false, }) } // shareOnFacebook() { // const url = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(this.props.link)}"e=${encodeURIComponent(this.props.text)}`; // window.open(url, "Sdílet přes Facebook", "width=600,height=600,left=100,top=100") // } copy(e) { const copied = copyToClipboard(`${this.props.text} ${this.props.link}`); if(copied) { this.setState({ copied: true, }) } } shareMore() { window.navigator.share({ text: this.props.text, url: this.props.link, }) } render() { return
{this.props.title}
{this.state.copied &&
Pozvánka byla zkopírována do schránky. Vložte ji do mailu, SMS nebo třeba do zprávy na Messengeru a odešlete.
||
{this.props.text}
{/*
Facebook
*/}
Kopírovat text do schránky
{window.navigator.share !== undefined &&
Více...
}
}
} } const AreaSearchPageDetail = ({ passedCity }) => { const [loading, setLoading] = React.useState(true); const [message, setMessage] = React.useState({ text: "", type: null, }); const city = React.useRef({...passedCity}); const sdRef = React.useRef(); React.useEffect(() => { window.history.pushState({}, null) ajax.post("ibiyc/area-detail", { place_id: passedCity.place_id, query: passedCity.title, }) .then(e => { if(e.status == "OK") { city.current = { ...city.current, ...e.payload, }; } else { setMessage({ text: e.message, type: "danger", }) } }) .catch(e => { setMessage({ text: "Nastala chyba. Zkuste akci opakovat později.", type: "danger", }) }) .finally(() => { setLoading(false) }) }, []) const openShareDialog = () => { sdRef.current.open() }; const goBack = () => { window.history.back() }; const c = city.current; let subtitle; if(!loading) { if(c.exists) { if(c.businesses.length == 0) { subtitle = `Ve měste ${c.title} ještě nejsou zaregistrovány žádné podniky. To ale nevadí! Stále se můžete zaregistrovat, a až bude ve městě alespoň 5 podniků, vyměňování voucherů bude moct začít!`; } else { if(c.startedBynapsing) { subtitle = `Ve měste ${c.title} už Bynaps jede v plném proudu! Zaregistrujte se a vyměňujte vouchery s místními podniky!`; } else { subtitle = `Ve měste ${c.title} jsou zatím ${c.businesses.length} podniky. Pro používání aplikace Bynaps je ale v oblasti potřeba alespoň 5 podniků. Zaregistrujte se a začněte vyměňovat vouchery!`; } } } else { subtitle = `Ve městě ${c.title} ještě nejsou zaregistrovány žádné podniky.`; } } const isSafe = message.type === null && !loading; return
Vyhledat jiné město

{c.title}

{isSafe &&

{subtitle}

{c.exists &&
Registrovat se
} {!c.startedBynapsing && }
}
{isSafe && c.businesses.length != 0 &&
{}
}
}; const token = uuid(); const App = () => { const [inDetail, setInDetail] = React.useState(false); const selectedCity = React.useRef(null); const savedCities = React.useRef([]); const savedValue = React.useRef(""); React.useEffect(() => { window.history.replaceState({ ...window.history.state, page: "search", }, null) window.addEventListener("popstate", e => { if(window.history.state !== null) { if(window.history.state.page == "search") { setInDetail(false) } } }) }, []) const handleCity = e => { selectedCity.current = {...e.city}; savedCities.current = e.cities; savedValue.current = e.value; setInDetail(true) }; if(inDetail) { return } return }; ReactDOM.render(, document.getElementById("area-search"))