Skip to content

Commit 574b593

Browse files
authored
add Dual Option Flip Switch Logic to the switch
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 !
1 parent 4c4120d commit 574b593

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

JS-CSS-Class-Switch-with-Memory.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,24 @@ function ClassSwitch( TagName, ClassName, MemoryName ) {
5555

5656
}
5757

58+
59+
/*
60+
Dual Flip CSS class Toggle Switch. Set THis OR the OTher CSS class.
61+
Flips or changes CSS class between two given options.
62+
If Class1 was NOT active: We switch it ON. Else: we flip switch Class2 ON.
63+
Only one can exist at the same time ! Class1 will always be switched on first !
64+
*/
65+
66+
67+
function DualFlipClassSwitch( TagName , Class1 , Class2 , MemoryName ) {
68+
69+
const ClassWasActive = document.querySelector( TagName ).classList.contains( Class1 ) ;
70+
71+
if ( !ClassWasActive ) { ClassSwitch( TagName , Class1 , MemoryName ) ; }
72+
73+
else { ClassSwitch( TagName , Class2 , MemoryName ) ; }
74+
75+
return false ;
76+
77+
}
78+

0 commit comments

Comments
 (0)