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() {
applyTheme();
$note = $("note");
$action = $("action");
$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 = {
'@background': themes[ui.theme].background.normal,
'@background_halftone': themes[ui.theme].background.halftone,
'@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
};
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 fontURL = "http://fonts.googleapis.com/" +
"css?family=PT+Serif:700|Noticia+Text:700%s" +
"&subset=latin,cyrillic",
injection = "";
var vars = {
'@background': themes[ui.theme].background.normal,
'@background_halftone': themes[ui.theme].background.halftone,
'@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"]) {
injection = ["header-font", "text-font"].reduce(function(acc, font){
if(ui[font]) {
vars['@' + font.replace(/-/, "_")] = ui[font].replace(/\+/g," ");
return acc + "|" + ui[font];
} else return acc;
}, "");
}
var fontURL = "http://fonts.googleapis.com/" +
"css?family=PT+Serif:700|Noticia+Text:700%s" +
"&subset=latin,cyrillic",
injection = "";
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)
if(ui["header-font"] || ui["text-font"]) {
injection = ["header-font", "text-font"].reduce(function(acc, font){
if(ui[font]) {
vars['@' + font.replace(/-/, "_")] = ui[font].replace(/\+/g," ");
return acc + "|" + ui[font];
} 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);