Я пытаюсь изменить плагин, который я нашел для Redactor, чтобы заставить его работать с самой новой версией, но мое незнание JavaScript мешает мне заставить его работать.
if (!RedactorPlugins) var RedactorPlugins = {};
RedactorPlugins.wordcount = function() {
return {
init: function() {
var self = this;
var $box = $(this.core.getBox());
if ($box.length>0) {
if ($box.find('.redactor-wordcount').length==0) {
var $wordcount_holder = $('#counter');
$box.on('keyup', function () {
$wordcount_holder.text('Words: ' + self.count());
});
$wordcount_holder.text('Words: ' + self.count());
}
}
},
count: function() {
var html = this.get(),
text = $(html).text().replace(/\t+/g, " ").replace(/\n/g, " ").replace(/\s+/g, " ");
return text.split(' ').length - 1;
}
};
};
При загрузке страницы выдает ошибку Uncaught TypeError: undefined is not a function
. Это относится к функции count
.
Я был под впечатлением этого синтаксиса:
return {
...
}
Вызывает возврат объекта, но по какой-то причине вызов self.count()
вызывает указанную выше ошибку.
Как я могу вызвать функцию count
из функции init
?
РЕДАКТИРОВАТЬ: В стороне, вот как должны быть определены плагины Redactor (для новой версии программного обеспечения):
if (!RedactorPlugins) var RedactorPlugins = {};
RedactorPlugins.myplugin = function()
{
return {
myMethod: function()
{
// your code
}
};
};
this
, когда вы звонитеinit()
? Вы используетеthis.core
иthis.get()
, но я нигде не вижу определенияcore
илиget()
. - person AJ Richardson   schedule 18.12.2014