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-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" />
Note: See TracChangeset for help on using the changeset viewer.