fonts are loadedsynchronously now

This commit is contained in:
Christian Mueller
2014-01-20 22:15:42 +01:00
parent 5bb42baf80
commit 8a6eadf79a
3 changed files with 39 additions and 41 deletions
-1
View File
@@ -14,7 +14,6 @@ function md2html(input){
} }
function onLoad() { function onLoad() {
applyTheme();
$note = $("note"); $note = $("note");
$action = $("action"); $action = $("action");
$preview = $("preview"); $preview = $("preview");
+37 -38
View File
@@ -61,46 +61,45 @@ var themes = {
} }
}; };
function applyTheme() {
var ui = { theme: "default" };
if (location.search.length > 0) {
location.search.slice(1).split("&").reduce(function(acc, e){
var p = e.split("=");
acc[p[0]] = p[1];
return acc
}, ui);
}
var vars = { var ui = { theme: "default" };
'@background': themes[ui.theme].background.normal, if (location.search.length > 0) {
'@background_halftone': themes[ui.theme].background.halftone, location.search.slice(1).split("&").reduce(function(acc, e){
'@foreground': themes[ui.theme].foreground.normal, var p = e.split("=");
'@foreground_halftone': themes[ui.theme].foreground.halftone, acc[p[0]] = p[1];
'@link_fresh': themes[ui.theme].link.fresh, return acc
'@link_visited': themes[ui.theme].link.visited, }, ui);
'@link_hover': themes[ui.theme].link.hover }
};
var fontURL = "http://fonts.googleapis.com/" + var vars = {
"css?family=PT+Serif:700|Noticia+Text:700%s" + '@background': themes[ui.theme].background.normal,
"&subset=latin,cyrillic", '@background_halftone': themes[ui.theme].background.halftone,
injection = ""; '@foreground': themes[ui.theme].foreground.normal,
'@foreground_halftone': themes[ui.theme].foreground.halftone,
'@link_fresh': themes[ui.theme].link.fresh,
'@link_visited': themes[ui.theme].link.visited,
'@link_hover': themes[ui.theme].link.hover
};
if(ui["header-font"] || ui["text-font"]) { var fontURL = "http://fonts.googleapis.com/" +
injection = ["header-font", "text-font"].reduce(function(acc, font){ "css?family=PT+Serif:700|Noticia+Text:700%s" +
if(ui[font]) { "&subset=latin,cyrillic",
vars['@' + font.replace(/-/, "_")] = ui[font].replace(/\+/g," "); injection = "";
return acc + "|" + ui[font];
} else return acc;
}, "");
}
fontURL = fontURL.replace(/%s/, injection); if(ui["header-font"] || ui["text-font"]) {
var fileref = document.createElement("link") injection = ["header-font", "text-font"].reduce(function(acc, font){
fileref.setAttribute("rel", "stylesheet") if(ui[font]) {
fileref.setAttribute("type", "text/css") vars['@' + font.replace(/-/, "_")] = ui[font].replace(/\+/g," ");
fileref.setAttribute("href", fontURL) return acc + "|" + ui[font];
document.getElementsByTagName("head")[0].appendChild(fileref) } else return acc;
}, "");
}
less.modifyVars(vars); fontURL = fontURL.replace(/%s/, injection);
} var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", fontURL)
document.getElementsByTagName("head")[0].appendChild(fileref)
less.modifyVars(vars);
+2 -2
View File
@@ -32,10 +32,10 @@
[:link {:rel "stylesheet/less" :type "text/css" :href "/style.less"}] [:link {:rel "stylesheet/less" :type "text/css" :href "/style.less"}]
(html (html
(include-js "/js/less.js") (include-js "/js/less.js")
(include-js "/js/themes.js")
(include-js "/js/md5.js") (include-js "/js/md5.js")
(include-js "/js/marked.js") (include-js "/js/marked.js")
(include-js "/js/main.js") (include-js "/js/main.js"))
(include-js "/js/themes.js"))
; google analytics code should appear in prod mode only ; google analytics code should appear in prod mode only
(if-not (get-setting :dev-mode) (include-js "/js/google-analytics.js"))] (if-not (get-setting :dev-mode) (include-js "/js/google-analytics.js"))]
[:body {:onload "onLoad()"} content])) [:body {:onload "onLoad()"} content]))