Files
zulip/static/js/templates.js
Kevin Mehall eac6463031 Implement message summarization experiment.
When you read messages in a narrow and then un-narrow, collapse
adjacent messages read in the narrow into a summary row that can
be clicked to expand those messages.

Scoped to staging with feature flags.

The implementation of this within our current MessageList is rather ugly.

(imported from commit bcb3a39d8c0c334136fe86318f18ead03f0f50bf)
2013-08-07 10:24:03 -04:00

42 lines
1.2 KiB
JavaScript

var templates = (function () {
var exports = {};
exports.render = function (name, arg) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
if (Handlebars.templates[name] === undefined) {
// Fetch the template using a synchronous AJAX request.
//
// This is only for local development. In prod we precompile
// templates and serve JavaScript which will have already
// populated Handlebars.templates.
$.ajax({
url: '/static/templates/'+name+'.handlebars?' + new Date().getTime(),
async: false,
success: function (data) {
Handlebars.templates[name] = Handlebars.compile(data);
}
});
}
return Handlebars.templates[name](arg);
};
$(function () {
// Regular Handlebars partials require pre-registering. This allows us
// to treat any template as a partial.
Handlebars.registerHelper('partial', function (template_name, context) {
return new Handlebars.SafeString(exports.render(template_name, this));
});
Handlebars.registerHelper('plural', function (condition, one, other) {
return (condition === 1) ? one : other;
});
});
return exports;
}());