Construct a new xjs_Document object.
the node to wrap
This wrapper’s node.
Remove all child nodes from this node, and return it.
this
the function to call in the context of this
this
the condition to evaluate; will be converted to boolean
the executable to call (in the context of this
) if the condition is truthy
the executable to call (in the context of this
) if the condition is falsy
this
Replace all link[rel~="import"][data-import]
elements with contents from their documents.
This method finds all link[rel~="import"][data-import]
s in this document,
and then replaces those links with a DocumentFragment
holding some contents.
These contents depend on the value set for data-import
:
[data-import="document"]
, then the replaced contents will be the contents of the link’s imported document itself[data-import="template"]
, then the replaced contents will be the contents of the first template
descendant in the link’s imported document[data-import]
attribute value is neither "document"
nor "template"
, or if it is absent, then the link
element is completely ignored and left as-isNote: If HTMLLinkElement#import
is supported (by the browser or jsdom), then when [data-import="document"]
is set,
the appended contents will instead be a Document
object, as defined by
HTML Imports, rather than a DocumentFragment
object.
Note: Document#querySelectorAll
does not traverse inside <template>
elements,
so any <link>
elements inside <template>
elements will be left untouched.
To modify those, you will need to call this method on that <template>
’s contents (another DocumentFragment
).
In the example below,
The link[rel="import"]
in this document has [data-import="template"]
, and so is replaced with
the contents of template#sect-template
in x-linked-doc.tpl.html
---namely,
a DocumentFragment
containing only the section
element.
However, if the link had had [data-import="document"]
, then the replaced content would consist of
a DocumentFragment
containing the entirety of x-linked-doc.tpl.html
,
including both the h1
along with the template#sect-template
.
// x-linked-doc.tpl.html:
<h1>top-level hed</h1>
<template id="sect-template">
<section>
<h2>section hed</h2>
<p>a graf</p>
</section>
</template>
// main.js:
// assume `this` is an `xjs.Document` instance.
this.innerHTML() === `
<link rel="import" data-import="document" href="./x-linked-doc.tpl.html"/>
`
// This call will work as intended.
this.importLinks(__dirname)
the absolute path to the directory of the template file containing the link
element
this
Asynchronous version of xjs_Document.importLinks.
the absolute path to the directory of the template file containing the link
element
Get the "innerHTML" of this document.
This method should be used only if this document is an HTML Document,
has doctype html
, and whose root element is the <html>
element (an instance of HTMLHtmlElement
).
You should only use this method if you do not have access to the original DOM object that this Document belongs to.
Otherwise, you should use dom.serialize()
.
a string serialization of this HTML Document
Execute a callback acting on this node, and then return this node.
Simplifies chaining when performing void tasks, especially tasks that have not been defined in this implementation. Note that this function is not asynchronous, and does not accept asynchronous arguments.
the function to call, taking this
as its only argument, and returning void
this
Execute a function based on a condition.
Given a condition, execute one function upon passing, or execute another upon failure. Note that this function is not asynchronous, and does not accept asynchronous arguments.
the condition to evaluate; will be converted to boolean
the callback to call (with this
as its parameter) if the condition is truthy
the callback to call (with this
as its parameter) if the condition is falsy
this
Get Node#textContent.
the textContent
of this node
Set Node#textContent, and returns this object when done.
This method exists simply for chaining.
the content to set
this
Remove all inner whitespace text nodes from this node, and return it.
let div = document.createElement('div')
div.innerHTML = `
<h1>
<em>Hello </em>
<b>Worl d</b>
</h1>
`
let trimmed_div = new xjs.Node(div).trimInner().node
return div.innerHTML === `
<h1>
<em>Hello </em>
<b>Worl d</b>
</h1>
`
&& trimmed_div.innerHTML = `<h1><em>Hello </em><b>Worl d</b></h1>`
this
Read an HTML file and return a document with its contents.
The Document object will be wrapped in an xjs.Document
object.
To access the actual document, call {@link xjs_Document#node}.
the path to the file
the document, wrapped
Synchronous version of xjs_Document.fromFile.
the path to the file
the document, wrapped
Read an HTML string and return a document with its contents.
The Document object will be wrapped in an xjs.Document
object.
To access the actual document, call {@link xjs_Document#node}.
a string of markup
the document, wrapped
Generated using TypeDoc
Wrapper for a Document.
https://www.w3.org/TR/dom/#document