Skip to content

Commit

Permalink
register-hash-cb function added, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
inasangit committed Jul 14, 2021
1 parent 4ab5ae3 commit 74613c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ But many of useful JS and DOM-manipulating functions are provided by `omgui` pac

- `(load-js-script url)` - load JS script from `url`.

- `(register-hash-cb hash cb)` - register a callback to call when URL hash part changes. With this function you can, for example, automatically mark session as debug one, when you open URL like `http://localhost:7500/#debug`:

```
(defun-r debug-me ()
(set-debug-session (current-session-id)))
(defun-r my-boot ()
(register-hash-cb "#debug" (lambda () (debug-me))))
(add-to-boot '(my-boot))
```

If the page is loaded with the registered hash part, the callback will be executed immediately during `register-hash-cb` call.

### Modal dialogs

You can display modal dialog in the browser using the `modal-dialog` macro:
Expand Down
2 changes: 1 addition & 1 deletion omg.asd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defsystem "omg"
:description "A Common Lisp library to build fully dynamic web interfaces"
:version "0.1.1"
:version "0.1.2"
:author "Pavel Kaygorodov <[email protected]>"
:licence "GPLv3"
:depends-on ("clack" "websocket-driver-server" "bordeaux-threads" "trivial-utf-8")
Expand Down
17 changes: 17 additions & 0 deletions omgui.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
page-height
parent-element
prevent-page-close
register-hash-cb
remove-element
visible-width
visible-height
Expand Down Expand Up @@ -515,3 +516,19 @@
(load-js-script "https://www.youtube.com/iframe_api"))
(make-player))))
nil)


(defparameter-f *hash-change-cbs* nil)

(defun-f register-hash-cb (hsh cb)
(labels ((mcb (&optional ev)
(let* ((hs (jscl::oget (jscl::%js-vref "location") "hash"))
(cb (assoc hs *hash-change-cbs* :test #'equal)))
(jslog hs)
(if cb (funcall (cdr cb))))))
(if (not *hash-change-cbs*)
(setf (jscl::oget (jscl::%js-vref "window") "onhashchange")
#'mcb))
(push (cons hsh cb) *hash-change-cbs*)
(mcb))
nil)

0 comments on commit 74613c4

Please sign in to comment.