mirror of https://github.com/layui/layui
更新 code 用例
parent
d792678f89
commit
796a064e09
|
@ -191,63 +191,61 @@ layui.use(['code', 'dropdown'], function(){
|
||||||
'full',
|
'full',
|
||||||
{
|
{
|
||||||
title: ['文字换行'],
|
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: ['切换高亮主题'],
|
title: ['切换高亮主题'],
|
||||||
type: 'theme'
|
type: 'theme',
|
||||||
}
|
event: function(obj) {
|
||||||
],
|
dropdown.render({
|
||||||
toolsEvent: function(obj) {
|
elem: obj.elem,
|
||||||
if (obj.type === 'form') {
|
data: themeData,
|
||||||
dropdown.render({
|
show: true,
|
||||||
elem: obj.elem,
|
click: function(data, othis) {
|
||||||
data: [{title: '自动换行', wordWrap: true}, {title: '不自动换行', wordWrap: false}],
|
$('#layuicss-layui-code-theme').remove();
|
||||||
show: true,
|
layui.link(data.link, 'layui-code-theme');
|
||||||
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');
|
|
||||||
|
|
||||||
// 若高亮器有变化,则重载
|
// 若高亮器有变化,则重载
|
||||||
if (data.highlighter !== codeInst.config.highlighter) {
|
if (data.highlighter !== codeInst.config.highlighter) {
|
||||||
var highlighter = {
|
var highlighter = {
|
||||||
hljs: function(code, opts) {
|
hljs: function(code, opts) {
|
||||||
return hljs.highlight(code, {
|
return hljs.highlight(code, {
|
||||||
language: opts.lang
|
language: opts.lang
|
||||||
}).value;
|
}).value;
|
||||||
},
|
},
|
||||||
prism: function(code, opts) {
|
prism: function(code, opts) {
|
||||||
return Prism.highlight(
|
return Prism.highlight(
|
||||||
code,
|
code,
|
||||||
Prism.languages[opts.lang],
|
Prism.languages[opts.lang],
|
||||||
opts.lang
|
opts.lang
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 重载
|
// 重载
|
||||||
codeInst.reload({
|
codeInst.reload({
|
||||||
highlighter: data.highlighter,
|
highlighter: data.highlighter,
|
||||||
codeRender: function (code, opts) {
|
codeRender: function (code, opts) {
|
||||||
return highlighter[data.highlighter](code, opts);
|
return highlighter[data.highlighter](code, opts);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
// 仅重载 code
|
// 仅重载 code
|
||||||
|
|
Loading…
Reference in New Issue