-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbanner.js
36 lines (36 loc) · 1.42 KB
/
banner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$(document).ready(function() {
var scratchpad = document.createElement("textarea");
// @link http://stackoverflow.com/a/9251169
var escapeMarkup = function(html) {
scratchpad.innerHTML = html;
return scratchpad.innerHTML;
};
var fillSnippetContainerWithBannerMarkup = function() {
var snippetContainer = document.getElementById("code-snippet");
var bannerContainer = document.getElementById("ucsf-banner-nav");
snippetContainer.innerHTML = escapeMarkup(bannerContainer.outerHTML);
hljs.highlightBlock(snippetContainer);
};
var setBannerClassesFromForm = function() {
var classes = "";
classes += $("#font-options option:selected").val();
classes += " " + $("#color-options option:selected").val();
if($("#logo-enabled").is(':checked')) {
classes += " no-logo";
}
classes = $.trim(classes);
if (classes) {
$("#ucsf-banner-nav").removeClass().addClass(classes);
} else {
$("#ucsf-banner-nav").removeAttr('class');
}
};
var onFormStateChange = function(evt) {
setBannerClassesFromForm();
fillSnippetContainerWithBannerMarkup();
};
$("#font-options").on("change", onFormStateChange);
$("#color-options").on("change", onFormStateChange);
$("#logo-enabled").on("change", onFormStateChange);
fillSnippetContainerWithBannerMarkup();
});