This repository has been archived by the owner on Mar 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
380 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,6 @@ rules: | |
- 2 | ||
- max-depth: | ||
- 4 | ||
class-name-format: | ||
- 1 | ||
- convention: hyphenatedbem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
var Velocity = require('velocity-animate'); | ||
|
||
module.exports = { | ||
|
||
init: function(selector) { | ||
var elems = document.querySelectorAll(selector); | ||
for (var i = 0; i < elems.length; i++) { | ||
var toggle = elems[i].querySelector('.accordion-button, summary'); | ||
var panel = elems[i].querySelector('.accordion-panel'); | ||
var panelLabel; | ||
|
||
if (elems[i].getAttribute('data-label')) { | ||
panelLabel = elems[i].getAttribute('data-label'); | ||
} else { | ||
panelLabel = elems[i].className; | ||
} | ||
|
||
this._initToggle(elems[i], toggle, panel, panelLabel); | ||
this._initPanel(elems[i], panel, panelLabel); | ||
|
||
} | ||
}, | ||
|
||
_initToggle: function(elem, toggle, panel, label) { | ||
toggle.targetElem = elem; | ||
toggle.targetPanel = panel; | ||
toggle.setAttribute('aria-controls', label); | ||
toggle.addEventListener('click', this._togglePanel.bind(this)); | ||
}, | ||
|
||
_initPanel: function(elem, panel, label) { | ||
elem.id = label; | ||
|
||
if (elem.getAttribute('aria-expanded') === 'false') { | ||
this._slidePanel(panel, true); | ||
} | ||
}, | ||
|
||
_togglePanel: function(event) { | ||
var toggle = event.target, | ||
elem = event.target.targetElem, | ||
panel = event.target.targetPanel, | ||
expanded = elem.getAttribute('aria-expanded') === 'true'; | ||
|
||
event.preventDefault(); | ||
|
||
toggle.setAttribute('aria-expanded', expanded ? 'false' : 'true'); | ||
elem.setAttribute('aria-expanded', expanded ? 'false' : 'true'); | ||
|
||
this._slidePanel(panel, expanded); | ||
}, | ||
|
||
_slidePanel: function(panel, bool) { | ||
Velocity(panel, bool ? 'slideUp' : 'slideDown', { duration: 300 }); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var ResponsiveNav = require('responsive-nav'); | ||
|
||
module.exports = { | ||
|
||
init: function(selectors) { | ||
selectors.forEach(function(selector) { | ||
if (document.querySelector(selector)) { | ||
ResponsiveNav(selector); | ||
} | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
var ResponsiveNav = require('responsive-nav'); | ||
|
||
module.exports = { | ||
|
||
init: function(selector) { | ||
ResponsiveNav(selector); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,26 @@ | ||
var smoothScroll = require('smoothscroll'); | ||
var responsiveNav = require('responsive-nav'); | ||
var Velocity = require('velocity-animate'); | ||
'use strict'; | ||
|
||
(function (document) { | ||
|
||
initResponsiveNav = function(elementSelector) { | ||
if (document.querySelector(elementSelector)) { | ||
responsiveNav(elementSelector); | ||
} | ||
} | ||
|
||
initAccordions = function(elems) { | ||
for (var i = 0; i < elems.length; i++) { | ||
var toggle = elems[i].querySelector('.accordion-button, summary'); | ||
var panel = elems[i].querySelector('.accordion-panel'); | ||
|
||
if (elems[i].getAttribute('data-label')) { | ||
panelLabel = elems[i].getAttribute('data-label'); | ||
} else { | ||
panelLabel = elems[i].className; | ||
} | ||
var SmoothScroll = require('smoothscroll'); | ||
|
||
initToggle(elems[i], toggle, panel, panelLabel); | ||
initPanel(elems[i], panel, panelLabel); | ||
|
||
} | ||
} | ||
|
||
initToggle = function(elem, toggle, panel, label) { | ||
toggle.targetElem = elem; | ||
toggle.targetPanel = panel; | ||
toggle.setAttribute('aria-controls', label); | ||
toggle.addEventListener('click', togglePanel); | ||
} | ||
var components = { | ||
'Accordion': require('./components/accordion'), | ||
'LocalNav': require('./components/local-nav'), | ||
'SiteNav': require('./components/site-nav') | ||
}; | ||
|
||
initPanel = function(elem, panel, label) { | ||
elem.id = label; | ||
(function (document) { | ||
|
||
if (elem.getAttribute('aria-expanded') === 'false') { | ||
slidePanel(panel, true); | ||
function initComponent(component, selector) { | ||
if (document.querySelector(selector)) { | ||
components[component].init(selector); | ||
} | ||
} | ||
|
||
togglePanel = function(event) { | ||
var toggle = event.target, | ||
elem = event.target.targetElem, | ||
panel = event.target.targetPanel, | ||
expanded = elem.getAttribute('aria-expanded') === 'true'; | ||
|
||
event.preventDefault(); | ||
|
||
toggle.setAttribute('aria-expanded', expanded ? 'false' : 'true'); | ||
elem.setAttribute('aria-expanded', expanded ? 'false' : 'true'); | ||
|
||
slidePanel(panel, expanded); | ||
} | ||
|
||
slidePanel = function(panel, bool) { | ||
Velocity(panel, bool ? 'slideUp' : 'slideDown', { duration: 300 }); | ||
} | ||
|
||
// Kick of the JavaScript party when the DOM is ready | ||
document.addEventListener('DOMContentLoaded', function() { | ||
|
||
initResponsiveNav('.global-nav'); | ||
initResponsiveNav('.local-nav'); | ||
initResponsiveNav('.local-nav-demo'); | ||
|
||
initAccordions(document.querySelectorAll('.accordion, details')); | ||
initComponent('Accordion', '.accordion, details'); | ||
initComponent('LocalNav', ['.global-nav', '.local-nav', '.local-nav-demo']); | ||
initComponent('SiteNav', '.site-nav__wrapper'); | ||
}); | ||
|
||
})(document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.