PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / team-updraft / common-libs / src / updraft-theme / helpers / handlebar-helpers.js

handlebar-helpers.js in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/team-updraft/common-libs/src/updraft-theme/helpers/handlebar-helpers.js

50 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * A Handlebarsjs helper function that is used to compare
3 * two values if they are equal. Please refer to the example below.
4 * Assuming "comment_status" contains the value of "spam".
5 *
6 * @param {mixed} a The first value to compare
7 * @param {mixed} b The second value to compare
8 *
9 * @example
10 * // returns "<span>I am spam!</span>", otherwise "<span>I am not a spam!</span>"
11 * {{#ifeq "spam" comment_status}}
12 * <span>I am spam!</span>
13 * {{else}}
14 * <span>I am not a spam!</span>
15 * {{/ifeq}}
16 *
17 * @return {string}
18 */
19 Handlebars.registerHelper('ifeq', function (a, b, opts) {
20 if ('string' !== typeof a && 'undefined' !== typeof a && null !== a) a = a.toString();
21 if ('string' !== typeof b && 'undefined' !== typeof b && null !== b) b = b.toString();
22 if (a === b) {
23 return opts.fn(this);
24 } else {
25 return opts.inverse(this);
26 }
27 });
28
29 /**
30 * A Handlebarsjs helper function that is used to compare
31 * two values if they are not equal. Please refer to the example below.
32 * Assuming "user_id" contains the value of "123".
33 *
34 * @param {mixed} a The first value to compare
35 * @param {mixed} b The second value to compare
36 *
37 * @example returns "<span>Valid user!</span>", otherwise "<span>Invalid user!</span>" {{#ifneq user_id 0}} <span>Valid user!</span> {{else}} <span>Invalid user!</span> {{/ifneq}}
38 *
39 * @return {string}
40 */
41 Handlebars.registerHelper('ifneq', function (a, b, opts) {
42 if (typeof a !== 'string') a = a.toString();
43 if (typeof b !== 'string') b = b.toString();
44 if (a !== b) {
45 return opts.fn(this);
46 } else {
47 return opts.inverse(this);
48 }
49 });
50