mirror of https://github.com/zulip/zulip.git
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:
parent
15afdf65eb
commit
f7784a2f1d
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue