-
Notifications
You must be signed in to change notification settings - Fork 2
/
form-with-sticky-buttons-view.lisp
47 lines (41 loc) · 2.1 KB
/
form-with-sticky-buttons-view.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(in-package :weblocks-cms)
(defclass form-with-sticky-buttons-view (form-view)
())
(defclass form-with-sticky-buttons-view-field (form-view-field)
())
(defclass form-with-sticky-buttons-scaffold (form-scaffold)
())
(defun make-form-buttons-sticky-js (&rest args)
(with-html
(:script :type "text/javascript"
(str
(ps:ps
(j-query
(lambda ()
(let* ((div (j-query "div.submit"))
(height (ps:chain (j-query "div.submit") (outer-height)))
(wrapper (ps:chain
div
(wrap "<div class='scroll-wrapper'></div>")
(parent)
(height height)))
(start-offset 10))
(unless (ps:chain (j-query ".modal-backdrop") length)
(ps:chain (j-query window)
(scroll
(lambda ()
(let* ((original-offset (ps:chain wrapper (offset)))
(el-bottom-point-from-top (+ (ps:@ original-offset top) height))
(win-bottom-point-from-top (+ (ps:chain (j-query window) (scroll-top))
(ps:chain (j-query window) (height)))))
(if (<=
(- win-bottom-point-from-top start-offset)
el-bottom-point-from-top)
(ps:chain (j-query "div.submit") (add-class "fixed"))
(progn
(ps:chain (j-query "div.submit") (remove-class "fixed"))
; XXX, this for bug fixing
(setf original-offset (ps:chain (j-query "div.submit") (offset))))))))
(trigger "scroll")))))))))))
(defmethod render-form-view-buttons :before ((view form-with-sticky-buttons-view) obj widget &rest args)
(make-form-buttons-sticky-js))