Skip to content

Instantly share code, notes, and snippets.

Created Dec 16, 2014
What would you like to do?
Object JavaScript - Loading big template using Infuser
<!DOCTYPE html>
<title>Infuser Page Load</title>
<input id="btnTemplate" type="button" value="Say Hello!">
<span id="msg"></span>
<div id="target"></div>
<script type="text/javascript" src="Scripts/jquery-2.0.0.js"></script>
<script type="text/javascript" src="Scripts/TrafficCop.js"></script>
<script type="text/javascript" src="Scripts/infuser.js"></script>
var toggled = false;
$(function () {
// pre-loading image for our custom "loading template"
var loadingImg = $('<img />').attr('src', './images/ajax-loader.gif'),
origRender = infuser.defaults.render;
$('#btnTemplate').click(function () {
infuser.defaults.templateUrl = "./templates";
infuser.defaults.loadingTemplate.content =
"<div class='infuser-loading'>" +
"<img src='./images/ajax-loader.gif'>Loading...</div>"
infuser.defaults.loadingTemplate.transitionOut = function () { };
infuser.infuse("Hello", {
target: "#target",
render: function (target, template) {
// really ugly way to simulate long running template retrieval
setTimeout(function () {
origRender(target, template);
}, 4000);
postRender: function (target) {
if (!toggled) {
$("#msg").text("Click uses a locally cached template");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment