diff --git a/wp-includes/js/wp-backbone.js b/wp-includes/js/wp-backbone.js index 4e16956455..9e0041d4d0 100644 --- a/wp-includes/js/wp-backbone.js +++ b/wp-includes/js/wp-backbone.js @@ -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 = {}; diff --git a/wp-includes/js/wp-util.js b/wp-includes/js/wp-util.js new file mode 100644 index 0000000000..9177e54ace --- /dev/null +++ b/wp-includes/js/wp-util.js @@ -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)); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 9c1a59ab8f..1ecb16df33 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -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 );