From 796a064e0998f52ac7585e970a5d1c054dbaeb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 10 Sep 2023 20:20:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20code=20=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/code.html | 100 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/examples/code.html b/examples/code.html index 9fb16927..375922a8 100644 --- a/examples/code.html +++ b/examples/code.html @@ -191,63 +191,61 @@ layui.use(['code', 'dropdown'], function(){ 'full', { title: ['文字换行'], - type: 'form' + type: 'form', + event: function(obj) { + dropdown.render({ + elem: obj.elem, + data: [{title: '自动换行', wordWrap: true}, {title: '不自动换行', wordWrap: false}], + show: true, + click: function(data, othis) { + codeInst.reload({ + wordWrap: data.wordWrap + }); + } + }); + } }, { title: ['切换高亮主题'], - type: 'theme' - } - ], - toolsEvent: function(obj) { - if (obj.type === 'form') { - dropdown.render({ - elem: obj.elem, - data: [{title: '自动换行', wordWrap: true}, {title: '不自动换行', wordWrap: false}], - show: true, - click: function(data, othis) { - codeInst.reload({ - wordWrap: data.wordWrap, - content: [+new Date()] - }); - } - }); - } else if (obj.type === 'theme') { - dropdown.render({ - elem: obj.elem, - data: themeData, - show: true, - click: function(data, othis) { - $('#layuicss-layui-code-theme').remove(); - layui.link(data.link, 'layui-code-theme'); + type: 'theme', + event: function(obj) { + dropdown.render({ + elem: obj.elem, + data: themeData, + show: true, + click: function(data, othis) { + $('#layuicss-layui-code-theme').remove(); + layui.link(data.link, 'layui-code-theme'); - // 若高亮器有变化,则重载 - if (data.highlighter !== codeInst.config.highlighter) { - var highlighter = { - hljs: function(code, opts) { - return hljs.highlight(code, { - language: opts.lang - }).value; - }, - prism: function(code, opts) { - return Prism.highlight( - code, - Prism.languages[opts.lang], - opts.lang - ); - } - }; - // 重载 - codeInst.reload({ - highlighter: data.highlighter, - codeRender: function (code, opts) { - return highlighter[data.highlighter](code, opts); - } - }); + // 若高亮器有变化,则重载 + if (data.highlighter !== codeInst.config.highlighter) { + var highlighter = { + hljs: function(code, opts) { + return hljs.highlight(code, { + language: opts.lang + }).value; + }, + prism: function(code, opts) { + return Prism.highlight( + code, + Prism.languages[opts.lang], + opts.lang + ); + } + }; + // 重载 + codeInst.reload({ + highlighter: data.highlighter, + codeRender: function (code, opts) { + return highlighter[data.highlighter](code, opts); + } + }); + } } - } - }); + }); + } } - } + ] }); // 仅重载 code