Wordpress/wp-includes/js/wp-backbone.js
Daryl Koopersmith 2dcee73454 Begin a common WordPress Backbone helpers file.
Moves the `wp.template` helper to `wp-backbone.js`.



git-svn-id: https://develop.svn.wordpress.org/trunk@24358 602fd350-edb4-49c9-b593-d223f7449a82
2013-05-25 20:47:55 +00:00

30 lines
798 B
JavaScript

window.wp = window.wp || {};
(function ($) {
var template;
/**
* 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.
*/
template = 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));