| GhostWriter | |
| ghostwriter | Runs a script within an simulated pre-load environment, handling onload event notification and document.write() output. |
| config attributes | |
| script | {Function|Object} Defines the script which will be attached or executed under the pre-load emulation context. |
| insertType | {Function|String} Defines how output created by script should be added to <element>. |
| done | {Function} Callback function to run after the script and all children have been loaded. |
| Examples | |
| Simple | Run a JS script that appends to the #writeto element. |
| Remote script | Loads a script and insert any content before the first script tag on the page. |
| Utility Functions | |
| Functions | |
| flog | Logs a message to the YUI console or browser console if available |
Runs a script within an simulated pre-load environment, handling onload event notification and document.write() output.
function ghostwriter(
HTMLELement element,
Object config
);Note: See ghostwriter.loadscripts for information on how to use HTML tags to defer all scripts.
null
| element | {HTMLElement} The Element around which to insert the DOM elements. Can also be the id of an element. |
| config | {Object} Specifies the config options for execution, including the script itself . |
{Function|Object} Defines the script which will be attached or executed under the pre-load emulation context.
| Function | Will execute |
| Object | A HTMLScriptElement will be created and attached to the DOM. Must contain either |
url - The url of a remote script resource text - The text of a script to execute
{Function|String} Defines how output created by script should be added to <element>.
| Function | Called every time a new HTML tag is encountered. |
| String | Must be one of the following (Default is “after”). |
"append" - Appends to element "before" Inserts before element "after" Inserts immediately following element
Loads a script and insert any content before the first script tag on the page. When complete, execute any onload observers registered during execution
var scriptMap= document.getElementsByTagName("SCRIPT")[0],
ghostwriter(
scriptMap[scriptMap.length],
{
insertType: "before",
script: { url: "/js/mylib.js" },
done: ghostwriter.flushloadhandlers
}
);+------------------------------------------------------------------
| document.write('<link href="...." rel="stylesheet" type="text/css"/>');
| document.write('<script src="http://ajax.googleapis..."><\/script>');
| document.addEventListener("load", function(){ ... } );
------------------------------------------------------------------Only after the ajax.googleapis script has finished loading will the ghostwriter.flushloadhandlers() method be run.
Logs a message to the YUI console or browser console if available
function flog( msg )