<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ConfigCat Demo</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/configcat-js@latest/dist/configcat.min.js">
</script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style type="text/css">
</style>
</head>
<body>
<h2 class="mb-5">ConfigCat Demo</h2>
<div>
<p><a href="https://app.configcat.com/apikey" target="_blank">Login</a> and copy your API Key and Feature Flag Key from ConfigCat. Or <a href="https://app.configcat.com/startnow" target="_blank">Get an API Key and Feature Flag Key without
registering.</a></p>
<label for="apikey">API Key:</label>
<input type="text" class="form-control mb-3" name="apikey" id="apikey" size="47">
<label for="flagkey">Feature Flag Key:</label>
<input type="text" class="form-control" name="flagkey" id="flagkey" value="isAwesomeFeatureEnabled">
<button id="start" class="btn btn-primary mt-3">Start</button>
</div>
<p id="flip" hidden>Flip the switch <img src="switch.png" alt="switch"> under <a href="https://app.configcat.com" target="_blank">Feature Flags & Settings</a> to see the page update dynamically.</p>
<h5>The current state of your Feature Flag is:</h5>
<h1 id="unknown"><span class="badge badge-secondary">Unknown</span></h1>
<h1 id="on" hidden><span class="badge badge-success">ON</span></h1>
<h1 id="off" hidden><span class="badge badge-danger">OFF</span></h1>
</body>
</html>
html,
body {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 2em;
height: 100%;
width: 100%;
}
$(document).ready(function() {
$("#start").click(function() {
var configCatClient = configcat.createClientWithAutoPoll(
$("#apikey").val(),
{
pollIntervalSeconds: 4,
configChanged: function() {
updateFeatureFlagValue();
}
}
);
$("#apikey").prop("disabled", true);
$("#flagkey").prop("disabled", true);
$("#start").prop("disabled", true);
function updateFeatureFlagValue() {
configCatClient.getValue($("#flagkey").val(), false, function(value) {
$("#unknown").prop("hidden", true);
$("#flip").prop("hidden", false);
if (value) {
$("#on").prop("hidden", false);
$("#off").prop("hidden", true);
} else {
$("#on").prop("hidden", true);
$("#off").prop("hidden", false);
}
});
}
updateFeatureFlagValue();
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.