1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
A tabs control against data, using {{tmpl}}
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A tabs control against data, using {{tmpl}}</title>
<link href="resources/tabs.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Tabs</h1>
<div id="tabsView">..loading</div>
<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
<script src="../../../jquery.tmpl.js" type="text/javascript"></script>
<script id="tabsTmpl" type="text/x-jquery-tmpl">
<table class="tabsView"><tbody>
<tr>{{tmpl(items) "#headerItemTmpl"}}</tr>
<tr><td colspan="${items.length}">
<div class="body">{{tmpl(activeDataItem) "#contentTmpl"}}</div>
</td></tr>
</tbody></table>
</script>
<script id="headerItemTmpl" type="text/x-jquery-tmpl">
<th class="header_${$data === activeDataItem}">${name}</th>
</script>
<script id="contentTmpl" type="text/x-jquery-tmpl">
<h3>${title}</h3>
<div>{{html description}}</div>
</script>
<script type="text/javascript">
// ******************** Data for categories and samples ********************
var samples = {
title: "Templating samples",
items: [
{ name: "Inline", title: "Template inline in a script block",
description:"Rendering a <span class='special'>template</span> declared in script block" },
{ name: "String", title: "Template as string",
description:"Rendering a <span class='special'>template</span> passed as a string" },
{ name: "Remote", title: "Render remote data",
description:"Rendering remote data using <span class='special'>templates</span>" },
{ name: "TreeView", title: "Building a Tree View",
description:"A tree view using recursive nested <span class='special'>templates</span>" },
{ name: "Tabs", title: "A Tabs control",
description:"Create a tabs control using <span class='special'>templates</span>" }
]
},
activeDataItem = samples.items[0];
// ******************** Load UI ********************
$( "#tabsView" ).empty();
$( "#tabsTmpl" ).tmpl( samples ).appendTo( "#tabsView" );
// ******************** Events ********************
$( "#tabsView" )
.delegate( ".header_false", "click", function() {
// Get the 'template item' for this tab
var activeHeaderTmplItem = $.tmplItem( this );
activeDataItem = activeHeaderTmplItem.data;
// Update the template item for the whole tabs control
activeHeaderTmplItem.parent.update();
})
</script>
</body>
</html>
|