From 89fef5d882749593739db1fae0c8de958a82a513 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Sun, 26 May 2013 06:43:13 +0000 Subject: [PATCH] Branch the generic JS utilities from the Backbone commands. See #24424. git-svn-id: https://develop.svn.wordpress.org/trunk@24368 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/js/wp-backbone.js | 25 ------------------------- wp-includes/js/wp-util.js | 27 +++++++++++++++++++++++++++ wp-includes/script-loader.php | 4 +++- 3 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 wp-includes/js/wp-util.js 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 );