namespace lib_dom { /** * @author fenris */ export function clone( element : Element, options : { context ?: Document; } = {} ) : Node { options = Object.assign( { "context": document, }, options ); return options.context.importNode(element, true); } /** * @author fenris */ export function request( id : string, options : { context ?: Document; arguments ?: (null | Record); } = {} ) : DocumentFragment { options = Object.assign( { "context": document, "arguments": null, }, options ); const template : (null | Element) = document.querySelector("template#" + id); if (template === null) { throw (new Error("template not found: " + id)); } else { const fragment : DocumentFragment = ( clone( template["content"], { "context": options.context, } ) as DocumentFragment ); if (options.arguments === null) { // do nothing } else { for (let index : int = 0; index < fragment.children.length; index += 1) { const element : Element = fragment.children[index]; element.innerHTML = lib_string.coin(element.innerHTML, options.arguments); } } return fragment; } } }