FineAdmin.Web/Content/lib/wangEditor/src/js/menus/code/index.js

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/*
    menu - code
*/
import $ from '../../util/dom-core.js'
import { getRandom, replaceHtmlSymbol } from '../../util/util.js'
import Panel from '../panel.js'
import { UA } from '../../util/util.js'

// 构造函数
function Code(editor) {
    this.editor = editor
    this.$elem = $(
        `<div class="w-e-menu">
            <i class="w-e-icon-terminal"></i>
        </div>`
    )
    this.type = 'panel'

    // 当前是否 active 状态
    this._active = false
}

// 原型
Code.prototype = {
    constructor: Code,

    onClick: function (e) {
        const editor = this.editor
        const $startElem = editor.selection.getSelectionStartElem()
        const $endElem = editor.selection.getSelectionEndElem()
        const isSeleEmpty = editor.selection.isSelectionEmpty()
        const selectionText = editor.selection.getSelectionText()
        let $code

        if (!$startElem.equal($endElem)) {
            // 跨元素选择,不做处理
            editor.selection.restoreSelection()
            return
        }
        if (!isSeleEmpty) {
            // 选取不是空,用 <code> 包裹即可
            $code = $(`<code>${selectionText}</code>`)
            editor.cmd.do('insertElem', $code)
            editor.selection.createRangeByElem($code, false)
            editor.selection.restoreSelection()
            return
        }

        // 选取是空,且没有夸元素选择,则插入 <pre><code></code></prev>
        if (this._active) {
            // 选中状态,将编辑内容
            this._createPanel($startElem.html())
        } else {
            // 未选中状态,将创建内容
            this._createPanel()
        }
    },

    _createPanel: function (value) {
        // value - 要编辑的内容
后面还有 90 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。