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
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
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"Drupal": true,
"jQuery": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
// Errors.
"array-bracket-spacing": [2, "never"],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ scss
public/css
public/styleguide/js
public/styleguide/vendor
components/main_cli.scss
149 changes: 99 additions & 50 deletions components/11-base/base/base.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,116 @@
var gent_styleguide = (function () { // eslint-disable-line no-unused-vars
'use strict';
var gent_styleguide = gent_styleguide || {};

/**
* Generates a tabTrap object.
*
* @param {object} container DOM-element.
* @constructor
*/
export class TabTrap {
constructor(container) {
this.focusPosition = -1;
this.focusables = this.getFocusables(container);
this.hasFocusables = this.focusables && this.focusables.length > 0;
}

/**
* Generates a tabTrap object
* Returns all focusable elements within a given container.
*
* @param {object} container DOM-element
* @constructor
* @param {object} container hamburger DOM-element
* @return {array} focusable elements
*/
function TabTrap(container) {
var focusPosition = -1;
var focusables = getFocusables(container);
getFocusables(container) {
var focusables = container
.querySelectorAll('a[href], ' +
'area[href], ' +
'input:not([disabled]):not([hidden]), ' +
'select:not([disabled]), ' +
'textarea:not([disabled]), ' +
'button:not([disabled]), ' +
'[tabindex="0"]');
return Array.prototype.slice.call(focusables);
}

/**
* Returns all focusable elements within a given container.
*
* @param {object} container hamburger DOM-element
* @return {array} focusable elements
*/
function getFocusables(container) {
var focusables = container
.querySelectorAll('a[href], ' +
'area[href], ' +
'input:not([disabled]):not([hidden]), ' +
'select:not([disabled]), ' +
'textarea:not([disabled]), ' +
'button:not([disabled]), ' +
'[tabindex="0"]');
return Array.prototype.slice.call(focusables);
next() {
if (++this.focusPosition > this.focusables.length - 1) {
this.focusPosition = 0;
}
this.focusables[this.focusPosition].focus();
}

this.next = function () {
if (++focusPosition > focusables.length - 1) {
focusPosition = 0;
}
focusables[focusPosition].focus();
};
back() {
if (--this.focusPosition < 0) {
this.focusPosition = this.focusables.length - 1;
}
this.focusables[this.focusPosition].focus();
}

this.back = function () {
if (--focusPosition < 0) {
focusPosition = focusables.length - 1;
}
focusables[focusPosition].focus();
};
home() {
this.focusPosition = 0;
this.focusables[this.focusPosition].focus();
}

this.home = function () {
focusPosition = 0;
focusables[focusPosition].focus();
};
end() {
this.focusPosition = this.focusables.length - 1;
this.focusables[this.focusPosition].focus();
}

this.end = function () {
focusPosition = focusables.length - 1;
focusables[focusPosition].focus();
};
reset() {
this.focusPosition = -1;
}
}

this.reset = function () {
focusPosition = -1;
};
gent_styleguide.helper = (function () {

this.hasFocusables = focusables && focusables.length > 0;
}
// @todo document functions
// @todo refactor or remove addClass, removeClass
/**
* Removes a class from a DOM-element.
*
* @param {object} element DOM-element.
* @param {string} className A class name.
*/
var removeClass = function (element, className) {
if (element.classList) {
element.classList.remove(className);
}
};

/**
* Adds a class from a DOM-element.
*
* @param {object} element DOM-element.
* @param {string} className A class name.
*/
var addClass = function (element, className) {
if (element.classList) {
element.classList.add(className);
}
else {
element.classList += ' ' + className;
}
};

/**
* Adds an animation event to a DOM-element for
* mozilla, IE, chrome and opera
*
* @param {object} element DOM-element.
* @param {string} type geneneric name of the event.
* @param {function} next callback function for the event.
*/
var prefixedAnimationEvent = function (element, type, next) {
var prefixes = ['webkit', 'moz', 'MS', 'o', ''];

for (var i = prefixes.length; i--;) {
element.addEventListener(prefixes[i] + type, next);
}
};

return {
TabTrap: TabTrap
removeClass: removeClass,
addClass: addClass,
prefixedAnimationEvent: prefixedAnimationEvent
};

})();
1 change: 0 additions & 1 deletion components/21-atoms/button-drop/button-drop.binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* binding of button-drop.functions.js
*/
(function ($) {
'use strict';

$(window).on('load', function (e) {
$('.dropbutton-wrapper').dropButtonLoad();
Expand Down
1 change: 0 additions & 1 deletion components/21-atoms/button-drop/button-drop.functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
*/
(function ($) {
'use strict';

$.fn.extend({

Expand Down
1 change: 0 additions & 1 deletion components/21-atoms/button-drop/button-drop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(function ($) {
'use strict';

/**
* Invoked after after loading the initial page and after each AJAX request.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(function ($) {
'use strict';

$(document).ready(function () {
$('.datepicker').loadDatepicker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
*/
(function ($) {
'use strict';

$.fn.extend({

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(function ($) {
'use strict';

/**
* Invoked after after loading the initial page and after each AJAX request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
*/
(function ($) {
'use strict';

$.fn.extend({

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Javascript binding of breadcrumb.functions.js
*/
(function ($) {
'use strict';

$(window).on('load', function (e) {
this.gentStyleGuideBreadcrumb.updateMobileBreadcrumb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
var gentStyleGuideBreadcrumb = {};

(function ($) {
'use strict';

/**
* Replace the mobile breadcrumb of Gent base by our own.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(function ($) {
'use strict';

$(document).ready(function () {
var $gallery = $('.gallery');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
*/
(function ($) {
'use strict';

$.fn.extend({

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* @file
* Javascript binding of hamburger-menu.functions.js.
*/
(function ($) {
'use strict';

$(window).on('load', function (e) {
var $hamburgerMenu = $('.hamburger-menu');
document.addEventListener('DOMContentLoaded', function () {

if ($hamburgerMenu.length > 0) {
$hamburgerMenu.loadHamburgerMenu();
}
});
var hamburgerMenus = document.querySelectorAll('.hamburger-menu');

})(jQuery);
for (var i = hamburgerMenus.length; i--;) {
console.log('test'); // eslint-disable-line no-console

new gent_styleguide.components.HamburgerMenu(hamburgerMenus[i]); // eslint-disable-line no-undef
}


});
Loading