Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

115: ES6 support, ESLint, Babel 7 Upgrade and Babel Polyfill #322

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> 0.5%
not dead
ie 11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using browserlist, I think the emulsify-gulp gulp-css.js and gulp-config.js files needs to be updated, so you won't pass browser arguments through the cssConfig.autoPrefixerBrowsers variable anymore?

Maybe it could be augmented so the variable will accept the autoprefixer options? like {grid: autoplace}?

https://github.com/fourkitchens/emulsify-gulp/pull/108/files

13 changes: 13 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Artifacts
build/**/*
dist/**/*
pattern-lab/**/*

# 3rd party scripts
components/_annotations/annotations.js
components/js/babel-polyfill.js
components/js/fitvids.js
components/js/init.js
components/js/jquery*.js
components/js/modernizr.js
components/js/svgxuse.min.js
8 changes: 8 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends: airbnb-base
rules:
global-require: off
comma-dangle: 0
env:
browser: true
globals:
Drupal: true
14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = (api) => {
api.cache(true);

const presets = [
[
'@babel/preset-env', {
useBuiltIns: 'entry'
},
],
'minify',
];

return { presets };
};
2 changes: 2 additions & 0 deletions components/_meta/_00-head.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<!-- <script src="../../js/ready.min.js"></script> -->
<!-- <script src="../../js/drupal.js"></script> -->

<script src="../../js/babel-polyfill.js"></script>

<!-- Begin Pattern Lab (Required for Pattern Lab to run properly) -->
{{ patternLabHead | raw }}
<!-- End Pattern Lab -->
Expand Down
2 changes: 1 addition & 1 deletion components/_meta/_01-foot.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{ patternLabFoot | raw }}

<!-- This makes attach_library work wherever it is in the document flow. -->
<script src="../../js/reload-scripts.js"></script>
<script src="../../../../dist/reload-scripts.js"></script>

</body>
</html>
50 changes: 22 additions & 28 deletions components/_patterns/02-molecules/accordion-item/accordion-item.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
// UNCOMMENT IF DRUPAL - see components/_meta/_01-foot.twig for attachBehaviors
// UNCOMMENT NEXT 2 LINES IF DRUPAL - see components/_meta/_01-foot.twig for attachBehaviors
// Drupal.behaviors.accordion = {
// attach: function (context, settings) {

(function () { // REMOVE IF DRUPAL

'use strict';

// REMOVE NEXT LINE IF DRUPAL
(function accordion() {
// Set 'document' to 'context' if Drupal
var accordionTerm = document.querySelectorAll('.accordion-term');
var accordionDef = document.querySelectorAll('.accordion-def');
const accordionTerms = document.querySelectorAll('.accordion-term');
const accordionDefs = document.querySelectorAll('.accordion-def');

// If javascript, hide accordion definition on load
function jsCheck() {
for (var i = 0; i < accordionDef.length; i++) {
if (accordionDef[i].classList) {
accordionDef[i].classList.add('active');
accordionDef[0].previousElementSibling.classList.add('is-active');
Array.from(accordionDefs).forEach((accordionDef) => {
evanmwillhite marked this conversation as resolved.
Show resolved Hide resolved
if (accordionDef.classList) {
accordionDef.classList.add('active');
accordionDefs[0].previousElementSibling.classList.add('is-active');
} else {
accordionDef.className += ' active'; // eslint-disable-line no-param-reassign
evanmwillhite marked this conversation as resolved.
Show resolved Hide resolved
accordionDefs[0].previousElementSibling.classList.add('is-active');
}
else {
accordionDef[i].className += ' active';
accordionDef[0].previousElementSibling.classList.add('is-active');
}
}
});
}

jsCheck();

// Accordion Toggle
// Mobile Click Menu Transition
for (var i = 0; i < accordionTerm.length; i++) {
accordionTerm[i].addEventListener('click', function (e) {
var className = 'is-active';
Array.from(accordionTerms).forEach((accordionTerm) => {
accordionTerm.addEventListener('click', function accordionClick(e) {
const className = 'is-active';
// Add is-active class
if (this.classList) {
this.classList.toggle(className);
}
else {
var classes = this.className.split(' ');
var existingIndex = classes.indexOf(className);
} else {
const classes = this.className.split(' ');
const existingIndex = classes.indexOf(className);

if (existingIndex >= 0) {
classes.splice(existingIndex, 1);
}
else {
} else {
classes.push(className);
}
this.className = classes.join(' ');
}
e.preventDefault();
});
}

})(); // REMOVE IF DRUPAL
});
}()); // REMOVE IF DRUPAL

// UNCOMMENT IF DRUPAL
// }
Expand Down
35 changes: 16 additions & 19 deletions components/_patterns/02-molecules/menus/main-menu/main-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,29 @@
// Drupal.behaviors.mainMenu = {
// attach: function (context) {

(function () { // REMOVE IF DRUPAL.

'use strict';

// REMOVE NEXT LINE IF DRUPAL.
(function mainMenu() {
// Use context instead of document IF DRUPAL.
var toggle_expand = document.getElementById('toggle-expand');
var menu = document.getElementById('main-nav');
var expand_menu = menu.getElementsByClassName('expand-sub');
const toggleExpand = document.getElementById('toggle-expand');
const menu = document.getElementById('main-nav');
const expandMenu = menu.getElementsByClassName('expand-sub');

// Mobile Menu Show/Hide.
toggle_expand.addEventListener('click', function (e) {
toggle_expand.classList.toggle('toggle-expand--open');
toggleExpand.addEventListener('click', () => {
toggleExpand.classList.toggle('toggle-expand--open');
menu.classList.toggle('main-nav--open');
});

// Expose mobile sub menu on click.
for (var i = 0; i < expand_menu.length; i++) {
expand_menu[i].addEventListener('click', function (e) {
var menu_item = e.currentTarget;
var sub_menu = menu_item.nextElementSibling;
Array.from(expandMenu).forEach((expand) => {
expand.addEventListener('click', (e) => {
const menuItem = e.currentTarget;
const subMenu = menuItem.nextElementSibling;

menu_item.classList.toggle('expand-sub--open');
sub_menu.classList.toggle('main-menu--sub-open');
menuItem.classList.toggle('expand-sub--open');
subMenu.classList.toggle('main-menu--sub-open');
});
}

})(); // REMOVE IF DRUPAL.
});
}()); // REMOVE IF DRUPAL.

// })(Drupal); // UNCOMMENT IF DRUPAL.
// }(Drupal)); // UNCOMMENT IF DRUPAL.
67 changes: 37 additions & 30 deletions components/_patterns/02-molecules/menus/tabs/tabs.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
(function () {
/**
* @file
* A JavaScript file containing the main menu functionality (small/large screen)
*
*/

'use strict';
// JavaScript should be made compatible with libraries other than jQuery by
// wrapping it with an "anonymous closure". See:
// - https://drupal.org/node/1446420
// - http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

var el = document.querySelectorAll('.tabs');
var tabNavigationLinks = document.querySelectorAll('.tabs__link');
var tabContentContainers = document.querySelectorAll('.tabs__tab');
var activeIndex = 0;

/**
* handleClick
* @description Handles click event listeners on each of the links in the
* tab navigation. Returns nothing.
* @param {HTMLElement} link The link to listen for events on
* @param {Number} index The index of that link
*/
var handleClick = function (link, index) {
link.addEventListener('click', function (e) {
e.preventDefault();
goToTab(index);
});
};
(function tabs() {
const el = document.querySelectorAll('.tabs');
const tabNavigationLinks = document.querySelectorAll('.tabs__link');
const tabContentContainers = document.querySelectorAll('.tabs__tab');
let activeIndex = 0;

/**
* goToTab
* @description Goes to a specific tab based on index. Returns nothing.
* @param {Number} index The index of the tab to go to
*/
var goToTab = function (index) {
function goToTab(index) {
if (index !== activeIndex && index >= 0 && index <= tabNavigationLinks.length) {
tabNavigationLinks[activeIndex].classList.remove('is-active');
tabNavigationLinks[index].classList.add('is-active');
tabContentContainers[activeIndex].classList.remove('is-active');
tabContentContainers[index].classList.add('is-active');
activeIndex = index;
}
};
}

/**
* handleClick
* @description Handles click event listeners on each of the links in the
* tab navigation. Returns nothing.
* @param {HTMLElement} link The link to listen for events on
* @param {Number} index The index of that link
*/
function handleClick(link, index) {
link.addEventListener('click', (e) => {
evanmwillhite marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();
goToTab(index);
});
}

/**
* init
* @description Initializes the component by removing the no-js class from
* the component, and attaching event listeners to each of the nav items.
* Returns nothing.
*/
for (var e = 0; e < el.length; e++) {
el[e].classList.remove('no-js');
}
Array.from(el).forEach((item) => {
item.classList.remove('no-js');
});

for (var i = 0; i < tabNavigationLinks.length; i++) {
var link = tabNavigationLinks[i];
Array.from(tabNavigationLinks).forEach((tabNavigationLink, i) => {
const link = tabNavigationLink;
handleClick(link, i);
}

})();
});
}());
4 changes: 4 additions & 0 deletions components/js/babel-polyfill.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions components/js/reload-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function async(src, callback) {
script.src = src;
if (callback) {
script.addEventListener(
"load",
e => {
'load',
(e) => {
callback(null, e);
},
false
Expand All @@ -24,7 +24,7 @@ function async(src, callback) {
head.appendChild(script);
}

scripts.forEach(element => {
Array.from(scripts).forEach((element) => {
// If the script has the data-name attribute.
if (element.dataset.name) {
const scriptSrc = element.dataset.src;
Expand All @@ -34,7 +34,7 @@ scripts.forEach(element => {
const behaviors = Object.values(Drupal.behaviors);
// Only run attachBehaviors once.
behaviors.forEach(behavior => {
Drupal.attachBehaviors(document);
Drupal.attachBehaviors(d);
});
}
});
Expand Down
3 changes: 3 additions & 0 deletions emulsify.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ global:
css:
theme:
dist/style.css: {}
js:
components/js/babel-polyfill.js: {}

main-menu:
js:
dist/02-molecules/menus/main-menu/main-menu.js: {}
dependencies:
- core/drupal


sprite:
js:
Expand Down
13 changes: 5 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/* globals require */

// eslint-disable-next-line strict
'use strict';

// General
var gulp = require('gulp-help')(require('gulp'));
var localConfig = {};
const gulp = require('gulp-help')(require('gulp')); // eslint-disable-line import/no-extraneous-dependencies

let localConfig = {};

try {
localConfig = require('./local.gulp-config');
}
catch (e) {
localConfig = require('./local.gulp-config'); // eslint-disable-line import/no-unresolved
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
Expand Down
Loading