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
| 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 |