Typecho custom background editor function

 HaoOuBa
2021-02-08 / 76 Comments / 9776 Reading / Checking whether it is included ..
reminder:
This article was last updated on April 23, 2021, and has not been updated for more than 1531 days. If the content or picture is invalid, please leave a message for feedback.

First, look at the renderings

 kldmmdpu.png

usage method

 Typecho_Plugin::factory('admin/write-post.php')->bottom = array('Editor', 'edit'); Typecho_Plugin::factory('admin/write-page.php')->bottom = array('Editor', 'edit'); class Editor { public static function edit() { echo "<script src='" . Helper::options()->themeUrl . '/typecho/editor/joe.extend.js' . "'></script>"; echo "<script src='" . Helper::options()->themeUrl . '/typecho/editor/joe.editor.js' . "'></script>"; } }

The following joe.extend.js is neither compressed nor encrypted. The following is the source code of joe.extend.js

 (function ($) { $.fn.extend({ /*Press the keyboard to insert content*/ shortcuts: function () { this.keydown(function (e) { var _this = $(this); e.stopPropagation(); if (e.altKey) { switch (e.keyCode) { case 67: _this.insertContent('[code]' + _this.selectionRange() + '[/code]'); break; } } }); }, /*Insert Content*/ 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(); } }, /*Select*/ 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);
The shortcuts method above is mainly used to insert content by pressing the keyboard

Then look joe.edit.js Content of

 /*Add custom function*/ const items = [ { Title: 'The reply is visible', id: 'wmd-hide-button', svg: '<svg t="1612402690962" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns=" http://www.w3.org/2000/svg " p-id="15751" width="20" height="20 "><path d="M554.666667 438.101333V277.333333h-85.333334v160.768L330.112 357.717333l-42.666667 73.898667L426.666667 512l-139.221334 80.384 42.666667 73.898667L469.333333 585.898667V746.666667h85.333334v-160.768l139.221333 80.384 42.666667-73.898667L597.333333 512l139.221334-80.384-42.666667-73.898667L554.666667 438.101333z" p-id="15752 " fill="#9b9b9b"></path></svg>', Text: ' n [@ hide] You can only see [/hide] after replying to the content here  n' } ]; items.forEach(_ => { let item = $(`<li class="wmd-button" id="${_.id}" title="${_.title}">${_.svg}</li>`); item.on('click', function () { $('#text').insertContent(_.text); }); $('#wmd-button-row').append(item); });
one hundred and seven

Comments (76)

cancel
  1.  head portrait
    one
    Windows 10 · Google Chrome

     Draw

    reply
  2.  head portrait
    five hundred and fifty-five
    Windows 10 · Google Chrome

     Draw

    reply
  3.  head portrait
    Lin San
    Windows 10 · Google Chrome

     Draw

    reply
  4.  head portrait
    Cool
    Android · Google Chrome

    If I want to add the second function button, how can I add the content of the js code? thank you

    reply
  5.  head portrait
    darylyexu
    Windows 10 · Google Chrome

    Added in function.php, the editor page js can also see the call, but even if there is no button display, the theme is apollo, you can't use the one above. Typecho version 1.2

    reply
  6.  head portrait
    sjus
    Android · Google Chrome

     Draw

    reply
    1.  head portrait
      two
      Windows 10 · Google Chrome
      @ sjus

      123 Ha ha

      reply
  7.  head portrait
    hhh
    Android · Google Chrome

     Draw

    reply
  8.  head portrait
    Ultraman
    Windows 10 · Google Chrome

     Draw

    reply
  9.  head portrait
    Reward Father
    Android · Google Chrome

     Draw

    reply
  10.  head portrait
    TFI
    Windows 10 · Google Chrome

     Draw

    reply