eliminated the dependency from jQuery/jayq
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
[hiccup "1.0.0"]
|
||||
[ring/ring-core "1.1.0"]
|
||||
[cssgen "0.2.6"]
|
||||
[jayq "0.1.0-alpha2"]
|
||||
[cheshire "4.0.0"]
|
||||
[clj-redis "0.0.12"]
|
||||
[org.pegdown/pegdown "1.1.0"]
|
||||
|
||||
+43
-25
@@ -1,19 +1,37 @@
|
||||
(ns NoteHub.main
|
||||
(:use [jayq.core :only [$ xhr css inner val anim show]])
|
||||
(:require [goog.dom :as gdom]
|
||||
[goog.crypt.Md5 :as md5]
|
||||
(:require [goog.crypt.Md5 :as md5]
|
||||
[goog.crypt :as crypt]
|
||||
[NoteHub.crossover.lib :as lib]
|
||||
[clojure.browser.dom :as dom]))
|
||||
[NoteHub.crossover.lib :as lib]))
|
||||
|
||||
(defn log
|
||||
"Logs to console.log"
|
||||
[text]
|
||||
(.log js/console text))
|
||||
|
||||
(defn $
|
||||
"Returns DOM element by Id"
|
||||
[id]
|
||||
(.getElementById js/document (name id)))
|
||||
|
||||
(defn val
|
||||
"Returns the value of the element or sets the value if the value was provided"
|
||||
([element] (.-value element))
|
||||
([element value]
|
||||
(set! (.-value element) value)))
|
||||
|
||||
(defn show
|
||||
"show the element"
|
||||
[element]
|
||||
(set! (.-display (.-style element)) "block"))
|
||||
|
||||
; frequently used selectors
|
||||
(def $draft ($ :#draft))
|
||||
(def $action ($ :#action))
|
||||
(def $preview ($ :#preview))
|
||||
(def $password ($ :#password))
|
||||
(def $plain-password ($ :#plain-password))
|
||||
(def $input-elems ($ :#input-elems))
|
||||
(def $dashed-line ($ :#dashed-line))
|
||||
(def $draft ($ :draft))
|
||||
(def $action ($ :action))
|
||||
(def $preview ($ :preview))
|
||||
(def $password ($ :password))
|
||||
(def $plain-password ($ :plain-password))
|
||||
(def $input-elems ($ :input-elems))
|
||||
(def $dashed-line ($ :dashed-line))
|
||||
|
||||
; Markdown Converter & Sanitizer instantiation
|
||||
(def md-converter (Markdown.Converter.))
|
||||
@@ -43,8 +61,8 @@
|
||||
#(do
|
||||
(show $dashed-line)
|
||||
(show $input-elems)
|
||||
(inner $preview
|
||||
(.makeHtml md-converter content))) delay)))))
|
||||
(set! (.-innerHTML $preview)
|
||||
(.makeHtml md-converter content))) delay)))))
|
||||
|
||||
; set focus to the draft textarea (if there is one)
|
||||
(when $action
|
||||
@@ -54,21 +72,21 @@
|
||||
(val $draft ""))
|
||||
; foces setting is impossible in iOS, so we border the field instead
|
||||
(if ios-detected
|
||||
(.addClass $draft "ui-border")
|
||||
(set! (.-className $draft) (str (.-className $draft) "ui-border"))
|
||||
(.focus $draft))))
|
||||
|
||||
; show the preview & publish buttons as soon as the user starts typing.
|
||||
(.keyup $draft update-preview)
|
||||
(set! (.-onkeyup $draft) update-preview)
|
||||
|
||||
; when the publish button is clicked, compute the hash of the entered text and
|
||||
; provided session key and assign to the field session-value;
|
||||
; moreover, compute the password hash as md5 before transmission
|
||||
(.click ($ :#publish-button)
|
||||
(fn [e]
|
||||
(do
|
||||
(.update md5 (val $plain-password))
|
||||
(val $plain-password nil)
|
||||
(when (val $plain-password)
|
||||
(val $password (crypt/byteArrayToHex (.digest md5))))
|
||||
(val ($ :#session-value)
|
||||
(lib/hash #(.charCodeAt % 0) (str (val $draft) (val ($ :#session-key))))))))
|
||||
(set! (.-onclick ($ :publish-button))
|
||||
(fn [e]
|
||||
(do
|
||||
(.update md5 (val $plain-password))
|
||||
(val $plain-password nil)
|
||||
(when (val $plain-password)
|
||||
(val $password (crypt/byteArrayToHex (.digest md5))))
|
||||
(val ($ :session-value)
|
||||
(lib/hash #(.charCodeAt % 0) (str (val $draft) (val ($ :session-key))))))))
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
(when (params :js)
|
||||
(html
|
||||
(javascript-tag "var CLOSURE_NO_DEPS = true;")
|
||||
(include-js "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js")
|
||||
(include-js "/js/pagedown/Markdown.Converter.js")
|
||||
(include-js "/cljs/main.js")))])))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user