diff --git a/_src/_assets/js/_analytics.js b/_src/_assets/js/_analytics.js deleted file mode 100644 index 0c0d9aad..00000000 --- a/_src/_assets/js/_analytics.js +++ /dev/null @@ -1,78 +0,0 @@ -/* global ga */ - -// -// Track Responsive Breakpoints -// -// stolen & adapted from -// http://philipwalton.com/articles/measuring-your-sites-responsive-breakpoint-usage/ -// -const gaBreakpoints = () => { - // Do nothing in browsers that don't support `window.matchMedia`. - if (!window.matchMedia) { - return - } - - // Prevent rapid breakpoint changes for all firing at once. - let timeout - - const breakpoints = { - xxs: '(max-width: 479px)', - xs: '(min-width: 480px) and (max-width: 767px)', - sm: '(min-width: 768px) and (max-width: 991px)', - md: '(min-width: 992px) and (max-width: 1199px)', - lg: '(min-width: 1200px) and (max-width: 1599px)', - hg: '(min-width: 1600px)' - } - - Object.keys(breakpoints).forEach(breakpoint => { - const mql = window.matchMedia(breakpoints[breakpoint]) - - // Set the initial breakpoint on page load. - if (mql.matches) { - ga('set', 'dimension1', breakpoint) - } - - // Update the breakpoint as the matched media changes - mql.addListener(() => { - if (mql.matches) { - clearTimeout(timeout) - timeout = setTimeout(() => { - ga('set', 'dimension1', breakpoint) - }, 1000) - } - }) - }) -} - - -// -// Track Viewport -// -const gaViewport = () => { - const width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0) - const height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - const dimensions = width + 'x' + height - - ga('set', 'dimension2', dimensions) -} - - -// -// Track Pixel Density -// -const gaPixelDensity = () => { - // Heads up! - // window.devicePixelRatio doesn't work correctly in IE but whatever - const pixeldensity = window.devicePixelRatio - - ga('set', 'dimension3', pixeldensity) -} - - -const dnt = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack - -if (dnt !== 'yes' && dnt !== '1') { - gaBreakpoints() - gaViewport() - gaPixelDensity() -} diff --git a/_src/_assets/js/_menu.js b/_src/_assets/js/_menu.js index 1a38bc0a..80546c51 100644 --- a/_src/_assets/js/_menu.js +++ b/_src/_assets/js/_menu.js @@ -1,27 +1,32 @@ -$(document).ready(() => { - const thesite = $('.site') - const thelink = $('.menu-btn') - const thepop = $('.nav-popover') +/* exported krlcMenu */ - thelink.on('click', e => { - e.preventDefault() +const krlcMenu = (() => { // eslint-disable-line no-unused-vars + const _config = { + thesite: document.getElementsByClassName('site')[0], + thelink: document.getElementsByClassName('menu-btn')[0], + thepop: document.getElementsByClassName('nav-popover')[0] + } - // Toggle menu - thesite.toggleClass('has-menu-open') + const _private = { + toggleMenu() { + _config.thelink.addEventListener('click', e => { + e.preventDefault() - // Bind the hide controls - $(document).bind('click.hidethepop', () => { - thesite.removeClass('has-menu-open') - // Unbind the hide controls - $(document).unbind('click.hidethepop') - }) + // Toggle menu + _config.thesite.classList.toggle('has-menu-open') - // Dont close thepop when you click on thepop - thepop.on('click', e => { - e.stopPropagation() - }) + // Dont close thepop when you click on thepop + _config.thepop.addEventListener('click', e => { + e.stopPropagation() + }) - // And dont close thepop now - e.stopPropagation() - }) -}) + // And dont close thepop now + e.stopPropagation() + }) + } + } + + return { + init: _private.toggleMenu + } +})(); // eslint-disable-line semi diff --git a/_src/_assets/js/_modals.js b/_src/_assets/js/_modals.js new file mode 100644 index 00000000..67ffbb96 --- /dev/null +++ b/_src/_assets/js/_modals.js @@ -0,0 +1,52 @@ +// +// Vex modals +// + +/* global vex, fetch */ +/* exported krlcModals */ + +/* eslint-disable spaced-comment */ +//=require vex-js/dist/js/vex.combined.js +/* eslint-enable spaced-comment */ + +const krlcModals = (() => { // eslint-disable-line no-unused-vars + const _config = { + btcVexTriggers: document.querySelectorAll('.js-vex-btc') + } + + let btcAddress + + const _private = { + getBtcAddress() { + const url = '/api/site.json' + + fetch(url) + .then(res => res.json()) + .then(data_ => { + btcAddress = data_[0].author.bitcoin + }) + .catch(err => console.error(err)) + + return btcAddress + }, + + vexBtc() { + _config.btcVexTriggers.forEach(el => { + el.addEventListener('click', e => { + e.preventDefault() + + vex.defaultOptions.className = 'vex-theme-kremalicious vex-bitcoin' + vex.dialog.buttons.YES.text = 'Close' + vex.open({unsafeContent: '

My Bitcoin Address

\n \n
' + btcAddress + '
'}) + }) + }) + } + } + + return { + init() { + _private.getBtcAddress() + _private.vexBtc() + } + } +})(); // eslint-disable-line semi diff --git a/_src/_assets/js/_search.js b/_src/_assets/js/_search.js index 373b7607..117250e7 100644 --- a/_src/_assets/js/_search.js +++ b/_src/_assets/js/_search.js @@ -1,84 +1,90 @@ /* global SimpleJekyllSearch */ +/* exported krlcSearch */ /* eslint-disable spaced-comment */ //=require simple-jekyll-search/dest/simple-jekyll-search.js /* eslint-enable spaced-comment */ -$(document).ready(() => { - const searchlink = $('.search-btn, .js-search-init') - const searcharea = $('.search-area') - const searchfield = $('#search-input') - const searchpop = $('#search-popover') - - const searchReset = () => { - // Revert all search elements - searcharea - .removeClass('animation-slidedown') - .addClass('animation-bounceOutUp') - .on('animationend webkitAnimationEnd oAnimationEnd', () => { - $('body').removeClass('has-search-open') - }) - searchpop.addClass('hide') +const krlcSearch = (() => { // eslint-disable-line no-unused-vars + const _config = { + searchlink: document.getElementsByClassName('search-btn')[0], + searcharea: document.getElementsByClassName('search-area')[0], + searchclose: document.getElementsByClassName('search-close')[0], + searchfield: document.getElementById('search-input'), + searchpop: document.getElementById('search-popover'), + searchresults: document.getElementById('search-results') } - searchlink.on('click', e => { - e.preventDefault() + const _private = { + searchHide() { + // Revert all search elements + _config.searcharea.classList.remove('animation-slidedown') + _config.searcharea.classList.add('animation-bounceOutUp') + _config.searchpop.classList.add('hide') + document.body.classList.remove('has-search-open') + }, - // Show search field - searcharea - .removeClass('is-ready animation-bounceOutUp') - .addClass('is-ready animation-slidedown') - .on('animationend webkitAnimationEnd oAnimationEnd', () => { - $('body').addClass('has-search-open') + searchClose() { + _config.searchclose.addEventListener('click', e => { + e.preventDefault() + + _private.searchHide() + + // Empty search field + _config.searchfield.value = '' + _config.searchfield.blur() + }) + }, + + searchShow() { + _config.searchlink.addEventListener('click', e => { + e.preventDefault() + + // Show search field + _config.searcharea.classList.remove('is-ready', 'animation-bounceOutUp') + _config.searcharea.classList.add('is-ready', 'animation-slidedown') + document.body.classList.add('has-search-open') + + _config.searchfield.focus() + + SimpleJekyllSearch({ // eslint-disable-line new-cap + searchInput: _config.searchfield, + resultsContainer: _config.searchresults, + json: '/api/search.json', + searchResultTemplate: '{title}', + fuzzy: false + }) + + // Hide menu too just in case + if (document.body.classList.contains('has-menu-open')) { + document.body.classList.remove('has-menu-open') + } + + // Dont close thepop when click on thepop + _config.searchpop.addEventListener('click', e => { + e.stopPropagation() + }) + + // Dont close thepop when click on search field + _config.searchfield.addEventListener('click', e => { + e.stopPropagation() + }) + + // And dont close thepop now + e.stopPropagation() }) - searchfield.focus() + // Show popup upon first keypress + _config.searchfield.addEventListener('keyup', () => { + _config.searchpop.classList.remove('hide') + }) - SimpleJekyllSearch({ // eslint-disable-line new-cap - searchInput: document.getElementById('search-input'), - resultsContainer: document.getElementById('search-results'), - json: '/api/search.json', - searchResultTemplate: '{title}', - fuzzy: false - }) - - // Hide menu too just in case - if ($('body').hasClass('has-menu-open')) { - $('body').removeClass('has-menu-open') + // Listen for close icon + _private.searchClose() } + } - // Bind the hide controls - $(document).bind('click.hidethepop', () => { - searchReset() - - // Unbind the hide controls - $(document).unbind('click.hidethepop') - }) - - // Dont close thepop when click on thepop - searchpop.on('click', e => { - e.stopPropagation() - }) - // Dont close thepop when click on search field - searchfield.on('click', e => { - e.stopPropagation() - }) - - // And dont close thepop now - e.stopPropagation() - }) - - // Show popup upon first keypress - searchfield.on('keyup', () => { - searchpop.removeClass('hide') - }) - - $('.search-close').on('click', e => { - e.preventDefault() - - searchReset() - - // Empty search field - searchfield.val('').blur() - }) -}) + return { + init: _private.searchShow + } +})(); // eslint-disable-line semi diff --git a/_src/_assets/js/analytics.js b/_src/_assets/js/analytics.js new file mode 100644 index 00000000..c77dcb17 --- /dev/null +++ b/_src/_assets/js/analytics.js @@ -0,0 +1,82 @@ +const krlcAnalytics = (() => { // eslint-disable-line no-unused-vars + // + // Track Responsive Breakpoints + // + // stolen & adapted from + // http://philipwalton.com/articles/measuring-your-sites-responsive-breakpoint-usage/ + // + const gaBreakpoints = () => { + // Do nothing in browsers that don't support `window.matchMedia`. + if (!window.matchMedia) { + return + } + + // Prevent rapid breakpoint changes for all firing at once. + let timeout + + const breakpoints = { + xxs: '(max-width: 479px)', + xs: '(min-width: 480px) and (max-width: 767px)', + sm: '(min-width: 768px) and (max-width: 991px)', + md: '(min-width: 992px) and (max-width: 1199px)', + lg: '(min-width: 1200px) and (max-width: 1599px)', + hg: '(min-width: 1600px)' + } + + Object.keys(breakpoints).forEach(breakpoint => { + const mql = window.matchMedia(breakpoints[breakpoint]) + + // Set the initial breakpoint on page load. + if (mql.matches) { + window.ga('set', 'dimension1', breakpoint) + } + + // Update the breakpoint as the matched media changes + mql.addListener(() => { + if (mql.matches) { + clearTimeout(timeout) + timeout = setTimeout(() => { + window.ga('set', 'dimension1', breakpoint) + }, 1000) + } + }) + }) + } + + + // + // Track Viewport + // + const gaViewport = () => { + const width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0) + const height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) + const dimensions = width + 'x' + height + + window.ga('set', 'dimension2', dimensions) + } + + + // + // Track Pixel Density + // + const gaPixelDensity = () => { + // Heads up! + // window.devicePixelRatio doesn't work correctly in IE but whatever + const pixeldensity = window.devicePixelRatio + + window.ga('set', 'dimension3', pixeldensity) + } + + + return { + init() { + const dnt = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack + + if (dnt !== 'yes' && dnt !== '1') { + gaBreakpoints() + gaViewport() + gaPixelDensity() + } + } + } +})(); // eslint-disable-line semi diff --git a/_src/_assets/js/kremalicious3.js b/_src/_assets/js/kremalicious3.js index 3dc722b2..558f1a47 100644 --- a/_src/_assets/js/kremalicious3.js +++ b/_src/_assets/js/kremalicious3.js @@ -1,40 +1,17 @@ -/* global svg4everybody, vex */ +/* global krlcMenu, krlcSearch, krlcModals */ /* eslint-disable spaced-comment */ //=require webcomponents.js/CustomElements.js -//=require svg4everybody/dist/svg4everybody.js -//=require jquery/dist/jquery.js //=require time-elements/time-elements.js -//=require vex-js/dist/js/vex.combined.js -/* eslint-disable spaced-comment */ -//=include _analytics.js -//=include _search.js //=include _menu.js +//=include _search.js +//=include _modals.js /* eslint-enable spaced-comment */ - // -// Vex modals +// Init js modules // -const vexInit = () => { - const vexTriggers = document.querySelectorAll('.js-vex-btc') - - vexTriggers.forEach(el => { - el.addEventListener('click', e => { - e.preventDefault() - - vex.defaultOptions.className = 'vex-theme-kremalicious vex-bitcoin' - vex.dialog.buttons.YES.text = 'Close' - vex.open({ - unsafeContent: '

My Bitcoin Address

\n \n
171qDmKEXm9YBgBLXyGjjPvopP5o9htQ1V
' - }) - }, false) - }) -} - -vexInit() - -svg4everybody({ - nosvg: false -}) +krlcSearch.init() +krlcMenu.init() +krlcModals.init() diff --git a/_src/_includes/scripts.html b/_src/_includes/scripts.html index deb667d0..34f3c10e 100644 --- a/_src/_includes/scripts.html +++ b/_src/_includes/scripts.html @@ -1,7 +1,7 @@ {% if page.js %} - + {% endif %} @@ -69,3 +69,5 @@ {% else %} {% endif%} + + diff --git a/_src/api/site.json b/_src/api/site.json index e95267d3..b9015cfb 100644 --- a/_src/api/site.json +++ b/_src/api/site.json @@ -1,10 +1,13 @@ --- -layout: null --- [ { "name" : "{{ site.name }}", "description" : "{{ site.description | xml_escape }}", - "url" : "{{ site.url }}" + "url" : "{{ site.url }}", + "author" : { + {% for item in site.author %}"{{ item[0] }}": "{{ item[1] }}"{% unless forloop.last %},{% endunless %} + {% endfor %} + } } ] diff --git a/gulpfile.babel.js b/gulpfile.babel.js index b549992c..17f36e30 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -213,7 +213,8 @@ export const criticalCss = done => { // export const js = () => src([ - SRC + '/_assets/js/kremalicious3.js', + SRC + '/_assets/js/*.js', + '!' + SRC + '/_assets/js/_*.js', 'node_modules/picturefill/dist/picturefill.js' ]) .pipe($.sourcemaps.init()) diff --git a/package.json b/package.json index dd9bc3d9..d15785d1 100644 --- a/package.json +++ b/package.json @@ -38,13 +38,10 @@ ] }, "dependencies": { - "bootstrap": "^3.3.7", - "jquery": "^3.2.1", "normalize-css": "^2.3.1", "normalize-opentype.css": "^0.2.4", "picturefill": "^3.0.2", "simple-jekyll-search": "^1.4.1", - "svg4everybody": "^2.1.9", "time-elements": "^0.6.1", "vex-js": "^4.0.0", "webcomponents.js": "^0.7.24"