JSFiddle - React, Tailwind, and code Playground
by mgibsonbr
CSS
* {
width: 100%;
height: 100%;
overflow: hidden;
}
JavaScript
var funcoesToggle = {};
function toggle(qual) {
if (!funcoesToggle[qual]) funcoesToggle[qual] = {
contador: -1,
funcoes: Array.prototype.slice.call(arguments, 1, arguments.length)
};
var escolhido = funcoesToggle[qual];
escolhido.contador = (escolhido.contador + 1) % escolhido.funcoes.length;
escolhido.funcoes[escolhido.contador]();
}
// Exemplo de uso:
toggle("D", function () {
alert("A");
}, function () {
alert("B");
}, function () {
alert("C");
}); // A
toggle("D", function () {
alert("A");
}, function () {
alert("B");
}, function () {
alert("C");
}); // B
toggle("Ee", function () {
alert("A");
}, function () {
alert("B");
}, function () {
alert("C");
}); // A
toggle("D", function () {
alert("A");
}, function () {
alert("B");
}, function () {
alert("C");
}); // C
toggle("Ee", function () {
alert("A");
}, function () {
alert("B");
}, function () {
alert("C");
}); // B