我正在努力扩展wagtailembedvideos
添加正确hallo.js
插件:https ://github.com/SalahAdDin/wagtail-embedvideos
我有这个embed-video-chooser.js
:
function createEmbedVideoChooser(id) {
var chooserElement = $('#' + id + '-chooser');
var previewEmbedVideo = chooserElement.find('.preview-image img');
var input = $('#' + id);
var editLink = chooserElement.find('.edit-link');
$('.action-choose', chooserElement).click(function() {
ModalWorkflow({
'url': window.chooserUrls.embedVideoChooser,
'responses': {
'embedVideoChosen': function(embedVideoData) {
input.val(embedVideoData.id);
previewEmbedVideo.attr({
src: embedVideoData.preview.url,
width: embedVideoData.preview.width,
height: embedVideoData.preview.height,
alt: embedVideoData.title
});
chooserElement.removeClass('blank');
editLink.attr('href', embedVideoData.edit_link);
}
}
});
});
$('.action-clear', chooserElement).on('click', function() {
input.val('');
chooserElement.addClass('blank');
});
}
这是插件:
(function() {
(function($) {
return $.widget('IKS.halloembedvideos', {
options: {
uuid: '',
editable: null
},
populateToolbar: function(toolbar) {
var button, widget;
widget = this;
button = $('<span class="' + this.widgetName + '"></span>');
button.hallobutton({
uuid: this.options.uuid,
editable: this.options.editable,
label: 'Videos',
icon: 'icon-media',
command: null
});
toolbar.append(button);
return button.on('click', function(event) {
var insertionPoint, lastSelection;
lastSelection = widget.options.editable.getSelection();
insertionPoint = $(lastSelection.endContainer).parentsUntil('.richtext').last();
return ModalWorkflow({
url: window.chooserUrls.embedVideoChooser + '?select_format=true',
responses: {
embedVideoChosen: function(embedVideoData) {
var elem;
elem = $(embedVideoData.html).get(0);
lastSelection.insertNode(elem);
if (elem.getAttribute('contenteditable') === 'false') {
insertRichTextDeleteControl(elem);
}
return widget.options.editable.element.trigger('change');
}
}
});
});
}
});
})(jQuery);
}).call(this);
该按钮有效,选择器出现,我可以上传或选择视频,但我收到此错误:
rangy-core.js:33 Uncaught TypeError: Cannot read property 'nodeType' of undefined
at L (rangy-core.js:33)
at I.insertNode (rangy-core.js:47)
at Object.embedVideoChosen (hallo-embedvideos.js:33)
at Object.ModalWorkflow.self.respond (modal-workflow.js:75)
at Object.onload (eval at ModalWorkflow.self.loadResponseText (modal-workflow.js:54), <anonymous>:2:11)
at Object.ModalWorkflow.self.loadBody (modal-workflow.js:68)
at Object.ModalWorkflow.self.loadResponseText [as success] (modal-workflow.js:56)
at i (jquery-2.2.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-2.2.1.min.js:2)
at z (jquery-2.2.1.min.js:4)
我不明白如何imageData.html
工作,因此我不知道如何解决这个问题。
谁能给我解释一下?