1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-02-14 21:10:25 +01:00

rewrite menu.js without jQuery

This commit is contained in:
Matthias Kretschmann 2017-09-09 19:35:12 +02:00
parent c031a063f0
commit 11dd15c584
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 10 additions and 17 deletions

View File

@ -2,28 +2,21 @@
const krlcMenu = (() => { // eslint-disable-line no-unused-vars const krlcMenu = (() => { // eslint-disable-line no-unused-vars
const _config = { const _config = {
thesite: $('.site'), thesite: document.getElementsByClassName('site')[0],
thelink: $('.menu-btn'), thelink: document.getElementsByClassName('menu-btn')[0],
thepop: $('.nav-popover') thepop: document.getElementsByClassName('nav-popover')[0]
} }
const _private = { const _private = {
toggleMenu() { toggleMenu() {
_config.thelink.on('click', e => { _config.thelink.addEventListener('click', e => {
e.preventDefault() e.preventDefault()
// Toggle menu // Toggle menu
_config.thesite.toggleClass('has-menu-open') _config.thesite.classList.toggle('has-menu-open')
// Bind the hide controls
$(document).bind('click.hidethepop', () => {
_config.thesite.removeClass('has-menu-open')
// Unbind the hide controls
$(document).unbind('click.hidethepop')
})
// Dont close thepop when you click on thepop // Dont close thepop when you click on thepop
_config.thepop.on('click', e => { _config.thepop.addEventListener('click', e => {
e.stopPropagation() e.stopPropagation()
}) })

View File

@ -16,7 +16,6 @@
// Init jQuery-based modules // Init jQuery-based modules
// //
$(document).ready(() => { $(document).ready(() => {
krlcMenu.init()
krlcSearch.init() krlcSearch.init()
}) })
@ -24,6 +23,7 @@ $(document).ready(() => {
// //
// Init js modules // Init js modules
// //
krlcMenu.init()
krlcModals.init() krlcModals.init()
svg4everybody({ svg4everybody({

View File

@ -1,7 +1,7 @@
<script src="/assets/js/kremalicious3.min.js" async></script> <script src="/assets/js/kremalicious3.min.js" async></script>
{% if page.js %} {% if page.js %}
<script src="/assets/js/{{ page.js }}"></script> <script src="/assets/js/{{ page.js }}" async></script>
{% endif %} {% endif %}

View File

@ -213,8 +213,8 @@ export const criticalCss = done => {
// //
export const js = () => export const js = () =>
src([ src([
SRC + '/_assets/js/kremalicious3.js', SRC + '/_assets/js/*.js',
SRC + '/_assets/js/analytics.js', '!' + SRC + '/_assets/js/_*.js',
'node_modules/picturefill/dist/picturefill.js' 'node_modules/picturefill/dist/picturefill.js'
]) ])
.pipe($.sourcemaps.init()) .pipe($.sourcemaps.init())