Skip to content

Commit

Permalink
Merge pull request #40 from viivue/default-active-sections
Browse files Browse the repository at this point in the history
Show multiple items when initialize
  • Loading branch information
phucbm authored Jun 20, 2023
2 parents 91fa9f4 + eef2a59 commit b108b3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
13 changes: 2 additions & 11 deletions src/_index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {slideDown, slideUp, destroySlide, updateSlide} from "./slide";
import {fadeIn, fadeOut, destroyFade, updateFade} from "./fade";
import {getHash, isValidHash, hashScroll, updateURL} from "./hash";
import {hashScroll, updateURL} from "./hash";
import {
validID,
getToggleState,
getIndexById,
getElements,
removeActiveClass, addActiveClass, getIdByIndex, defaultActiveSections, log, getOptions
removeActiveClass, addActiveClass, getIdByIndex, log, getOptions
} from "./helpers";
import {debounce, uniqueId} from "./utils";
import {initSetup, onLoad, onResize} from "./methods";
Expand Down Expand Up @@ -141,15 +141,6 @@ export class EasyTabAccordion{
if(this.enabled && !this.hasInitialized) initSetup(this);
if(!this.enabled && this.hasInitialized) this.destroy();

// toggle via hash
if(this.enabled){
if(isValidHash(this)){
this.toggle(getHash().id, 'hash');
}else{
defaultActiveSections(this);
}
}

// watch for resize/load events
window.addEventListener('resize', debounce(e => onResize(this, e), 300));
window.addEventListener('load', e => onLoad(this, e));
Expand Down
8 changes: 5 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export function getToggleState(context, id){
if(!validID(context, id)) return false;
// close: -1
// open: 1
// exit: 0
// exit: 0 // prevent open or close

// check if option is avoid double click
if(context.options.avoidDoubleClick){
// exit if it is animating, and
// when has not initialized, allow to run multiple animation due to possible multiple active sections
if(context.hasInitialized && context.options.avoidDoubleClick){
// avoid multiple animation at the same time
if(context.isAnimating){
log(context, 'warn', `Block [${id}] to avoid double click on animating item.`);
return 0;
Expand Down
16 changes: 14 additions & 2 deletions src/methods.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {responsive} from "./responsive";
import {setCSS, setTransition} from "./animation";
import {getHash} from "./hash";
import {getHash, isValidHash} from "./hash";
import {defaultActiveSections} from "./helpers";

export function initSetup(context){
// event: onBeforeInit
context.options.onBeforeInit(context);

context.hasInitialized = true;
context.wrapper.classList.add(context._class.enabled);

// loop through triggers
Expand Down Expand Up @@ -50,6 +50,18 @@ export function initSetup(context){

assignTriggerElements(context);

// toggle via hash
if(context.enabled){
if(isValidHash(context)){
context.toggle(getHash().id, 'hash');
}else{
defaultActiveSections(context);
}
}

// initialized flag
context.hasInitialized = true;

// event: onAfterInit
context.options.onAfterInit(context);
}
Expand Down

0 comments on commit b108b3c

Please sign in to comment.