【问题标题】:Add a custom dropdown/button to Redactor WYSIWYG将自定义下拉/按钮添加到 Redactor 所见即所得
【发布时间】:2012-11-23 16:42:59
【问题描述】:
我有两个问题:
-
我正在尝试使用这样的按钮:
buttons: buttons,
buttonsCustom: {
sh: {
title: 'Syntax Highlighter',
callback: function(){
var html = "<pre class='brush:'></pre>";
this.execCommand('inserthtml', html);
}
}
}
我的按钮出现了,但是当我点击它时,它说“this”没有“execCommand”功能。它是如何工作的 ?我怎么能说“这个”是 Redactor ?
你知道我的意思吗?
是否可以创建下拉列表?
【问题讨论】:
标签:
javascript
jquery
wysiwyg
redactor
【解决方案1】:
我想添加一个自定义按钮,例如在 redactor 中。我拿了你的代码,并为我的目的更改了代码。它对我有用,你可以看看:
$(document).ready(
function()
{
$('.redactor').redactor({
focus: true,
buttonsAdd: ['|', 'token'],
buttonsCustom: {
token: {
title: 'Ajouter une variable',
dropdown: {
header: {title: 'Entête',callback: function(obj){obj.insertHtml('%header%');}},
footer: {title: 'Signature',callback: function(obj){obj.insertHtml('%footer%');}},
last_name: {title: 'Nom',callback: function(obj){obj.insertHtml('%last_name%');}},
first_name: {title: 'Prénom',callback: function(obj){obj.insertHtml('%first_name%');}},
date: {title: 'Date',callback: function(obj){obj.insertHtml('%date%');}},
contract: {title: 'Contrat',callback: function(obj){obj.insertHtml('%contract%');}}
}
}
}
});
}
);
干杯
【解决方案2】:
我自己修好了:
callback: function(obj){
var html = "<pre class='brush:'></pre>";
obj.execCommand('inserthtml', html);
}
【解决方案3】:
查看编辑器源代码(最新版本 8.2.6),我注意到您可以将第四个参数传递给插件 API 的 addBtn 函数来描述下拉菜单。所以,假设你想从插件内部添加一个字体大小下拉菜单:
RedactorPlugins.fontSize = {
init: function(obj) {
btnCallback = function(obj,event,key) {
// button actions, if any
}
dropdown = {
small: {
title: 'Small'
callback: function(obj,event,key) { //set the font size to small }
}
medium: {
title: 'Medium'
callback: function(obj,event,key) { //set the font size to medium }
}
}
this.addBtn('fontSize','Change font size', btnCallback, dropdown);
}
}