Changeset 4968 for trunk/wp-includes/script-loader.php
- Timestamp:
- 03/06/2007 12:39:46 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/script-loader.php
r4948 r4968 22 22 $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116'); 23 23 $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '20070118'); 24 $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '20070118'); 24 $this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070305'); 25 $this->localize( 'listman', 'listManL10n', array( 26 'jumpText' => __('Jump to new item'), 27 'delText' => __('Are you sure you want to delete this %s?') 28 ) ); 25 29 $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.7.0'); 26 30 $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.7.0'); … … 84 88 $src = apply_filters( 'script_loader_src', $src ); 85 89 echo "<script type='text/javascript' src='$src'></script>\n"; 90 $this->print_scripts_l10n( $handle ); 86 91 } 87 92 $this->printed[] = $handle; … … 90 95 } 91 96 97 function print_scripts_l10n( $handle ) { 98 if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) ) 99 return; 100 101 $object_name = $this->scripts[$handle]->l10n_object; 102 103 echo "<script type='text/javascript'>\n"; 104 echo "/* <![CDATA[ */\n"; 105 echo "\t$object_name = {\n"; 106 $eol = ''; 107 foreach ( $this->scripts[$handle]->l10n as $var => $val ) { 108 echo "$eol\t\t$var: \"" . js_escape( $val ) . '"'; 109 $eol = ",\n"; 110 } 111 echo "\n\t}\n"; 112 echo "/* ]]> */\n"; 113 echo "</script>\n"; 114 } 92 115 93 116 /** … … 141 164 } 142 165 166 /** 167 * Localizes a script 168 * 169 * Localizes only if script has already been added 170 * 171 * @param string handle Script name 172 * @param string object_name Name of JS object to hold l10n info 173 * @param array l10n Array of JS var name => localized string 174 * @return bool Successful localization 175 */ 176 function localize( $handle, $object_name, $l10n ) { 177 if ( !isset($this->scripts[$handle]) ) 178 return false; 179 return $this->scripts[$handle]->localize( $object_name, $l10n ); 180 } 181 143 182 function remove( $handles ) { 144 183 foreach ( (array) $handles as $handle ) … … 183 222 var $deps = array(); 184 223 var $ver = false; 185 var $args = false; 224 var $l10n_object = ''; 225 var $l10n = array(); 186 226 187 227 function _WP_Script() { … … 192 232 $this->ver = false; 193 233 } 234 235 function localize( $object_name, $l10n ) { 236 if ( !$object_name || !is_array($l10n) ) 237 return false; 238 $this->l10n_object = $object_name; 239 $this->l10n = $l10n; 240 return true; 241 } 194 242 } 195 243 … … 228 276 } 229 277 278 /** 279 * Localizes a script 280 * 281 * Localizes only if script has already been added 282 * 283 * @see WP_Script::localize() 284 */ 285 function wp_localize_script( $handle, $object_name, $l10n ) { 286 global $wp_scripts; 287 if ( !is_a($wp_scripts, 'WP_Scripts') ) 288 return false; 289 290 return $wp_scripts->localize( $handle, $object_name, $l10n ); 291 } 292 230 293 function wp_deregister_script( $handle ) { 231 294 global $wp_scripts;
Note: See TracChangeset
for help on using the changeset viewer.