Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

STIJ-196: Added JS namespaces setup. #171

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

Conversation

meirege
Copy link
Contributor

@meirege meirege commented Dec 1, 2017

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have updated the CHANGELOG accordingly.
  • I have read the CONTRIBUTING document.

@meirege meirege self-assigned this Dec 1, 2017
Copy link
Contributor

@delrueba delrueba left a 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 ;)

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
Copy link
Contributor

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 ($) {

Copy link
Contributor

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.

* @param {object} element DOM-element.
* @param [string] className A class name.
*/
this.removeClass = function (element, className) {
Copy link
Contributor

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.

element.classList.add(className);
}
else {
element.classList += ' ' + className;
Copy link
Contributor

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();
Copy link
Contributor

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.

* Removes a class from a DOM-element.
*
* @param {object} element DOM-element.
* @param [string] className A class name.
Copy link
Contributor

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();
Copy link
Contributor

@delrueba delrueba Dec 3, 2017

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 () {
Copy link
Contributor

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');
Copy link
Contributor

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) {
Copy link
Contributor

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.

@meirege meirege added this to the 2.8.0 milestone Dec 5, 2017
@meirege meirege removed this from the 2.8.0 milestone Dec 8, 2017
@@ -0,0 +1,17 @@
// inject:settings
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this file ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed :)

@meirege meirege added this to the 2.8.0 milestone Dec 12, 2017
@meirege meirege modified the milestones: 2.8.0, 2.9.0 Jan 18, 2018
@meirege meirege modified the milestones: 2.9.0, 3.0.0 Jan 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants