summaryrefslogtreecommitdiffstats
path: root/wp-includes/script-loader.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-03-09 15:17:25 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-03-09 15:17:25 +0000
commit492aa4ee7086ed94cb2f37a2bce3b52905841659 (patch)
tree825b6d0ae66246bae7a65c1f610a65b59789a6b5 /wp-includes/script-loader.php
parent359223a4711934ea6ec20e4c7613832e1f1132b5 (diff)
downloadwordpress-mu-492aa4ee7086ed94cb2f37a2bce3b52905841659.tar.gz
wordpress-mu-492aa4ee7086ed94cb2f37a2bce3b52905841659.tar.xz
wordpress-mu-492aa4ee7086ed94cb2f37a2bce3b52905841659.zip
WP Merge to rev 5007
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@909 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/script-loader.php')
-rw-r--r--wp-includes/script-loader.php144
1 files changed, 136 insertions, 8 deletions
diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php
index 8026973..a763315 100644
--- a/wp-includes/script-loader.php
+++ b/wp-includes/script-loader.php
@@ -19,9 +19,26 @@ class WP_Scripts {
$mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
$this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20070225' );
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0-0');
- $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116');
- $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '20070118');
- $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '20070118');
+ $this->add( 'autosave', '/wp-includes/js/autosave.js', array('prototype', 'sack'), '20070306');
+ $this->localize( 'autosave', 'autosaveL10n', array(
+ 'autosaveInterval' => apply_filters('autosave_interval', '120'),
+ 'errorText' => __('Error: %response%'),
+ 'saveText' => __('Saved at %time%.'),
+ 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
+ 'savingText' => __('Saving Draft...')
+ ) );
+ $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306');
+ $this->localize( 'wp-ajax', 'WPAjaxL10n', array(
+ 'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
+ 'permText' => __("You don't have permission to do that."),
+ 'strangeText' => __("Something strange happened. Try refreshing the page."),
+ 'whoaText' => __("Slow down, I'm still sending your data!")
+ ) );
+ $this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070306');
+ $this->localize( 'listman', 'listManL10n', array(
+ 'jumpText' => __('Jump to new item'),
+ 'delText' => __('Are you sure you want to delete this %thing%?')
+ ) );
$this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.7.0');
$this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.7.0');
$this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.7.0');
@@ -33,14 +50,66 @@ class WP_Scripts {
$this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.1.1');
$this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.1.1');
if ( is_admin() ) {
- $this->add( 'dbx-admin-key', '/wp-admin/dbx-admin-key-js.php', array('dbx'), '3651' );
- $this->add( 'ajaxcat', '/wp-admin/cat-js.php', array('listman'), '20070118' );
+ global $pagenow;
+ $man = false;
+ switch ( $pagenow ) :
+ case 'post.php' :
+ case 'post-new.php' :
+ $man = 'postmeta';
+ break;
+ case 'page.php' :
+ case 'page-new.php' :
+ $man = 'pagemeta';
+ break;
+ case 'link.php' :
+ $man = 'linkmeta';
+ break;
+ endswitch;
+ if ( $man ) {
+ $this->add( 'dbx-admin-key', '/wp-admin/dbx-admin-key.js', array('dbx'), '20070306' );
+ $this->localize( 'dbx-admin-key', 'dbxL10n', array(
+ 'manager' => $man,
+ 'open' => __('open'),
+ 'close' => __('close'),
+ 'moveMouse' => __('click-down and drag to move this box'),
+ 'toggleMouse' => __('click to %toggle% this box'),
+ 'moveKey' => __('use the arrow keys to move this box'),
+ 'toggleKey' => __(', or press the enter key to %toggle% it'),
+ ) );
+ }
+ $this->add( 'ajaxcat', '/wp-admin/cat.js', array('listman'), '20070306' );
+ $this->localize( 'ajaxcat', 'catL10n', array(
+ 'add' => attribute_escape(__('Add')),
+ 'how' => __('Separate multiple categories with commas.')
+ ) );
$this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' );
$this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' );
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' );
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' );
$this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
- $this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), '20070118' );
+ $this->add( 'upload', '/wp-admin/upload.js', array('prototype'), '20070306' );
+ $this->localize( 'upload', 'uploadL10n', array(
+ 'browseTitle' => attribute_escape(__('Browse your files')),
+ 'back' => __('&laquo; Back'),
+ 'directTitle' => attribute_escape(__('Direct link to file')),
+ 'edit' => __('Edit'),
+ 'thumb' => __('Thumbnail'),
+ 'full' => __('Full size'),
+ 'icon' => __('Icon'),
+ 'title' => __('Title'),
+ 'show' => __('Show:'),
+ 'link' => __('Link to:'),
+ 'file' => __('File'),
+ 'page' => __('Page'),
+ 'none' => __('None'),
+ 'editorText' => attribute_escape(__('Send to editor &raquo;')),
+ 'insert' => __('Insert'),
+ 'urlText' => __('URL'),
+ 'desc' => __('Description'),
+ 'deleteText' => attribute_escape(__('Delete File')),
+ 'saveText' => attribute_escape(__('Save &raquo;')),
+ 'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.")
+ ) );
}
}
@@ -81,14 +150,33 @@ class WP_Scripts {
$ver .= '&amp;' . $this->args[$handle];
$src = 0 === strpos($this->scripts[$handle]->src, 'http://') ? $this->scripts[$handle]->src : get_option( 'siteurl' ) . $this->scripts[$handle]->src;
$src = add_query_arg('ver', $ver, $src);
- $src = apply_filters( 'script_loader_src', $src );
+ $src = attribute_escape(apply_filters( 'script_loader_src', $src ));
echo "<script type='text/javascript' src='$src'></script>\n";
+ $this->print_scripts_l10n( $handle );
}
$this->printed[] = $handle;
}
}
}
+ function print_scripts_l10n( $handle ) {
+ if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) )
+ return;
+
+ $object_name = $this->scripts[$handle]->l10n_object;
+
+ echo "<script type='text/javascript'>\n";
+ echo "/* <![CDATA[ */\n";
+ echo "\t$object_name = {\n";
+ $eol = '';
+ foreach ( $this->scripts[$handle]->l10n as $var => $val ) {
+ echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
+ $eol = ",\n";
+ }
+ echo "\n\t}\n";
+ echo "/* ]]> */\n";
+ echo "</script>\n";
+ }
/**
* Determines dependencies of scripts
@@ -140,6 +228,22 @@ class WP_Scripts {
return true;
}
+ /**
+ * Localizes a script
+ *
+ * Localizes only if script has already been added
+ *
+ * @param string handle Script name
+ * @param string object_name Name of JS object to hold l10n info
+ * @param array l10n Array of JS var name => localized string
+ * @return bool Successful localization
+ */
+ function localize( $handle, $object_name, $l10n ) {
+ if ( !isset($this->scripts[$handle]) )
+ return false;
+ return $this->scripts[$handle]->localize( $object_name, $l10n );
+ }
+
function remove( $handles ) {
foreach ( (array) $handles as $handle )
unset($this->scripts[$handle]);
@@ -182,7 +286,8 @@ class _WP_Script {
var $src;
var $deps = array();
var $ver = false;
- var $args = false;
+ var $l10n_object = '';
+ var $l10n = array();
function _WP_Script() {
@list($this->handle, $this->src, $this->deps, $this->ver) = func_get_args();
@@ -191,6 +296,14 @@ class _WP_Script {
if ( !$this->ver )
$this->ver = false;
}
+
+ function localize( $object_name, $l10n ) {
+ if ( !$object_name || !is_array($l10n) )
+ return false;
+ $this->l10n_object = $object_name;
+ $this->l10n = $l10n;
+ return true;
+ }
}
/**
@@ -227,6 +340,21 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
$wp_scripts->add( $handle, $src, $deps, $ver );
}
+/**
+ * Localizes a script
+ *
+ * Localizes only if script has already been added
+ *
+ * @see WP_Script::localize()
+ */
+function wp_localize_script( $handle, $object_name, $l10n ) {
+ global $wp_scripts;
+ if ( !is_a($wp_scripts, 'WP_Scripts') )
+ return false;
+
+ return $wp_scripts->localize( $handle, $object_name, $l10n );
+}
+
function wp_deregister_script( $handle ) {
global $wp_scripts;
if ( !is_a($wp_scripts, 'WP_Scripts') )