mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-01 00:27:38 +02:00
c4e0a1fc06
git-svn-id: http://core.svn.wordpress.org/trunk@24359 1a063a9b-81f0-0310-95a4-ce76da25c4cd
29 lines
772 B
JavaScript
29 lines
772 B
JavaScript
window.wp = window.wp || {};
|
|
|
|
(function ($) {
|
|
/**
|
|
* wp.template( id )
|
|
*
|
|
* Fetches a template by id.
|
|
*
|
|
* @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-".
|
|
* For example, "attachment" maps to "tmpl-attachment".
|
|
* @return {function} A function that lazily-compiles the template requested.
|
|
*/
|
|
wp.template = _.memoize(function ( id ) {
|
|
var compiled,
|
|
options = {
|
|
evaluate: /<#([\s\S]+?)#>/g,
|
|
interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
|
|
escape: /\{\{([^\}]+?)\}\}(?!\})/g,
|
|
variable: 'data'
|
|
};
|
|
|
|
return function ( data ) {
|
|
compiled = compiled || _.template( $( '#tmpl-' + id ).html(), null, options );
|
|
return compiled( data );
|
|
};
|
|
});
|
|
|
|
}(jQuery));
|