使用cleditor,我试图建立与下面的代码自定义按钮:jQuery的cleditor插件:创建一个新的按钮
(function($) {
$.cleditor.buttons.link_species = {
name: "link_species",
image: "fish.gif",
title: "Species Link",
command: "inserthtml",
popupName: "link_species",
popupClass: "cleditorPrompt",
popupContent: "Genus: <input type='text' size='15'> Species: <input type='text' size='15'><br />Remove italics? <input type='checkbox' value='remove'> <input type='button' value='Ok' />",
buttonClick: link_speciesClick
};
// Handle the hello button click event
function link_speciesClick(e, data) {
// Wire up the submit button click event
$(data.popup).children(":button")
.unbind("click")
.bind("click", function(e) {
// Get the editor
var editor = data.editor;
var $text = $(data.popup).find(":text"),
genus = $text[0].value,
species = $text[1].value;
var slug = genus + '-' + species;
slug = htmlEntities(slug);
var link = '/dev/species/' + slug + '/';
var rel = link + '?preview=true';
var display = firstUpper(genus) + ' ' + species;
// Get the entered name
var html = '<a href="' + link + '" rel="' + rel + '">' + display + '</a>';
if (!$(data.popup).find(":checkbox").is(':checked')) {
html = '<em>' + html + '</em>';
}
// Insert some html into the document
editor.execCommand(data.command, html, null, data.button);
// Hide the popup and set focus back to the editor
editor.hidePopups();
editor.focus();
});
}
})(jQuery);
这是一个WordPress网站,目录结构是这样的:
/wp-content/plugins/sf-species-profile/cleditor
在那里我有所有的cleditor文件和config.js
。这文件是上面的代码存储在哪里。
我也有一个images
文件夹包含一个24 * 24 fish.gif
文件。
出于某种原因,当我运行这段代码,我得到以下错误:
[firefox]
a is undefined
<<myurl>>/wp-content/plugins/sf-species-profiles/cleditor/jquery.cleditor.min.js?ver=3.3.1
Line 17
[chrome]
Uncaught TypeError: Cannot read property 'length' of undefined
如果我改变了“形象”的说法图像:“B”出现“在同一图像”,但该插件没有错误地工作。
有没有人有什么想法可能是错的?
嗨,你好,感谢你的帖子 - 这是很好的想法!确切的错误,使用完整的JS文件,是这样的:'href是undefined:return href.substr(0,href.length - cssFile.length)+“images /”;'。所以,你是完全正确的,但它似乎不是与CSS文件 - 这是正确链接。任何其他想法? – dunc 2012-03-11 18:54:02
Aahhhhh,它是css文件!当我深入了解'link [href $ = ...'如何工作时,我意识到如果它结束'jquery.cleditor.css',它将只能找到CSS文件。 WordPress自然将'ver = 3.3.1'添加到入队样式表的末尾,所以当我删除它时,问题就解决了! – dunc 2012-03-11 19:37:36
整蛊现货!很高兴它解决了。 – widged 2012-03-11 22:46:57