wv-element
| (require wv-element) |
DOM element wrapper used by the window layer.
This module exports the wv-element% class. Instances of this class represent one DOM element within a wv-window% and provide a small object-oriented interface for event dispatch, content replacement, CSS class manipulation, style access, and attribute access.
1 Overview
A wv-element% object is associated with:
one window
one DOM element identifier
The class delegates DOM operations to the JavaScript-based API from racket-webview. The accepted argument shapes and result values of its methods therefore follow the contracts of those lower-level functions.
The class also stores per-element event callbacks used by wv-window% when dispatching JavaScript events received from the browser.
2 Class: wv-element%
constructor
(new wv-element% [window window] [element-id element-id]) → (is-a?/c wv-element%) window : (is-a?/c wv-window%) element-id : symbol? Creates an element wrapper.window is the owning window object. element-id is the DOM element identifier used in calls to the lower-level DOM manipulation functions.
Returns the element id.
method
(send a-wv-element add-event-callback! evt cb) → void? evt : symbol? cb : procedure? Associates cb with evt.If a callback was already stored for evt, it is replaced.
Removes the callback associated with evt, if any.
method
(send a-wv-element event-callback-count) → exact-integer?
Returns the number of registered event callbacks.
method
(send a-wv-element dispatch-event evt data)
→ (or/c 'wv-unhandled-js-event 'wv-handled-js-event) evt : symbol? data : any/c Dispatches an event to the callback registered for evt.If no callback is registered, the method returns 'wv-unhandled-js-event.
If a callback is found, it is invoked as:
(cb this evt data)
and the method returns 'wv-handled-js-event.
Sets the innerHTML of this element using JavaScript and returns this element.The operation delegates to:
(webview-set-innerHTML! wv element-id html)
Adds one or more CSS classes to this element.The accepted values follow the contract of webview-add-class!. The operation delegates to:
(webview-add-class! wv element-id cl)
Removes one or more CSS classes from this element.The accepted values follow the contract of webview-remove-class!. The operation delegates to:
(webview-remove-class! wv element-id cl)
Gets or sets the CSS display property of this element.If no argument is supplied, the current value is returned by delegating to:
(webview-get-style wv element-id 'display)
If an argument is supplied, only the first argument is used. The value may be a symbol or string and is converted internally before being passed to webview-set-style!.
The resulting style value is then read back and returned.
Gets or sets the CSS visibility property of this element.If no argument is supplied, the current value is returned by delegating to:
(webview-get-style wv element-id 'visibility)
If an argument is supplied, only the first argument is used. The value may be a symbol or string and is converted internally before being passed to webview-set-style!.
The resulting style value is then read back and returned.
method
(send a-wv-element set-style! styles) → any/c
styles : (or/c kv? list-of-kv?) Sets one or more inline style properties on this element.The accepted values follow the contract of webview-set-style!. The method delegates to:
(webview-set-style! wv element-id styles)
Clears one or more inline style properties on this element.The accepted values follow the contract of webview-unset-style!. The method delegates to:
(webview-unset-style! wv element-id styles)
method
(send a-wv-element set-attr! attr-entries) → any/c
attr-entries : (or/c kv? list-of-kv?) Sets one or more attributes on this element.The accepted values follow the contract of webview-set-attr!. The method delegates to:
(webview-set-attr! wv element-id attr-entries)
Returns the value of the attribute identified by attr.The result follows the contract of webview-attr. If the underlying JavaScript result is null, the lower layer returns #f.
The method delegates to:
(webview-attr wv element-id attr)
Returns the attribute value converted to a number.The method delegates to:
(webview-attr/number wv element-id attr)
Returns the attribute value converted to a symbol.The method delegates to:
(webview-attr/symbol wv element-id attr)
Returns the attribute value converted to a boolean.The method delegates to:
(webview-attr/boolean wv element-id attr)
Returns the attribute value converted to a date.The method delegates to:
(webview-attr/date wv element-id attr)
Returns the attribute value converted to a time.The method delegates to:
(webview-attr/time wv element-id attr)
Returns the attribute value converted to a datetime.The method delegates to:
(webview-attr/datetime wv element-id attr)