Branch the generic JS utilities from the Backbone commands. See #24424.

git-svn-id: http://core.svn.wordpress.org/trunk@24368 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2013-05-26 06:43:13 +00:00
parent 452c0f4166
commit 35bb7c6848
3 changed files with 30 additions and 26 deletions

View File

@ -1,31 +1,6 @@
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 );
};
});
// Create the WordPress Backbone namespace.
wp.Backbone = {};

27
wp-includes/js/wp-util.js Normal file
View File

@ -0,0 +1,27 @@
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));

View File

@ -273,7 +273,9 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'underscore', '/wp-includes/js/underscore.min.js', array(), '1.4.4', 1 );
$scripts->add( 'backbone', '/wp-includes/js/backbone.min.js', array('underscore','jquery'), '1.0.0', 1 );
$scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array('backbone'), false, 1 );
$scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array('underscore', 'jquery'), false, 1 );
$scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array('backbone', 'wp-util'), false, 1 );
$scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'jquery-ui-tooltip' ), false, 1 );