mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Add a handlebars helper for variadic compound AND conditions.
e.g., from a comment in the commit:
// Execute the conditional code if all conditions are true.
// Example usage:
// {{#if_and cond1 cond2 cond3}}
// <p>All true</p>
// {{/if_and}}
We'll use this for the email forwarding UI, but it may also be
generally useful, and easy to generalize to OR.
(imported from commit da601f94d9da300213ff46be50255135c014eca0)
This commit is contained in:
@@ -35,6 +35,22 @@ $(function () {
|
||||
Handlebars.registerHelper('plural', function (condition, one, other) {
|
||||
return (condition === 1) ? one : other;
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('if_and', function () {
|
||||
// Execute the conditional code if all conditions are true.
|
||||
// Example usage:
|
||||
// {{#if_and cond1 cond2 cond3}}
|
||||
// <p>All true</p>
|
||||
// {{/if_and}}
|
||||
var options = arguments[arguments.length - 1];
|
||||
var i;
|
||||
for (i = 0; i < arguments.length - 1; i++) {
|
||||
if (!arguments[i]) {
|
||||
return options.inverse(this);
|
||||
}
|
||||
}
|
||||
return options.fn(this);
|
||||
});
|
||||
});
|
||||
|
||||
return exports;
|
||||
|
||||
Reference in New Issue
Block a user