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

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

Loading…
Cancel
Save