✨ feat: 新增 WYSIWYG 编辑器功能和相关工具栏事件处理
This commit is contained in:
@@ -34,28 +34,6 @@ if ($pr_flag) {
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.md pre {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.md-code-copy {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
z-index: 1;
|
||||
font-size: 12px;
|
||||
color: #4d4d4d;
|
||||
background-color: #fff;
|
||||
border: 1px solid #e0e0e0;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.md-code-copy:hover {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
</style>
|
||||
<script src="<?php echo $OJ_CDN_URL . $path_fix . "template/$OJ_TEMPLATE/" ?>clipboard.min.js"></script>
|
||||
<script src="include/vditor-adapter.js"></script>
|
||||
@@ -537,55 +515,6 @@ if ($pr_flag) {
|
||||
$(document).ready(function () {
|
||||
$("#creator").load("problem-ajax.php?pid=<?php echo $id ?>");
|
||||
|
||||
function copyText(content, onSuccess, onFail) {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(content).then(onSuccess).catch(onFail);
|
||||
return;
|
||||
}
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = content;
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.left = '-9999px';
|
||||
document.body.appendChild(textarea);
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
try {
|
||||
const copied = document.execCommand('copy');
|
||||
copied ? onSuccess() : onFail();
|
||||
} catch (err) {
|
||||
onFail();
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
|
||||
function initMarkdownCodeCopy() {
|
||||
$('.md pre').each(function () {
|
||||
const pre = $(this);
|
||||
if (pre.find('.md-code-copy').length > 0) return;
|
||||
|
||||
const btn = $('<button type="button" class="md-code-copy"><?php echo $MSG_COPY; ?></button>');
|
||||
btn.on('click', function () {
|
||||
const code = pre.find('code').first();
|
||||
const text = code.length > 0 ? code.text() : pre.text();
|
||||
const currentBtn = $(this);
|
||||
|
||||
copyText(
|
||||
text,
|
||||
function () {
|
||||
currentBtn.text('<?php echo $MSG_COPY . $MSG_SUCCESS; ?>!');
|
||||
setTimeout(function () { currentBtn.text('<?php echo $MSG_COPY; ?>'); }, 1500);
|
||||
},
|
||||
function () {
|
||||
currentBtn.text('<?php echo $MSG_COPY . $MSG_FAIL; ?>!');
|
||||
setTimeout(function () { currentBtn.text('<?php echo $MSG_COPY; ?>'); }, 1500);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
pre.prepend(btn);
|
||||
});
|
||||
}
|
||||
|
||||
function addMarkdownInputOutputLabels() {
|
||||
for (let i = 1; i < 10; i++) {
|
||||
$(".language-input" + i).parent().each(function () {
|
||||
@@ -623,7 +552,6 @@ if ($pr_flag) {
|
||||
return HustOJVditor.renderMarkdownBlocks('.md').then(function () {
|
||||
addMarkdownInputOutputLabels();
|
||||
styleMarkdownTables();
|
||||
initMarkdownCodeCopy();
|
||||
});
|
||||
<?php } ?>
|
||||
return Promise.resolve([]);
|
||||
|
||||
Reference in New Issue
Block a user