forked from elementor/elementor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from davseve/internal/ED-11261-one-click-clou…
…d-release Add default values to bump and get previous release
- Loading branch information
Showing
29 changed files
with
1,271 additions
and
307 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
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
142 changes: 142 additions & 0 deletions
142
assets/dev/js/frontend/handlers/accessibility/nested-title-keyboard-handler.js
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,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' ); | ||
} | ||
} |
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.