diff --git a/core/core.php b/core/core.php index c9c1218..861e275 100644 --- a/core/core.php +++ b/core/core.php @@ -18,7 +18,6 @@ require_once('factory.php'); /* 页面加载计时 */ _startCountTime(); - /* 主题初始化 */ function themeInit($self) { diff --git a/core/factory.php b/core/factory.php index d415a58..833a595 100644 --- a/core/factory.php +++ b/core/factory.php @@ -8,6 +8,7 @@ class Editor public static function edit() { echo ""; + echo ""; echo ""; } } diff --git a/core/short.php b/core/short.php index 5293217..0a37022 100644 --- a/core/short.php +++ b/core/short.php @@ -3,7 +3,7 @@ function _parseShortCode($content) { /* 过滤网易云音乐歌单 */ - if (preg_match('/\[music-list\s{0,}id="\d{0,}"\s{0,}\/]/', $content)) { + if (preg_match('/\[music-list\s{0,}id="\d{0,}"\s{0,}\/\]/', $content)) { $content = preg_replace( '/\[music-list\s{0,}id="(\d{0,})"\s{0,}\/]/', '', @@ -11,9 +11,9 @@ function _parseShortCode($content) ); } /* 过滤网易云音乐单首歌 */ - if (preg_match('/\[music\s{0,}id="\d{0,}"\s{0,}\/]/', $content)) { + if (preg_match('/\[music\s{0,}id="\d{0,}"\s{0,}\/\]/', $content)) { $content = preg_replace( - '/\[music\s{0,}id="(\d{0,})"\s{0,}\/]/', + '/\[music\s{0,}id="(\d{0,})"\s{0,}\/\]/', '', $content ); diff --git a/index.php b/index.php index 388447d..c2e4c27 100644 --- a/index.php +++ b/index.php @@ -16,6 +16,8 @@ need('public/include.php'); ?> + + diff --git a/public/include.php b/public/include.php index 15c06ee..1e2a979 100644 --- a/public/include.php +++ b/public/include.php @@ -55,7 +55,6 @@ - @@ -65,10 +64,9 @@ - - + \ No newline at end of file diff --git a/typecho/editor/joe.editor.css b/typecho/editor/joe.editor.css index ae2fd3e..022660d 100644 --- a/typecho/editor/joe.editor.css +++ b/typecho/editor/joe.editor.css @@ -1 +1 @@ -table.typecho-list-table textarea[name='fields[thumb]'],table.typecho-list-table textarea[name='fields[abstract]']{width:100%;height:80px}#wmd-button-row{height:auto} +table.typecho-list-table textarea[name='fields[thumb]'],table.typecho-list-table textarea[name='fields[abstract]']{width:100%;height:80px}#wmd-button-row{height:auto}#wmd-button-row .wmd-button .icon{width:20px;height:20px;vertical-align:middle;fill:#9b9b9b} diff --git a/typecho/editor/joe.editor.js b/typecho/editor/joe.editor.js index 35194fe..083772e 100644 --- a/typecho/editor/joe.editor.js +++ b/typecho/editor/joe.editor.js @@ -1,18 +1,64 @@ $(function () { - $('#wmd-editarea textarea').attr('placeholder', '请输入文章内容...(支持图片粘贴上传)') - $('#wmd-button-bar .wmd-edittab').remove() - $('#wmd-button-row .wmd-spacer').remove() + $('#wmd-editarea textarea').attr('placeholder', '请输入文章内容...(支持图片粘贴上传)'); + $('#wmd-button-bar .wmd-edittab').remove(); + $('#wmd-button-row .wmd-spacer').remove(); - /* 增加自定义功能 */ - const items = [ - { - title: '回复可见', - id: 'wmd-hide-button' - } - ] + /* 增加自定义功能 */ + const items = [ + { + title: '回复可见', + id: 'wmd-hide-button', + svg: '' + }, + { + title: '网易云歌单', + id: 'wmd-mlist-button', + svg: '' + }, + { + title: '网易云音乐', + id: 'wmd-music-button', + svg: '' + }, + { + title: 'BiliBili视频', + id: 'wmd-bili-button', + svg: '' + }, + { + title: 'DPlayer视频', + id: 'wmd-dplayer-button', + svg: '' + } + ]; - items.forEach(_ => { - let item = `
  • ` - $('#wmd-button-row').append(item) - }) -}) + /* 用于设置插入到文章的短代码内容 */ + function getInsertTextById(id) { + let str = ''; + switch (id) { + case 'wmd-hide-button': + str = `\n\n[hide]${$('#text').selectionRange() ? $('#text').selectionRange() : '回复可见'}[/hide]\n\n`; + break; + case 'wmd-mlist-button': + str = `\n\n[music-list id="网易云歌单ID" /]\n\n`; + break; + case 'wmd-music-button': + str = `\n\n[music id="网易云音乐ID" /]\n\n`; + break; + case 'wmd-bili-button': + str = `\n\n[bilibili bvid="哔哩哔哩的Bvid" /]\n\n`; + break; + case 'wmd-dplayer-button': + str = `\n\n[dplayer src="M3U8或MP4地址" /]\n\n`; + break; + } + return str; + } + + /* 此处无需修改 */ + items.forEach(_ => { + let item = $(`
  • ${_.svg}
  • `); + item.on('mousedown touchstart', () => $('#text').insertContent(getInsertTextById(_.id))); + $('#wmd-button-row').append(item); + }); +}); diff --git a/typecho/editor/joe.editor.scss b/typecho/editor/joe.editor.scss index 77013d2..31b3042 100644 --- a/typecho/editor/joe.editor.scss +++ b/typecho/editor/joe.editor.scss @@ -8,6 +8,11 @@ table.typecho-list-table { #wmd-button-row { height: auto; .wmd-button { - + .icon { + width: 20px; + height: 20px; + vertical-align: middle; + fill: #9b9b9b; + } } } \ No newline at end of file diff --git a/typecho/editor/joe.extend.js b/typecho/editor/joe.extend.js new file mode 100644 index 0000000..a06963d --- /dev/null +++ b/typecho/editor/joe.extend.js @@ -0,0 +1,60 @@ +(function ($) { + $.fn.extend({ + insertContent: function (myValue, t) { + var $t = $(this)[0]; + if (document.selection) { + this.focus(); + var sel = document.selection.createRange(); + sel.text = myValue; + this.focus(); + sel.moveStart('character', -l); + var wee = sel.text.length; + if (arguments.length == 2) { + var l = $t.value.length; + sel.moveEnd('character', wee + t); + t <= 0 ? sel.moveStart('character', wee - 2 * t - myValue.length) : sel.moveStart('character', wee - t - myValue.length); + sel.select(); + } + } else if ($t.selectionStart || $t.selectionStart == '0') { + var startPos = $t.selectionStart; + var endPos = $t.selectionEnd; + var scrollTop = $t.scrollTop; + $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length); + this.focus(); + $t.selectionStart = startPos + myValue.length; + $t.selectionEnd = startPos + myValue.length; + $t.scrollTop = scrollTop; + if (arguments.length == 2) { + $t.setSelectionRange(startPos - t, $t.selectionEnd + t); + this.focus(); + } + } else { + this.value += myValue; + this.focus(); + } + }, + selectionRange: function (start, end) { + var str = ''; + var thisSrc = this[0]; + if (start === undefined) { + if (/input|textarea/i.test(thisSrc.tagName) && /firefox/i.test(navigator.userAgent)) str = thisSrc.value.substring(thisSrc.selectionStart, thisSrc.selectionEnd); + else if (document.selection) str = document.selection.createRange().text; + else str = document.getSelection().toString(); + } else { + if (!/input|textarea/.test(thisSrc.tagName.toLowerCase())) return false; + end === undefined && (end = start); + if (thisSrc.setSelectionRange) { + thisSrc.setSelectionRange(start, end); + this.focus(); + } else { + var range = thisSrc.createTextRange(); + range.move('character', start); + range.moveEnd('character', end - start); + range.select(); + } + } + if (start === undefined) return str; + else return this; + } + }); +})(jQuery);