Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header controls and styles [TMZ-60] #30

Merged
merged 35 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e7a6d85
TMZ-70 wip adding header
mserino Oct 1, 2024
117ae35
TMZ-70 add style and content controls
mserino Oct 2, 2024
ecafaf7
TMZ-70 adding advanced controls
mserino Oct 3, 2024
cf16840
TMZ-70 lint
mserino Oct 3, 2024
386037d
TMZ-70 lint
mserino Oct 3, 2024
2fc0050
TMZ-70 addressing CR comments
mserino Oct 7, 2024
e72dfde
TMZ-70 adding and styling header logo and title
mserino Oct 7, 2024
4a6803a
TMZ-70 styles for site identity and placeholders
mserino Oct 8, 2024
f7ff73b
TMZ-70 wip adding toggle
mserino Oct 8, 2024
c40ba68
TMZ-70 lint
mserino Oct 8, 2024
1cc4748
TMZ-70 wip
mserino Oct 8, 2024
ff97d66
TMZ-70 moving Header into TemplateParts module
mserino Oct 8, 2024
72dfe45
Merge branch 'feature/TMZ-70-header' into feature/TMZ-70-header-logo-…
mserino Oct 8, 2024
edef777
TMZ-70 CR comments
mserino Oct 8, 2024
df700fc
Merge branch 'feature/TMZ-70-header' into feature/TMZ-70-header-logo-…
mserino Oct 8, 2024
40b3adf
TMZ-70 add menu item and style highlight and underline on hover
mserino Oct 8, 2024
fa97bee
use wp native function for site logo / title/ url
nuritsha Oct 9, 2024
e720cdd
TMZ-70 navigation active state
mserino Oct 9, 2024
1a4d6c1
Merge pull request #3 from 10up/tweak/TMZ-70-structure-changes
mserino Oct 9, 2024
76a4885
remove custom advanced tab
nuritsha Oct 9, 2024
be8e2b6
remove advanced related code
nuritsha Oct 9, 2024
0208724
Merge branch 'tweak/TMZ-70-structure-changes' into feature/TMZ-70-hea…
nuritsha Oct 9, 2024
78c081e
Merge branch 'master' into feature/TMZ-70-header-logo-title
mserino Oct 9, 2024
2097c1f
TMZ-70 chevron and submenu style wip
mserino Oct 9, 2024
f471593
TMZ-70 box stylings and responsive
mserino Oct 11, 2024
b18347c
TMZ-70 responsive styles
mserino Oct 11, 2024
30eff69
TMZ-70 last child styles
mserino Oct 11, 2024
3a60982
Merge branch 'master' into feature/TMZ-70-header-logo-title
mserino Oct 11, 2024
ec722f6
TMZ-70 lint
mserino Oct 13, 2024
677cbb2
TMZ-70 adding JS functionality
mserino Oct 13, 2024
e95e5d6
TMZ-60 header dropdown functionality
mserino Oct 14, 2024
a55ec75
TMZ-60 behavior functionality wip
mserino Oct 15, 2024
7335e30
TMZ-60 adding scroll behavior
mserino Oct 16, 2024
a73c74c
TMZ-60 lint
mserino Oct 16, 2024
589b403
TMZ-60 lint
mserino Oct 16, 2024
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
211 changes: 211 additions & 0 deletions modules/template-parts/assets/js/hello-plus-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
class elementorHelloPlusHeaderHandler {
constructor() {
this.initSettings();
this.initElements();
this.bindEvents();
this.lastScrollY = window.scrollY;
}

initSettings() {
this.settings = {
selectors: {
main: '.ehp-header',
navigationToggle: '.ehp-header__button-toggle',
dropdownToggle: '.ehp-header__dropdown-toggle',
navigation: '.ehp-header__navigation',
dropdown: '.ehp-header__dropdown',
wpAdminBar: '#wpadminbar',
},
constants: {
mobilePortrait: 767,
tabletPortrait: 1024,
mobile: 'mobile',
tablet: 'tablet',
desktop: 'desktop',
dataScrollBehavior: 'data-scroll-behavior',
dataBehaviorFloat: 'data-behavior-float',
scrollUp: 'scroll-up',
always: 'always',
none: 'none',
no: 'no',
},
};
}

initElements() {
this.elements = {
window,
main: document.querySelector( this.settings.selectors.main ),
navigationToggle: document.querySelector( this.settings.selectors.navigationToggle ),
dropdownToggle: document.querySelectorAll( this.settings.selectors.dropdownToggle ),
navigation: document.querySelector( this.settings.selectors.navigation ),
dropdown: document.querySelector( this.settings.selectors.dropdown ),
wpAdminBar: document.querySelector( this.settings.selectors.wpAdminBar ),
};
}

bindEvents() {
if ( this.elements.navigationToggle ) {
this.elements.navigationToggle.addEventListener( 'click', () => this.toggleNavigation() );
}

if ( this.elements.dropdownToggle.length > 0 ) {
this.elements.dropdownToggle.forEach( ( menuItem ) => {
menuItem.addEventListener( 'click', ( event ) => this.toggleSubMenu( event ) );
} );
}

if ( this.elements.main ) {
window.addEventListener( 'resize', () => this.onResize() );
window.addEventListener( 'scroll', () => this.onScroll() );

this.onInit();
}
}

onInit() {
const { none, no } = this.settings.constants;

this.handleAriaAttributesMenu();
this.handleAriaAttributesDropdown();
this.handleOffsetTop();

if ( none === this.getDataScrollBehavior() && no === this.getBehaviorFloat() ) {
this.setupInnerContainer();
}
}

getBehaviorFloat() {
const { dataBehaviorFloat } = this.settings.constants;
return this.elements.main.getAttribute( dataBehaviorFloat );
}

getDataScrollBehavior() {
const { dataScrollBehavior } = this.settings.constants;
return this.elements.main.getAttribute( dataScrollBehavior );
}

setupInnerContainer() {
this.elements.main.closest( '.e-con-inner' ).classList.add( 'e-con-inner--ehp-header' );
this.elements.main.closest( '.e-con' ).classList.add( 'e-con--ehp-header' );
}

onResize() {
this.handleAriaAttributesMenu();
}

onScroll() {
const { scrollUp, always } = this.settings.constants;

if ( scrollUp === this.getDataScrollBehavior() || always === this.getDataScrollBehavior() ) {
this.handleScrollDown( this.getDataScrollBehavior() );
}

if ( always === this.getDataScrollBehavior() ) {
this.applyBodyPadding();
}
}

handleOffsetTop() {
const wpAdminBarOffsetHeight = this.elements.wpAdminBar?.offsetHeight || 0;
this.elements.main.style.setProperty( '--header-wp-admin-bar-height', `${ wpAdminBarOffsetHeight }px` );
}

applyBodyPadding() {
const mainHeight = this.elements.main.offsetHeight;
document.body.style.paddingTop = `${ mainHeight }px`;
}

handleAriaAttributesDropdown() {
this.elements.dropdownToggle.forEach( ( item ) => {
item.nextElementSibling.setAttribute( 'aria-hidden', 'true' );
} );
}

handleAriaAttributesMenu() {
if ( this.isResponsiveBreakpoint() ) {
this.elements.navigationToggle.setAttribute( 'aria-expanded', 'false' );
this.elements.navigation.setAttribute( 'aria-hidden', 'true' );
}
}

toggleSubMenu( event ) {
event.preventDefault();
const subMenu = event.target.nextElementSibling;
const itemTarget = event.target;
const ariaHidden = subMenu.getAttribute( 'aria-hidden' );

if ( 'true' === ariaHidden ) {
this.openSubMenu( itemTarget, subMenu );
} else {
this.closeSubMenu( itemTarget, subMenu );
}
}

openSubMenu( itemTarget, subMenu ) {
itemTarget.setAttribute( 'aria-expanded', 'true' );
subMenu.setAttribute( 'aria-hidden', 'false' );
}

closeSubMenu( itemTarget, subMenu ) {
itemTarget.setAttribute( 'aria-expanded', 'false' );
subMenu.setAttribute( 'aria-hidden', 'true' );
}

handleScrollDown( behaviorOnScroll ) {
const { scrollUp } = this.settings.constants;

const currentScrollY = window.scrollY;
const headerHeight = this.elements.main.offsetHeight;
const wpAdminBarOffsetHeight = this.elements.wpAdminBar?.offsetHeight || 0;
const headerFloatOffsetProperty = getComputedStyle( this.elements.main ).getPropertyValue( '--header-float-offset' );
const headerFloatOffset = parseInt( headerFloatOffsetProperty, 10 ) || 0;
const totalOffset = headerHeight + wpAdminBarOffsetHeight + headerFloatOffset;

if ( currentScrollY > this.lastScrollY ) {
this.elements.main.classList.add( 'scroll-down' );

if ( scrollUp === behaviorOnScroll ) {
this.elements.main.style.setProperty( '--header-scroll-down', `${ totalOffset }px` );
}
} else {
this.elements.main.classList.remove( 'scroll-down' );
}
this.lastScrollY = currentScrollY;
}

isResponsiveBreakpoint() {
const device = this.getCurrentDevice();
return this.elements.main.classList.contains( `has-navigation-breakpoint-${ device }-portrait` );
}

getCurrentDevice() {
const { mobilePortrait, tabletPortrait, mobile, tablet, desktop } = this.settings.constants;

const isMobile = this.elements.window.innerWidth <= mobilePortrait;
const isTablet = this.elements.window.innerWidth <= tabletPortrait;

if ( isMobile ) {
return mobile;
} else if ( isTablet ) {
return tablet;
}
return desktop;
}

toggleNavigation() {
const isNavigationHidden = this.elements.navigation.getAttribute( 'aria-hidden' );

if ( 'true' === isNavigationHidden ) {
this.elements.navigation.setAttribute( 'aria-hidden', 'false' );
this.elements.navigationToggle.setAttribute( 'aria-expanded', 'true' );
} else {
this.elements.navigation.setAttribute( 'aria-hidden', 'true' );
this.elements.navigationToggle.setAttribute( 'aria-expanded', 'false' );
}
}
}

document.addEventListener( 'DOMContentLoaded', () => {
new elementorHelloPlusHeaderHandler();
} );
27 changes: 27 additions & 0 deletions modules/template-parts/assets/scss/breakpoints.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$breakpoints: (
sm: 480px, // Mobile landscape
md: 768px, // Tablet
lg: 1025px, // Desktop
xl: 1440px, // Larger devices
xxl: 1600px // Largest devices
);

$screen-mobile-min: map_get($breakpoints, sm);
$screen-mobile-max: map_get($breakpoints, md) - 1;
$screen-tablet-min: map_get($breakpoints, md);
$screen-mobile-next: map_get($breakpoints, md);
$screen-tablet-max: map_get($breakpoints, lg) - 1;
$screen-desktop-min: map_get($breakpoints, lg);
$screen-desktop-max: 99999px;
$screen-tablet-next: map_get($breakpoints, lg);

// Additional Custom Breakpoints - SCSS placeholders
$screen-mobile-extra-min: -1;
$screen-mobile-extra-max: -1;
$screen-mobile-extra-next: -1;
$screen-tablet-extra-min: -1;
$screen-tablet-extra-max: -1;
$screen-tablet-extra-next: -1;
$screen-laptop-min: -1;
$screen-laptop-max: -1;
$screen-widescreen-min: -1;
Loading
Loading