Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/internal/ED-11261-one-click-clou…
Browse files Browse the repository at this point in the history
…d-release' into internal/ED-11261-one-click-cloud-release
  • Loading branch information
davseve committed Aug 16, 2023
2 parents 6bbe962 + c75624b commit f7e7808
Show file tree
Hide file tree
Showing 14 changed files with 660 additions and 227 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Base from '../base';

const directionNext = 'next',
directionPrevious = 'previous';

export default class NestedTitleKeyboardHandler extends Base {
getDefaultSettings() {
return {
selectors: {
itemTitle: '.e-n-tab-title',
$itemContainer: '.e-n-tabs-content > .e-con',
},
ariaAttributes: {
titleStateAttribute: 'aria-selected',
activeTitleSelector: '[aria-selected="true"]',
},
datasets: {
titleIndex: 'data-tab-index',
},
keyDirection: {
ArrowLeft: elementorFrontendConfig.is_rtl ? directionNext : directionPrevious,
ArrowUp: directionPrevious,
ArrowRight: elementorFrontendConfig.is_rtl ? directionPrevious : directionNext,
ArrowDown: directionNext,
},
};
}

getDefaultElements() {
const selectors = this.getSettings( 'selectors' );

return {
$itemTitles: this.findElement( selectors.itemTitle ),
$itemContainers: this.findElement( selectors.$itemContainer ),
};
}

/**
* @param {HTMLElement} itemTitleElement
*
* @return {string}
*/
getTitleIndex( itemTitleElement ) {
const { titleIndex: indexAttribute } = this.getSettings( 'datasets' );
return itemTitleElement.getAttribute( indexAttribute );
}

/**
* @param {string|number} titleIndex
*
* @return {string}
*/
getTitleFilterSelector( titleIndex ) {
const { titleIndex: indexAttribute } = this.getSettings( 'datasets' );
return `[${ indexAttribute }="${ titleIndex }"]`;
}

bindEvents() {
this.elements.$itemTitles.on( this.getTitleEvents() );
this.elements.$itemContainers.children().on( 'keydown', this.handleContentElementEscapeEvent.bind( this ) );
}

unbindEvents() {
this.elements.$itemTitles.off();
this.elements.$itemContainers.children().off();
}

handleTitleKeyboardNavigation( event ) {
const directionKeys = [ 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End' ],
activationKeys = [ 'Enter', 'Space' ];

if ( directionKeys.includes( event.key ) ) {
event.preventDefault();

const currentTitleIndex = parseInt( this.getTitleIndex( event.currentTarget ) ) || 1,
numberOfTitles = this.elements.$itemTitles.length,
titleIndexUpdated = this.getTitleIndexFocusUpdated( event, currentTitleIndex, numberOfTitles );

this.changeTitleFocus( currentTitleIndex, titleIndexUpdated );
} else if ( activationKeys.includes( event.key ) ) {
event.preventDefault();

const titleIndex = this.getTitleIndex( event.currentTarget );

elementorFrontend.elements.$window.trigger( 'elementor/nested-elements/activate-by-keyboard', titleIndex );
}
}

getTitleEvents() {
return {
keydown: this.handleTitleKeyboardNavigation.bind( this ),
};
}

getTitleIndexFocusUpdated( event, currentTitleIndex, numberOfTitles ) {
let titleIndexUpdated = 0;

switch ( event.key ) {
case 'Home':
titleIndexUpdated = 1;
break;
case 'End':
titleIndexUpdated = numberOfTitles;
break;
default:
const direction = this.getSettings( 'keyDirection' )[ event.key ],
directionValue = directionNext === direction ? 1 : -1,
isEndReached = numberOfTitles < currentTitleIndex + directionValue,
isStartReached = 0 === currentTitleIndex + directionValue;

if ( isEndReached ) {
titleIndexUpdated = 1;
} else if ( isStartReached ) {
titleIndexUpdated = numberOfTitles;
} else {
titleIndexUpdated = currentTitleIndex + directionValue;
}
}

return titleIndexUpdated;
}

changeTitleFocus( currentTitleIndex, titleIndexUpdated ) {
const $currentTitle = this.elements.$itemTitles.filter( this.getTitleFilterSelector( currentTitleIndex ) ),
$newTitle = this.elements.$itemTitles.filter( this.getTitleFilterSelector( titleIndexUpdated ) );

$currentTitle.attr( 'tabindex', '-1' );
$newTitle.attr( 'tabindex', '0' );
$newTitle.trigger( 'focus' );
}

handleContentElementEscapeEvent( event ) {
if ( 'Escape' !== event.key ) {
return;
}

const activeTitleFilter = this.getSettings( 'ariaAttributes' ).activeTitleSelector,
$activeTitle = this.elements.$itemTitles.filter( activeTitleFilter );

$activeTitle.trigger( 'focus' );
}
}
2 changes: 2 additions & 0 deletions assets/dev/js/frontend/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CarouselBase from './handlers/base-carousel';
import NestedTabs from 'elementor/modules/nested-tabs/assets/js/frontend/handlers/nested-tabs';
import NestedTabsHtml from 'elementor/modules/nested-tabs-html/assets/js/frontend/handlers/nested-tabs-html';
import NestedAccordion from 'elementor/modules/nested-accordion/assets/js/frontend/handlers/nested-accordion';
import NestedTitleKeyboardHandler from './handlers/accessibility/nested-title-keyboard-handler';

elementorModules.frontend = {
Document,
Expand All @@ -22,5 +23,6 @@ elementorModules.frontend = {
NestedTabs,
NestedTabsHtml,
NestedAccordion,
NestedTitleKeyboardHandler,
},
};
22 changes: 11 additions & 11 deletions core/schemes/color.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
* colors.
*
* @since 1.0.0
* @deprecated 3.15.0 Use Global_Colors instead
* @deprecated 3.0.0 Use `Global_Colors` instead.
*/
class Color {

/**
* 1st color scheme.
* @deprecated 3.15.0 Use Global_Colors::COLOR_PRIMARY instead
* @deprecated 3.0.0 Use `Global_Colors::COLOR_PRIMARY` instead.
*/
const COLOR_1 = '1';

/**
* 2nd color scheme.
* @deprecated 3.15.0 Use Global_Colors::COLOR_SECONDARY instead
* @deprecated 3.0.0 Use `Global_Colors::COLOR_SECONDARY` instead.
*/
const COLOR_2 = '2';

/**
* 3rd color scheme.
* @deprecated 3.15.0 Use Global_Colors::COLOR_TEXT instead
* @deprecated 3.0.0 Use `Global_Colors::COLOR_TEXT` instead.
*/
const COLOR_3 = '3';

/**
* 4th color scheme.
* @deprecated 3.15.0 Use Global_Colors::COLOR_ACCENT instead
* @deprecated 3.0.0 Use `Global_Colors::COLOR_ACCENT` instead.
*/
const COLOR_4 = '4';

Expand All @@ -48,7 +48,7 @@ class Color {
* @since 1.0.0
* @access public
* @static
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return string Color scheme type.
*/
Expand All @@ -63,7 +63,7 @@ public static function get_type() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return string Color scheme title.
*/
Expand All @@ -78,7 +78,7 @@ public function get_title() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return string Color scheme disabled title.
*/
Expand All @@ -93,7 +93,7 @@ public function get_disabled_title() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return array Color scheme titles.
*/
Expand All @@ -108,7 +108,7 @@ public function get_scheme_titles() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return array Default color scheme.
*/
Expand All @@ -124,7 +124,7 @@ public function get_default_scheme() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*/
public function print_template_content() {}
}
22 changes: 11 additions & 11 deletions core/schemes/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
* for typography.
*
* @since 1.0.0
* @deprecated 3.15.0 Use Global_Typography instead
* @deprecated 3.0.0 Use `Global_Typography` instead.
*/
class Typography {

/**
* 1st typography scheme.
* @deprecated 3.15.0 Use Global_Typography::TYPOGRAPHY_PRIMARY instead
* @deprecated 3.0.0 Use `Global_Typography::TYPOGRAPHY_PRIMARY` instead.
*/
const TYPOGRAPHY_1 = '1';

/**
* 2nd typography scheme.
* @deprecated 3.15.0 Use Global_Typography::TYPOGRAPHY_SECONDARY instead
* @deprecated 3.0.0 Use `Global_Typography::TYPOGRAPHY_SECONDARY` instead.
*/
const TYPOGRAPHY_2 = '2';

/**
* 3rd typography scheme.
* @deprecated 3.15.0 Use Global_Typography::TYPOGRAPHY_TEXT instead
* @deprecated 3.0.0 Use `Global_Typography::TYPOGRAPHY_TEXT` instead.
*/
const TYPOGRAPHY_3 = '3';

/**
* 4th typography scheme.
* @deprecated 3.15.0 Use Global_Typography::TYPOGRAPHY_ACCENT instead
* @deprecated 3.0.0 Use `Global_Typography::TYPOGRAPHY_ACCENT` instead.
*/
const TYPOGRAPHY_4 = '4';

Expand All @@ -48,7 +48,7 @@ class Typography {
* @since 1.0.0
* @access public
* @static
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return string Typography scheme type.
*/
Expand All @@ -63,7 +63,7 @@ public static function get_type() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return string Typography scheme title.
*/
Expand All @@ -78,7 +78,7 @@ public function get_title() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return string Typography scheme disabled title.
*/
Expand All @@ -93,7 +93,7 @@ public function get_disabled_title() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return array Typography scheme titles.
*/
Expand All @@ -108,7 +108,7 @@ public function get_scheme_titles() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*
* @return array Default typography scheme.
*/
Expand All @@ -124,7 +124,7 @@ public function get_default_scheme() {
*
* @since 1.0.0
* @access public
* @deprecated 3.15.0
* @deprecated 3.0.0
*/
public function print_template_content() {}
}
Loading

0 comments on commit f7e7808

Please sign in to comment.