// CONSTRUCTOR
// construct a new DOM Document that uses our element definitions
//
- // static function initHTML5()
+ // static function initHTML5([$doc])
// initialize as an HTML5 document and return references to its basic elements.
+ // If a $doc is handed over (an ExtendedDocument or a derived class), load the content into that document.
// returns an associative array with the following elements: 'html', 'head', 'title', 'body'
//
// public function appendElement($name, [$value])
// appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
// NO return value!
//
- // public function appendJSFile($jsURL)
+ // public function appendJSFile($jsURL, [$defer], [$async])
// appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
// returns the new child
//
// public function createElementJS($jsdata)
// returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
//
- // public function createElementJSFile($jsURL)
+ // public function createElementJSFile($jsURL, [$defer], [$async])
// returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
+ // $defer and $async are boolean attributes that set if the script should be executed after parsing but before onload, and if it should be loaded asynchronously.
function __construct($version = '1.0', $encoding = 'utf-8') {
// make sure the default DOMDocument constructor runs
$this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
}
- static function initHTML5() {
- $doc = new ExtendedDocument();
+ static function initHTML5($doc = null) {
+ if (is_null($doc)) { $doc = new ExtendedDocument(); }
$doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
// Created basic HTML document structure.
public function appendJSElement($jsdata) {
$this->appendChild($this->createElementJS($jsdata));
}
- public function appendJSFile($jsdata) {
- return $this->appendChild($this->createElementJSFile($jsdata));
+ public function appendJSFile($jsdata, $defer = false, $async = false) {
+ return $this->appendChild($this->createElementJSFile($jsdata, $defer, $async));
}
public function appendHTMLMarkup($htmldata, $parentNode = null) {
return $jselem;
}
- public function createElementJSFile($jsURL) {
+ public function createElementJSFile($jsURL, $defer = false, $async = false) {
$jselem = $this->createElement('script');
// Note: type can/should be left out for HTML5.
$jselem->setAttribute('type', 'text/javascript');
+ if ($defer) {
+ $jselem->setAttribute('defer', '');
+ }
+ if ($async) {
+ $jselem->setAttribute('async', '');
+ }
$jselem->setAttribute('src', $jsURL);
return $jselem;
}
// appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
// NO return value!
//
- // public function appendJSFile($jsURL)
+ // public function appendJSFile($jsURL, [$defer], [$async])
// appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
// returns the new child
public function appendJSElement($jsdata) {
$this->appendChild($this->ownerDocument->createElementJS($jsdata));
}
- public function appendJSFile($jsdata) {
- return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
+ public function appendJSFile($jsdata, $defer = false, $async = false) {
+ return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
}
}
// appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
// NO return value!
//
- // public function appendJSFile($jsURL)
+ // public function appendJSFile($jsURL, [$defer], [$async])
// appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
// returns the new child
public function appendJSElement($jsdata) {
$this->appendChild($this->ownerDocument->createElementJS($jsdata));
}
- public function appendJSFile($jsdata) {
- return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
+ public function appendJSFile($jsdata, $defer = false, $async = false) {
+ return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
}
}
?>