@verb #5406:":insertBefore" this none this rxdo #7788 @program #5406:":insertBefore" this none this " Node insertBefore(in Node newChild, in Node refChild) raises (DOMException);" "" "Inserts the node newChild before the existing child node refChild. If refChild is $dom.null, insert newChild at the end of the list of children. If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before refChild. If newChild is already in the tree, it is first removed." {newChild, refChild} = args "check that we have the right document" if (newChild->__ownerDocument != this->__ownerDocument && newChild->__ownerDocument != this) $dom:raise_exception($dom.wrong_document_err) endif "check that newChild is not ourselves or our ancestors" par = newChild while (par != $dom.null) if (par == this) $dom:raise_exception($dom.hierarchy_request_err) endif par = par->__parentNode endwhile if (newChild->isa($dom_documentfragment)) for child in ($dom_document->__children) this->insertBefore($dom:instanciate(child[3], newChild, newChild->__ownerDocument), refChild) endfor return newChild endif if (newChild->__parentNode != $dom.null) newChild->__parentNode->removeChild(newChild) endif "determine insertion index" index = length(this->__children) + 1 if (refChild != $dom.null) index = listiassoc(refChild->__nodeId, this->__children, 2) if (!index) $dom:raise_Exception($dom.not_found_err) endif endif "conf that newChild->__parentNode is $dom.null here for storage as text. otherwise, toliteral(newChild) would describe the entire document, where we want it to contain just the branch" newChild->__parentNode = $dom.null newChild->__ownerDocument = $dom.null this->__children = listinsert(this->__children, {newChild->__nodeType, newChild->__nodeId, toliteral(newChild)}, index) "now that it's stored as text, we can set the __parentNode attr to ourselves." newChild->__parentNode = this newChild->__ownerDocument = this->__ownerDocument $dom:updateParentsChildren(this) return newChild "Last modified by Floyd (#7788) on Fri Nov 15 21:31:47 2002 MST." .