forked from blueimp/JavaScript-Templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
48 lines (44 loc) · 1.24 KB
/
demo.js
File metadata and controls
48 lines (44 loc) · 1.24 KB
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
/*
* JavaScript Templates Demo JS 2.2.1
* https://github.com/blueimp/JavaScript-Templates
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
/*global window, $ */
$(function () {
'use strict';
var render = function (event) {
event.preventDefault();
var result;
try {
result = window.tmpl(
$('#template').val(),
$.parseJSON($('#data').val())
);
} catch (e) {
result = window.tmpl('tmpl-error', e);
}
$('#result').html(result);
},
init = function (event) {
if (event) {
event.preventDefault();
}
$('#template').val($.trim($('#tmpl-demo').html()));
$('#data').val($.trim($('#tmpl-data').html()));
$('#result').empty();
},
error = function (e) {
$('#result').html(
window.tmpl('tmpl-error', e.originalEvent.message)
);
};
$(window).on('error', error);
$('#render').on('click', render);
$('#reset').on('click', init);
init();
});