3 * BackPress Scripts enqueue.
5 * These classes were refactored from the WordPress WP_Scripts and WordPress
13 * BackPress Scripts enqueue class.
16 * @uses WP_Dependencies
19 class WP_Scripts extends WP_Dependencies {
20 var $base_url; // Full URL with trailing slash
23 function __construct() {
24 do_action_ref_array( 'wp_default_scripts', array(&$this) );
30 * Prints the scripts passed to it or the print queue. Also prints all necessary dependencies.
32 * @param mixed handles (optional) Scripts to be printed. (void) prints queue, (string) prints that script, (array of strings) prints those scripts.
33 * @return array Scripts that have been printed
35 function print_scripts( $handles = false ) {
36 return $this->do_items( $handles );
39 function print_scripts_l10n( $handle ) {
40 if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) )
43 $object_name = $this->registered[$handle]->extra['l10n'][0];
45 echo "<script type='text/javascript'>\n";
46 echo "/* <![CDATA[ */\n";
47 echo "\t$object_name = {\n";
49 foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) {
50 if ( 'l10n_print_after' == $var ) {
54 echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
58 echo isset($after) ? "\t$after\n" : '';
65 function do_item( $handle ) {
66 if ( !parent::do_item($handle) )
69 $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
70 if ( isset($this->args[$handle]) )
71 $ver .= '&' . $this->args[$handle];
73 $src = $this->registered[$handle]->src;
74 if ( !preg_match('|^https?://|', $src) && !preg_match('|^' . preg_quote(WP_CONTENT_URL) . '|', $src) ) {
75 $src = $this->base_url . $src;
78 $src = add_query_arg('ver', $ver, $src);
79 $src = clean_url(apply_filters( 'script_loader_src', $src, $handle ));
81 $this->print_scripts_l10n( $handle );
83 echo "<script type='text/javascript' src='$src'></script>\n";
91 * Localizes only if script has already been added
93 * @param string handle Script name
94 * @param string object_name Name of JS object to hold l10n info
95 * @param array l10n Array of JS var name => localized string
96 * @return bool Successful localization
98 function localize( $handle, $object_name, $l10n ) {
99 if ( !$object_name || !$l10n )
101 return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) );
104 function all_deps( $handles, $recursion = false ) {
105 $r = parent::all_deps( $handles, $recursion );
107 $this->to_do = apply_filters( 'print_scripts_array', $this->to_do );