share/htdocs/js/mustache.js in omf_web-0.9.7 vs share/htdocs/js/mustache.js in omf_web-0.9.8

- old
+ new

@@ -6,24 +6,30 @@ var moustache = { version: "0.1", } - var template_url = opts.template; - if (! template_url) { - throw "Missing template declaration in mustache widget"; - } - var context = {}; + var context = opts.context || {}; var el = $('#' + opts.base_id); - - $.ajax({ - url: '/resource/' + template_url, - type: 'get' - }).done(function(template) { + var render_f = function(template) { var html = Mustache.to_html(template, context); el.html(html); var i = 0; - }) + }; + + var text = opts.text; + if (text) { //} != undefined) { + render_f(text); + } else { + var template_url = opts.template; + if (! template_url) { + throw "Missing template declaration in mustache widget"; + } + $.ajax({ + url: '/resource/' + template_url, + type: 'get' + }).done(render_f); + } return moustache; } }) \ No newline at end of file