"use strict"; // https://help.market.envato.com/hc/en-us/articles/202822450-WordPress-Theme-Submission-Requirements var $, $body, $document, $html, $main, $nav, $wrapper, Header, article, customFileInput, expandableArticle, floatingLabel, groups, i, j, k, len, len1, ref, ref1, responsiveMenu, responsiveVideo, rv, slideToggler, indexOf = [].indexOf; $ = jQuery.noConflict(); $html = $('html'); $body = $('body'); $main = $('#main'); $nav = $('#nav'); $wrapper = $('#wrapper'); $document = $(document); floatingLabel = class floatingLabel { constructor(labels, classes = {}) { var event, input, j, k, label, len, len1, ref, ref1, span; classes.focus || (classes.focus = "focus"); classes.active || (classes.active = "active"); classes.error || (classes.error = "error"); for (j = 0, len = labels.length; j < len; j++) { label = labels[j]; if (!(input = label.control)) { return; } if (label.querySelector('input, textarea')) { span = document.createElement('span'); span.appendChild(document.createTextNode(label.firstChild.nodeValue)); label.replaceChild(span, label.firstChild); label = label.firstChild; } label.classList.add('floating-label'); while ((ref = (input.parent || (input.parent = input)).tagName) !== 'DIV' && ref !== 'P' && ref !== 'LI') { input.parent = input.parent.parentNode; } ref1 = ['keyup', 'input', 'change']; for (k = 0, len1 = ref1.length; k < len1; k++) { event = ref1[k]; input.addEventListener(event, function() { this.parent.classList.remove(classes.error); return this.parent.classList.toggle(classes.active, !!this.value); }); } input.addEventListener('focus', function() { return this.parent.classList.add(classes.focus); }); input.addEventListener('blur', function() { return this.parent.classList.remove(classes.focus); }); input.parent.classList.toggle(classes.active, !!input.value); } } }; // initialize new floatingLabel(document.querySelectorAll('form label')); customFileInput = class customFileInput { constructor(fileInputs) { var fileInput, j, len; for (j = 0, len = fileInputs.length; j < len; j++) { fileInput = fileInputs[j]; fileInput.classList.add('custom-file-input'); fileInput.addEventListener('change', function() { var file, files, k, len1, ref; files = []; ref = this.files; for (k = 0, len1 = ref.length; k < len1; k++) { file = ref[k]; files.push(file.name); } if (this.parentNode.lastChild.nodeValue) { return this.parentNode.lastChild.nodeValue = files.join(', '); } else { return this.parentNode.appendChild(document.createTextNode(files.join(', '))); } }); } } }; new customFileInput(document.querySelectorAll('[type=file]')); responsiveVideo = class responsiveVideo { constructor(video) { this.update = this.update.bind(this); this.video = video; if (!this.video) { return; } this.img = new Image(this.video.width, this.video.height); this.img.onload = this.update; this.img.className = `rv-img rv-img-${document.querySelectorAll('.rv-img').length + 1}`; this.img.src = `data:image/svg+xml;charset=utf-8,%3Csvg xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg' width%3D'${this.video.width}' height%3D'${this.video.height}' %2F%3E`; this.img.setAttribute('style', 'position:absolute; top:0; left:0; opacity:0; pointer-events:none; width: auto; height: auto; max-width: 100%;'); this.video.parentNode.setAttribute('style', 'position:relative; padding:0;'); this.video.parentNode.appendChild(this.img); window.addEventListener('resize', this.update); } update() { return [this.video.width, this.video.height] = [this.img.width, this.img.height]; } }; ref = document.querySelectorAll('iframe'); // initialize for (i = j = 0, len = ref.length; j < len; i = ++j) { rv = ref[i]; window[`rv${i}`] = new responsiveVideo(rv); } slideToggler = class slideToggler { constructor(el1) { this.getHeight = this.getHeight.bind(this); this.toggle = this.toggle.bind(this); this.el = el1; if (!this.el) { return; } } getHeight() { var clone; clone = this.el.cloneNode(true); clone.style.cssText = 'visibility: hidden; display: block; margin: -999px 0'; this.height = (this.el.parentNode.appendChild(clone)).clientHeight; this.el.parentNode.removeChild(clone); return this.height; } toggle(time) { var currHeight, disp, el, end, init, repeat, start; this.getHeight(); time || (time = this.height / 3 + 150); currHeight = this.el.clientHeight * (getComputedStyle(this.el).display !== 'none'); [start, end] = currHeight > this.height / 2 ? [this.height, 0] : [0, this.height]; disp = end - start; el = this.el; this.el.classList[end === 0 ? 'remove' : 'add']('open'); this.el.style.cssText = "overflow: hidden; display: block;"; init = (new Date).getTime(); repeat = function() { var instance, ref1, repeatLoop, step; instance = (new Date).getTime() - init; step = start + disp * instance / time; if (instance <= time) { el.style.height = step + 'px'; // if Math.floor(step) in [start..end] } else { el.style.cssText = `display: ${(end === 0 ? 'none' : 'block')}`; } repeatLoop = requestAnimationFrame(repeat); if (ref1 = Math.floor(step), indexOf.call((function() { var results = []; for (var k = start; start <= end ? k <= end : k >= end; start <= end ? k++ : k--){ results.push(k); } return results; }).apply(this), ref1) < 0) { return cancelAnimationFrame(repeatLoop); } }; return repeat(); } }; responsiveMenu = class responsiveMenu { constructor(nav, opt) { var base, k, l, len1, len2, len3, m, menu, menuToggle, ref1, ref2, ref3, sub, subMenu, subMenuToggle; this.createToggle = this.createToggle.bind(this); this.breaking = this.breaking.bind(this); this.opt = opt; (base = this.opt).breaking || (base.breaking = '640px'); this.opt.maxBreaking = parseInt(this.opt.maxBreaking) || 1040; menu = nav.querySelector('.menu'); if (!slideToggler) { slideToggler = class slideToggler { constructor(el1) { this.toggle = this.toggle.bind(this); this.el = el1; if (!this.el) { return; } } toggle() { this.el.classList.toggle('open'); return this.el.style.cssText = `display: ${(this.el.classList.contains('open') ? 'block' : 'none')}`; } }; } ref1 = menu.querySelectorAll('ul'); for (k = 0, len1 = ref1.length; k < len1; k++) { sub = ref1[k]; sub.toggler = new slideToggler(sub); } menuToggle = this.createToggle(nav, 'menu-toggle', 'Menu'); menuToggle.addEventListener('click', function() { document.documentElement.classList.toggle('nav-open'); return menuToggle.menu.classList.toggle('open', document.documentElement.classList.contains('nav-open')); }); ref2 = menu.querySelectorAll('ul'); for (l = 0, len2 = ref2.length; l < len2; l++) { subMenu = ref2[l]; subMenu.parentNode.classList.add('has-children'); subMenuToggle = this.createToggle(subMenu, 'sub-menu-toggle', '+'); subMenuToggle.addEventListener('click', function() { var len3, m, open, ref3, results; this.menu.toggler.toggle(); ref3 = this.parentNode.parentNode.querySelectorAll('ul.open'); results = []; for (m = 0, len3 = ref3.length; m < len3; m++) { open = ref3[m]; if (open !== this.menu) { results.push(open.toggler.toggle()); } else { results.push(void 0); } } return results; }); } ref3 = menu.querySelectorAll('.has-children[class*=current] > ul'); for (m = 0, len3 = ref3.length; m < len3; m++) { sub = ref3[m]; sub.classList.add('open'); } document.addEventListener('DOMContentLoaded', this.breaking); window.addEventListener('resize', this.breaking); setTimeout(this.breaking, 3000); } createToggle(menu, klass, label) { var toggle; toggle = menu.parentNode.querySelector(`.${klass}`) || document.createElement("button"); toggle.classList.add(klass); toggle.appendChild(document.createTextNode(label)); toggle.menu = menu.nodeName === 'UL' ? menu : menu.querySelector('.menu'); return menu.parentNode.insertBefore(toggle, menu.nextSibling); } breaking() { var div, el, isMobile, k, len1, ref1, windowWidth; document.body.classList.remove('menu-mobile'); document.body.classList.add('menu-desktop'); div = document.createElement('div'); div.style.cssText = `position: absolute; width: ${this.opt.breaking}`; document.body.appendChild(div); this.menuBreak = div.clientWidth || 0; document.body.removeChild(div); ref1 = document.querySelectorAll(`${this.opt.breaking}`); for (k = 0, len1 = ref1.length; k < len1; k++) { el = ref1[k]; this.menuBreak += this.getWidth(el); } isMobile = (windowWidth = document.body.clientWidth) <= Math.min(this.menuBreak, this.opt.maxBreaking); document.body.classList.toggle('menu-mobile', isMobile); document.body.classList.toggle('menu-desktop', !isMobile); if (!isMobile) { return document.documentElement.classList.remove('nav-open'); } } getWidth(el) { var clone, width; if (el.clientWidth > 0) { return el.clientWidth; } clone = el.cloneNode(true); clone.style.cssText = 'position: absolute; visibility: hidden; display: block;'; el.parentNode.appendChild(clone); width = clone.clientWidth; el.parentNode.removeChild(clone); return width; } }; new responsiveMenu(document.querySelector('#nav'), { breaking: '.logo, .tagline, .menu' }); // class gallery // constructor: -> // for image in document.querySelectorAll('img') // image.parentNode.style.backgroundImage = "url('#{image.src}')" // new gallery $('.caption-outside').each(function() { return $(this).parents('.gallery-item').width($(this).parents('.gallery-item').find('img').width()); }); groups = {}; $('.gallery a').filter('[href$=".gif"], [href$=".jpg"], [href$=".png"], [href$=".bmp"]').each(function() { var id; id = $(this).parents('[id*="gallery"]').first().prop('id') || Math.random(100); if (!groups[id]) { groups[id] = []; } return groups[id].push(this); }); $.each(groups, function() { return $(this).magnificPopup({ type: 'image', closeOnContentClick: true, closeBtnInside: false, mainClass: 'mfp-with-zoom mfp-img-mobile', removalDelay: 0, overflowY: 'scroll', image: { verticalFit: true, titleSrc: function(item) { return item.el.parents('figure').find('figcaption').text() || item.el.attr('title'); } }, zoom: { enabled: true }, gallery: { enabled: true, navigateByImgClick: false, tCounter: '' }, // disableOn: -> // $(window).width() > 480 callbacks: { // beforeOpen: -> open: function() { return this.currItem.el.parents('article').addClass('active'); }, close: function() {}, // @currItem.el.parents('article').removeClass 'active' // alert 'close' afterClose: function() { return setTimeout(function() { return $('article.active').removeClass('active'); }, 300); } } }); }); $('.gallery').each(function() { var g; g = $(this); if (!(g.is('.gallery-size-thumbnail') || g.parents('.wp-article-list').length)) { g.packery({ gutter: 0, itemSelector: '.gallery-item', percentPosition: true }); // transitionDuration: 0 g.imagesLoaded().progress(function(instance) { return g.packery(); }); g.imagesLoaded().done(function(instance) { var fig, figure, image, k, len1, n, ref1, results, w; ref1 = instance.images; results = []; for (k = 0, len1 = ref1.length; k < len1; k++) { image = ref1[k]; figure = $(image.img).parents('figure'); fig = figure[0]; n = parseFloat(fig.style.left); w = 100 * parseFloat(figure.css('width')) / parseFloat(figure.parent().css('width')); results.push(fig.style.left = 100 * Math.round(n / w) / Math.round(100 / w) + '%'); } return results; }); return g.on('layoutComplete', function(event, items) { var fig, figure, item, k, len1, n, results, w; results = []; for (k = 0, len1 = items.length; k < len1; k++) { item = items[k]; fig = item.element; figure = $(fig); n = parseFloat(fig.style.left); w = 100 * parseFloat(figure.css('width')) / parseFloat(figure.parent().css('width')); results.push(fig.style.left = 100 * Math.round(n / w) / Math.round(100 / w) + '%'); } return results; }); } }); // for article in document.querySelectorAll('[class*=article-list] article') // article.addEventListener 'mouseenter', -> // space = parseInt(getComputedStyle(@nextElementSibling||@).getPropertyValue("margin-top")) // contentBottom = @querySelector('[class*=content]').getBoundingClientRect().bottom // titleTop = @nextElementSibling?.querySelector('[class*=title]').getBoundingClientRect().top || @getBoundingClientRect().bottom // difference = contentBottom - titleTop + space * 2 // return if difference >= -space * 1.5 // @style.marginBottom = "#{difference}px" // article.addEventListener 'mouseleave', -> // @style.marginBottom = "0" // article.addEventListener 'click', -> // @classList.toggle 'open' // space = parseInt(getComputedStyle(@nextElementSibling||@).getPropertyValue("margin-top")) // contentBottom = @querySelector('[class*=content]').getBoundingClientRect().bottom // titleTop = @nextElementSibling.querySelector('[class*=title]').getBoundingClientRect().top // difference = contentBottom - titleTop + space // console.log space, contentBottom, titleTop // @style.marginBottom = "#{parseInt(@style.marginBottom) + difference}px" // ), false expandableArticle = class expandableArticle { constructor(article1) { this.unclick = this.unclick.bind(this); this.article = article1; if (!this.article) { return; } this.article.addEventListener('mouseenter', this.show); this.article.addEventListener('mouseleave', this.hide); this.article.addEventListener('click', this.toggle); this.article.close = this.close; this.article.toTop = this.toTop; document.addEventListener('click', this.unclick); } show() { var contentBottom, difference, ref1, space, titleTop; space = parseInt(getComputedStyle(this).getPropertyValue("padding-top")); contentBottom = this.querySelector('[class*=content]').getBoundingClientRect().bottom; titleTop = ((ref1 = this.nextElementSibling) != null ? ref1.querySelector('[class*=title]').getBoundingClientRect().top : void 0) || this.getBoundingClientRect().bottom; difference = contentBottom - titleTop + space * 2; // console.log contentBottom, space*2, titleTop, difference // contentHeight = @querySelector('[class*=content]').offsetHeight this.nextElementSibling.close(); if (difference > space) { return this.style.marginBottom = `${difference}px`; } } toggle(e) { var k, len1, ref1, ref2, sibling; console.log('toggle'); console.log(e); e.stopImmediatePropagation(); if ((ref1 = e.target.nodeName) === 'A' || ref1 === 'INPUT' || ref1 === 'TEXTAREA') { return; } ref2 = this.parentNode.querySelectorAll(this.nodeName); for (k = 0, len1 = ref2.length; k < len1; k++) { sibling = ref2[k]; if (sibling !== this) { sibling.classList.remove('open'); } } this.classList.toggle('open'); this.parentNode.classList.toggle('has-open', this.parentNode.querySelector('.open')); return this.toTop(); } close() { this.classList.remove('open'); this.parentNode.classList.remove('has-open'); return this.style.marginBottom = "0px"; } toTop() { return window.scrollTo(0, this.getBoundingClientRect().top + window.scrollY - parseInt(getComputedStyle(this).getPropertyValue("padding-top"))); } hide() { if (!this.classList.contains('open')) { // if parseInt(@style.marginBottom) > @space return this.style.marginBottom = "0px"; } } unclick(e) { var openArticle; e.stopPropagation(); if (!(openArticle = document.querySelector('article.open'))) { return; } openArticle.close(); return openArticle.toTop(); } }; ref1 = document.querySelectorAll('[class*=article-list] article'); for (k = 0, len1 = ref1.length; k < len1; k++) { article = ref1[k]; new expandableArticle(article); // $('html:not(.touchevents) [class*=article-list] article').hover (-> // space = parseInt $(@).next().css('marginTop') || 0 // return unless (content = $(@).find('[class*=content]')).length // contentBottom = content.offset().top + content.innerHeight() // if $(@).next().length // return unless (title = $(@).next().find('[class*=title], .gallery').first()).length // nextTop = title.offset().top // else // nextTop = $(@).parent().offset().top + $(@).parent().innerHeight() // difference = nextTop - space * 2 - contentBottom // # console.log space, contentBottom, nextTop, difference // return if difference >= -space // if $(@).next().length // $(@).next().css // marginTop: -difference // else // $(@).parent().css // paddingBottom: -difference // ), -> // el = $(@) // el.next().add(el.parent()).removeAttr('style') $('.search-form').submit(function(e) { var s; s = $(this).find('.search-field'); if (!$.trim(s.val())) { e.preventDefault(); return s.focus(); } }); } Header = class Header { constructor(header) { this.update = this.update.bind(this); this.header = header; if (!this.header) { return; } document.addEventListener("DOMContentLoaded", this.update); window.addEventListener('resize', this.update); } update() { var hContMax, hHeight, offset, tolerance; hHeight = this.header.clientHeight; hContMax = Math.max(this.header.querySelector('.brand').clientHeight, this.header.querySelector('nav').clientHeight); offset = hHeight; tolerance = { up: 5, down: 0 }; if (this.header.querySelector('.wp-custom-header') && this.header.querySelector('.wp-custom-header').style.display !== 'none') { offset -= hContMax; tolerance = { up: 5, down: 40 }; } document.querySelector('#wrapper').style.marginTop = hHeight + 'px'; this.header.headroom = new Headroom(this.header, { offset: offset, tolerance: tolerance }); return this.header.headroom.init(); } }; window.header = new Header(document.querySelector('#header')); $(function() { return $('select').customSelect(); }); // PREMIUM //- require modules/_parallax-header.coffee // DEBUG // notify = (body) -> // return unless 'Notification' of window // # console.log Notification.permission // if Notification.permission == 'default' // Notification.requestPermission -> // notify(body) // else if Notification.permission == 'granted' // n = new Notification(document.title, // 'body': body // 'tag': 'uniques string' // ) // n.onclick = -> // @close() // n.onclose = -> // return // console.log 'Notification closed' // else if Notification.permission == 'denied' // return // notify() // console.table(document.body.classList) // $('a').on 'click', (e) -> // return unless @pathname == window.location.pathname // ports = ['4567','4568'] // current = ports.indexOf(e.target.port) // ports.splice current, 1 if current > -1 // e.target.port = ports[0] if ports.length == 1