Merge pull request #16 from Cito/sticky-switcher

Make the switcher sticky at the top of the page
pull/30/head
Liam Doherty 4 years ago committed by GitHub
commit 50ac1a7769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,14 @@
body {
padding-left: 24px;
}
#switcher {
position: sticky;
top: 0;
padding-bottom: 9px;
background: white;
box-shadow: 0 2px 1px -1px #ccc;
z-index: 999999;
}
</style>
<script type="text/javascript">
function quick_api() {
@ -413,6 +421,6 @@
<p>View this project on <a href="https://github.com/dohliam/dropin-minimal-css">GitHub</a>.</p>
</footer>
</div>
<script src="https://dohliam.github.io/dropin-minimal-css/switcher.js" type="text/javascript"></script>
<script src="./switcher.js" type="text/javascript"></script>
</body>
</html>

@ -3,7 +3,7 @@ var frameworks = "a11yana,bahunya,bare,base,bullframe,bulma,caiuss,caramel,cardi
add_switcher();
function switch_css(css) {
document.getElementsByTagName("link")[0].href = "https://dohliam.github.io/dropin-minimal-css/min/" + css + ".min.css";
css_link.href = "https://dohliam.github.io/dropin-minimal-css/min/" + css + ".min.css";
}
function capitalize(s) {
@ -13,6 +13,12 @@ function capitalize(s) {
return u;
}
function on_css_load() {
var bgColor = getComputedStyle(document.body).backgroundColor;
if (bgColor.match(/^rgba\(.*\)/) ) bgColor = 'white';
switcher.style.backgroundColor = bgColor;
}
function inline_switcher() {
switcher = document.getElementById("switcher");
frameworks_array = frameworks.split(",");
@ -30,20 +36,23 @@ function inline_switcher() {
}
function add_switcher() {
stylesheet = document.getElementsByTagName("link")[0];
if (stylesheet == undefined) {
css_link = document.getElementsByTagName("link")[0];
if (css_link == undefined) {
head = document.getElementsByTagName('head')[0];
link = document.createElement('link');
link.rel="stylesheet";
link.type="text/css";
link.href="https://dohliam.github.io/dropin-minimal-css/min/" + frameworks.split(",")[0] + ".min.css";
head.appendChild(link);
css_link = document.createElement('link');
css_link.rel="stylesheet";
css_link.type="text/css";
css_link.href="https://dohliam.github.io/dropin-minimal-css/min/" + frameworks.split(",")[0] + ".min.css";
head.appendChild(css_link);
}
var new_div = document.createElement("div");
new_div.innerHTML = ' <div id="switcher">&nbsp;</div>\n <script type="text/javascript">inline_switcher();</script>';
document.body.insertBefore(new_div, document.body.firstChild);
document.body.style.paddingLeft = "24px"
var new_div = document.createElement('div');
new_div.id = 'switcher';
new_div.innerHTML = ' <div>&nbsp;</div>\n <script type="text/javascript">inline_switcher();</script>';
document.body.prepend(new_div);
document.body.style.paddingLeft = "24px";
inline_switcher();
css_link.onload = on_css_load;
}

Loading…
Cancel
Save