namespace Views { export namespace Templates { let _templates ; function initialiseSuccess ( data , textStatus , jqXHR , callback ) { let templates = { } ; let jquery = $ ( data ) ; for ( let i = 0 ; i < jquery . length ; ++ i ) { let template = jquery [ i ] ; if ( ( template ) && ( template . getAttribute ) && ( template . getAttribute ( 'data-view' ) ) ) { templates [ template . getAttribute ( 'data-view' ) ] = template ; } } _templates = templates ; callback ( ) ; } function initialiseError ( jqXHR , textStatus , errorThrown ? ) { Utils . log ( Utils . LogSeverity . Error , "Failed to initialise template framework" , textStatus , errorThrown ) ; } export function initialise ( url , callback ) { if ( _templates ) return ; $ . ajax ( { type : 'GET' , url : url , success : ( data , textStatus , jqXHR ) => initialiseSuccess ( data , textStatus , jqXHR , callback ) , error : initialiseError } ) ; } export function cloneTemplate < T extends Element > ( view ) { if ( ! _templates ) throw "Template framework not initialised" ; let template = _templates [ view ] ; if ( ! template ) throw "Template not found: " + view ; return < T > template . firstElementChild . cloneNode ( true ) ; } export function createDiv ( className ) { let div = document . createElement ( 'div' ) ; div . className = className ; return div ; } } }