-
This commit is contained in:
Binary file not shown.
@@ -43,12 +43,29 @@
|
||||
webview-value/bool
|
||||
webview-value/symbol
|
||||
webview-value/number
|
||||
;webview-value/date
|
||||
;webview-value/time
|
||||
;webview-value/datetime
|
||||
|
||||
webview-add-class!
|
||||
webview-remove-class!
|
||||
webview-set-style!
|
||||
webview-unset-style!
|
||||
|
||||
webview-set-attr!
|
||||
webview-attr
|
||||
;webview-attr/bool
|
||||
;webview-attr/symbol
|
||||
;webview-attr/number
|
||||
;webview-attr/date
|
||||
;webview-attr/time
|
||||
;webview-attr/datetime
|
||||
|
||||
;webview-del-attr!
|
||||
|
||||
webview-standard-file-getter
|
||||
|
||||
test
|
||||
)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@@ -242,10 +259,10 @@
|
||||
|
||||
(define/contract (webview-close wv)
|
||||
(-> wv? symbol?)
|
||||
(let ((r (rkt-webview-close (wv-handle wv))))
|
||||
(begin
|
||||
(rkt-webview-close (wv-handle wv))
|
||||
(kill-thread (wv-webserver-thread wv))
|
||||
r)
|
||||
)
|
||||
'oke))
|
||||
|
||||
(define/contract (webview-bind! wv selector event)
|
||||
(-> wv? (or/c symbol? string?) symbol? list?)
|
||||
@@ -283,9 +300,12 @@
|
||||
(if (webview-call-js-result? result)
|
||||
(if (eq? (car result) 'oke)
|
||||
(hash-ref (fromJson (cadr result)) 'result #f)
|
||||
(error "Error calling javascript. Message: ~a" (hash-ref (fromJson (cadr result)) 'exn result))
|
||||
(error
|
||||
(format "Error calling javascript. Message: ~a"
|
||||
(hash-ref (fromJson (cadr result)) 'exn result)))
|
||||
)
|
||||
(error "Wrong result from webview-call-js: ~a" result)
|
||||
(error
|
||||
(format "Wrong result from webview-call-js: ~a" result))
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -331,12 +351,9 @@
|
||||
" }\n"
|
||||
"};\n"))
|
||||
-> "f()"))))
|
||||
(if (eq? (car v) 'oke)
|
||||
(let ((h (fromJson (cadr v))))
|
||||
(hash-ref h 'result #f))
|
||||
#f)
|
||||
)
|
||||
)
|
||||
(if (eq? v #f)
|
||||
#f
|
||||
v)))
|
||||
|
||||
(define/contract (webview-value/number wv id)
|
||||
(-> wv? symbol? (or/c number? boolean?))
|
||||
@@ -403,8 +420,96 @@
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(define/contract (webview-set-style! wv selector style-entries)
|
||||
(-> wv? (or/c symbol? string?) (or/c kv? list-of-kv?) hash?)
|
||||
(let ((sel (if (symbol? selector)
|
||||
(format "#~a" selector)
|
||||
selector))
|
||||
(cl (mk-js-array (if (kv? style-entries)
|
||||
(list style-entries)
|
||||
style-entries)))
|
||||
)
|
||||
(webview-call-js wv
|
||||
(with-selector sel
|
||||
(format
|
||||
(js-code
|
||||
"function(id, el) {"
|
||||
" let cl = ~a;"
|
||||
" cl.forEach(function(st) {"
|
||||
" el.style[st[0]] = st[1];"
|
||||
" });"
|
||||
" return id;"
|
||||
"}") cl))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(define/contract (webview-unset-style! wv selector style-entries)
|
||||
(-> wv? (or/c symbol? string?) (or/c symbol? list-of-symbol?) hash?)
|
||||
(let ((sel (if (symbol? selector)
|
||||
(format "#~a" selector)
|
||||
selector))
|
||||
(cl (mk-js-array (if (symbol? style-entries)
|
||||
(list style-entries)
|
||||
style-entries)))
|
||||
)
|
||||
(webview-call-js wv
|
||||
(with-selector sel
|
||||
(format
|
||||
(js-code
|
||||
"function(id, el) {"
|
||||
" let cl = ~a;"
|
||||
" cl.forEach(function(st) {"
|
||||
" el.style[st] = '';"
|
||||
" });"
|
||||
" return id;"
|
||||
"}") cl)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(define/contract (webview-set-attr! wv selector attr-entries)
|
||||
(-> wv? (or/c symbol? string?) (or/c kv? list-of-kv?) hash?)
|
||||
(let ((sel (if (symbol? selector)
|
||||
(format "#~a" selector)
|
||||
selector))
|
||||
(cl (mk-js-array (if (kv? attr-entries)
|
||||
(list attr-entries)
|
||||
attr-entries)))
|
||||
)
|
||||
(webview-call-js wv
|
||||
(with-selector sel
|
||||
(format
|
||||
(js-code
|
||||
"function(id, el) {"
|
||||
" let cl = ~a;"
|
||||
" cl.forEach(function(av) {"
|
||||
" el.setAttribute(av[0], av[1]);"
|
||||
" });"
|
||||
" return id;"
|
||||
"}") cl))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(define/contract (webview-attr wv id attr)
|
||||
(-> wv? symbol? (or/c symbol? string?) (or/c string? boolean?))
|
||||
(let ((v (webview-call-js wv
|
||||
(with-id id el
|
||||
-> (format "el.getAttribute('~a');" attr))
|
||||
)))
|
||||
(if (eq? v 'null)
|
||||
#f
|
||||
v)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#|(define/contract (webview-set-style! wv selector style-entries)
|
||||
(-> wv? (or/c symbol? string?) (or/c list? list-of-kv?) hash?)
|
||||
|
||||
(define (webview-set-style!* wv selector h)
|
||||
@@ -435,7 +540,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|#
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; testing
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
fromJson
|
||||
mk-js-array
|
||||
js-code
|
||||
kv?
|
||||
list-of-kv?
|
||||
list-of-symbol?
|
||||
list-of?
|
||||
)
|
||||
|
||||
(define-syntax while
|
||||
@@ -82,12 +85,14 @@
|
||||
(with-input-from-string str read-json))
|
||||
|
||||
(define (mk-js-array l)
|
||||
(if (list? l)
|
||||
(string-append "[ " (string-join (map (λ (e) (format "'~a'"
|
||||
(esc-quote (format "~a" e)))) l) ", ") " ]")
|
||||
(format "[ '~a' ]" (esc-quote (format "~a" l)))
|
||||
)
|
||||
)
|
||||
(if (list-of-kv? l)
|
||||
(string-append "[ " (string-join (map (λ (e) (mk-js-array e)) l) ", ") " ]")
|
||||
(if (list? l)
|
||||
(string-append "[ " (string-join (map (λ (e) (format "'~a'"
|
||||
(esc-quote (format "~a" e)))) l) ", ") " ]")
|
||||
(if (pair? l)
|
||||
(format "[ '~a', '~a' ]" (car l) (cdr l))
|
||||
(format "[ '~a' ]" (esc-quote (format "~a" l)))))))
|
||||
|
||||
(define (js-code . a)
|
||||
(define (code* l)
|
||||
@@ -97,21 +102,26 @@
|
||||
)
|
||||
)
|
||||
(code* a))
|
||||
|
||||
|
||||
(define (list-of-kv? l)
|
||||
(define (kv? e)
|
||||
(let ((e (car l)))
|
||||
(and (list? e)
|
||||
(= (length e) 2)
|
||||
(symbol? (car e)))))
|
||||
(define (all-kv? l)
|
||||
(define (kv? e)
|
||||
(or
|
||||
(and (list? e) (= (length e) 2) (symbol? (car e)))
|
||||
(and (pair? e) (symbol? (car e)))))
|
||||
|
||||
(define (list-of? pred? l)
|
||||
(define (all-pred? l)
|
||||
(if (null? l)
|
||||
#t
|
||||
(if (kv? (car e))
|
||||
(all-kv? (cdr l))
|
||||
(if (pred? (car l))
|
||||
(all-pred? (cdr l))
|
||||
#f)))
|
||||
(if (list? l)
|
||||
(all-kv? l)
|
||||
(all-pred? l)
|
||||
#f))
|
||||
|
||||
(define (list-of-kv? l)
|
||||
(list-of? kv? l))
|
||||
|
||||
(define (list-of-symbol? l)
|
||||
(list-of? symbol? l))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user