Product Description
/**
* Common event handler for click and keydown events.
* @param {Event} event – The event object.
* @param {Function} handleClickOrEnter – Function to handle click or Enter key events.
* @param {Function} handleEsc – Function to handle Esc key events.
*/
// [TODO][AplusMantle-8064] Create common event handler util(key events, click events) in AplusModuleResources
function handleClickAndKeyEvents(event, handleClickOrEnterOrSpace) {
const ENTER_KEY_CODE = 13;
const ESCAPE_KEY_CODE = 27;
const SPACE_KEY_CODE = 32;
const isClick = event.type === ‘click’;
const isKeydown = event.type === ‘keydown’;
const isEnter = isKeydown && event.keyCode === ENTER_KEY_CODE;
const isSpace = isKeydown && event.keyCode === SPACE_KEY_CODE;
const isEsc = isKeydown && event.keyCode === ESCAPE_KEY_CODE;
if (isClick || isEnter || isSpace) {
handleClickOrEnterOrSpace();
} else if (isEsc) {
handleEsc(event);
}
}
/**
* Function to handle esc key event.
* @param {Event} event – The event object.
*/
function handleEsc(event) {
event.target.blur() // force remove focus
}
P.now(“premium-aplus-13-carousel-4”).execute(function(init) {
if (init) {
return;
}
P.register(“premium-aplus-13-carousel-4”, function(){
return function() {
P.when(“A”, “jQuery”, “a-carousel-framework”, “ready”).execute(function (A, $, framework) {
const ENTER_KEY_CODE = 13;
const ESCAPE_KEY_CODE = 27;
var moduleId = “4”;
var carouselName = “premium-aplus-13-carousel-4”;
var paginationAction = “aplus-pagination-dot-action-” + moduleId + “-” + carouselName;
var paginationGroup = “#aplus-pagination-group-” + moduleId + “-” + carouselName;
/* If the carousel goes to a new page */
A.on(“a:carousel:”+carouselName+”:change:pageNumber”, function (data) {
A.$(paginationGroup+” .carousel-slider-circle”).removeClass(“aplus-carousel-active”).attr(‘aria-selected’, ‘false’).attr(‘tabindex’, -1)
.eq(data.newValue – 1).addClass(“aplus-carousel-active”).attr(‘aria-selected’, ‘true’).attr(‘tabindex’, 0);
});
function syncPaginationDotsWithCarouselPages(numPages) {
const children = document.querySelector(paginationGroup).children;
for(let i = 0; i < children.length; i++) {
if (i >= numPages) {
// If number of dots > num of pages, we should hide other dots
children[i].classList.add(‘aplus-pagination-dot–display-none’);
} else if(children[i].classList.contains(‘aplus-pagination-dot–display-none’)){
// Reset display of dots if it was hidden before
children[i].classList.remove(‘aplus-pagination-dot–display-none’);
}
}
}
framework.onInit(carouselName, function (carousel) {
var totalPages = carousel.getAttr(‘totalPages’);
syncPaginationDotsWithCarouselPages(totalPages);
/* Resize event handler to re-calculate the pagination dots count based on orientation */
window.addEventListener(‘resize’, function() {
carousel.resize();
totalPages = carousel.getAttr(‘totalPages’);
syncPaginationDotsWithCarouselPages(totalPages);
});
A.declarative(paginationAction, ‘click keydown’, function(event){
var isClick = event.type === ‘click’;
var isKeydown = event.type === ‘keydown’;
var isEnter = isKeydown && event.$event.keyCode === ENTER_KEY_CODE;
var isEsc = isKeydown && event.$event.keyCode === ESCAPE_KEY_CODE;
if (isClick || isEnter) {
var data = event.data;
carousel.gotoPage(data.page);
} else if (isEsc) {
// force remove focus
event.$target.blur()
}
});
});
});
}
});
});




































































Reviews
There are no reviews yet.