Skip to content

Commit

Permalink
add Dual Option Flip Switch Logic to the switch
Browse files Browse the repository at this point in the history
Introducing the new DualFlipClassSwitch() function to make Dual Flip Switch Logic fail proof against exception cases, where user had dark or similar colors active. Resolves conflict between preset colors and switch colors on mobile devices.

We now can have a dual logic switch with two options that we can set in the switch outside of the functon.

Multi Option Flip Switch could be possible too, but that will be another "for each of" function to write in another time....

Happy flip switching everyone !
  • Loading branch information
Dorson authored Apr 19, 2020
1 parent 4c4120d commit 574b593
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions JS-CSS-Class-Switch-with-Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,24 @@ function ClassSwitch( TagName, ClassName, MemoryName ) {

}


/*
Dual Flip CSS class Toggle Switch. Set THis OR the OTher CSS class.
Flips or changes CSS class between two given options.
If Class1 was NOT active: We switch it ON. Else: we flip switch Class2 ON.
Only one can exist at the same time ! Class1 will always be switched on first !
*/


function DualFlipClassSwitch( TagName , Class1 , Class2 , MemoryName ) {

const ClassWasActive = document.querySelector( TagName ).classList.contains( Class1 ) ;

if ( !ClassWasActive ) { ClassSwitch( TagName , Class1 , MemoryName ) ; }

else { ClassSwitch( TagName , Class2 , MemoryName ) ; }

return false ;

}

0 comments on commit 574b593

Please sign in to comment.