1 .. title:: MochiKit.DOM - painless DOM manipulation API
6 MochiKit.DOM - painless DOM manipulation API
15 ["dataA1", "dataA2", "dataA3"],
16 ["dataB1", "dataB2", "dataB3"]
18 row_display = function (row) {
19 return TR(null, map(partial(TD, null), row));
21 var newTable = TABLE({'class': 'prettytable'},
23 row_display(["head1", "head2", "head3"])),
25 row_display(["foot1", "foot2", "foot3"])),
27 map(row_display, rows)));
28 // put that in your document.createElement and smoke it!
29 swapDOM(oldTable, newTable);
35 As you probably know, the DOM APIs are some of the most painful
36 Java-inspired APIs you'll run across from a highly dynamic
37 language. Don't worry about that though, because they provide a
38 reasonable basis to build something that sucks a lot less.
40 MochiKit.DOM takes much of its inspiration from Nevow's [1]_ stan
41 [2]_. This means you choose a tag, give it some attributes, then
42 stuff it full of *whatever objects you want*. MochiKit.DOM isn't
43 stupid, it knows that a string should be a text node, and that you
44 want functions to be called, and that ``Array``-like objects should be
45 expanded, and stupid ``null`` values should be skipped.
47 Hell, it will let you return strings from functions, and use iterators
48 from :mochiref:`MochiKit.Iter`. If that's not enough, just teach it
49 new tricks with :mochiref:`registerDOMConverter`. If you have never
50 used an API like this for creating DOM elements, you've been wasting
51 your damn time. Get with it!
57 - :mochiref:`MochiKit.Base`
58 - :mochiref:`MochiKit.Style` (optional since MochiKit 1.4 for
59 backwards-compatibility)
60 - :mochiref:`MochiKit.Iter` (optional since MochiKit 1.4)
69 In order of precedence, :mochiref:`createDOM` coerces given arguments
70 to DOM nodes using the following rules:
72 1. Functions are called with a ``this`` and first argument of the
73 parent node and their return value is subject to the following
74 rules (even this one).
75 2. ``undefined`` and ``null`` are ignored.
76 3. If :mochiref:`MochiKit.Iter` is loaded, iterables are flattened
77 (as if they were passed in-line as nodes) and each return value is
78 subject to these rules.
79 4. Values that look like DOM nodes (objects with a ``.nodeType > 0``)
80 are ``.appendChild``'ed to the created DOM fragment.
81 5. Strings are wrapped up with ``document.createTextNode``
82 6. Objects that have a ``.dom(node)`` or ``.__dom__(node)`` method
83 are called with the parent node and their result is coerced using
84 these rules. (MochiKit 1.4+).
85 7. Objects that are not strings are run through the ``domConverters``
86 :mochiref:`MochiKit.Base.AdapterRegistry` (see
87 :mochiref:`registerDOMConverter`). The adapted value is subject
88 to these same rules (e.g. if the adapter returns a string, it
89 will be coerced to a text node).
90 8. If no adapter is available, ``.toString()`` is used to create a
94 Creating DOM Element Trees
95 --------------------------
97 :mochiref:`createDOM` provides you with an excellent facility for
98 creating DOM trees that is easy on the wrists. One of the best ways to
99 understand how to use it is to take a look at an example::
102 ["dataA1", "dataA2", "dataA3"],
103 ["dataB1", "dataB2", "dataB3"]
105 row_display = function (row) {
106 return TR(null, map(partial(TD, null), row));
108 var newTable = TABLE({'class': 'prettytable'},
110 row_display(["head1", "head2", "head3"])),
112 row_display(["foot1", "foot2", "foot3"])),
114 map(row_display, rows)));
117 This will create a table with the following visual layout (if it were
118 inserted into the document DOM):
120 +--------+--------+--------+
121 | head1 | head2 | head3 |
122 +========+========+========+
123 | dataA1 | dataA2 | dataA3 |
124 +--------+--------+--------+
125 | dataB1 | dataB2 | dataB3 |
126 +--------+--------+--------+
127 | foot1 | foot2 | foot3 |
128 +--------+--------+--------+
130 Corresponding to the following HTML::
132 <table class="prettytable">
165 In order to prevent having to pass a ``window`` and/or ``document``
166 variable to every MochiKit.DOM function (e.g. when working with a
167 child window), MochiKit.DOM maintains a context variable for each of
168 them. They are managed with the :mochiref:`withWindow` and
169 :mochiref:`withDocument` functions, and can be acquired with
170 :mochiref:`currentWindow()` and :mochiref:`currentDocument()`
172 For example, if you are creating DOM nodes in a child window, you
173 could do something like this::
175 withWindow(child, function () {
176 var doc = currentDocument();
177 appendChildNodes(doc.body, H1(null, "This is in the child!"));
180 Note that :mochiref:`withWindow(win, ...)` also implies
181 :mochiref:`withDocument(win.document, ...)`.
187 Performance Tradeoff:
188 DOM is much easier to get correct and more flexible than working
189 directly with markup as strings. Modifying ``innerHTML`` is still
190 the fastest way to make document changes.
193 Internet Explorer's DOM implementation is quite poor in comparison
194 to the other popular implementations. In order to avoid memory
195 leaks due to circular references, you should use
196 :mochiref:`MochiKit.Signal.connect` for all of your event handling
197 needs. Additionally, when creating tables with DOM, it is required
198 to use a ``TBODY`` tag (see `Creating DOM Element Trees`_ for an
208 :mochidef:`$(id[, ...])`:
210 An alias for :mochiref:`getElement(id[, ...])`
213 Available in MochiKit 1.3.1+
216 :mochidef:`addElementClass(element, className)`:
218 Ensure that the given ``element`` has ``className`` set as part of
219 its class attribute. This will not disturb other class names.
220 ``element`` is looked up with :mochiref:`getElement`, so string
221 identifiers are also acceptable.
224 Available in MochiKit 1.3.1+
227 :mochidef:`addLoadEvent(func)`:
229 Note that :mochiref:`addLoadEvent` can not be used in combination
230 with :mochiref:`MochiKit.Signal` if the ``onload`` event is
231 connected. Once an event is connected with
232 :mochiref:`MochiKit.Signal`, no other APIs may be used for that
235 This will stack ``window.onload`` functions on top of each other.
236 Each function added will be called after ``onload`` in the order
237 that they were added.
240 Available in MochiKit 1.3.1+
243 :mochidef:`addToCallStack(target, path, func[, once])`:
245 Note that :mochiref:`addToCallStack` is not compatible with
246 :mochiref:`MochiKit.Signal`. Once an event is connected with
247 :mochiref:`MochiKit.Signal`, no other APIs may be used for that
250 Set the property ``path`` of ``target`` to a function that calls
251 the existing function at that property (if any), then calls
254 If ``target[path]()`` returns exactly ``false``, then ``func``
257 If ``once`` is ``true``, then ``target[path]`` is set to ``null``
258 after the function call stack has completed.
260 If called several times for the same ``target[path]``, it will
261 create a stack of functions (instead of just a pair).
264 Available in MochiKit 1.3.1+
267 :mochidef:`appendChildNodes(node[, childNode[, ...]])`:
269 Append children to a DOM element using the `DOM Coercion Rules`_.
272 A reference to the DOM element to add children to (if a string
273 is given, :mochiref:`getElement(node)` will be used to locate
277 All additional arguments, if any, will be coerced into DOM
278 nodes that are appended as children using the `DOM Coercion
282 The given DOM element
285 Available in MochiKit 1.3.1+
287 :mochidef:`insertSiblingNodesBefore(node[, siblingNode[, ...]])`:
289 Insert children into the DOM structure using the `DOM Coercion
293 A reference to the DOM element you want to insert children
294 before (if a string is given, :mochiref:`getElement(node)`
295 will be used to locate the node)
298 All additional arguments, if any, will be coerced into DOM
299 nodes that are inserted as siblings using the `DOM Coercion
303 The parent of the given DOM element
306 Available in MochiKit 1.4+
309 :mochidef:`insertSiblingNodesAfter(node[, siblingNode[, ...]])`:
311 Insert children into the DOM structure using the `DOM Coercion
315 A reference to the DOM element you want to insert children
316 after (if a string is given, :mochiref:`getElement(node)`
317 will be used to locate the node)
320 All additional arguments, if any, will be coerced into DOM
321 nodes that are inserted as siblings using the `DOM Coercion
325 The parent of the given DOM element
328 Available in MochiKit 1.4+
331 :mochidef:`createDOM(name[, attrs[, node[, ...]]])`:
333 Create a DOM fragment in a really convenient manner, much like
334 Nevow`s [1]_ stan [2]_.
336 Partially applied versions of this function for common tags are
337 available as aliases:
374 See `Creating DOM Element Trees`_ for a comprehensive example.
377 The kind of fragment to create (e.g. 'span'), such as you
378 would pass to ``document.createElement``.
381 An object whose properties will be used as the attributes
382 (e.g. ``{'style': 'display:block'}``), or ``null`` if no
383 attributes need to be set.
385 See :mochiref:`updateNodeAttributes` for more information.
387 For convenience, if ``attrs`` is a string, ``null`` is used
388 and the string will be considered the first ``node``.
391 All additional arguments, if any, will be coerced into DOM
392 nodes that are appended as children using the `DOM Coercion
399 Available in MochiKit 1.3.1+
402 :mochidef:`createDOMFunc(tag[, attrs[, node[, ...]]])`:
404 Convenience function to create a partially applied createDOM
405 function. You'd want to use this if you add additional convenience
406 functions for creating tags, or if you find yourself creating a
407 lot of tags with a bunch of the same attributes or contents.
409 See :mochiref:`createDOM` for more detailed descriptions of the
416 Optionally specify the attributes to apply
419 Optionally specify any children nodes it should have
422 function that takes additional arguments and calls
423 :mochiref:`createDOM`
426 Available in MochiKit 1.3.1+
429 :mochidef:`currentDocument()`:
431 Return the current ``document`` `DOM Context`_. This will always
432 be the same as the global ``document`` unless
433 :mochiref:`withDocument` or :mochiref:`withWindow` is currently
437 Available in MochiKit 1.3.1+
440 :mochidef:`currentWindow()`:
442 Return the current ``window`` `DOM Context`_. This will always be
443 the same as the global ``window`` unless :mochiref:`withWindow` is
447 Available in MochiKit 1.3.1+
450 :mochidef:`emitHTML(dom[, lst])`:
452 Convert a DOM tree to an ``Array`` of HTML string fragments. This should
453 be used for debugging/testing purposes only.
455 The DOM property ``innerHTML`` or ``cloneNode(true)`` method should
456 be used for most purposes.
459 Available in MochiKit 1.3.1+
462 :mochidef:`escapeHTML(s)`:
464 Make a string safe for HTML, converting the usual suspects (lt,
468 Available in MochiKit 1.3.1+
471 :mochidef:`focusOnLoad(element)`:
473 Note that :mochiref:`focusOnLoad` can not be used in combination
474 with :mochiref:`MochiKit.Signal` if the ``onload`` event is
475 connected. Once an event is connected with
476 :mochiref:`MochiKit.Signal`, no other APIs may be used for that
479 This adds an onload event to focus the given element.
482 Available in MochiKit 1.3.1+
485 :mochidef:`formContents(elem=document.body)`:
487 Search the DOM tree, starting at ``elem``, for any elements with a
488 ``name`` and ``value`` attribute. Return a 2-element ``Array`` of
489 ``names`` and ``values`` suitable for use with
490 :mochiref:`MochiKit.Base.queryString`.
493 Available in MochiKit 1.3.1+
496 :mochidef:`getElement(id[, ...])`:
498 A small quick little function to encapsulate the
499 ``getElementById`` method. It includes a check to ensure we can
502 If the id isn't a string, it will be returned as-is.
504 Also available as :mochiref:`$(...)` for convenience and
505 compatibility with other JavaScript frameworks.
507 If multiple arguments are given, an ``Array`` will be returned.
510 Available in MochiKit 1.3.1+
513 :mochidef:`getElementsByTagAndClassName(tagName, className, parent=document)`:
515 Returns an array of elements in ``parent`` that match the tag name
516 and class name provided. If ``parent`` is a string, it will be
517 looked up with :mochiref:`getElement`.
519 If ``tagName`` is ``null`` or ``"*"``, all elements will be
520 searched for the matching class.
522 If ``className`` is ``null``, all elements matching the provided
526 Available in MochiKit 1.3.1+
529 :mochidef:`getFirstElementByTagAndClassName(tagName, className, parent=document)`:
531 Return the first element in ``parent`` that matches the tag name
532 and class name provided. If ``parent`` is a string, it will be
533 looked up with :mochiref:`getElement`.
535 If ``tagName`` is ``null`` or ``"*"``, all elements will be searched
536 for the matching class.
538 If ``className`` is ``null``, the first element matching the provided
539 tag will be returned.
542 Available in MochiKit 1.4+
545 :mochidef:`getFirstParentByTagAndClassName(elem, tagName='*', className=null)`:
547 Returns the first parent of ``elem`` matches the tag name and class name
548 provided. If parent is a string, it will be looked up using
549 :mochiref:`getElement`.
551 If ``tagName`` is ``null`` or ``"*"``, all elements will be searched
552 for the matching class.
554 If ``className`` is ``null``, the first element matching the provided
555 tag will be returned.
558 Available in MochiKit 1.4+
561 :mochidef:`getNodeAttribute(node, attr)`:
563 Get the value of the given attribute for a DOM element without
564 ever raising an exception (will return ``null`` on exception).
567 A reference to the DOM element to update (if a string is
568 given, :mochiref:`getElement(node)` will be used to locate the
572 The name of the attribute
574 Note that it will do the right thing for IE, so don't do
575 the ``class`` -> ``className`` hack yourself.
578 The attribute's value, or ``null``
581 Available in MochiKit 1.3.1+
584 :mochidef:`hasElementClass(element, className[, ...])`:
586 Return ``true`` if ``className`` is found on the ``element``.
587 ``element`` is looked up with :mochiref:`getElement`, so string
588 identifiers are also acceptable.
591 Available in MochiKit 1.3.1+
594 :mochidef:`isChildNode(node, maybeParent)`:
596 Determine whether ``node`` is a child node of ``maybeParent``.
597 Returns ``true`` if so, and ``false`` if not. A node is considered
598 a child node of itself for the purposes of this function.
600 If either ``node`` or ``maybeParent`` are strings, the related
601 nodes will be looked up with :mochiref:`getElement`.
604 Available in MochiKit 1.4+
607 :mochidef:`isParent(child, element)`:
609 Returns ``true`` if ``element`` contains ``child``. Returns ``false``
610 if ``element == child`` or ``child`` is not contained in ``element``.
611 If ``child`` or ``element`` are strings, they will be looked up with
612 :mochiref:`getElement`.
615 Available in MochiKit 1.4+
618 :mochidef:`makeClipping(element)`:
620 Ensure that ``element.style.overflow = 'hidden'``. If ``element`` is a
621 string, then it will be looked up with :mochiref:`getElement`.
623 Returns the original value of ``element.style.overflow``, so that it
624 may be restored with :mochiref:`undoClipping(element, overflow)`.
627 Available in MochiKit 1.4+
630 :mochidef:`makePositioned(element)`:
632 Ensure that ``element.style.position`` is set to ``"relative"`` if it
633 is not set or is ``"static"``. If ``element`` is a
634 string, then it will be looked up with :mochiref:`getElement`.
636 Returns the original value of ``element.style.position``, so that it
637 may be restored with :mochiref:`undoPositioned(element, position)`.
640 Available in MochiKit 1.4+
643 :mochidef:`registerDOMConverter(name, check, wrap[, override])`:
645 Register an adapter to convert objects that match ``check(obj,
646 ctx)`` to a DOM element, or something that can be converted to a
647 DOM element (i.e. number, bool, string, function, iterable).
650 Available in MochiKit 1.3.1+
653 :mochidef:`removeElement(node)`:
655 Remove and return ``node`` from a DOM tree.
658 the DOM element (or string id of one) to be removed
664 Available in MochiKit 1.3.1+
667 :mochidef:`removeElementClass(element, className)`:
669 Ensure that the given ``element`` does not have ``className`` set
670 as part of its class attribute. This will not disturb other class
671 names. ``element`` is looked up with :mochiref:`getElement`, so
672 string identifiers are also acceptable.
675 Available in MochiKit 1.3.1+
678 :mochidef:`removeEmptyTextNodes(node)`:
680 Remove all text node children that contain only whitespace from
681 ``node``. Useful in situations where such empty text nodes can
682 interfere with DOM traversal.
685 the DOM element (or string id of one) to remove whitespace child
689 Available in MochiKit 1.4+
692 :mochidef:`replaceChildNodes(node[, childNode[, ...]])`:
694 Remove all children from the given DOM element, then append any
695 given childNodes to it (by calling :mochiref:`appendChildNodes`).
698 A reference to the DOM element to add children to (if a string
699 is given, :mochiref:`getElement(node)` will be used to locate
703 All additional arguments, if any, will be coerced into DOM
704 nodes that are appended as children using the `DOM Coercion
708 The given DOM element
711 Available in MochiKit 1.3.1+
714 :mochidef:`scrapeText(node[, asArray=false])`:
716 Walk a DOM tree in-order and scrape all of the text out of it as a
719 If ``asArray`` is ``true``, then an ``Array`` will be returned
720 with each individual text node. These two are equivalent::
722 assert( scrapeText(node) == scrapeText(node, true).join("") );
725 Available in MochiKit 1.3.1+
728 :mochidef:`setElementClass(element, className)`:
730 Set the entire class attribute of ``element`` to ``className``.
731 ``element`` is looked up with :mochiref:`getElement`, so string
732 identifiers are also acceptable.
735 Available in MochiKit 1.3.1+
738 :mochidef:`setNodeAttribute(node, attr, value)`:
740 Set the value of the given attribute for a DOM element without
741 ever raising an exception (will return null on exception). If
742 setting more than one attribute, you should use
743 :mochiref:`updateNodeAttributes`.
746 A reference to the DOM element to update (if a string is
747 given, :mochiref:`getElement(node)` will be used to locate the
751 The name of the attribute
753 Note that it will do the right thing for IE, so don't do the
754 ``class`` -> ``className`` hack yourself.
757 The value of the attribute, may be an object to be merged
758 (e.g. for setting style).
761 The given DOM element or ``null`` on failure
764 Available in MochiKit 1.3.1+
767 :mochidef:`swapDOM(dest, src)`:
769 Replace ``dest`` in a DOM tree with ``src``, returning ``src``.
772 a DOM element (or string id of one) to be replaced
775 the DOM element (or string id of one) to replace it with, or
776 ``null`` if ``dest`` is to be removed (replaced with nothing).
779 a DOM element (``src``)
782 Available in MochiKit 1.3.1+
785 :mochidef:`swapElementClass(element, fromClass, toClass)`:
787 If ``fromClass`` is set on ``element``, replace it with
788 ``toClass``. This will not disturb other classes on that element.
789 ``element`` is looked up with :mochiref:`getElement`, so string
790 identifiers are also acceptable.
793 Available in MochiKit 1.3.1+
796 :mochidef:`toggleElementClass(className[, element[, ...]])`:
798 Toggle the presence of a given ``className`` in the class
799 attribute of all given elements. All elements will be looked up
800 with :mochiref:`getElement`, so string identifiers are acceptable.
803 Available in MochiKit 1.3.1+
806 :mochidef:`toHTML(dom)`:
808 Convert a DOM tree to a HTML string using :mochiref:`emitHTML`.
809 This should be used for debugging/testing purposes only.
811 The DOM property ``innerHTML`` or ``cloneNode(true)`` method should
812 be used for most purposes.
815 Available in MochiKit 1.3.1+
818 :mochidef:`undoClipping(element, overflow)`:
820 Restore the setting of ``element.style.overflow`` set by
821 :mochiref:`makeClipping(element)`. If ``element`` is a string, then
822 it will be looked up with :mochiref:`getElement`.
825 Available in MochiKit 1.4+
828 :mochidef:`undoPositioned(element, overflow)`:
830 Restore the setting of ``element.style.position`` set by
831 :mochiref:`makePositioned(element)`. If ``element`` is a string, then
832 it will be looked up with :mochiref:`getElement`.
835 Available in MochiKit 1.4+
838 :mochidef:`updateNodeAttributes(node, attrs)`:
840 Update the attributes of a DOM element from a given object.
843 A reference to the DOM element to update (if a string is
844 given, :mochiref:`getElement(node)` will be used to locate the
848 An object whose properties will be used to set the attributes
849 (e.g. ``{'class': 'invisible'}``), or ``null`` if no
850 attributes need to be set. If an object is given for the
851 attribute value (e.g. ``{'style': {'display': 'block'}}``)
852 then :mochiref:`MochiKit.Base.updatetree` will be used to set
855 Note that it will do the right thing for IE, so don't do the
856 ``class`` -> ``className`` hack yourself, and it deals with
857 setting "on..." event handlers correctly.
860 The given DOM element
863 Available in MochiKit 1.3.1+
866 :mochidef:`withWindow(win, func)`:
868 Call ``func`` with the ``window`` `DOM Context`_ set to ``win``
869 and the ``document`` `DOM Context`_ set to ``win.document``. When
870 ``func()`` returns or throws an error, the `DOM Context`_ will be
871 restored to its previous state.
873 The return value of ``func()`` is returned by this function.
876 Available in MochiKit 1.3.1+
879 :mochidef:`withDocument(doc, func)`:
881 Call ``func`` with the ``doc`` `DOM Context`_ set to ``doc``.
882 When ``func()`` returns or throws an error, the `DOM Context`_
883 will be restored to its previous state.
885 The return value of ``func()`` is returned by this function.
888 Available in MochiKit 1.3.1+
894 These functions are available in MochiKit 1.3.1, but have been moved to
895 :mochiref:`MochiKit.Style` in 1.4+.
898 :mochidef:`computedStyle(htmlElement, cssProperty, mozillaEquivalentCSS)`:
900 Looks up a CSS property for the given element. The element can be
901 specified as either a string with the element's ID or the element
905 MochiKit 1.3.1 expects camel case, e.g. ``backgroundColor``.
906 MochiKit 1.4+ expects CSS selector case, e.g. ``background-color``,
907 but will accept camel case for backwards-compatibility.
909 ``mozillaEquivalentCSS``:
910 MochiKit 1.3.1 expects selector case.
911 MochiKit 1.4+ ignores this argument.
914 Available in MochiKit 1.3.1, deprecated in favor of
915 :mochiref:`MochiKit.Style.getStyle` in 1.4+
918 :mochidef:`elementDimensions(element)`:
920 Return the absolute pixel width and height (including padding and border,
921 but not margins) of ``element`` as an object with ``w`` and ``h``
922 properties, or ``undefined`` if ``element`` is not in the document.
923 ``element`` may be specified as a string to be looked up with
924 :mochiref:`getElement`, a DOM element, or trivially as an object with
925 ``w`` and/or ``h`` properties.
928 Available in MochiKit 1.3.1, deprecated in favor of
929 :mochiref:`MochiKit.Style.getElementDimensions` in 1.4+
932 :mochidef:`elementPosition(element[, relativeTo={x: 0, y: 0}])`:
934 Return the absolute pixel position of ``element`` in the document
935 as an object with ``x`` and ``y`` properties, or ``undefined`` if
936 ``element`` is not in the document. ``element`` may be specified
937 as a string to be looked up with :mochiref:`getElement`, a DOM
938 element, or trivially as an object with ``x`` and/or ``y``
941 If ``relativeTo`` is given, then its coordinates are subtracted from
942 the absolute position of ``element``, e.g.::
944 var elemPos = elementPosition(elem);
945 var anotherElemPos = elementPosition(anotherElem);
946 var relPos = elementPosition(elem, anotherElem);
947 assert( relPos.x == (elemPos.x - anotherElemPos.x) );
948 assert( relPos.y == (elemPos.y - anotherElemPos.y) );
950 ``relativeTo`` may be specified as a string to be looked up with
951 :mochiref:`getElement`, a DOM element, or trivially as an object
952 with ``x`` and/or ``y`` properties.
955 Available in MochiKit 1.3.1, deprecated in favor of
956 :mochiref:`MochiKit.Style.getElementPosition` in 1.4+
959 :mochidef:`getViewportDimensions()`:
961 Return the pixel width and height of the viewport as an object
962 with ``w`` and ``h`` properties. ``element`` is looked up with
963 :mochiref:`getElement`, so string identifiers are also acceptable.
966 Available in MochiKit 1.3.1, moved to
967 :mochiref:`MochiKit.Style.getViewportDimensions` in 1.4+
970 :mochidef:`hideElement(element, ...)`:
972 Partial form of :mochiref:`setDisplayForElement`, specifically::
974 partial(setDisplayForElement, "none")
976 For information about the caveats of using a ``style.display``
977 based show/hide mechanism, and a CSS based alternative, see
978 `Element Visibility`_.
980 .. _`Element Visibility`: Style.html#element-visibility
983 Available in MochiKit 1.3.1, moved to
984 :mochiref:`MochiKit.Style.hideElement` in 1.4+
987 :mochidef:`setElementDimensions(element, dimensions[, units='px'])`:
989 Sets the dimensions of ``element`` in the document from an object
990 with ``w`` and ``h`` properties.
993 A reference to the DOM element to update (if a string is
994 given, :mochiref:`getElement(node)` will be used to locate the
998 An object with ``w`` and ``h`` properties
1001 Optionally set the units to use, default is ``px``
1004 Available in MochiKit 1.3.1, moved to
1005 :mochiref:`MochiKit.Style.setElementDimensions` in 1.4+
1008 :mochidef:`setElementPosition(element, position[, units='px'])`:
1010 Sets the absolute position of ``element`` in the document from an
1011 object with ``x`` and ``y`` properties.
1014 A reference to the DOM element to update (if a string is
1015 given, :mochiref:`getElement(node)` will be used to locate the
1019 An object with ``x`` and ``y`` properties
1022 Optionally set the units to use, default is ``px``
1025 Available in MochiKit 1.3.1, moved to
1026 :mochiref:`MochiKit.Style.setElementPosition` in 1.4+
1029 :mochidef:`setDisplayForElement(display, element[, ...])`:
1031 Change the ``style.display`` for the given element(s). Usually
1032 used as the partial forms:
1034 - :mochiref:`showElement(element, ...)`
1035 - :mochiref:`hideElement(element, ...)`
1037 Elements are looked up with :mochiref:`getElement`, so string
1038 identifiers are acceptable.
1040 For information about the caveats of using a ``style.display``
1041 based show/hide mechanism, and a CSS based alternative, see
1042 `Element Visibility`_.
1045 Available in MochiKit 1.3.1, moved to
1046 :mochiref:`MochiKit.Style.setDisplayForElement` in 1.4+
1049 :mochidef:`setOpacity(element, opacity)`:
1051 Sets ``opacity`` for ``element``. Valid ``opacity`` values range
1052 from 0 (invisible) to 1 (opaque). ``element`` is looked up with
1053 :mochiref:`getElement`, so string identifiers are also acceptable.
1056 Available in MochiKit 1.3.1, moved to
1057 :mochiref:`MochiKit.Style.setOpacity` in 1.4+
1060 :mochidef:`showElement(element, ...)`:
1062 Partial form of :mochiref:`setDisplayForElement`, specifically::
1064 partial(setDisplayForElement, "block")
1066 For information about the caveats of using a ``style.display``
1067 based show/hide mechanism, and a CSS based alternative, see
1068 `Element Visibility`_.
1071 Available in MochiKit 1.3.1, moved to
1072 :mochiref:`MochiKit.Style.showElement` in 1.4+
1078 These objects are available in MochiKit 1.3.1, but have been moved to
1079 :mochiref:`MochiKit.Style` in 1.4+.
1081 :mochidef:`Coordinates(x, y)`:
1083 Constructs an object with ``x`` and ``y`` properties. ``obj.toString()``
1084 returns something like ``{x: 0, y: 42}`` for debugging.
1087 Available in MochiKit 1.3.1, moved to
1088 :mochiref:`MochiKit.Style.Coordinates` in 1.4+
1090 :mochidef:`Dimensions(w, h)`:
1092 Constructs an object with ``w`` and ``h`` properties. ``obj.toString()``
1093 returns something like ``{w: 0, h: 42}`` for debugging.
1096 Available in MochiKit 1.3.1, moved to
1097 :mochiref:`MochiKit.Style.Dimensions` in 1.4+
1104 .. [1] Nevow, a web application construction kit for Python:
1105 http://divmod.org/trac/wiki/DivmodNevow
1106 .. [2] nevow.stan is a domain specific language for Python (read as
1107 "crazy getitem/call overloading abuse") that Donovan and I
1108 schemed up at PyCon 2003 at this super ninja Python/C++
1109 programmer's (David Abrahams) hotel room. Donovan later
1110 inflicted this upon the masses in Nevow. Check out the Nevow
1111 Guide for some examples:
1112 http://divmod.org/trac/wiki/DivmodNevow
1118 - Bob Ippolito <bob@redivi.com>
1124 Copyright 2005 Bob Ippolito <bob@redivi.com>. This program is
1125 dual-licensed free software; you can redistribute it and/or modify it
1126 under the terms of the `MIT License`_ or the `Academic Free License
1129 .. _`MIT License`: http://www.opensource.org/licenses/mit-license.php
1130 .. _`Academic Free License v2.1`: http://www.opensource.org/licenses/afl-2.1.php