X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=8e282a8d3f2271dab6f393d35426af018e198c91;hb=b02972410ce4e86179e43f92f66a9eb4a6d3e909;hp=7d5856e262561b8f28683c1ddb9bdd9f712e6e47;hpb=88a5ef9143b21328f8229f223ed8a8336b54e669;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 7d5856e..8e282a8 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -100,6 +100,29 @@ mkws.debug_function = function (string) { } var debug = mkws.debug_function; // local alias + +Handlebars.registerHelper('link', function(a) { + var result = ""; + for (var i in a) { + if (i > 0) result += "
"; + var text = Handlebars.Utils.escapeExpression(a[i]); + result += '' + text + ''; + } + + return new Handlebars.SafeString(result); +}); + + +Handlebars.registerHelper('json', function(obj) { + return JSON.stringify(obj); +}); + + +Handlebars.registerHelper('first', function(items, options) { + return options.fn(items[0]); +}); + + { /* default mkws config */ var config_default = { @@ -655,6 +678,23 @@ function renderDetails(data, marker) return '
' + details + '
'; } + +function maybeLoadTemplate(name) +{ + var source = $("#mkwsTemplate" + name).html(); + if (!source) { + debug("no template '" + name + "': falling back to default behaviour"); + // Mark template as not provided + mkws['template' + name] = 0; + return; + } + + var template = Handlebars.compile(source); + debug("compiled template '" + name + "'"); + mkws['template' + name] = template; +} + + function defaultRenderDetails(data, marker) { var details = ''; @@ -680,22 +720,6 @@ function defaultRenderDetails(data, marker) } -function maybeLoadTemplate(name) -{ - var source = $("#mkwsTemplate" + name).html(); - if (!source) { - debug("no template '" + name + "': falling back to default behaviour"); - // Mark template as not provided - mkws['template' + name] = 0; - return; - } - - var template = Handlebars.compile(source); - debug("compiled template '" + name + "'"); - mkws['template' + name] = template; -} - - function renderField(caption, data, data2, data3) { if (data === undefined) { return "";