-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(minimized): Enable minimizing for global headers. Todo : tests +…
… jQuery + docs
- Loading branch information
LE DIOURON Kevin
committed
Feb 9, 2022
1 parent
66f7891
commit 0a8fd4f
Showing
4 changed files
with
49 additions
and
17 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
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 |
---|---|---|
@@ -1,13 +1,45 @@ | ||
// .scroll-minimized is a class used to apply header-minimized to a navbar | ||
const headers = document.getElementsByTagName('header') | ||
if (headers[0].classList.contains('scroll-minimized')) { | ||
window.addEventListener('scroll', () => { | ||
const Scroll = window.scrollY | ||
if (Scroll > 0) { | ||
// Consider first element in array is obviously the first header | ||
headers[0].classList.add('header-minimized') | ||
} else { | ||
headers[0].classList.remove('header-minimized') | ||
} | ||
}) | ||
import EventHandler from './dom/event-handler' | ||
import BaseComponent from './base-component' | ||
import SelectorEngine from './dom/selector-engine' | ||
|
||
const NAME = 'orangenavbar' | ||
const DATA_KEY = 'bs.orangenavbar' | ||
const EVENT_KEY = `.${DATA_KEY}` | ||
const DATA_API_KEY = '.data-api' | ||
const EVENT_SCROLL_DATA_API = `scroll${EVENT_KEY}${DATA_API_KEY}` | ||
const SELECTOR_STICKY_TOP = '.sticky-top' | ||
|
||
class OrangeNavbar extends BaseComponent { | ||
|
||
// Getters | ||
static get NAME() { | ||
return NAME | ||
} | ||
|
||
enableMinimizing(el) { | ||
// The minimized behaviour works only if your header has .sticky-top (fixed-top will be sticky without minimizing) | ||
window.addEventListener('scroll', () => { | ||
const headers = document.getElementsByTagName('header') | ||
|
||
if (headers[0].classList.contains('sticky-top')) { | ||
const Scroll = window.scrollY | ||
let headerChildren = [...headers[0].children] | ||
let globalHeaderChild = headerChildren.find(element => !element.classList.contains('supra')) | ||
if (Scroll > 0) { | ||
// Consider first element not having .supra in array is the first header | ||
globalHeaderChild.classList.add("header-minimized") | ||
} else { | ||
globalHeaderChild.classList.remove("header-minimized") | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
EventHandler.on(document, EVENT_SCROLL_DATA_API, () => { | ||
for (const el of SelectorEngine.find(SELECTOR_STICKY_TOP)) { | ||
OrangeNavbar.getOrCreateInstance(el).enableMinimizing(el) | ||
} | ||
}) | ||
|
||
export default OrangeNavbar |
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