dQuery

dQuery is for querying and manipulating your server-side dom.

querying

dQuery uses the º symbol (alt+0).

    from domonic.html import *
    from domonic.dQuery import º

d = html(head(body(li(_class='things'), div(_id="test"))))

º(d) # you need to init a dom first. i.e. a html element

# now you can use it
print( º('#test') )
print( º('.things') )
a = º('<div class="test2"></div>')
print( a )

b = º('#test').append(a)
print(b)

You can quickly access returned elements as if it were a list…

somehtml = º('<html><table id="mytable" class="one"></table></html>')
str(º('html')[0])

But you don’t need a DOM fragment to use dquery. It also contains useful static methods. i.e.

first = ["a", "b", "c"]
second = ["d", "e", "f"]
result = º.merge(first, second)
print(result)

obj1 = {'a':1,'b':2}
obj2 = {'c':1,'b':5}
print(º.extend(obj1,obj2))

print(º.trim("  some tst \n   TEST."))

print(º.now())

domonic.dQuery

alt + 0

domonic.dQuery.dQuery

alias of o

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

alt + 0

dQuery - methods for querying domonic

add(elements)[source]

Create a new dQuery object with elements added to the set of matched elements.

addBack(selector)[source]

Add the previous set of elements on the stack to the current set, optionally filtered by a selector.

addClass(name: str)[source]

Adds the specified class to each element in the set of matched elements.

after(newnode)[source]

Insert content, specified by the parameter, after each element in the set of matched elements.

ajaxComplete(handler)[source]

Register a handler to be called when Ajax requests complete. This is an Ajax Event

ajaxError(handler)[source]

Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event

ajaxSend(handler)[source]

Register a handler to be called when Ajax requests complete successfully. This is an Ajax Event

ajaxStart(handler)[source]

Register a handler to be called when the first Ajax request begins. This is an Ajax Event

ajaxStop(handler)[source]

Register a handler to be called when all Ajax requests have completed. This is an Ajax Event

ajaxSuccess(handler)[source]

Attach a function to be executed whenever an Ajax request completes successfully. This is an Ajax Event.

andSelf()[source]

Add the previous set of elements on the stack to the current set.

animate()[source]

Perform a custom animation of a set of CSS properties.

append(html)[source]

Insert content, specified by the parameter, to the end of each element in the set of matched elements.

appendTo(target)[source]

Insert every element in the set of matched elements to the end of the target.

attr(property, value=None)[source]

Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.

before(content)[source]

Insert content, specified by the parameter, before each element in the set of matched elements.

bind(event, handler)[source]

Attach a function to be executed when an event occurs on a set of matched elements.

blur(handler)[source]

Bind an event handler to the “blur” JavaScript event, or trigger that event on an element.

change(handler)[source]

Bind an event handler to the “change” JavaScript event, or trigger that event on an element.

children(selector=None)[source]

Get the children of each element in the set of matched elements, optionally filtered by a selector.

clearQueue()[source]

Remove from the queue all items that have not yet been run.

click(handler)[source]

Bind an event handler to the “click” JavaScript event, or trigger that event on an element.

clone()[source]

Create a deep copy of the set of matched elements.

closest(selector=None)[source]

For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

contents(selector=None)[source]

Get the children of each element in the set of matched elements, including text and comment nodes.

property context

The DOM node context originally passed to dQuery if none was passed then context will likely be the document.

contextmenu()[source]

Bind an event handler to the “contextmenu” JavaScript event, or trigger that event on an element.

css(property, value=None)[source]

Get the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.

data(key, value=None)[source]

Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.

dblclick(handler)[source]

Bind an event handler to the “dblclick” JavaScript event, or trigger that event on an element.

delay(time)[source]

Set a timer to delay execution of subsequent items in the queue.

delegate(selector, event, handler)[source]

Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

dequeue()[source]

Execute the next function on the queue for the matched elements.

detach()[source]

Remove the set of matched elements from the DOM.

die()[source]

Remove event handlers previously attached using .live from the elements.

each(func)[source]

Iterate over a dQuery object, executing a function for each matched element.

empty()[source]

Remove all child nodes of the set of matched elements from the DOM.

end()[source]

End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.

eq(index)[source]

Reduce the set of matched elements to the one at the specified index.

error(handler)[source]

Bind an event handler to the “error” JavaScript event.

even()[source]

Reduce the set of matched elements to the even ones in the set, numbered from zero.

fadeIn()[source]

Display the matched elements by fading them to opaque.

fadeOut()[source]

Hide the matched elements by fading them to transparent.

fadeTo()[source]

Adjust the opacity of the matched elements.

fadeToggle()[source]

Display or hide the matched elements by animating their opacity.

filter(selector)[source]

Reduce the set of matched elements to those that match the selector or pass the function’s test.

find(selector)[source]

Get the descendants of each element in the current set of matched elements, filtered by a selector, dQuery object, or element.

finish()[source]

Stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements.

first()[source]

Reduce the set of matched elements to the first in the set.

focus()[source]

Bind an event handler to the “focus” JavaScript event, or trigger that event on an element.

focusin()[source]

Bind an event handler to the “focusin” event.

focusout()[source]

Bind an event handler to the “focusout” JavaScript event.

has(selector)[source]

Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.

hasClass(classname)[source]

Determine whether any of the matched elements are assigned the given class.

height()[source]

Get the current computed height for the first element in the set of matched elements or set the height of every matched element.

hide()[source]

Hide the matched elements.

hover()[source]

Bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.

html(html=None)[source]

Get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element.

index()[source]

Search for a given element from among the matched elements.

innerHeight()[source]

Get the current computed inner height (including padding but not border) for the first element in the set of matched elements or set the inner height of every matched element.

innerWidth()[source]

Get the current computed inner width (including padding but not border) for the first element in the set of matched elements or set the inner width of every matched element.

insertAfter(target)[source]

Insert the matched elements after the specified target element.

insertBefore(target)[source]

Insert every element in the set of matched elements before the target.

keydown()[source]

Bind an event handler to the “keydown” JavaScript event, or trigger that event on an element.

keypress()[source]

Bind an event handler to the “keypress” JavaScript event, or trigger that event on an element.

keyup()[source]

Bind an event handler to the “keyup” JavaScript event, or trigger that event on an element.

last()[source]

Reduce the set of matched elements to the final one in the set.

property length

The number of elements in the dQuery object.

live()[source]

Attach an event handler for all elements which match the current selector, now and in the future.

load(url, data=None, complete=None)[source]

Load data from the server and place the returned HTML into the matched elements.

map(func)[source]

Pass each element in the current matched set through a function, producing a new dQuery object containing the return values.

mousedown()[source]

Bind an event handler to the “mousedown” JavaScript event, or trigger that event on an element.

mouseenter()[source]

Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.

mouseleave()[source]

Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element.

mousemove()[source]

Bind an event handler to the “mousemove” JavaScript event, or trigger that event on an element.

mouseout()[source]

Bind an event handler to the “mouseout” JavaScript event, or trigger that event on an element.

mouseover()[source]

Bind an event handler to the “mouseover” JavaScript event, or trigger that event on an element.

mouseup()[source]

Bind an event handler to the “mouseup” JavaScript event, or trigger that event on an element.

next(selector)[source]

Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.

nextAll(selector)[source]

Get all following siblings of each element in the set of matched elements, optionally filtered by a selector.

nextUntil(selector)[source]

Get all following siblings of each element up to but not including the element matched by the selector, DOM node, or dQuery object passed.

odd()[source]

Reduce the set of matched elements to the odd ones in the set, numbered from zero.

off(event)[source]

Remove an event handler.

offset(coordinates)[source]

Get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.

offsetParent()[source]

Get the closest ancestor element that is positioned.

on(event, callback)[source]

Attach an event handler function for one or more events to the selected elements.

one()[source]

Attach a handler to an event for the elements. The handler is executed at most once per element per event type.

outerHeight()[source]

Get the current computed outer height (including padding, border, and optionally margin) for the first element in the set of matched elements or set the outer height of every matched element.

outerWidth()[source]

Get the current computed outer width (including padding, border, and optionally margin) for the first element in the set of matched elements or set the outer width of every matched element.

parent(selector)[source]

Get the parent of each element in the current set of matched elements, optionally filtered by a selector.

parents(selector)[source]

Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.

parentsUntil(selector)[source]

Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector, DOM node, or dQuery object.

position()[source]

Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.

prepend(html)[source]

Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.

prependTo(target)[source]

Insert every element in the set of matched elements to the beginning of the target.

prev(selector)[source]

Get the immediately preceding sibling of each element in the set of matched elements. If a selector is provided, it retrieves the previous sibling only if it matches that selector.

prevAll(selector)[source]

Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.

prevUntil(selector)[source]

Get all preceding siblings of each element up to but not including the element matched by the selector, DOM node, or dQuery object.

promise()[source]

Return a Promise object to observe when all actions of a certain type bound to the collection, queued or not, have finished.

prop(property, value)[source]

Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element.

pushStack(stack)[source]

Add a collection of DOM elements onto the dQuery.

queue()[source]

Show or manipulate the queue of functions to be executed on the matched elements.

ready(callback)[source]

Specify a function to execute when the DOM is fully loaded.

remove(items)[source]

Remove the set of matched elements from the DOM.

removeAttr(attr: str)[source]

Remove an attribute from each element in the set of matched elements.

removeClass(classname: str)[source]

Remove a single class, multiple classes, or all classes from each element in the set of matched elements.

removeData(name: str)[source]

Remove a previously-stored piece of data.

removeProp(prop: str)[source]

Remove a property for the set of matched elements.

replaceAll(elements)[source]

Replace each target element with the set of matched elements.

replaceWith(replacement)[source]

Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.

resize(callback)[source]

Bind an event handler to the “resize” JavaScript event, or trigger that event on an element.

scroll(callback)[source]

Bind an event handler to the “scroll” JavaScript event, or trigger that event on an element.

scrollLeft()[source]

Get the current horizontal position of the scroll bar for the first element in the set of matched elements or set the horizontal position of the scroll bar for every matched element.

scrollTop()[source]

Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.

select(selector)[source]

Bind an event handler to the “select” JavaScript event, or trigger that event on an element.

serialize()[source]

Encode a set of form elements as a string for submission.

serializeArray(array)[source]

Encode an array of form elements as a string for submission.

show()[source]

Display the matched elements.

siblings(selector)[source]

Return the siblings of the matched elements. filter by selector.

size()[source]

Return the number of elements in the dQuery object.

slice(start, end)[source]

Return a new dQuery object containing the set of matched elements starting at the specified index and ending at the specified index.

slideDown()[source]

Display the matched elements with a sliding motion.

slideToggle()[source]

Display or hide the matched elements with a sliding motion.

slideUp()[source]

Hide the matched elements with a sliding motion.

stop()[source]

Stop the currently-running animation on the matched elements.

submit()[source]

Bind an event handler to the “submit” JavaScript event, or trigger that event on an element.

text(newVal: Optional[str] = None)[source]

Get the combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.

toArray()[source]

Retrieve all the elements contained in the dQuery set, as an array.

toggle()[source]

Display or hide the matched elements.

toggleClass(className)[source]

Add or remove one or more classes from each element in the set of matched elements

trigger(eventName, eventArg=None)[source]

Execute all handlers and behaviors attached to the matched elements for the given event type.

triggerHandler()[source]

Execute all handlers attached to an element for an event.

unbind()[source]

Remove a previously-attached event handler from the elements.

undelegate()[source]

Remove a handler from the event for all elements which match the current selector, based upon a specific set of root elements.

unload()[source]

Bind an event handler to the “unload” JavaScript event.

unwrap()[source]

Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.

val(newVal=None)[source]

Get the current value of the first element in the set of matched elements or set the value of every matched element.

width()[source]

Get the current computed width for the first element in the set of matched elements or set the width of every matched element.

wrap(wrappingElement)[source]

Wrap an HTML structure around each element in the set of matched elements.

wrapAll(wrappingElement)[source]

Wrap an HTML structure around all elements in the set of matched elements.

wrapInner()[source]

Wrap an HTML struct

class domonic.dQuery.o(selector=None, *args, **kwargs)
static Callbacks()

A multi-purpose callbacks list object that provides a powerful way to manage callback lists.

static Deferred()

A factory function that returns a chainable utility object with methods to register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.

static ajax(url='/', type='GET', data=None, contentType=False, processData=False, cache=False, success=None, error=None)

make an ajax request

static ajaxPrefilter()

Handle custom Ajax options or modify existing options before each request is sent and before they are processed by .ajax

static ajaxSetup()

Set default values for future Ajax requests. Its use is not recommended.

static ajaxTransport()

Creates an object that handles the actual transmission of Ajax data.

static contains(parent, child)

Check to see if a DOM element is a descendant of another DOM element.

static data()

Store arbitrary data associated with the specified element and/or return the value that was set.

static dequeue()

Execute the next function on the queue for the matched element.

static each(arr, func)

A generic iterator function, which can be used to seamlessly iterate over both objects and arrays.

static error(msg)

Takes a string and throws an exception containing it.

static escapeSelector(selector)

Returns a string with all special characters replaced with their respective character codes.

static extend(*args)

Merge the contents of two or more objects together into the first object.

static get(url: str, data=None, dataType=False, success=None, error=None)

[simplified ajax request]

Parameters
  • url (str) – [the url to request]

  • data ([type]) – [the data to send]

  • dataType (bool, optional) – [the dataType]. Defaults to False.

  • success ([type], optional) – [a success function]. Defaults to None.

  • error ([type], optional) – [an error method]. Defaults to None.

Returns

[the response]

Return type

[type]

static getJSON()

Load JSON-encoded data from the server using a GET HTTP request.

static getScript(filename, *args)

execute another python file.

static globalEval(code)

Execute some python code globally.

static grep(arr, func)

Returns an array of elements from the original array which satisfy a filter function.

static hasData(element)

Determine whether an element has any dQuery data associated with it.

static holdReady()

Holds or releases the execution of dQuery’s ready event.

static htmlPrefilter()

Modify and filter HTML strings passed through dQuery manipulation methods.

static inArray(thing, arr)

Search for a specified value within an array and return its index or -1 if not found.

static isArray(item)

Determine whether the argument is an array.

static isEmptyObject(dct)

Check to see if an object is empty (contains no enumerable properties).

static isFunction(obj)

Determines if its argument is callable as a function.

static isNumeric(thing)

Determine whether the argument is numeric.

static isPlainObject(obj)

Check to see if an object is a plain object created using ‘{}’

static isWindow(obj)

Determine whether the argument is a window object.

static isXMLDoc(obj)

Check to see if a DOM node is within an XML document (or is an XML document).

static makeArray(somelist)

Convert an array-like object into a true JavaScript array.

static map(arr, func)

Translate all items in an array or object to new array of items.

static merge(one, *args)

Merge the contents of arrays into the first array.

static noConflict()

Relinquish dQuery’s control of the º variable.

static noop()

An empty function.

static now()

Return a number representing the current time.

static param(obj)

Create a serialized representation of an array, a plain object, or a dQuery object suitable for use in a URL query string or Ajax request. In case a dQuery object is passed, it should contain input elements with name/value properties.

static parseHTML(string)

Parses a string into an array of DOM nodes.

static parseJSON(string: str)

Takes a well-formed JSON string and returns the resulting JavaScript value.

static parseXML(string: str)

Parses an XMLstring into a pyml

static post(url, data, success)

Send data to the server using a HTTP POST request.

static proxy(func)

Takes a function and returns a new one that will always have a particular context.

static queue(func)

Show or manipulate the queue of functions to be executed on the matched element.

static readyException()

Handles errors thrown synchronously in functions wrapped in dQuery

static removeData()

Remove a previously-stored piece of data.

static sub()

Creates a new copy of dQuery whose properties and methods can be modified without affecting the original dQuery object.

static trim(content: str) str

Remove the whitespace from the beginning and end of a string.

static unique(arr)

[removes duplicate elements.]

Parameters

arr ([type]) – [list of elements]

Returns

[a sorted array without duplicates]

Return type

[type]

static uniqueSort(arr)

Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers.

static when()

Provides a way to execute callback functions based on zero or more Thenable objects, usually Deferred objects that represent asynchronous events.