Skip to content

Commit

Permalink
feat(minimized): Enable minimizing for global headers. Todo : tests +…
Browse files Browse the repository at this point in the history
… jQuery + docs
  • Loading branch information
LE DIOURON Kevin committed Feb 9, 2022
1 parent 66f7891 commit 0a8fd4f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
1 change: 1 addition & 0 deletions js/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as Collapse } from './src/collapse'
export { default as Dropdown } from './src/dropdown'
export { default as Modal } from './src/modal'
export { default as Offcanvas } from './src/offcanvas'
export { default as OrangeNavbar } from './src/orange-navbar'
export { default as Popover } from './src/popover'
export { default as ScrollSpy } from './src/scrollspy'
export { default as Tab } from './src/tab'
Expand Down
2 changes: 2 additions & 0 deletions js/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Collapse from './src/collapse'
import Dropdown from './src/dropdown'
import Modal from './src/modal'
import Offcanvas from './src/offcanvas'
import OrangeNavbar from './src/orange-navbar'
import Popover from './src/popover'
import ScrollSpy from './src/scrollspy'
import Tab from './src/tab'
Expand All @@ -27,6 +28,7 @@ export default {
Dropdown,
Modal,
Offcanvas,
OrangeNavbar,
Popover,
ScrollSpy,
Tab,
Expand Down
56 changes: 44 additions & 12 deletions js/src/orange-navbar.js
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
7 changes: 2 additions & 5 deletions scss/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,8 @@

// Boosted mod
.nav-item {
font-size: $h5-font-size;

&:not(:first-child) {
border-top: $border-width * .5 solid $gray-900;
}
font-size: 1rem;
border-top: $border-width * .5 solid $gray-900;
}

.nav-link {
Expand Down

0 comments on commit 0a8fd4f

Please sign in to comment.