Validate date/time fields for posts and comments, fixes #10309

git-svn-id: https://develop.svn.wordpress.org/trunk@12318 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2009-12-03 09:56:20 +00:00
parent 07f2fd2e4b
commit c2b584a91b
12 changed files with 56 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -211,7 +211,8 @@ strong .post-com-count span {
background-color: #ffebe8 !important;
}
.form-invalid input {
.form-invalid input,
.form-invalid select {
border-color: #c00 !important;
}

File diff suppressed because one or more lines are too long

View File

@ -211,7 +211,8 @@ strong .post-com-count span {
background-color: #ffebe8 !important;
}
.form-invalid input {
.form-invalid input,
.form-invalid select {
border-color: #c00 !important;
}

View File

@ -2629,10 +2629,12 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
$year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
$hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
$minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
echo '<div class="timestamp-wrap">';
/* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
echo '<input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
if ( $multi ) return;

View File

@ -22,15 +22,25 @@ jQuery(document).ready( function($) {
});
$('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(),
newD = new Date( aa, mm - 1, jj, hh, mn );
if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) {
$('.timestamp-wrap', '#timestampdiv').addClass('form-invalid');
return false;
} else {
$('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid');
}
$('#timestampdiv').slideUp("normal");
$('.edit-timestamp').show();
$('#timestamp').html(
commentL10n.submittedOn + ' <b>' +
$( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
$('#jj').val() + ', ' +
$('#aa').val() + ' @ ' +
$('#hh').val() + ':' +
$('#mn').val() + '</b> '
$( '#mm option[value=' + mm + ']' ).text() + ' ' +
jj + ', ' +
aa + ' @ ' +
hh + ':' +
mn + '</b> '
);
return false;
});

View File

@ -1 +1 @@
jQuery(document).ready(function(b){var a=b("#timestamp").html();b(".edit-timestamp").click(function(){if(b("#timestampdiv").is(":hidden")){b("#timestampdiv").slideDown("normal");b(".edit-timestamp").hide()}return false});b(".cancel-timestamp").click(function(){b("#timestampdiv").slideUp("normal");b("#mm").val(b("#hidden_mm").val());b("#jj").val(b("#hidden_jj").val());b("#aa").val(b("#hidden_aa").val());b("#hh").val(b("#hidden_hh").val());b("#mn").val(b("#hidden_mn").val());b("#timestamp").html(a);b(".edit-timestamp").show();return false});b(".save-timestamp").click(function(){b("#timestampdiv").slideUp("normal");b(".edit-timestamp").show();b("#timestamp").html(commentL10n.submittedOn+" <b>"+b("#mm option[value="+b("#mm").val()+"]").text()+" "+b("#jj").val()+", "+b("#aa").val()+" @ "+b("#hh").val()+":"+b("#mn").val()+"</b> ");return false})});
jQuery(document).ready(function(b){var a=b("#timestamp").html();b(".edit-timestamp").click(function(){if(b("#timestampdiv").is(":hidden")){b("#timestampdiv").slideDown("normal");b(".edit-timestamp").hide()}return false});b(".cancel-timestamp").click(function(){b("#timestampdiv").slideUp("normal");b("#mm").val(b("#hidden_mm").val());b("#jj").val(b("#hidden_jj").val());b("#aa").val(b("#hidden_aa").val());b("#hh").val(b("#hidden_hh").val());b("#mn").val(b("#hidden_mn").val());b("#timestamp").html(a);b(".edit-timestamp").show();return false});b(".save-timestamp").click(function(){var g=b("#aa").val(),h=b("#mm").val(),d=b("#jj").val(),c=b("#hh").val(),f=b("#mn").val(),e=new Date(g,h-1,d,c,f);if(e.getFullYear()!=g||(1+e.getMonth())!=h||e.getDate()!=d||e.getMinutes()!=f){b(".timestamp-wrap","#timestampdiv").addClass("form-invalid");return false}else{b(".timestamp-wrap","#timestampdiv").removeClass("form-invalid")}b("#timestampdiv").slideUp("normal");b(".edit-timestamp").show();b("#timestamp").html(commentL10n.submittedOn+" <b>"+b("#mm option[value="+h+"]").text()+" "+d+", "+g+" @ "+c+":"+f+"</b> ");return false})});

View File

@ -340,11 +340,21 @@ jQuery(document).ready( function($) {
}
function updateText() {
var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), optPublish = $('option[value=publish]', postStatus);
var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
optPublish = $('option[value=publish]', postStatus), aa = $('#aa').val(),
mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val() );
attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
$('.timestamp-wrap', '#timestampdiv').addClass('form-invalid');
return false;
} else {
$('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid');
}
if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
publishOn = postL10n.publishOnFuture;
$('#publish').val( postL10n.schedule );
@ -364,10 +374,10 @@ jQuery(document).ready( function($) {
$('#timestamp').html(
publishOn + ' <b>' +
$('option[value=' + $('#mm').val() + ']', '#mm').text() + ' ' +
$('#jj').val() + ', ' +
$('#aa').val() + ' @ ' +
$('#hh').val() + ':' +
$('#mn').val() + '</b> '
jj + ', ' +
aa + ' @ ' +
hh + ':' +
mn + '</b> '
);
}
@ -392,7 +402,8 @@ jQuery(document).ready( function($) {
} else {
optPublish.html( postL10n.published );
}
$('.edit-post-status', '#misc-publishing-actions').show();
if ( postStatus.is(':hidden') )
$('.edit-post-status', '#misc-publishing-actions').show();
}
$('#post-status-display').html($('option:selected', postStatus).text());
if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
@ -405,6 +416,7 @@ jQuery(document).ready( function($) {
$('#save-post').show().val( postL10n.saveDraft );
}
}
return true;
}
$('.edit-visibility', '#visibility').click(function () {
@ -473,9 +485,10 @@ jQuery(document).ready( function($) {
});
$('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels
$('#timestampdiv').slideUp("normal");
$('#timestampdiv').siblings('a.edit-timestamp').show();
updateText();
if ( updateText() ) {
$('#timestampdiv').slideUp("normal");
$('#timestampdiv').siblings('a.edit-timestamp').show();
}
return false;
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2276,8 +2276,9 @@ fieldset {
#timestampdiv select {
height: 20px;
line-height: 20px;
line-height: 14px;
padding: 0;
vertical-align: top;
}
#jj, #hh, #mn {

View File

@ -275,7 +275,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), '20091012' );
$scripts->add_data( 'postbox', 'group', 1 );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20091109' );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20091202' );
$scripts->add_data( 'post', 'group', 1 );
$scripts->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
@ -308,7 +308,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'link', "/wp-admin/js/link$suffix.js", array('wp-lists', 'postbox'), '20090506' );
$scripts->add_data( 'link', 'group', 1 );
$scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery'), '20090102' );
$scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery'), '20091202' );
$scripts->add_data( 'comment', 'group', 1 );
$scripts->localize( 'comment', 'commentL10n', array(
'cancel' => __('Cancel'),
@ -425,9 +425,9 @@ function wp_default_styles( &$styles ) {
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'plugin-install', 'farbtastic' );
// all colors stylesheets need to have the same query strings (cache manifest compat)
$colors_version = '20091128';
$colors_version = '20091202';
$styles->add( 'wp-admin', "/wp-admin/wp-admin$suffix.css", array(), '20091126' );
$styles->add( 'wp-admin', "/wp-admin/wp-admin$suffix.css", array(), '20091202' );
$styles->add_data( 'wp-admin', 'rtl', "/wp-admin/rtl$suffix.css" );
$styles->add( 'ie', '/wp-admin/css/ie.css', array(), '20091128' );