2013-02-28 16:14:34 +01:00
|
|
|
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.
|
|
|
|
*/
|
2013-05-25 22:58:35 +02:00
|
|
|
wp.template = _.memoize(function ( id ) {
|
2013-02-28 16:14:34 +01:00
|
|
|
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));
|