Make WordPress Core

Changeset 5804


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

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

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r5744 r5804  
    417417}
    418418
     419// return an option/select list with correct html escaping
     420function input_dropdown($name, $vals, $selected=null, $class='', $onchange='') {
     421
     422    // cf. http://www.w3.org/TR/html401/appendix/notes.html#h-B.3.2.2
     423    $out = '<select name="' . htmlspecialchars($name) . '" class="' . htmlspecialchars($class) . '" onchange="' . htmlspecialchars($onchange) . '">' . "\n";
     424    foreach ($vals as $k=>$v) {
     425        $out .= '<option value="' . htmlspecialchars($k) . '"';
     426        if ( $selected !== null and $k == $selected )
     427            $out .= ' selected="selected"';
     428        $out .= '>' . htmlspecialchars($v) . "</option>\n";
     429    }
     430    $out .= "</select>\n";
     431
     432    return $out;
     433}
     434
     435// return an array of month names for the current locale, indexed 1..12
     436function locale_months() {
     437    global $wp_locale;
     438
     439    $months = array();
     440    foreach ( range(1, 12) as $m )
     441        $months[$m] = $wp_locale->get_month( $m );
     442    return $months;
     443}
     444
    419445function touch_time( $edit = 1, $for_post = 1 ) {
    420446    global $wp_locale, $post, $comment;
     
    423449        $edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
    424450
    425     echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
     451    echo '<fieldset class="jcalendar"><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
    426452
    427453    $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
     
    434460    $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
    435461
    436     echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n";
    437     for ( $i = 1; $i < 13; $i = $i +1 ) {
    438         echo "\t\t\t<option value=\"$i\"";
    439         if ( $i == $mm )
    440             echo ' selected="selected"';
    441         echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
    442     }
    443 ?>
    444 </select>
    445 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/>
    446 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @
    447 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> :
     462    echo '<div class="jcalendar-selects">';
     463    echo input_dropdown( 'mm', locale_months(), $mm, 'jcalendar-select-month', 'edit_date.checked=true' );
     464
     465    foreach ( range(1, 31) as $i )
     466        $days[$i] = $i;
     467    echo input_dropdown( 'jj', $days, $jj, 'jcalendar-select-day', 'edit_date.checked=true' );
     468
     469    foreach ( range(1970, 2038) as $i )
     470        $years[$i] = $i;
     471    echo input_dropdown( 'aa', $years, $aa, 'jcalendar-select-year', 'edit_date.checked=true' );
     472    echo '</div>';
     473
     474    $jcal_css_url = get_bloginfo('wpurl') . '/wp-includes/js/jquery/css/jcalendar.css?version=' . get_bloginfo('version');
     475
     476?>
     477<script type="text/javascript">
     478<!--
     479jQuery(document).ready(function() {
     480    jQuery.jcalendar.setLanguageStrings(jcalendar_L10n.days, jcalendar_L10n.months, jcalendar_L10n.navLinks);
     481    jQuery('fieldset.jcalendar').jcalendar();
     482});
     483// -->
     484</script>
     485@ <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> :
    448486<input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
    449487<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
  • trunk/wp-admin/post-new.php

    r5749 r5804  
    77wp_enqueue_script('interface');
    88wp_enqueue_script('autosave');
     9wp_enqueue_script('jcalendar');
    910require_once ('./admin-header.php');
    1011
  • trunk/wp-admin/post.php

    r5159 r5804  
    5858        wp_enqueue_script('autosave');
    5959    }
     60    wp_enqueue_script('jcalendar');
    6061    require_once('admin-header.php');
    6162
  • trunk/wp-admin/wp-admin.css

    r5800 r5804  
    13331333}
    13341334
    1335 a.view-link {
    1336     position: absolute;
    1337     right: 5%;
    1338     margin-right: 220px;
    1339     text-decoration:underline;
    1340 }
     1335/* jcalendar */
     1336
     1337#moremeta select.jcalendar-select-day, #moremeta select.jcalendar-select-month, #moremeta select.jcalendar-select-year {
     1338    font-size: 11px;
     1339    width: auto;
     1340}
     1341
     1342div.jcalendar table {
     1343color:#000;
     1344width: 100%;
     1345background: #a1a5a9;
     1346}
     1347
     1348div.jcalendar table th {
     1349font-size: 10px;
     1350background:#eee;
     1351}
     1352
     1353div.jcalendar table td {
     1354background:#f9f9f9;
     1355padding:0;
     1356}
     1357
     1358div.jcalendar table th.weekend {
     1359background:#ddd;
     1360}
     1361
     1362div.jcalendar table td.weekend {
     1363background:#e9e9e9;
     1364}
     1365
     1366div.jcalendar table td a {
     1367font-size: 11px;
     1368color:#333;
     1369display:block;
     1370line-height:1.7em;
     1371text-align:center;
     1372text-decoration:none;
     1373}
     1374
     1375div.jcalendar table td.today a {
     1376background:#777;
     1377border-color:#aaa;
     1378color:#fff;
     1379font-weight:700;
     1380}
     1381
     1382div.jcalendar table td a:hover,div.jcalendar table td a:focus,div.jcalendar table td a:active {
     1383background:#77b0d3;
     1384color:#fff;
     1385padding:0;
     1386}
     1387
     1388div.jcalendar table td a.selected {
     1389background:#2685af;
     1390color:#E3EFF5;
     1391}
     1392
     1393div.jcalendar-links {
     1394text-align:center;
     1395}
     1396
     1397div.jcalendar-links a {
     1398font-size: 11px;
     1399margin: 0 .4em;
     1400}
     1401
  • 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.