<!DOCTYPE html>
<html>
<head>
	<script src="/usr/share/javascript/jsquery/jquery.min.js" type="text/javascript"></script>
	<script src="/usr/share/javascript/jsrender/jsrender.min.js" type="text/javascript"></script>
	<link href="../resources/demos.css" rel="stylesheet" type="text/css" />

	<link href="../resources/movielist.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a href="../demos.html">JsRender Demos</a><br />

<h3>Custom tags</h3>

<pre>
&lt;td>{{sort languages reverse=true}}...{{/sort}}&lt;/td>

$.views.tags({

    // Tag to reverse-sort an array

    sort: function( array ) {
        var ret = "";
        if ( this.props.reverse ) {
            // Render in reverse order
            for ( var i = array.length; i; i-- ) {
                ret += this.renderContent( array[ i - 1 ] );
            }
        } else {
            // Render in original order
            ret += this.renderContent( array );
        }
        return ret;
    }

});
</pre>

<!--================ Demo ================-->

<script id="movieTemplate" type="text/x-jsrender">
	<tr>
		<td>{{>title}}</td>
		<td>{{sort languages tmpl="#sortedTemplate"/}}</td>
		<td>
			{{sort languages reverse=true}}
				<div>
					<b>{{>name}}</b>
				</div>
			{{/sort}}
		</td>

	</tr>
</script>

<script id="sortedTemplate" type="text/x-jsrender">
	<div>{{>name}}</div>
</script>

<table>
	<thead><tr><th>Title</th><th>Languages</th><th>Reverse order</th></tr></thead>
	<tbody id="movieList"></tbody>
</table>

<script type="text/javascript">

	$.views.tags({

		// Tag to reverse-sort an array
		sort: function( array ) {
			var ret = "";
			if ( this.props.reverse ) {
				// Render in reverse order
				for ( var i = array.length; i; i-- ) {
					ret += this.renderContent( array[ i - 1 ] );
				}
			} else {
				// Render in original order
				ret += this.renderContent( array );
			}
			return ret;
		}

	});

	var movies = [
		{
			title: "Meet Joe Black",
			languages: [
				{ name: "English" },
				{ name: "French" }
			]
		},
		{
			title: "Eyes Wide Shut",
			languages: [
				{ name: "French" },
				{ name: "German" },
				{ name: "Spanish" }
			]
		}
	];

	$( "#movieList" ).html(
		$( "#movieTemplate" ).render( movies )
	);

</script>

</body>
</html>
