Monkey 修补 CKEditor 以嵌入 YouTube 视频
我正在尝试配置 CKEditor,以便它可以直接嵌入 YouTube 视频...我看到有一个建议的补丁< /a> 但我想保持原来的 CKEditor 发行版不变,所以我想知道是否可以在运行时“猴子修补”CKEditor,这样如果用户在 Flash 对话框中输入 YouTube URL,该 URL 就会转换为允许嵌入。
我已经尝试过这个:
CKEDITOR.on('dialogDefinition', function(ev){
if (dialogName == 'flash'){
var infotab = dialogDefinition.getContents('info');
var f = dialogDefinition.onOk;
dialogDefinition.onOk = function(ev) {
var cur = this.getContentElement('info', 'src').getValue();
var newurl = cur.replace('youtube.com/watch?v=', 'youtube.com/v/');
if (cur != newurl) {
this.getContentElement('info', 'src').setValue(newurl);
};
f(ev);
}
}
}
但它不起作用,因为在 f
内部代码使用 this
,而我的“补丁”改变了它......
I'm trying to configure CKEditor so that it could embed YouTube videos directly... I saw there's a proposed patch but I want to keep the original CKEditor distribution as it is, so I was wondering if it's possible to "monkey patch" CKEditor at runtime so that if the user types a YouTube URL inside the Flash dialog, the URL gets transformed to allow embedding.
I've tried this:
CKEDITOR.on('dialogDefinition', function(ev){
if (dialogName == 'flash'){
var infotab = dialogDefinition.getContents('info');
var f = dialogDefinition.onOk;
dialogDefinition.onOk = function(ev) {
var cur = this.getContentElement('info', 'src').getValue();
var newurl = cur.replace('youtube.com/watch?v=', 'youtube.com/v/');
if (cur != newurl) {
this.getContentElement('info', 'src').setValue(newurl);
};
f(ev);
}
}
}
but it won't work, since inside f
the code uses this
, and my "patch" changes it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将
onOK
附加到dialogDefinition
的另一个属性,则this
在其中将是正确的(我认为)。或者使用
Function.apply
:If you attach the
onOK
to another property ofdialogDefinition
,this
will be correct within it (I think).Or use
Function.apply
: