                      (.val $urlShortenerInput
                            "an error occurred"))}))
 
+(defn- get-short-url-jq-evt-handler-maker
+  "Returns a function suitable for a jQuery event handler; the returned function
+   tries to obtain a short url and sets the result in the #url-shortener
+   <input>"
+  [$urlShortenerInput localStorage]
+  (fn []
+    (let [currentUrl (aget js/document "URL")
+          localStorageKey (str "shortUrl-" currentUrl)
+
+          mbShortUrl (and localStorage
+                          (.getItem localStorage localStorageKey))]
+      (if mbShortUrl
+          (.val $urlShortenerInput mbShortUrl)
+          (make-request-to-get-short-url currentUrl $urlShortenerInput
+                                         localStorage localStorageKey)))))
+
 (defn- short-url-setup
   "Setup url shortening"
   []

        (initialize-exhibit3 (aget js/window "MODULES")
                             (aget js/window "AUXMODULES")))))

(defn- get-short-url
  "Tries to obtain a short url and sets the result in the #url-shortener
   <input>"
  [$urlShortenerInput localStorage]
  (ajax "/shorten"
        {:data     {:url (js/encodeURI
                           (aget js/document "URL"))}
         :dataType "json"

         :success

        zcbClient          (ZeroClipboard. $copy-to-clipboard)
        $urlShortenerInput ($ :#url-shortener)]
    (.click $urlShortenerInput
            (get-short-url-jq-evt-handler-maker $urlShortenerInput
                                                localStorage))))

; Main entry point of the program
(defn ^:export init [acad-year sem]
