From 327c61a2517ceb2eef0acf03a61e66608dbe70a8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 2 Oct 2022 14:25:22 +0800 Subject: [PATCH] refactor: problem_statement_manage with bs5 --- .../controllers/problem_statement_manage.php | 111 +++++++++++++++++- web/app/models/UOJBlogEditor.php | 4 +- web/app/views/blog-editor.php | 8 +- web/app/views/page-header.php | 2 +- web/js/blog-editor/blog-editor.js | 29 +++-- 5 files changed, 139 insertions(+), 15 deletions(-) diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php index 92f917e..692c81b 100644 --- a/web/app/controllers/problem_statement_manage.php +++ b/web/app/controllers/problem_statement_manage.php @@ -15,6 +15,10 @@ if (!hasProblemPermission($myUser, $problem)) { become403Page(); } + + if (!isset($_COOKIE['bootstrap4'])) { + $REQUIRE_LIB['bootstrap5'] = ''; + } $problem_content = queryProblemContent($problem['id']); $problem_tags = queryProblemTags($problem['id']); @@ -55,12 +59,33 @@ $problem_editor->runAtServer(); ?> -

# : 管理

+ + +
+
+ + + +
+
+ + + +

+ +

+ + #. 管理 +

+
@@ -71,5 +96,89 @@
  • 图片上传推荐使用 SM.MS 图床,以免后续产生外链图片大量失效的情况。
  • + +
    + printHTML() ?> + + + +
    +
    + + + +
    + + + +
    + + + + diff --git a/web/app/models/UOJBlogEditor.php b/web/app/models/UOJBlogEditor.php index c7f604a..d2c07af 100644 --- a/web/app/models/UOJBlogEditor.php +++ b/web/app/models/UOJBlogEditor.php @@ -241,6 +241,8 @@ EOD } } public function printHTML() { - uojIncludeView('blog-editor', array('editor' => $this)); + global $REQUIRE_LIB; + + uojIncludeView('blog-editor', array('editor' => $this, 'REQUIRE_LIB' => $REQUIRE_LIB)); } } diff --git a/web/app/views/blog-editor.php b/web/app/views/blog-editor.php index 44d889d..764efa4 100644 --- a/web/app/views/blog-editor.php +++ b/web/app/views/blog-editor.php @@ -21,7 +21,13 @@ -
    +
    name}_is_hidden", $editor->cur_data['is_hidden']) ?>
    diff --git a/web/app/views/page-header.php b/web/app/views/page-header.php index c7c3180..bc16724 100644 --- a/web/app/views/page-header.php +++ b/web/app/views/page-header.php @@ -118,7 +118,7 @@ - + diff --git a/web/js/blog-editor/blog-editor.js b/web/js/blog-editor/blog-editor.js index 7748fdb..ae08a2e 100644 --- a/web/js/blog-editor/blog-editor.js +++ b/web/js/blog-editor/blog-editor.js @@ -18,20 +18,27 @@ function blog_editor_init(name, editor_config) { // init buttons var save_btn = $(''); - var preview_btn = $(''); - var bold_btn = $(''); - var italic_btn = $(''); - - save_btn.tooltip({ container: 'body', title: '保存 (Ctrl-S)' }); - preview_btn.tooltip({ container: 'body', title: '预览 (Ctrl-D)' }); - bold_btn.tooltip({ container: 'body', title: '粗体 (Ctrl-B)' }); - italic_btn.tooltip({ container: 'body', title: '斜体 (Ctrl-I)' }); + var preview_btn = $(''); + var bold_btn = $(''); + var italic_btn = $(''); + if (typeof isBootstrap5Page !== 'undefined' && isBootstrap5Page) { + save_btn.get().map(el => new bootstrap.Tooltip(el, { container: 'body', title: '保存 (Ctrl-S)' })); + preview_btn.get().map(el => new bootstrap.Tooltip(el, { container: 'body', title: '预览 (Ctrl-D)' })); + bold_btn.get().map(el => new bootstrap.Tooltip(el, { container: 'body', title: '粗体 (Ctrl-B)' })); + italic_btn.get().map(el => new bootstrap.Tooltip(el, { container: 'body', title: '斜体 (Ctrl-I)' })); + } else { + save_btn.tooltip({ container: 'body', title: '保存 (Ctrl-S)' }); + preview_btn.tooltip({ container: 'body', title: '预览 (Ctrl-D)' }); + bold_btn.tooltip({ container: 'body', title: '粗体 (Ctrl-B)' }); + italic_btn.tooltip({ container: 'body', title: '斜体 (Ctrl-I)' }); + } + var all_btn = [save_btn, preview_btn, bold_btn, italic_btn]; // init toolbar var toolbar = $('
    '); - toolbar.append($('
    ') + toolbar.append($('
    ') .append(save_btn) .append(preview_btn) ); @@ -45,12 +52,12 @@ function blog_editor_init(name, editor_config) { if (val) { save_btn.removeClass('btn-warning'); save_btn.addClass('btn-success'); - save_btn.html(''); + save_btn.html(isBootstrap5Page ? '' : ''); before_window_unload_message = null; } else { save_btn.removeClass('btn-success'); save_btn.addClass('btn-warning'); - save_btn.html(''); + save_btn.html(isBootstrap5Page ? '' : ''); before_window_unload_message = '您所编辑的内容尚未保存'; } }