Domonic: DOM

The DOM is gradually evolving…

createElement

Here’s an exmaple of creating your own elements using the DOM API

from domonic.dom import *

site = html()
el = document.createElement('myelement')
site.appendChild(el)
print(site)

See the examples folder for other uses of a python virtual DOM.

A full list of available methods are below…

domonic.dom

methods on the dom

class domonic.dom.ChildNode(*args, **kwargs)[source]

not tested yet

after(newChild)[source]

Inserts a newChild node immediately after this ChildNode.

before(newChild)[source]

Inserts a newChild node immediately before this ChildNode.

remove()[source]

Removes this ChildNode from the children list of its parent.

replaceWith(newChild)[source]

Replaces this ChildNode with a new one.

class domonic.dom.Document(*args, **kwargs)[source]

Baseclass for the html tag

anchors()[source]

Returns a collection of all <a> elements in the document that have a name attribute

applets()[source]

Returns a collection of all <applet> elements in the document

body

returns the document’s body (the <body> element)

characterSet

Returns the character encoding for the document

charset

Use characterSet instead.

Type:Returns the character encoding for the document. Deprecated
static createAttribute(name)[source]

Creates an attribute node

static createComment(message)[source]

Creates a Comment node with the specified text

static createElement(_type)[source]

Creates an Element node - WARNING THIS WILL NOT CREATE A ‘DOMONIC ELEMENT’ (yet), so it wont have features

static createEvent(event_type=None)[source]

Creates a new event

static createTextNode(text)[source]

Creates a Text node

doctype

Returns the Document Type Declaration associated with the document

domain()[source]

Returns the domain name of the server that loaded the document

embeds

Returns a collection of all <embed> elements the document

forms

Returns a collection of all <form> elements in the document

fullscreenElement()[source]

Returns the current element that is displayed in fullscreen mode

fullscreenEnabled()[source]

Returns a Boolean value indicating whether the document can be viewed in fullscreen mode

getElementById(_id)[source]

Returns the element that has the ID attribute with the specified value

getElementsByName(name)[source]

Returns a NodeList containing all elements with a specified name

head

Returns the <head> element of the document

images

Returns a collection of all <img> elements in the document

implementation

Returns the DOMImplementation object that handles this document

links()[source]

Returns a collection of all <a> and <area> elements in the document that have a href attribute

normalizeDocument()[source]

Removes empty Text nodes, and joins adjacent nodes

renameNode(node, namespaceURI, nodename)[source]

Renames the specified node

scripts

Returns a collection of <script> elements in the document

title

Sets or returns the title of the document

write(html: str = '') → None[source]

Writes HTML expressions or JavaScript code to a document

writeln(html: str = '') → None[source]

Same as write(), but adds a newline character after each statement

class domonic.dom.Element(*args, **kwargs)[source]

Baseclass for all html tags

attributes

Returns a List of an element’s attributes

blur()[source]

Removes focus from an element

classList

Returns the value of the classList attribute of an element

className

Sets or returns the value of the className attribute of an element

click()[source]

Simulates a mouse-click on an element

clientHeight

Returns the height of an element, including padding

clientLeft

Returns the width of the left border of an element

clientTop

Returns the width of the top border of an element

clientWidth

Returns the width of an element, including padding

contentEditable()[source]

Sets or returns whether the content of an element is editable or not

dir

returns the value of the dir attribute of an element

exitFullscreen()[source]

Cancels an element in fullscreen mode

firstElementChild()[source]

Returns the first child element of an element

focus()[source]

Gives focus to an element

getAttribute(attribute: str) → str[source]

Returns the specified attribute value of an element node

getAttributeNode(attribute: str) → str[source]

Returns the specified attribute node

getBoundingClientRect()[source]

Returns the size of an element and its position relative to the viewport

getElementsByClassName(className)[source]

Returns a collection of all child elements with the specified class name

getElementsBySelector(all_selectors, document)[source]

Get DOM elements based on the given CSS Selector https://simonwillison.net/2003/Mar/25/getElementsBySelector/ < original author http://www.openjs.com/scripts/dom/css_selector/ < ported to support ‘,’ https://bin-co.com/python/scripts/getelementsbyselector-html-css-query.php < ported to py2 (broken/bugs) BSD LICENSED

note - always needs a tag in the query i.e. (‘a.classname’) will work. but just (‘.classname’) wont

fixed and ported to py3 here. quite cool means other peoples code works on my dom :) # TODO - needs to work in conjuctions with _matchElement so querySelector works a bit better and dQuery picks it up # TOOD - *= node content

Parameters:
  • all_selectors ([type]) – [description]
  • document ([type]) – [description]
Returns:

[description]

Return type:

[type]

getElementsByTagName(tag: str) → List[T][source]

Returns a collection of all child elements with the specified tag name

hasAttribute(attribute: str) → str[source]

Returns true if an element has the specified attribute, otherwise false

hasAttributes() → bool[source]

Returns true if an element has any attributes, otherwise false

id

Sets or returns the value of the id attribute of an element

innerHTML

Sets or returns the content of an element

insertAdjacentElement(position: str, element)[source]

Inserts an element adjacent to the current element

insertAdjacentHTML(position: str, html: str)[source]

Inserts raw HTML adjacent to the current element

insertAdjacentText(position: str, text: str)[source]

Inserts text adjacent to the current element

isContentEditable()[source]

Returns true if the content of an element is editable, otherwise false

isDefaultNamespace()[source]

Returns true if a specified namespaceURI is the default, otherwise false

lang()[source]

Sets or returns the value of the lang attribute of an element

lastElementChild()[source]

Returns the last child element of an element

matches(s: str)[source]

[checks to see if the Element would be selected by the provided selectorString]

Parameters:s (str) – [css selector]
Returns:[True if selector maches Element otherwise False]
Return type:[bool]
namespaceURI()[source]

Returns the namespace URI of an element

nextElementSibling

Returns the next element at the same node tree level

nextSibling

Returns the next node at the same node tree level

normalize()[source]

Joins adjacent text nodes and removes empty text nodes in an element

offsetHeight()[source]

Returns the height of an element, including padding, border and scrollbar

offsetLeft()[source]

Returns the horizontal offset position of an element

offsetParent()[source]

Returns the offset container of an element

offsetTop()[source]

Returns the vertical offset position of an element

offsetWidth()[source]

Returns the width of an element, including padding, border and scrollbar

ownerDocument

Returns the root element (document object) for an element

parentElement

Returns the parent element node of an element

previousElementSibling

Returns the previous element at the same node tree level

previousSibling

Returns the previous node at the same node tree level

querySelector(query)[source]

Returns the first child element that matches a specified CSS selector(s) of an element

querySelectorAll(query)[source]

Returns all child elements that matches a specified CSS selector(s) of an element

remove()[source]

Removes the element from the DOM

removeAttribute(attribute: str)[source]

Removes a specified attribute from an element

removeAttributeNode(attribute)[source]

Removes a specified attribute node, and returns the removed node

requestFullscreen()[source]

Shows an element in fullscreen mode

scrollHeight()[source]

Returns the entire height of an element, including padding

scrollIntoView()[source]

Scrolls the specified element into the visible area of the browser window

scrollLeft()[source]

Sets or returns the number of pixels an element’s content is scrolled horizontally

scrollTop()[source]

Sets or returns the number of pixels an element’s content is scrolled vertically

scrollWidth()[source]

Returns the entire width of an element, including padding

setAttribute(attribute, value)[source]

Sets or changes the specified attribute, to the specified value

setAttributeNode(attr)[source]

Sets or changes the specified attribute node

style

returns the value of the style attribute of an element

textContent

Sets or returns the textual content of a node and its descendants

title

Sets or returns the value of the title attribute of an element

toString()[source]

Converts an element to a string

class domonic.dom.EventTarget(*args, **kwargs)[source]

Baseclass for Node

class domonic.dom.Node(*args, **kwargs)[source]

Element extends from Node

appendChild(item)[source]

Adds a new child node, to an element, as the last child node

childElementCount

Returns the number of child elements an element has

childNodes

Returns a collection of an element’s child nodes (including text and comment nodes)

children

Returns a collection of an element’s child element (excluding text and comment nodes)

cloneNode(deep=True)[source]

Returns a copy.

compareDocumentPosition(otherElement)[source]

Compares the document position of two elements

contains(node)[source]

Check whether a node is a descendant of a given node

firstChild

Returns the first child node of an element

getNextSibling()[source]

Returns the next sibling of an element.

getPreviousSibling()[source]

Returns the previous sibling of an element.

hasChildNodes

Returns true if an element has any child nodes, otherwise false

insertBefore(new_node, reference_node)[source]

inserts a node before a reference node as a child of a specified parent node.

isDefaultNamespace(ns)[source]

Checks if a namespace is the default namespace

isEqualNode(node)[source]

Checks if two elements are equal

isSameNode(node)[source]

Checks if two elements are the same node

lastChild

Returns the last child node of an element

lookupNamespaceURI(ns)[source]

Returns the namespace URI for a given prefix

lookupPrefix(ns)[source]

Returns the prefix for a given namespace URI

nodeName

Returns the name of a node

nodeType

Returns the node type of a node

nodeValue

Sets or returns the value of a node

normaliz()[source]

Normalize a node’s value

removeChild(node)[source]

removes a child node from the DOM and returns the removed node.

replaceChild(newChild, oldChild)[source]

Replaces a child node within the given (parent) node.

rootNode

[read-only property returns a Node object representing the topmost node in the tree, or the current node if it’s the topmost node in the tree]

Returns:[the topmost Node in the tree]
Return type:[Node]
class domonic.dom.NodeList[source]
entries()[source]

Returns an iterator, allowing code to go through all key/value pairs contained in the collection. (In this case, the keys are numbers starting from 0 and the values are nodes.

forEach(func)[source]

Executes a provided function once per NodeList element, passing the element as an argument to the function.

item(index)[source]

Returns an item in the list by its index, or null if the index is out-of-bounds.

keys()[source]

Returns an iterator, allowing code to go through all the keys of the key/value pairs contained in the collection. (In this case, the keys are numbers starting from 0.)

values()[source]

Returns an iterator allowing code to go through all values (nodes) of the key/value pairs contained in the collection.

class domonic.dom.ParentNode(*args, **kwargs)[source]

not tested yet

class domonic.dom.ShadowRoot(host, mode='open')[source]

property on element that has hidden DOM

caretPositionFromPoint()[source]

Returns a CaretPosition object containing the DOM node containing the caret, and caret’s character offset within that node.

elementFromPoint()[source]

Returns the topmost element at the specified coordinates.

elementsFromPoint()[source]

Returns an array of all elements at the specified coordinates.

getSelection()[source]

Returns a Selection object representing the range of text selected by the user, or the current position of the caret.

class domonic.dom.TextNode(*args, **kwargs)[source]

not tested

textContent

Sets or returns the textual content of a node and its descendants

domonic.dom.document

alias of domonic.dom.Document

domonic.events

dom events

class domonic.events.AnimationEvent(_type, *args, **kwargs)[source]
ANIMATIONEND = 'animationend'
ANIMATIONITERATION = 'animationiteration'
ANIMATIONSTART = 'animationstart'
animationName = None

Returns the name of the animation

elapsedTime = None

Returns the number of seconds an animation has been running

pseudoElement = None

Returns the name of the pseudo-element of the animation

class domonic.events.BeforeUnloadEvent(_type, *args, **kwargs)[source]
BEFOREUNLOAD = 'beforeunload'

BeforeUnloadEvent

class domonic.events.ClipboardEvent(_type, *args, **kwargs)[source]
COPY = 'copy'
CUT = 'cut'
PASTE = 'paste'
clipboardData = None

Returns an object containing the data affected by the clipboard operation

class domonic.events.CompositionEvent(_type, *args, **kwargs)[source]
data = None

Returns the characters generated by the input method that raised the event

class domonic.events.CustomEvent(_type, *args, **kwargs)[source]
class domonic.events.DragEvent(_type, *args, **kwargs)[source]
DRAG = 'drag'
DROP = 'drop'
END = 'dragend'
ENTER = 'dragenter'
EXIT = 'dragexit'
LEAVE = 'dragleave'
OVER = 'dragover'
START = 'dragstart'
dataTransfer = None

Returns the data that is dragged/dropped

class domonic.events.ErrorEvent(_type, *args, **kwargs)[source]
ERROR = 'error'
class domonic.events.Event(_type=None, *args, **kwargs)[source]

event

ABORT = 'abort'
AFTERPRINT = 'afterprint'
BEFOREPRINT = 'beforeprint'
BEFOREUNLOAD = 'beforeunload'
CANPLAY = 'canplay'
CANPLAYTHROUGH = 'canplaythrough'
CHANGE = 'change'
DURATIONCHANGE = 'durationchange'
EMPTIED = 'emptied'
ENDED = 'ended'
ERROR = 'error'
FULLSCREENCHANGE = 'fullscreenchange'
FULLSCREENERROR = 'fullscreenerror'
INPUT = 'input'
INVALID = 'invalid'
LOAD = 'load'
LOADEDDATA = 'loadeddata'
LOADEDMETADATA = 'loadedmetadata'
MESSAGE = 'message'
OFFLINE = 'offline'
ONLINE = 'online'
OPEN = 'open'
PAUSE = 'pause'
PLAY = 'play'
PLAYING = 'playing'
PROGRESS = 'progress'
RATECHANGE = 'ratechange'
RESET = 'reset'
RESIZE = 'resize'
SCROLL = 'scroll'
SEARCH = 'search'
SEEKED = 'seeked'
SEEKING = 'seeking'
SELECT = 'select'
SHOW = 'show'
STALLED = 'stalled'
SUBMIT = 'submit'
SUSPEND = 'suspend'
TOGGLE = 'toggle'
UNLOAD = 'unload'
VOLUMECHANGE = 'volumechange'
WAITING = 'waiting'
stopPropagation()[source]

[prevents further propagation of the current event in the capturing and bubbling phases]

class domonic.events.EventDispatcher(*args, **kwargs)[source]

EventDispatcher is a class you can extend to give your obj event dispatching abilities

class domonic.events.FocusEvent(_type, *args, **kwargs)[source]
BLUR = 'blur'
FOCUS = 'focus'
FOCUSIN = 'focusin'
FOCUSOUT = 'focusout'
class domonic.events.GamePadEvent(_type, *args, **kwargs)[source]
START = 'gamepadconnected'
STOP = 'gamepaddisconnected'
class domonic.events.HashChangeEvent(_type, *args, **kwargs)[source]
CHANGE = 'hashchange'
class domonic.events.InputEvent(_type, *args, **kwargs)[source]
data = None

Returns the inserted characters

class domonic.events.KeyboardEvent(_type, *args, **kwargs)[source]

keyboard events

KEYDOWN = 'keydown'
KEYPRESS = 'keypress'
KEYUP = 'keyup'
class domonic.events.MouseEvent(_type, *args, **kwargs)[source]

mouse events

CLICK = 'click'
CONTEXTMENU = 'contextmenu'
DBLCLICK = 'dblclick'
MOUSEDOWN = 'mousedown'
MOUSEENTER = 'mouseenter'
MOUSELEAVE = 'mouseleave'
MOUSEMOVE = 'mousemove'
MOUSEOUT = 'mouseout'
MOUSEOVER = 'mouseover'
MOUSEUP = 'mouseup'
class domonic.events.PageTransitionEvent(_type, *args, **kwargs)[source]
PAGEHIDE = 'pagehide'
PAGESHOW = 'pageshow'
persisted = None

Returns whether the webpage was cached by the browser

class domonic.events.PointerEvent(_type, *args, **kwargs)[source]
POINTER = 'pointer'
class domonic.events.PopStateEvent(_type, *args, **kwargs)[source]
state = None

Returns an object containing a copy of the history entries

class domonic.events.ProgressEvent(_type, *args, **kwargs)[source]
LOADSTART = 'loadstart'
class domonic.events.SVGEvent(_type, *args, **kwargs)[source]
class domonic.events.StorageEvent(_type, *args, **kwargs)[source]
key = None

Returns the key of the changed storage item

newValue = None

Returns the new value of the changed storage item

oldValue = None

Returns the old value of the changed storage item

storageArea = None

Returns an object representing the affected storage object

url = None

Returns the URL of the changed item’s document

class domonic.events.SubmitEvent(_type, *args, **kwargs)[source]
SUBMIT = 'submit'
class domonic.events.TimerEvent(_type, *args, **kwargs)[source]
TIMER = 'timer'

TimerEvent

class domonic.events.TouchEvent(_type, *args, **kwargs)[source]
TOUCHCANCEL = 'touchcancel'
TOUCHEND = 'touchend'
TOUCHMOVE = 'touchmove'
TOUCHSTART = 'touchstart'
class domonic.events.TransitionEvent(_type, *args, **kwargs)[source]
TRANSITIONEND = 'transitionend'
elapsedTime = None

Returns the number of seconds a transition has been running

propertyName = None

Returns the name of the transition

pseudoElement = None

Returns the name of the pseudo-element of the transition

class domonic.events.TweenEvent(_type, source=None, bubbles=False, cancelable=False)[source]
COMPLETE = 'onComplete'
PAUSE = 'onPause'
RESET = 'onReset'
START = 'onStart'
STOP = 'onStop'
TIMER = 'onTimer'
UNPAUSE = 'onUnPause'
UPDATE_END = 'onUpdateEnd'
UPDATE_START = 'onUpdateStart'
class domonic.events.UIEvent(_type, *args, **kwargs)[source]
class domonic.events.WheelEvent(_type, *args, **kwargs)[source]
WHEEL = 'wheel'