<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Callback usage example</title>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../xtemplate.js"></script>
<script src="http://diegolamonica.info/demo/SourceViewer/sourceviewer.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<style>
div#example {
border-radius: 10px;
border: 2px dashed #ddd;
margin: 1em;
padding: 1em;
}
</style>
</head>
<body>
<script type="text/x-template" id="country-template">
and I am from {$country}
</script>
<script type="text/x-template" id="name-template">
<div class="row">
<div class="col-md-12">
Hello, my name is {$name}
{#country-template}
</div>
</div>
</script>
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="./">XTemplate</a>
</div>
<p class="navbar-text">Using callback</p>
</div><!-- /.container-fluid -->
</nav>
<div class="row" id="example">
<div class="col-md-12" id="my-section">
This text will be replaced
</div>
</div>
<div class="row">
<div class="well well-lg">
<h1>Did you enjoyed this example?</h1>
<p>
Producing this library and an example like this, bring me a lot of time away from me, so I need to
know how much this library is of community interest to program its evolutions, updates and upgrades.
</p>
<p>
Then I'm asking you to perform 3 simple things to demonstrate your interest:
</p>
<ol>
<li><a target="_blank" href="https://github.com/diegolamonica/XTemplate">Star</a> (and watch) this library on GitHub</li>
<li><a target="_blank" href="https://twitter.com/jast">Follow me</a> on Twitter</li>
<li>Add a like to <a target="_blank" href="https://www.facebook.com/DiegoLaMonica.FanPage">my Facebook page</a></li>
</ol>
</div>
</div>
<!-- Source code viewer -->
<ul class="nav nav-tabs">
<li class="active"><a href="#js-code" data-toggle="tab">Javascript</a></li>
<li><a href="#xt-code" data-toggle="tab">Templates</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="js-code"><pre class="sh_javascript" id="js"></pre></div>
<div class="tab-pane" id="xt-code"><pre class="sh_html" id="xt"></pre></div>
</div>
<!-- End source code -->
</div>
<script type="text/javascript" id="source-code">
function showExample() {
function myDataCallback(row) {
var names = {
John: 'London',
Aaron: 'New York City',
Anita: 'Spain'
}
if (names[row.name] !== undefined) {
row.country = names[row.name];
}
return row;
}
var x = new Xtemplate(),
rows = [
{name: 'Diego', country: 'Italy'},
{name: 'John'},
{name: 'Aaron'},
{name: 'Anita'}
],
output = x.apply('#name-template', rows, myDataCallback);
$('#my-section').html(output);
}
</script>
<link rel="stylesheet" type="text/css" href="http://shjs.sourceforge.net/css/sh_nedit.min.css" />
<script type="text/javascript" src="http://shjs.sourceforge.net/sh_main.min.js"></script>
<script type="text/javascript" src="http://shjs.sourceforge.net/lang/sh_html.min.js"></script>
<script type="text/javascript" src="http://shjs.sourceforge.net/lang/sh_javascript.min.js"></script>
<script>
SourceViewer.createDisplayArea(null, 'xt',
SourceViewer.getSource('#country-template',true) + "\n\n" +
SourceViewer.getSource('#name-template',true)
);
SourceViewer.createDisplayArea(null, 'js', '#source-code');
showExample();
sh_highlightDocument();
</script>
<a href="https://github.com/diegolamonica/XTemplate"><img style="position: fixed; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
</body>
</html>
|