Skip to content

Designed to be a replacement for jQuery's ".html()." It was the only thing I used jQuery for anymore, and I don't think that justifies loading it in.

License

Notifications You must be signed in to change notification settings

based-jace/load-script-async

Repository files navigation

loadScriptAsync

Allows loading html, including scripts - similar to jQuery's ".html()"

https://www.danielcrabtree.com/blog/25/gotchas-with-dynamically-adding-script-tags-to-html
and
https://stackoverflow.com/questions/8097026/how-to-run-javascript-in-html-loaded-via-ajax/8097325#8097325
used as references - thanks guys!

Kind: global class
Author:: footjohnson

loadScriptAsync.ReplaceHtml(html, domLocation) ⇒ boolean

Replaces html on page with given html, executing scripts in the process.

Kind: instance method of loadScriptAsync
Returns: boolean - True if success; false if failure

Param Type Description
html string Html to replace current html
domLocation HTMLElement Node whose html should be replaced

Example

// html should be stringified HTML
// domLocation would be given via something like document.getElementById("elementId");
// returns true
loadScriptAsync.ReplaceHtml(html, domLocation)

loadScriptAsync.CheckForScripts(node) ⇒ boolean

Checks if there are any script tags in the node

Kind: instance method of loadScriptAsync
Returns: boolean - True if it contains scripts; false if it doesn't

Param Type Description
node Node Node to check for scripts

Example

// Returns whether a node or HTMLElement has script tags as children or grandchildren
// returns true
loadScriptAsync.CheckForScripts(node)

loadScriptAsync.PlaceElems(element, domLocation, checkScripts, isHead) ⇒ boolean

Recursively places html elements on the DOM

Kind: instance method of loadScriptAsync
Returns: boolean - True if success; false if failure

Param Type Default Description
element HTMLElement Element whose children should be placed on the DOM
domLocation Node Where to put the elements
checkScripts boolean true If the function should first check if any scripts tags are within the given elems. If there are, use innerHTML instead
isHead boolean false If html should be placed in the head of the document (not yet supported)

Example

// returns true
loadScriptAsync.PlaceElems()

About

Designed to be a replacement for jQuery's ".html()." It was the only thing I used jQuery for anymore, and I don't think that justifies loading it in.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •