Make WordPress Core


Ignore:
Timestamp:
01/14/2009 02:18:51 PM (16 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.