Browse Source

excluded heavy js where not necessary

master
Christian Mueller 12 years ago
parent
commit
6557de2fdf
  1. 11
      resources/public/js/main.js
  2. 17
      resources/public/js/themes.js
  3. 4
      src/notehub/handler.clj
  4. 20
      src/notehub/views.clj

11
resources/public/js/main.js

@ -38,14 +38,5 @@ function onLoad() { @@ -38,14 +38,5 @@ function onLoad() {
}
if(iosDetected) $note.className += " ui-border"; else $note.focus();
}
var links = $("links");
if(links){
if(window.innerHeight * 0.85 >= document.body.clientHeight) {
links.style.position = "fixed";
links.style.bottom = 0;
}
show(links);
}
showLinks();
}

17
resources/public/js/themes.js

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
var $ = function(id){ return document.getElementById(id); }
var show = function(elem) { elem.style.display = "block" }
var themes = {
"dark": {
background: {
@ -103,3 +106,17 @@ fileref.setAttribute("href", fontURL) @@ -103,3 +106,17 @@ fileref.setAttribute("href", fontURL)
document.getElementsByTagName("head")[0].appendChild(fileref)
less.modifyVars(vars);
function showLinks(){
var links = $("links");
if(links){
if(window.innerHeight * 0.85 >= document.body.clientHeight) {
links.style.position = "fixed";
links.style.bottom = 0;
}
show(links);
}
}
// for the case if main.js is not loaded
var onLoad = showLinks;

4
src/notehub/handler.clj

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
[code]
{:status code
:body (let [message (get-message (keyword (str "status-" code)))]
(layout message
(layout :no-js message
[:article [:h1 message]]))})
(defn redirect [url]
@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
(generate-string (api/version-manager api/update-note params))))
(defroutes app-routes
(GET "/api" [] (layout (get-message :api-title)
(GET "/api" [] (layout :no-js (get-message :api-title)
[:article (md/to-html (slurp "API.md"))]))
(context "/api" []

20
src/notehub/views.clj

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
; Creates the main html layout
(defn layout
[title & content]
[js? title & content]
(html5
[:head
[:title (print-str (get-message :name) "—" title)]
@ -25,10 +25,12 @@ @@ -25,10 +25,12 @@
[:link {:rel "stylesheet/less" :type "text/css" :href "/styles/main.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"))
(when (= :js js?)
(html
(include-js "/js/md5.js")
(include-js "/js/marked.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]))
@ -41,7 +43,7 @@ @@ -41,7 +43,7 @@
; input form for the markdown text with a preview area
(defn- input-form [form-url command fields content passwd-msg]
(let [css-class (when (= :publish command) :hidden)]
(layout (get-message :new-note)
(layout :js (get-message :new-page)
[:article#preview ""]
[:div#dashed-line {:class css-class}]
[:div.central-element.helvetica {:style "margin-bottom: 3em"}
@ -58,7 +60,7 @@ @@ -58,7 +60,7 @@
:id :publish-button} (get-message command))])])))
(def landing-page
(layout (get-message :page-title)
(layout :no-js (get-message :page-title)
[:div#hero
[:h1 (get-message :name)]
[:h2 (get-message :title)]
@ -74,7 +76,7 @@ @@ -74,7 +76,7 @@
(defn statistics-page [resp]
(let [stats (:statistics resp)
title (get-message :statistics)]
(layout title
(layout :no-js title
[:h2.central-element (api/derive-title (:note resp))]
[:h3.central-element.helvetica title]
[:table#stats.helvetica.central-element
@ -101,7 +103,7 @@ @@ -101,7 +103,7 @@
(defn note-page [note-id short-url]
(let [note (api/get-note {:noteID note-id})
sanitized-note (sanitize (:note note))]
(layout (:title note)
(layout :no-js (:title note)
[:article.bottom-space (md/to-html sanitized-note)]
(let [urls {:short-url (api/url short-url)
:notehub "/"}

Loading…
Cancel
Save