Skip to content

Commit

Permalink
优化状态提示
Browse files Browse the repository at this point in the history
  • Loading branch information
webersongao committed Mar 8, 2024
1 parent 53e57b8 commit 3a44c48
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 44 deletions.
24 changes: 5 additions & 19 deletions microblog/css/admin-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,9 @@ Based on simple-microblogging plugin developed by Samuel Coskey, Victoria Gitman
.microblog-admin-bar-free{color:#fff;background-color:#52b754;font-size:12px;padding:2px 5px;border-radius:3px;margin-left:10px;vertical-align:top;text-decoration: none;}
.microblog-admin-checkbox-label { margin-right: 15px; }

#quick-micropost-form { margin-top: 20px; }
#quick-micropost-form { margin-top: 20px;}
#quick-micropost-form label { display: block; margin-bottom: 5px; }
#micropost-title,
#micropost-content { width: 100%; max-width: 100%; margin-bottom: 10px; padding: 5px; }
#micropost-title { margin-bottom: 10px; }
.button.button-primary.button-large { display: block; max-width: 200px; border: none; }

#micropost-message {
color:#2271b1;
}
#quick-micropost-form .button.button-primary.button-large {
margin-right: 10px; /* 按钮与消息之间的间距 */
}

#quick-micropost-form .micropost-message {
flex-grow: 1; /* 消息填充剩余空间 */
}



#quick-micropost-title,
#quick-micropost-content { width: 100%; max-width: 100%; margin-bottom: 10px; padding: 5px; }
.button.button-primary.button-large {max-width: 200px; border: none; }
#quick-micropost-message { color:#2271b1; float: right;}
17 changes: 10 additions & 7 deletions microblog/includes/microblog-quick-pub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function register_quick_micropost_widget() {
// 小部件内容
function display_quick_micropost_widget() {
?>
<form id="quick-micropost-form" method="post" action="">
<label for="micropost-title">标题:</label>
<input type="text" id="micropost-title" name="micropost_title" placeholder=" 标题">
<form id="quick-micropost-form" method="post" action="<?php echo admin_url('admin-post.php'); ?>">
<label for="quick-micropost-title">标题:</label>
<input type="text" id="quick-micropost-title" name="micropost_title" placeholder=" 标题">
<label for="micropost-content">内容:</label>
<textarea id="micropost-content" name="micropost_content" rows="5" cols="15" placeholder=" 请输入微博内容"></textarea>
<textarea id="quick-micropost-content" name="micropost_content" rows="5" cols="15" placeholder=" 请输入微博内容"></textarea>
<input type="hidden" name="action" value="quick_micropost">
<input type="submit" value="发布微博" class="button button-primary button-large">
<input type="submit" value="发布微博" class="button button-primary button-large button-quick-gao">
<?php wp_nonce_field('quick-micropost-action', 'quick-micropost-nonce'); ?>
<span id="micropost-message" class="micropost-message"></span>
<span id="quick-micropost-message" class="quick-micropost-message"></span>
</form>
<?php
}
Expand Down Expand Up @@ -56,10 +56,13 @@ function handle_quick_micropost_submission() {
} else {
$message = '非法请求!';
}
echo $message;
// 将消息存储为查询参数以便在页面刷新后显示
wp_safe_redirect(add_query_arg('micropost_quick_message', urlencode($message), wp_get_referer()));
exit();
}
}


// 注册 admin-post.php 处理程序
add_action('admin_post_quick_micropost', 'handle_quick_micropost_submission');
add_action('admin_post_nopriv_quick_micropost', 'handle_quick_micropost_submission');
Expand Down
26 changes: 8 additions & 18 deletions microblog/js/admin-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,14 @@ document.addEventListener('DOMContentLoaded', function () {
} else {
updateLinksTextAndTarget('a[href*="post_type=micropost"]', '写文章', '发微博');
}

// ======= 快速发微博 状态提示
var urlParams = new URLSearchParams(window.location.search);
var message = urlParams.get('micropost_quick_message');
// 如果消息存在,则填充到 #micropost-message 元素中
if (message) {
document.getElementById('quick-micropost-message').textContent = message;
}
});


jQuery("#quick-micropost-form").submit(function (event) {
event.preventDefault();
jQuery.ajax({
type: "POST",
url: "<?php echo admin_url('admin-post.php'); ?>",
data: jQuery("#quick-micropost-form").serialize(), // 将表单数据序列化
success: function (response) {
jQuery("#micropost-message").html(response);
// 清空标题和内容输入框
jQuery("#micropost-title").val('');
jQuery("#micropost-content").val('');
setTimeout(function () {
jQuery("#micropost-message").html('');
}, 2000);
}
});
});

0 comments on commit 3a44c48

Please sign in to comment.