Browse Source

fonts are loadedsynchronously now

master
Christian Mueller 12 years ago
parent
commit
8a6eadf79a
  1. 1
      resources/public/js/main.js
  2. 75
      resources/public/js/themes.js
  3. 4
      src/NoteHub/views/pages.clj

1
resources/public/js/main.js

@ -14,7 +14,6 @@ function md2html(input){ @@ -14,7 +14,6 @@ function md2html(input){
}
function onLoad() {
applyTheme();
$note = $("note");
$action = $("action");
$preview = $("preview");

75
resources/public/js/themes.js

@ -61,46 +61,45 @@ var themes = { @@ -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 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 fontURL = "http://fonts.googleapis.com/" +
"css?family=PT+Serif:700|Noticia+Text:700%s" +
"&subset=latin,cyrillic",
injection = "";
var fontURL = "http://fonts.googleapis.com/" +
"css?family=PT+Serif:700|Noticia+Text:700%s" +
"&subset=latin,cyrillic",
injection = "";
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;
}, "");
}
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;
}, "");
}
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)
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);
}
less.modifyVars(vars);

4
src/NoteHub/views/pages.clj

@ -32,10 +32,10 @@ @@ -32,10 +32,10 @@
[:link {:rel "stylesheet/less" :type "text/css" :href "/style.less"}]
(html
(include-js "/js/less.js")
(include-js "/js/themes.js")
(include-js "/js/md5.js")
(include-js "/js/marked.js")
(include-js "/js/main.js")
(include-js "/js/themes.js"))
(include-js "/js/main.js"))
; google analytics code should appear in prod mode only
(if-not (get-setting :dev-mode) (include-js "/js/google-analytics.js"))]
[:body {:onload "onLoad()"} content]))

Loading…
Cancel
Save