-
Notifications
You must be signed in to change notification settings - Fork 2
STIJ-196: Added JS namespaces setup. #171
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored the whole thing in a new commit.
I haven't incorporated all my comments into it, so check it out and let's combine the best of both ;)
components/11-base/base/base.js
Outdated
var gent_styleguide = (function () { // eslint-disable-line no-unused-vars | ||
var gent_styleguide = gent_styleguide || {}; | ||
|
||
var base = gent_styleguide.base = (function () { // eslint-disable-line no-unused-vars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary variable.
Since gent_styleguide is already an object, we can just append properties to it.
gent_styleguide.tabtrap = ...
gent_styleguide.helper = ...
@@ -2,15 +2,16 @@ | |||
* @file | |||
* Javascript binding of hamburger-menu.functions.js. | |||
*/ | |||
(function ($) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place scripts at the bottom of the page
- faster loading
- automatically ensures all DOM content is loaded
Also: if you insist on placing them in 'head', use DOMContentLoaded.
No need to wait for the render tree.
components/11-base/base/base.js
Outdated
* @param {object} element DOM-element. | ||
* @param [string] className A class name. | ||
*/ | ||
this.removeClass = function (element, className) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, but are these really helpful?
These functions don't really add much to the existing classList method.
We could potentially use them as a polyfill for IE9, using string.split(' ') on element.className.
components/11-base/base/base.js
Outdated
element.classList.add(className); | ||
} | ||
else { | ||
element.classList += ' ' + className; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Element.classList is falsy.
var trigger; | ||
|
||
if (typeof gent_styleguide === 'undefined') { | ||
console.error('You need to include base.js.'); // eslint-disable-line no-console | ||
return; | ||
} | ||
|
||
// TabTrap doens't use jquery opbjects. | ||
var tabTrap = new gent_styleguide.TabTrap($drawer[0]); // eslint-disable-line no-undef | ||
var helper = new base.Helper(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to create a new instance of 'Helper'.
Helper should not be a constructor function.
components/11-base/base/base.js
Outdated
* Removes a class from a DOM-element. | ||
* | ||
* @param {object} element DOM-element. | ||
* @param [string] className A class name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My phpstorm doesn't understand this bracket notation.
$hamburgerMenu.loadHamburgerMenu(); | ||
for (var i = hamburgerMenu.length; i--;) { | ||
var menu = new hamburger_component.HamburgerMenu(hamburgerMenu[i]); // eslint-disable-line no-undef | ||
menu.loadHamburgerMenu(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of the HamburgerMenu returning functions, but I would load the menu automatically.
We could instead return open() and close() so you can open/close the drawer from code.
I don't know why we'd do this, but it's nice to know we can 😺
@@ -71,11 +65,11 @@ | |||
|
|||
// add the menu to the tabindex | |||
// jquery .css() doesn't now 'important' | |||
$drawer.attr('style', 'display: block'); | |||
drawer.setAttribute('style', 'display: block'); | |||
|
|||
setTimeout(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have commented this, took me a moment to figure out why we have to wait for the next tick.
@@ -144,8 +138,10 @@ | |||
* | |||
* @event click | |||
*/ | |||
$('.hamburger-menu__toggle').on('click', open); | |||
|
|||
var toggle = element.querySelector('.hamburger-menu__toggle'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define variables on top
$('.hamburger-menu__toggle').on('click', open); | ||
|
||
var toggle = element.querySelector('.hamburger-menu__toggle'); | ||
if (toggle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the check.
But
- the toggle element is not optional, so we shouldn't even reach this far in the code if it's not present.
- why not check closeBtn and overlay too?
Suggestion:
maybe we should check all compulsory elements at the start of the script.
components/main_cli.scss
Outdated
@@ -0,0 +1,17 @@ | |||
// inject:settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed :)
Description
Proposed solution for JS namespaces. What do you think @Jeroen005 @delrueba @wim-vantomme ?
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: