1 (in-package "PARENSCRIPT")
3 ;; Utilities for accessing standard DOM functionality in a Lispier, PSier way.
5 (defpsmacro inner-html
(el)
6 `(@ ,el
:inner-h-t-m-l
))
8 (defpsmacro uri-encode
(str)
9 `(if (null ,str
) "" (encode-u-r-i-component ,str
)))
11 (defpsmacro attribute
(el attr
)
12 `((@ ,el
:get-attribute
) ,attr
))
14 (defun assert-is-one-of (val options
)
15 (unless (member val options
)
16 (error "~s is not one of ~s" val options
)))
18 (defpsmacro offset
(what el
)
20 `(offset ,(eval what
) ,el
)
21 (progn (assert-is-one-of what
'(:top
:left
:height
:width
:bottom
:right
))
22 (if (member what
'(:top
:left
:height
:width
))
23 `(@ ,el
,(intern (format nil
"OFFSET-~a" what
)))
24 (aif (assoc what
'((:bottom
:top
:height
) (:right
:left
:width
)))
25 `(+ (offset ,(second it
) ,el
) (offset ,(third it
) ,el
)))))))
27 (defpsmacro scroll
(what el
)
28 (assert-is-one-of what
'(:top
:left
:right
:bottom
:width
:height
))
29 (cond ((member what
'(:top
:left
:width
:height
))
30 `(@ ,el
,(intern (format nil
"SCROLL-~a" what
))))
32 `(+ (scroll :left
,el
) (offset :width
,el
)))
34 `(+ (scroll :top
,el
) (offset :height
,el
)))))
36 (defpsmacro inner
(what el
)
37 (assert-is-one-of what
'(:width
:height
))
38 `(@ ,el
,(intern (format nil
"INNER-~a" what
))))
40 (defpsmacro client
(what el
)
41 (assert-is-one-of what
'(:width
:height
))
42 `(@ ,el
,(intern (format nil
"CLIENT-~a" what
))))