Skip to content

Instantly share code, notes, and snippets.

@rafaelcanovas
Created October 18, 2016 04:50
Show Gist options
  • Save rafaelcanovas/5c69c0cd2ab842270bb83441e65fdff1 to your computer and use it in GitHub Desktop.
Save rafaelcanovas/5c69c0cd2ab842270bb83441e65fdff1 to your computer and use it in GitHub Desktop.
var loadTemplate = function (path, callback, asElement) {
/*
* Carrega um template Mustache remoto.
*/
var request = window.XMLHttpRequest ?
new XMLHttpRequest() :
new ActiveXObject('Microsoft.XMLHTTP');
request.addEventListener('load', function () {
var templateContent = this.responseText,
wrapper = document.createElement('div');
Mustache.parse(templateContent);
wrapper.innerHTML = templateContent;
if (asElement)
callback(wrapper.firstChild);
else
callback(templateContent);
});
request.open('GET', path);
request.send();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment