|
1 /* global _wpUtilSettings */ |
1 window.wp = window.wp || {}; |
2 window.wp = window.wp || {}; |
2 |
3 |
3 (function ($) { |
4 (function ($) { |
4 // Check for the utility settings. |
5 // Check for the utility settings. |
5 var settings = typeof _wpUtilSettings === 'undefined' ? {} : _wpUtilSettings; |
6 var settings = typeof _wpUtilSettings === 'undefined' ? {} : _wpUtilSettings; |
6 |
7 |
7 /** |
8 /** |
8 * wp.template( id ) |
9 * wp.template( id ) |
9 * |
10 * |
10 * Fetches a template by id. |
11 * Fetch a JavaScript template for an id, and return a templating function for it. |
11 * |
12 * |
12 * @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-". |
13 * @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-". |
13 * For example, "attachment" maps to "tmpl-attachment". |
14 * For example, "attachment" maps to "tmpl-attachment". |
14 * @return {function} A function that lazily-compiles the template requested. |
15 * @return {function} A function that lazily-compiles the template requested. |
15 */ |
16 */ |
16 wp.template = _.memoize(function ( id ) { |
17 wp.template = _.memoize(function ( id ) { |
17 var compiled, |
18 var compiled, |
|
19 /* |
|
20 * Underscore's default ERB-style templates are incompatible with PHP |
|
21 * when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax. |
|
22 * |
|
23 * @see trac ticket #22344. |
|
24 */ |
18 options = { |
25 options = { |
19 evaluate: /<#([\s\S]+?)#>/g, |
26 evaluate: /<#([\s\S]+?)#>/g, |
20 interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, |
27 interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, |
21 escape: /\{\{([^\}]+?)\}\}(?!\})/g, |
28 escape: /\{\{([^\}]+?)\}\}(?!\})/g, |
22 variable: 'data' |
29 variable: 'data' |