Brian McKenna avatar Brian McKenna committed 2cbb894

Rename from Climacs to Cajole

Comments (0)

Files changed (3)

 <!doctype html>
 <html>
   <head>
-    <title>Climacs</title>
+    <title>Cajole</title>
     <style>
       body {
         padding: 0;
     <script src="out/goog/base.js"></script>
     <script src="out/core.js"></script>
     <script>
-      goog.require('climacs.editor');
+      goog.require('cajole.editor');
     </script>
   </body>
 </html>

src/cajole/editor.cljs

+(ns cajole.editor
+  (:require [goog.editor.Field :as Field]
+            [goog.events.FileDropHandler :as FileDropHandler]
+            [goog.dom :as dom]
+            [goog.events :as events]
+            [goog.style :as style]))
+
+; Editor
+
+(def field (goog.editor/Field. "editor"))
+
+(. field (makeEditable))
+
+(def iframe (. field (getEditableIframe)))
+(def iframe-doc (. iframe contentDocument))
+(def iframe-body (. iframe-doc body))
+(def iframe-html (. iframe-body parentNode))
+
+(style/setStyle
+ iframe-html
+ (.strobj
+  {"font-family" "monospace"
+   "background-color" "#000"
+   "color" "#FFF"}))
+
+(defn upload-file [e]
+  (js* "console.log(~{})" (. e (getBrowserEvent))))
+
+(events/listen
+ (events/FileDropHandler. iframe-html)
+ FileDropHandler/EventType.DROP
+ upload-file)
+
+; Editor plugin
+
+(defn Cajole []
+  (. goog.editor/Plugin (call (js* "this"))))
+
+(goog.inherits Cajole goog.editor/Plugin)
+
+(set! (.. Cajole prototype getTrogClassId)
+      (fn [] "Cajole"))
+
+(set! (.. Cajole prototype isSupportedCommand)
+      (fn [c]
+        (condp = c
+          "bold" true
+          false)))
+
+(defn get-content []
+  (.innerText iframe-body))
+
+(defn run-field []
+  (dom/append
+   (.body (dom/getDocument))
+   (dom/createDom
+    "script" "" (get-content))))
+
+(defn set-token-color [sel tkn end color]
+  (let [node (aget (.childNodes iframe-body) 0)
+        start (.pos tkn)
+        range (. iframe-doc (createRange))]
+    (. sel (removeAllRanges))
+    (. range (setStart node start))
+    (. range (setEnd node end))
+    (. sel (addRange range))
+    (. iframe-doc (execCommand "ForeColor" false color))))
+
+(defn highlight-token [sel tkn end]
+  (set-token-color
+   sel tkn end
+   (condp = (.type tkn)
+     "string" "#FFAC85"
+     "keyword" "#00FFFF"
+     "operator" "#BACFE6"
+     "#FFF")))
+
+(defn get-selection []
+  (. iframe-doc (getSelection)))
+
+(defn highlight-content []
+  (let [t (goog.global.tokenizer (get-content))
+        a (array)]
+    (loop [tkn (t)]
+      (.push a tkn)
+      (if (= (.type tkn) "eof")
+        tkn
+        (recur (t))))
+    (let [sel (get-selection)
+          tokens (sort #(compare (.pos %2) (.pos %1)) a)
+          wo-eof (rest tokens)
+          ends (map #(.pos %) tokens)]
+      (doall (map #(highlight-token sel %1 %2) wo-eof ends)))))
+
+(defn get-current-pos [node pos]
+  (let [node (if (= (.nodeType node) goog.global.Node.TEXT_NODE) (.parentNode node) node)
+        nodes (.childNodes iframe-body)
+        under-nodes (goog.array.slice nodes 0 (goog.array.indexOf (goog.array.slice nodes) node))
+        under-length (goog.array.map under-nodes #(count (dom/getTextContent %)))]
+
+    (+ (apply + under-length) pos)))
+
+(defn get-character-node [pos]
+  (let [nodes (.childNodes iframe-body)
+        sum-lengths #(apply + %)
+        under-nodes (loop [accum [] lengths (goog.array.map nodes #(count (dom/getTextContent %)))]
+                      (let [total (+ (sum-lengths accum) (first lengths))]
+                        (if (and (count lengths) (< total pos))
+                          (recur (cons (first lengths) accum) (rest lengths))
+                          accum)))
+        node (aget nodes (count under-nodes))]
+
+    (if (and node (> (.. node childNodes length) 0))
+      {:pos (- pos (sum-lengths under-nodes))
+       :node (aget (.childNodes node) 0)}
+      {:pos (.. iframe-body childNodes length)
+       :node iframe-body})))
+
+(defn get-range-nodes [start end]
+  [(get-character-node start)
+   (get-character-node end)])
+
+(set! (.. Cajole prototype handleKeyUp)
+      (fn [e]
+        (let [sel (get-selection)
+              range (. sel (getRangeAt 0))
+              start-node (.startContainer range)
+              end-node (.endContainer range)
+              start-pos (.startOffset range)
+              end-pos (.endOffset range)
+              start (get-current-pos start-node start-pos)
+              end (get-current-pos end-node end-pos)]
+
+          (. field (setHtml false (get-content)))
+          (try*
+           (highlight-content)
+           (catch e))
+
+          (let [nodes-pos (get-range-nodes start end)
+                start-node-pos (first nodes-pos)
+                end-node-pos (second nodes-pos)
+                range (. iframe-doc (createRange))]
+
+            (. sel (removeAllRanges))
+            (. range (setStart (:node start-node-pos) (:pos start-node-pos)))
+            (. range (setEnd (:node end-node-pos) (:pos end-node-pos)))
+            (. sel (addRange range))))))
+
+(set! (.. Cajole prototype handleKeyboardShortcut)
+      (fn [e key modifier]
+        (condp = key
+          \j (run-field)
+          nil)))
+
+(. field (registerPlugin (Cajole.)))

src/climacs/editor.cljs

-(ns climacs.editor
-  (:require [goog.editor.Field :as Field]
-            [goog.events.FileDropHandler :as FileDropHandler]
-            [goog.dom :as dom]
-            [goog.events :as events]
-            [goog.style :as style]))
-
-; Editor
-
-(def field (goog.editor/Field. "editor"))
-
-(. field (makeEditable))
-
-(def iframe (. field (getEditableIframe)))
-(def iframe-doc (. iframe contentDocument))
-(def iframe-body (. iframe-doc body))
-(def iframe-html (. iframe-body parentNode))
-
-(style/setStyle
- iframe-html
- (.strobj
-  {"font-family" "monospace"
-   "background-color" "#000"
-   "color" "#FFF"}))
-
-(defn upload-file [e]
-  (js* "console.log(~{})" (. e (getBrowserEvent))))
-
-(events/listen
- (events/FileDropHandler. iframe-html)
- FileDropHandler/EventType.DROP
- upload-file)
-
-; Editor plugin
-
-(defn Climacs []
-  (. goog.editor/Plugin (call (js* "this"))))
-
-(goog.inherits Climacs goog.editor/Plugin)
-
-(set! (.. Climacs prototype getTrogClassId)
-      (fn [] "Climacs"))
-
-(set! (.. Climacs prototype isSupportedCommand)
-      (fn [c]
-        (condp = c
-          "bold" true
-          false)))
-
-(defn get-content []
-  (.innerText iframe-body))
-
-(defn run-field []
-  (dom/append
-   (.body (dom/getDocument))
-   (dom/createDom
-    "script" "" (get-content))))
-
-(defn set-token-color [sel tkn end color]
-  (let [node (aget (.childNodes iframe-body) 0)
-        start (.pos tkn)
-        range (. iframe-doc (createRange))]
-    (. sel (removeAllRanges))
-    (. range (setStart node start))
-    (. range (setEnd node end))
-    (. sel (addRange range))
-    (. iframe-doc (execCommand "ForeColor" false color))))
-
-(defn highlight-token [sel tkn end]
-  (set-token-color
-   sel tkn end
-   (condp = (.type tkn)
-     "string" "#FFAC85"
-     "keyword" "#00FFFF"
-     "operator" "#BACFE6"
-     "#FFF")))
-
-(defn get-selection []
-  (. iframe-doc (getSelection)))
-
-(defn highlight-content []
-  (let [t (goog.global.tokenizer (get-content))
-        a (array)]
-    (loop [tkn (t)]
-      (.push a tkn)
-      (if (= (.type tkn) "eof")
-        tkn
-        (recur (t))))
-    (let [sel (get-selection)
-          tokens (sort #(compare (.pos %2) (.pos %1)) a)
-          wo-eof (rest tokens)
-          ends (map #(.pos %) tokens)]
-      (doall (map #(highlight-token sel %1 %2) wo-eof ends)))))
-
-(defn get-current-pos [node pos]
-  (let [node (if (= (.nodeType node) goog.global.Node.TEXT_NODE) (.parentNode node) node)
-        nodes (.childNodes iframe-body)
-        under-nodes (goog.array.slice nodes 0 (goog.array.indexOf (goog.array.slice nodes) node))
-        under-length (goog.array.map under-nodes #(count (dom/getTextContent %)))]
-
-    (+ (apply + under-length) pos)))
-
-(defn get-character-node [pos]
-  (let [nodes (.childNodes iframe-body)
-        sum-lengths #(apply + %)
-        under-nodes (loop [accum [] lengths (goog.array.map nodes #(count (dom/getTextContent %)))]
-                      (let [total (+ (sum-lengths accum) (first lengths))]
-                        (if (and (count lengths) (< total pos))
-                          (recur (cons (first lengths) accum) (rest lengths))
-                          accum)))
-        node (aget nodes (count under-nodes))]
-
-    (if (and node (> (.. node childNodes length) 0))
-      {:pos (- pos (sum-lengths under-nodes))
-       :node (aget (.childNodes node) 0)}
-      {:pos (.. iframe-body childNodes length)
-       :node iframe-body})))
-
-(defn get-range-nodes [start end]
-  [(get-character-node start)
-   (get-character-node end)])
-
-(set! (.. Climacs prototype handleKeyUp)
-      (fn [e]
-        (let [sel (get-selection)
-              range (. sel (getRangeAt 0))
-              start-node (.startContainer range)
-              end-node (.endContainer range)
-              start-pos (.startOffset range)
-              end-pos (.endOffset range)
-              start (get-current-pos start-node start-pos)
-              end (get-current-pos end-node end-pos)]
-
-          (. field (setHtml false (get-content)))
-          (try*
-           (highlight-content)
-           (catch e))
-
-          (let [nodes-pos (get-range-nodes start end)
-                start-node-pos (first nodes-pos)
-                end-node-pos (second nodes-pos)
-                range (. iframe-doc (createRange))]
-
-            (. sel (removeAllRanges))
-            (. range (setStart (:node start-node-pos) (:pos start-node-pos)))
-            (. range (setEnd (:node end-node-pos) (:pos end-node-pos)))
-            (. sel (addRange range))))))
-
-(set! (.. Climacs prototype handleKeyboardShortcut)
-      (fn [e key modifier]
-        (condp = key
-          \j (run-field)
-          nil)))
-
-(. field (registerPlugin (Climacs.)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.