wv-element
1 Overview
2 Class:   wv-element%
wv-element%
new
id
add-event-callback!
remove-event-callback!
event-callback-count
dispatch-event
set-inner  HTML!
add-class!
remove-class!
display
visibility
set-style!
unset-style!
set-attr!
attr
attr/  number
attr/  symbol
attr/  boolean
attr/  date
attr/  time
attr/  datetime
9.1

wv-element🔗ℹ

Hans Dijkema <hans@dijkewijk.nl>

 (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%🔗ℹ

class

wv-element% : class?

  superclass: object%

Represents one DOM element identified by its id.
The class stores the owning window and the element id supplied at construction time. It also maintains an internal hash table mapping event symbols to callbacks.

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.

method

(send a-wv-element id)  symbol?

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.

method

(send a-wv-element remove-event-callback! evt)  void?

  evt : symbol?
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.

method

(send a-wv-element set-innerHTML! html)  (is-a?/c wv-element%)

  html : (or/c string? xexpr?)
Sets the innerHTML of this element using JavaScript and returns this element.

The operation delegates to:

(webview-set-innerHTML! wv element-id html)

method

(send a-wv-element add-class! cl)  any/c

  cl : (or/c symbol? string? list?)
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)

method

(send a-wv-element remove-class! cl)  any/c

  cl : (or/c symbol? string? list?)
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)

method

(send a-wv-element display d ...)  any/c

  d : (or/c symbol? string?)
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.

method

(send a-wv-element visibility v ...)  any/c

  v : (or/c symbol? string?)
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)

method

(send a-wv-element unset-style! styles)  any/c

  styles : (or/c symbol? list-of-symbol?)
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)

method

(send a-wv-element attr attr)  (or/c string? boolean?)

  attr : (or/c symbol? string?)
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)

method

(send a-wv-element attr/number attr)  (or/c number? #f)

  attr : (or/c symbol? string?)
Returns the attribute value converted to a number.

The method delegates to:

(webview-attr/number wv element-id attr)

method

(send a-wv-element attr/symbol attr)  (or/c symbol? #f)

  attr : (or/c symbol? string?)
Returns the attribute value converted to a symbol.

The method delegates to:

(webview-attr/symbol wv element-id attr)

method

(send a-wv-element attr/boolean attr)  (or/c boolean? #f)

  attr : (or/c symbol? string?)
Returns the attribute value converted to a boolean.

The method delegates to:

(webview-attr/boolean wv element-id attr)

method

(send a-wv-element attr/date attr)  any/c

  attr : (or/c symbol? string?)
Returns the attribute value converted to a date.

The method delegates to:

(webview-attr/date wv element-id attr)

method

(send a-wv-element attr/time attr)  any/c

  attr : (or/c symbol? string?)
Returns the attribute value converted to a time.

The method delegates to:

(webview-attr/time wv element-id attr)

method

(send a-wv-element attr/datetime attr)  any/c

  attr : (or/c symbol? string?)
Returns the attribute value converted to a datetime.

The method delegates to:

(webview-attr/datetime wv element-id attr)