WordPress.org

Make WordPress Core

Changeset 10357


Ignore:
Timestamp:
01/14/09 14:18:51 (5 years ago)
Author:
azaozz
Message:

Split the script queue in head and footer part, concatenate and compress the default js and css, first run, see #8628

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r10349 r10357  
    6363    echo join( $results, "\n" ); 
    6464    die; 
     65    break; 
     66case 'wp-compression-test' : 
     67    if ( !current_user_can( 'manage_options' ) ) 
     68        die('-1'); 
     69     
     70    if ( isset($_GET['tested']) ) { 
     71        if ( 1 == $_GET['tested'] ) 
     72            update_option('can_compress_scripts', 1); 
     73        elseif ( 0 == $_GET['tested'] ) 
     74            update_option('can_compress_scripts', 0); 
     75    } 
     76    die('0'); 
    6577    break; 
    6678default : 
  • trunk/wp-admin/admin-footer.php

    r9964 r10357  
    2323<div class="clear"></div> 
    2424</div> 
    25 <?php do_action('admin_footer', ''); ?> 
     25<?php 
     26do_action('admin_footer', ''); 
     27do_action('admin_print_footer_scripts'); 
     28 
     29if ( false === get_option('can_compress_scripts') ) 
     30    compression_test(); 
     31?> 
    2632<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> 
    2733</body> 
    2834</html> 
     35 
  • trunk/wp-admin/includes/template.php

    r10348 r10357  
    33883388} 
    33893389 
     3390/** 
     3391 * Test support for compressed JavaScript and CSS 
     3392 * 
     3393 * Outputs JavaScript that tests if compression from PHP works as expected 
     3394 * and sets an option with the result. Has no effect when the current user 
     3395 * is not an administrator. To run the test again the option 'can_compress_scripts' 
     3396 * has to be deleted.  
     3397 * 
     3398 * @since 2.8.0 
     3399 */ 
     3400function compression_test() { 
    33903401?> 
     3402    <script type="text/javascript" src="load-scripts.php?test=1"></script> 
     3403    <script type="text/javascript"> 
     3404    /* <![CDATA[ */ 
     3405    (function() { 
     3406        var x, test = typeof wpCompressionTest == 'undefined' ? 0 : 1; 
     3407        if ( window.XMLHttpRequest ) { 
     3408            x = new XMLHttpRequest(); 
     3409        } else { 
     3410            try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};} 
     3411        } 
     3412     
     3413        if (x) { 
     3414            x.open('GET', 'admin-ajax.php?action=wp-compression-test&tested='+test+'&'+(new Date()).getTime(), true); 
     3415            x.send(''); 
     3416        } 
     3417    })(); 
     3418    /* ]]> */ 
     3419    </script> 
     3420<?php 
     3421} 
     3422 
     3423?> 
  • trunk/wp-includes/class.wp-dependencies.php

    r9002 r10357  
    2323    var $done = array(); 
    2424    var $args = array(); 
     25    var $groups = array(); 
     26    var $group = 0; 
    2527 
    2628    function WP_Dependencies() { 
     
    3941     * @return array Items that have been processed 
    4042     */ 
    41     function do_items( $handles = false ) { 
     43    function do_items( $handles = false, $group = false ) { 
    4244        // Print the queue if nothing is passed.  If a string is passed, print that script.  If an array is passed, print those scripts. 
    4345        $handles = false === $handles ? $this->queue : (array) $handles; 
    4446        $this->all_deps( $handles ); 
    4547 
    46         foreach( $this->to_do as $handle ) { 
     48        foreach( $this->to_do as $key => $handle ) { 
    4749            if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) { 
    48                 if ( $this->registered[$handle]->src ) { // Else it defines a group. 
    49                     $this->do_item( $handle ); 
     50 
     51                if ( ! $this->registered[$handle]->src ) { // Defines a group. 
     52                    $this->done[] = $handle; 
     53                    continue; 
    5054                } 
    51                 $this->done[] = $handle; 
     55 
     56                if ( $this->do_item( $handle, $group ) ) 
     57                    $this->done[] = $handle; 
     58 
     59                unset( $this->to_do[$key] ); 
    5260            } 
    5361        } 
    5462 
    55         $this->to_do = array(); 
    5663        return $this->done; 
    5764    } 
     
    7077     * @param bool recursion Used internally when function calls itself 
    7178     */ 
    72     function all_deps( $handles, $recursion = false ) { 
     79    function all_deps( $handles, $recursion = false, $group = false ) { 
    7380        if ( !$handles = (array) $handles ) 
    7481            return false; 
    7582 
    7683        foreach ( $handles as $handle ) { 
    77             $handle = explode('?', $handle); 
    78             if ( isset($handle[1]) ) 
    79                 $this->args[$handle[0]] = $handle[1]; 
    80             $handle = $handle[0]; 
    81  
    82             if ( isset($this->to_do[$handle]) ) // Already grobbed it and its deps 
     84            $handle_parts = explode('?', $handle); 
     85            $handle = $handle_parts[0]; 
     86 
     87            if ( in_array($handle, $this->done, true) ) // Already done 
    8388                continue; 
     89 
     90            $this->set_group( $handle, $recursion, $group ); 
     91 
     92            if ( in_array($handle, $this->to_do, true) ) // Already grobbed it and its deps 
     93                continue; 
     94 
     95            if ( isset($handle_parts[1]) ) 
     96                $this->args[$handle] = $handle_parts[1]; 
    8497 
    8598            $keep_going = true; 
     
    88101            elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) 
    89102                $keep_going = false; // Script requires deps which don't exist (not a necessary check.  efficiency?) 
    90             elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true ) ) 
     103            elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) ) 
    91104                $keep_going = false; // Script requires deps which don't exist 
    92105 
     
    98111            } 
    99112 
    100             $this->to_do[$handle] = true; 
     113            $this->to_do[] = $handle; 
    101114        } 
    102115 
    103         if ( !$recursion ) // at the end 
    104             $this->to_do = array_keys( $this->to_do ); 
    105116        return true; 
    106117    } 
     
    182193    } 
    183194 
     195    function set_group( $handle, $recursion, $group ) { 
     196        $group = (int) $group; 
     197 
     198        if ( $recursion ) 
     199            $group = min($this->group, $group); 
     200        else 
     201            $this->group = $group; 
     202 
     203        if ( isset($this->groups[$handle]) && $this->groups[$handle] <= $group ) 
     204            return false; 
     205 
     206        $this->groups[$handle] = $group; 
     207        return true; 
     208    } 
     209 
    184210} 
    185211 
  • trunk/wp-includes/class.wp-scripts.php

    r10135 r10357  
    1919class WP_Scripts extends WP_Dependencies { 
    2020    var $base_url; // Full URL with trailing slash 
     21    var $content_url; 
    2122    var $default_version; 
     23    var $in_footer = array(); 
     24    var $concat = ''; 
     25    var $concat_version = ''; 
     26    var $do_concat = false; 
     27    var $print_html = ''; 
     28    var $print_code = ''; 
     29    var $default_dirs; 
    2230 
    2331    function __construct() { 
     
    3139     * 
    3240     * @param mixed handles (optional) Scripts to be printed.  (void) prints queue, (string) prints that script, (array of strings) prints those scripts. 
     41     * @param int group (optional) If scripts were queued in groups prints this group number. 
    3342     * @return array Scripts that have been printed 
    3443     */ 
    35     function print_scripts( $handles = false ) { 
    36         return $this->do_items( $handles ); 
     44    function print_scripts( $handles = false, $group = false ) { 
     45        return $this->do_items( $handles, $group ); 
    3746    } 
    3847 
    39     function print_scripts_l10n( $handle ) { 
     48    function print_scripts_l10n( $handle, $echo = true ) { 
    4049        if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) ) 
    4150            return false; 
     
    4352        $object_name = $this->registered[$handle]->extra['l10n'][0]; 
    4453 
    45         echo "<script type='text/javascript'>\n"; 
    46         echo "/* <![CDATA[ */\n"; 
    47         echo "\t$object_name = {\n"; 
     54        $data = "var $object_name = {\n"; 
    4855        $eol = ''; 
    4956        foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) { 
     
    5259                continue; 
    5360            } 
    54             echo "$eol\t\t$var: \"" . js_escape( $val ) . '"'; 
     61            $data .= "$eol\t$var: \"" . js_escape( $val ) . '"'; 
    5562            $eol = ",\n"; 
    5663        } 
    57         echo "\n\t}\n"; 
    58         echo isset($after) ? "\t$after\n" : ''; 
    59         echo "/* ]]> */\n"; 
    60         echo "</script>\n"; 
     64        $data .= "\n};\n"; 
     65        $data .= isset($after) ? "$after\n" : ''; 
    6166 
    62         return true; 
     67        if ( $echo ) { 
     68            echo "<script type='text/javascript'>\n"; 
     69            echo "/* <![CDATA[ */\n"; 
     70            echo $data; 
     71            echo "/* ]]> */\n"; 
     72            echo "</script>\n"; 
     73            return true; 
     74        } else { 
     75            return $data; 
     76        } 
    6377    } 
    6478 
    65     function do_item( $handle ) { 
     79    function do_item( $handle, $group = false ) { 
    6680        if ( !parent::do_item($handle) ) 
    6781            return false; 
     82 
     83        if ( 0 === $group && $this->groups[$handle] > 0 ) { 
     84            $this->in_footer[] = $handle; 
     85            return false; 
     86        } 
     87 
     88        if ( false === $group && in_array($handle, $this->in_footer, true) ) 
     89            $this->in_footer = array_diff( $this->in_footer, (array) $handle ); 
    6890 
    6991        $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 
     
    7294 
    7395        $src = $this->registered[$handle]->src; 
    74         if ( !preg_match('|^https?://|', $src) && !preg_match('|^' . preg_quote(WP_CONTENT_URL) . '|', $src) ) { 
     96 
     97        if ( $this->do_concat ) { 
     98            $srce = apply_filters( 'script_loader_src', $src, $handle, $echo ); 
     99            if ( $this->in_default_dir($srce) ) { 
     100                $this->print_code .= $this->print_scripts_l10n( $handle, false ); 
     101                $this->concat .= $handle . ','; 
     102                $this->concat_version .= $ver; 
     103                return true; 
     104            } 
     105        } 
     106 
     107        $this->print_scripts_l10n( $handle ); 
     108        if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { 
    75109            $src = $this->base_url . $src; 
    76110        } 
    77111 
    78112        $src = add_query_arg('ver', $ver, $src); 
    79         $src = clean_url(apply_filters( 'script_loader_src', $src, $handle )); 
     113        $src = clean_url(apply_filters( 'script_loader_src', $src, $handle, $echo )); 
    80114 
    81         $this->print_scripts_l10n( $handle ); 
    82  
    83         echo "<script type='text/javascript' src='$src'></script>\n"; 
     115        if ( $this->do_concat ) 
     116            $this->print_html .= "<script type='text/javascript' src='$src'></script>\n"; 
     117        else 
     118            echo "<script type='text/javascript' src='$src'></script>\n"; 
    84119 
    85120        return true; 
     
    102137    } 
    103138 
     139    function set_group( $handle, $recursion, $group = false ) { 
     140        $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0; 
     141        if ( false !== $group && $grp > $group ) 
     142            $grp = $group; 
     143 
     144        parent::set_group( $handle, $recursion, $grp ); 
     145    } 
     146 
    104147    function all_deps( $handles, $recursion = false ) { 
    105148        $r = parent::all_deps( $handles, $recursion ); 
     
    108151        return $r; 
    109152    } 
     153 
     154    function do_head_items() { 
     155        $this->do_items(false, 0); 
     156        return $this->done; 
     157    } 
     158 
     159    function do_footer_items() { 
     160        if ( !empty($this->in_footer) ) { 
     161            foreach( $this->in_footer as $key => $handle ) { 
     162                if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { 
     163                    $this->do_item($handle, false, $this->doecho); 
     164                    $this->done[] = $handle; 
     165                    unset( $this->in_footer[$key] ); 
     166                } 
     167            } 
     168        } 
     169        return $this->done; 
     170    } 
     171 
     172    function in_default_dir($src) { 
     173        if ( ! $this->default_dirs ) 
     174            return true; 
     175 
     176        foreach ( (array) $this->default_dirs as $test ) { 
     177            if ( 0 === strpos($src, $test) ) 
     178                return true; 
     179        } 
     180        return false; 
     181    } 
    110182} 
  • trunk/wp-includes/class.wp-styles.php

    r10258 r10357  
    1919class WP_Styles extends WP_Dependencies { 
    2020    var $base_url; 
     21    var $content_url; 
    2122    var $default_version; 
    2223    var $text_direction = 'ltr'; 
     24    var $concat = ''; 
     25    var $concat_version = ''; 
     26    var $do_concat = false; 
     27    var $print_html = ''; 
     28    var $default_dirs; 
    2329 
    2430    function __construct() { 
     
    3440            $ver .= '&amp;' . $this->args[$handle]; 
    3541 
     42        if ( $this->do_concat ) { 
     43            if ( $this->in_default_dir($this->registered[$handle]->src) && !isset($this->registered[$handle]->extra['conditional']) && !isset($this->registered[$handle]->extra['alt']) ) { 
     44                $this->concat .= $handle . ','; 
     45                $this->concat_version .= $ver; 
     46                return true; 
     47            } 
     48        } 
     49 
    3650        if ( isset($this->registered[$handle]->args) ) 
    3751            $media = attribute_escape( $this->registered[$handle]->args ); 
     
    4357        $title = isset($this->registered[$handle]->extra['title']) ? "title='" . attribute_escape( $this->registered[$handle]->extra['title'] ) . "'" : ''; 
    4458 
    45         $end_cond = ''; 
     59        $end_cond = $tag = ''; 
    4660        if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) { 
    47             echo "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n"; 
     61            $tag .= "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n"; 
    4862            $end_cond = "<![endif]-->\n"; 
    4963        } 
    5064 
    51         echo apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$href' type='text/css' media='$media' />\n", $handle ); 
     65        $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$href' type='text/css' media='$media' />\n", $handle ); 
    5266        if ( 'rtl' === $this->text_direction && isset($this->registered[$handle]->extra['rtl']) && $this->registered[$handle]->extra['rtl'] ) { 
    5367            if ( is_bool( $this->registered[$handle]->extra['rtl'] ) ) 
     
    5670                $rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" ); 
    5771 
    58             echo apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle ); 
     72            $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle ); 
    5973        } 
    6074 
    61         echo $end_cond; 
     75        $tag .= $end_cond; 
     76 
     77        if ( $this->do_concat ) 
     78            $this->print_html .= $tag; 
     79        else 
     80            echo $tag; 
    6281 
    6382        // Could do something with $this->registered[$handle]->extra here to print out extra CSS rules 
     
    7897 
    7998    function _css_href( $src, $ver, $handle ) { 
    80         if ( !preg_match('|^https?://|', $src) && !preg_match('|^' . preg_quote(WP_CONTENT_URL) . '|', $src) ) { 
     99        if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { 
    81100            $src = $this->base_url . $src; 
    82101        } 
     
    87106    } 
    88107 
     108    function in_default_dir($src) { 
     109        if ( ! $this->default_dirs ) 
     110            return true; 
     111 
     112        foreach ( (array) $this->default_dirs as $test ) { 
     113            if ( 0 === strpos($src, $test) ) 
     114                return true; 
     115        } 
     116        return false; 
     117    } 
     118 
    89119} 
  • trunk/wp-includes/default-filters.php

    r10108 r10357  
    182182add_action('do_robots', 'do_robots'); 
    183183add_action('sanitize_comment_cookies', 'sanitize_comment_cookies'); 
    184 add_action('admin_print_scripts', 'wp_print_scripts', 20); 
    185 add_action('admin_print_styles', 'wp_print_styles', 20); 
     184add_action('admin_print_scripts', 'wp_print_head_scripts', 20); 
     185add_action('admin_print_footer_scripts', 'wp_print_footer_scripts', 20); 
     186add_action('admin_print_styles', 'wp_print_admin_styles', 20); 
    186187add_action('init', 'smilies_init', 5); 
    187188add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 
  • trunk/wp-includes/script-loader.php

    r10349 r10357  
    3636 */ 
    3737function wp_default_scripts( &$scripts ) { 
    38     if (!$guessurl = site_url()) 
     38 
     39    if ( !$guessurl = site_url() ) 
    3940        $guessurl = wp_guess_url(); 
    4041 
    4142    $scripts->base_url = $guessurl; 
     43    $scripts->content_url = WP_CONTENT_URL; 
    4244    $scripts->default_version = get_bloginfo( 'version' ); 
     45    $scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); 
     46 
    4347    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : ''; 
    4448 
     49 
    4550    $scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20090102' ); 
    46      
     51 
    4752    $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090106' ); 
     53    $scripts->add_data( 'common', 'group', 1 ); 
    4854    $scripts->localize( 'common', 'commonL10n', array( 
    4955        'warnDelete' => __("You are about to delete the selected items.\n  'Cancel' to stop, 'OK' to delete."), 
     
    5258 
    5359    $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1' ); 
     60    $scripts->add_data( 'sack', 'group', 1 ); 
    5461 
    5562    $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20090102' ); 
     
    8087 
    8188    $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), '20090102' ); 
     89    $scripts->add_data( 'wp-ajax-response', 'group', 1 ); 
    8290    $scripts->localize( 'wp-ajax-response', 'wpAjax', array( 
    8391        'noPerm' => __('You do not have permission to do that.'), 
     
    8795 
    8896    $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20090106' ); 
     97    $scripts->add_data( 'autosave', 'group', 1 ); 
    8998 
    9099    $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), '20090102' ); 
     100    $scripts->add_data( 'wp-lists', 'group', 1 ); 
    91101    $scripts->localize( 'wp-lists', 'wpListL10n', array( 
    92102        'url' => admin_url('admin-ajax.php') 
     
    105115 
    106116    $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.3b2'); 
     117 
     118    $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5.2' ); 
     119    $scripts->add_data( 'jquery-ui-core', 'group', 1 ); 
     120 
     121    $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5.2' ); 
     122    $scripts->add_data( 'jquery-ui-tabs', 'group', 1 ); 
     123 
     124    $scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui.sortable.js', array('jquery-ui-core'), '1.5.2c' ); 
     125    $scripts->add_data( 'jquery-ui-sortable', 'group', 1 ); 
     126 
     127    $scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui.draggable.js', array('jquery-ui-core'), '1.5.2' ); 
     128    $scripts->add_data( 'jquery-ui-draggable', 'group', 1 ); 
     129 
     130    $scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' ); 
     131    $scripts->add_data( 'jquery-ui-resizable', 'group', 1 ); 
     132 
     133    $scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' ); 
     134    $scripts->add_data( 'jquery-ui-dialog', 'group', 1 ); 
     135 
    107136    $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array('jquery'), '2.02m'); 
     137    $scripts->add_data( 'jquery-form', 'group', 1 ); 
     138 
    108139    $scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color$suffix.js", array('jquery'), '2.0-4561m'); 
     140    $scripts->add_data( 'jquery-color', 'group', 1 ); 
     141 
    109142    $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' ); 
     143 
    110144    $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1bm'); 
     145    $scripts->add_data( 'suggest', 'group', 1 ); 
     146 
    111147    $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m'); 
     148    $scripts->add_data( 'schedule', 'group', 1 ); 
     149 
    112150    $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array('jquery'), '0.0.2m' ); 
     151    $scripts->add_data( 'jquery-hotkeys', 'group', 1 ); 
     152 
    113153    $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), '20090102' ); 
     154    $scripts->add_data( 'jquery-table-hotkeys', 'group', 1 ); 
     155 
    114156    $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20080430m'); 
     157    $scripts->add_data( 'thickbox', 'group', 1 ); 
     158 
    115159 
    116160    if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) { 
     
    145189            'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};' 
    146190    ) ); 
    147      
     191 
    148192    $scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.2.0-20081031'); 
    149193    $scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array( 
     
    151195    ) ); 
    152196 
    153     $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5.2' ); 
    154     $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5.2' ); 
    155     $scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui.sortable.js', array('jquery-ui-core'), '1.5.2c' ); 
    156     $scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui.draggable.js', array('jquery-ui-core'), '1.5.2' ); 
    157     $scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' ); 
    158     $scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' ); 
    159  
    160197    $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102'); 
    161198 
    162199    if ( is_admin() ) { 
    163200        $scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ), '20090102' ); 
     201        $scripts->add_data( 'ajaxcat', 'group', 1 ); 
    164202        $scripts->localize( 'ajaxcat', 'catL10n', array( 
    165203            'add' => attribute_escape(__('Add')), 
     
    169207 
    170208        $scripts->add( 'admin-categories', "/wp-admin/js/categories$suffix.js", array('wp-lists'), '20090102' ); 
     209        $scripts->add_data( 'admin-categories', 'group', 1 ); 
    171210 
    172211        $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('wp-lists'), '20090102' ); 
     212        $scripts->add_data( 'admin-tags', 'group', 1 ); 
    173213 
    174214        $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' ); 
     215        $scripts->add_data( 'admin-custom-fields', 'group', 1 ); 
    175216 
    176217        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), '20090102' ); 
     218        $scripts->add_data( 'password-strength-meter', 'group', 1 ); 
    177219        $scripts->localize( 'password-strength-meter', 'pwsL10n', array( 
    178220            'empty' => __('Strength indicator'), 
     
    185227 
    186228        $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20090112' ); 
     229        $scripts->add_data( 'admin-comments', 'group', 1 ); 
    187230        $scripts->localize( 'admin-comments', 'adminCommentsL10n', array( 
    188231            'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']), 
     
    193236 
    194237        $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), '20090102' ); 
     238        $scripts->add_data( 'postbox', 'group', 1 ); 
    195239        $scripts->localize( 'postbox', 'postboxL10n', array( 
    196240            'requestFile' => admin_url('admin-ajax.php') 
     
    198242 
    199243        $scripts->add( 'slug', "/wp-admin/js/slug$suffix.js", array('jquery'), '20090102' ); 
     244        $scripts->add_data( 'slug', 'group', 1 ); 
    200245        $scripts->localize( 'slug', 'slugL10n', array( 
    201246            'requestFile' => admin_url('admin-ajax.php'), 
     
    206251 
    207252        $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20090102' ); 
     253        $scripts->add_data( 'post', 'group', 1 ); 
    208254        $scripts->localize( 'post', 'postL10n', array( 
    209255            'tagsUsed' =>  __('Tags used on this post:'), 
     
    233279 
    234280        $scripts->add( 'page', "/wp-admin/js/page$suffix.js", array('jquery', 'slug', 'wp-lists', 'postbox'), '20090102' ); 
     281        $scripts->add_data( 'page', 'group', 1 ); 
    235282        $scripts->localize( 'page', 'postL10n', array( 
    236283            'cancel' => __('Cancel'), 
     
    255302 
    256303        $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20090102' ); 
     304        $scripts->add_data( 'link', 'group', 1 ); 
    257305 
    258306        $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery'), '20090102' ); 
     307        $scripts->add_data( 'comment', 'group', 1 ); 
    259308        $scripts->localize( 'comment', 'commentL10n', array( 
    260309            'cancel' => __('Cancel'), 
     
    266315 
    267316        $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090102' ); 
     317        $scripts->add_data( 'media-upload', 'group', 1 ); 
    268318 
    269319        $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'interface' ), '20090106' ); 
     
    278328 
    279329        $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090102' ); 
     330        $scripts->add_data( 'word-count', 'group', 1 ); 
    280331        $scripts->localize( 'word-count', 'wordCountL10n', array( 
    281332            'count' => __('Word count: %d'), 
     
    291342 
    292343        $scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090102' ); 
    293  
    294         $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'jquery-form', 'suggest' ), '20090102' ); 
     344        $scripts->add_data( 'theme-preview', 'group', 1 ); 
     345 
     346        $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery-form', 'suggest' ), '20090102' ); 
     347        $scripts->add_data( 'inline-edit-post', 'group', 1 ); 
    295348        $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array( 
    296349            'error' => __('Error while saving the changes.'), 
     
    300353        ) ); 
    301354 
    302         $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery', 'jquery-form' ), '20090109' ); 
     355        $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery-form' ), '20090109' ); 
     356        $scripts->add_data( 'inline-edit-tax', 'group', 1 ); 
    303357        $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array( 
    304358            'error' => __('Error while saving the changes.'), 
     
    307361 
    308362        $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'thickbox', 'jquery' ), '20090102' ); 
     363        $scripts->add_data( 'plugin-install', 'group', 1 ); 
    309364        $scripts->localize( 'plugin-install', 'plugininstallL10n', array( 
    310365            'plugin_information' => __('Plugin Information:'), 
     
    313368 
    314369        $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' ); 
     370        $scripts->add_data( 'farbtastic', 'group', 1 ); 
    315371 
    316372        $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), '20090102' ); 
     373        $scripts->add_data( 'dashboard', 'group', 1 ); 
    317374 
    318375        $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), '20090102' ); 
     376        $scripts->add_data( 'hoverIntent', 'group', 1 ); 
     377 
     378        $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable', 'jquery-ui-resizable' ), '20090113' ); 
     379        $scripts->add_data( 'media', 'group', 1 ); 
    319380 
    320381    } 
     
    341402    if ( ! $guessurl = site_url() ) 
    342403        $guessurl = wp_guess_url(); 
     404 
    343405    $styles->base_url = $guessurl; 
     406    $styles->content_url = WP_CONTENT_URL; 
    344407    $styles->default_version = get_bloginfo( 'version' ); 
    345408    $styles->text_direction = 'rtl' == get_bloginfo( 'text_direction' ) ? 'rtl' : 'ltr'; 
     409    $styles->default_dirs = array('/wp-admin/'); 
    346410 
    347411    $rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'plugin-install', 'farbtastic' ); 
     
    385449 */ 
    386450function wp_prototype_before_jquery( $js_array ) { 
    387     if ( false === $jquery = array_search( 'jquery', $js_array ) ) 
     451    if ( false === $jquery = array_search( 'jquery', $js_array, true ) ) 
    388452        return $js_array; 
    389453 
    390     if ( false === $prototype = array_search( 'prototype', $js_array ) ) 
     454    if ( false === $prototype = array_search( 'prototype', $js_array, true ) ) 
    391455        return $js_array; 
    392456 
     
    462526} 
    463527 
     528/** 
     529 * Print the script queue in the HTML head. 
     530 * 
     531 * Postpones the scripts that were queued for the footer. 
     532 * wp_print_footer_scripts() has to be called in the footer to print these scripts. 
     533 * 
     534 * @since unknown 
     535 * @see wp_print_scripts() 
     536 */ 
     537function wp_print_head_scripts() { 
     538    do_action( 'wp_print_scripts' ); 
     539    global $wp_scripts, $concatenate_scripts, $compress_scripts; 
     540 
     541    if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     542        $wp_scripts = new WP_Scripts(); 
     543 
     544    if ( ! isset($concatenate_scripts) ) 
     545        script_concat_settings(); 
     546 
     547    $wp_scripts->do_concat = $concatenate_scripts; 
     548    $wp_scripts->do_head_items(); 
     549 
     550    _pring_scripts(); 
     551 
     552    $wp_scripts->do_concat = false; 
     553    return $wp_scripts->done; 
     554} 
     555 
     556/** 
     557 * Print the scripts that were queued for the footer. 
     558 * 
     559 * @since unknown 
     560 */ 
     561function wp_print_footer_scripts() { 
     562    global $wp_scripts, $concatenate_scripts; 
     563 
     564    if ( !is_a($wp_scripts, 'WP_Scripts') ) 
     565        return array(); // No need to run if not instantiated. 
     566 
     567    if ( ! isset($concatenate_scripts) ) 
     568        script_concat_settings(); 
     569 
     570    $wp_scripts->do_concat = $concatenate_scripts; 
     571    $wp_scripts->do_footer_items(); 
     572 
     573    _pring_scripts(); 
     574 
     575    $wp_scripts->do_concat = false; 
     576    return $wp_scripts->done; 
     577} 
     578 
     579function _pring_scripts() { 
     580    global $wp_scripts, $compress_scripts; 
     581 
     582    $zip = $compress_scripts ? 1 : 0; 
     583 
     584    if ( !empty($wp_scripts->concat) ) { 
     585 
     586        if ( !empty($wp_scripts->print_code) ) { 
     587            echo "<script type='text/javascript'>\n"; 
     588            echo "/* <![CDATA[ */\n"; 
     589            echo $wp_scripts->print_code; 
     590            echo "/* ]]> */\n"; 
     591            echo "</script>\n"; 
     592            $wp_scripts->print_code = ''; 
     593        } 
     594 
     595        $ver = md5($wp_scripts->concat_version); 
     596        $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . rtrim($wp_scripts->concat, ',') . "&ver=$ver"; 
     597        echo "<script type='text/javascript' src='$src'></script>\n"; 
     598        $wp_scripts->concat = $wp_scripts->concat_version = ''; 
     599    } 
     600 
     601    if ( !empty($wp_scripts->print_html) ) { 
     602        echo $wp_scripts->print_html; 
     603        $wp_scripts->print_html = ''; 
     604    } 
     605} 
     606 
     607function wp_print_admin_styles() { 
     608    global $wp_styles, $concatenate_scripts, $compress_scripts; 
     609 
     610    if ( !is_a($wp_styles, 'WP_Styles') ) 
     611        $wp_styles = new WP_Styles(); 
     612 
     613    if ( ! isset($concatenate_scripts) ) 
     614        script_concat_settings(); 
     615 
     616    $wp_styles->do_concat = $concatenate_scripts; 
     617    $zip = $compress_scripts ? 1 : 0; 
     618 
     619    $wp_styles->do_items(false); 
     620 
     621    if ( !empty($wp_styles->concat) ) { 
     622        $ver = md5($wp_styles->concat_version); 
     623        $rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0; 
     624        $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&rtl={$rtl}&load=" . rtrim($wp_styles->concat, ',') . "&ver=$ver"; 
     625        echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n"; 
     626        $wp_styles->concat = $wp_styles->concat_version = ''; 
     627    } 
     628 
     629    if ( !empty($wp_styles->print_html) ) { 
     630        echo $wp_styles->print_html; 
     631        $wp_styles->print_html = ''; 
     632    } 
     633 
     634    $wp_styles->do_concat = false; 
     635    return $wp_styles->done; 
     636} 
     637 
     638function script_concat_settings() { 
     639    global $concatenate_scripts, $compress_scripts; 
     640 
     641    $concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true; 
     642    if ( $concatenate_scripts && -1 == get_option('concatenate_scripts') ) 
     643        $concatenate_scripts = false; 
     644 
     645    $compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true; 
     646    if ( $compress_scripts && ! get_option('can_compress_scripts') ) 
     647        $compress_scripts = false; 
     648} 
     649 
    464650add_action( 'wp_default_scripts', 'wp_default_scripts' ); 
    465651add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); 
Note: See TracChangeset for help on using the changeset viewer.