WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/16/2007 07:22:27 PM (13 years ago)
Author:
ryan
Message:

jquery data selector for post timestamps. Props tellyworth. fixes #4641

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/script-loader.php

    r5794 r5804  
    7575        $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '1.0.3');
    7676        $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2');
     77        $this->add( 'jcalendar', '/wp-includes/js/jquery/jcalendar.js', array('jquery'), '0.5' );
     78
     79        // this would be much nicer if localize used json so it could handle arrays
     80        global $wp_locale;
     81        $this->localize( 'jcalendar', 'jcalendar_L10n', array(
     82            'days' => array_values($wp_locale->weekday_abbrev),
     83            'months' => array_values($wp_locale->month),
     84            'navLinks' => array(
     85                'p' => __('Prev'),
     86                'n' => __('Next'),
     87                't' => __('Today'),
     88            ),
     89        ) );
    7790
    7891        if ( is_admin() ) {
     
    206219        echo "<script type='text/javascript'>\n";
    207220        echo "/* <![CDATA[ */\n";
    208         echo "\t$object_name = {\n";
    209         $eol = '';
    210         foreach ( $this->scripts[$handle]->l10n as $var => $val ) {
    211             echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
    212             $eol = ",\n";
     221        echo $this->js_encode_array( $object_name, $this->scripts[$handle]->l10n );
     222        echo "\n/* ]]> */\n";
     223        echo "</script>\n";
     224    }
     225
     226    /**
     227     * Poor man's json: recursively encode an associative array of strings or arrays as a javascript array definition
     228     */
     229    function js_encode_array( $name, $vals, $level=0 ) {
     230        $out = array();
     231        foreach ( $vals as $var => $val ) {
     232            if ( is_array($val) )
     233                $out[] = $this->js_encode_array( $var, $val, $level+1 );
     234            else
     235                $out[] = str_repeat("\t", $level+1) . "{$var}: \"" . js_escape( $val ) . '"';
    213236        }
    214         echo "\n\t}\n";
    215         echo "/* ]]> */\n";
    216         echo "</script>\n";
     237
     238        return str_repeat("\t", $level) . "{$name} " . ($level ? ':' : '=') . " {\n"
     239            . join( ",\n", $out )
     240            . "\n" . str_repeat("\t", $level) . "}";
    217241    }
    218242
Note: See TracChangeset for help on using the changeset viewer.