2011-02-16 107 views
0

我想配置CKEditor,以便它可以直接嵌入YouTube視頻...我看到有一個proposed patch但我想保留原來的CKEditor發行版,因此我想知道如果可以在運行時「修補」CKEditor,那麼如果用戶在Flash對話框中鍵入一個YouTube URL,則該URL將被轉換爲允許嵌入。如果附加猴子修補CKEditor嵌入YouTube視頻

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,和我的「補丁」改變它......

回答

1

我已經試過這onOKdialogDefinition,this的其他財產將是正確的(我認爲)。

CKEDITOR.on('dialogDefinition', function(ev){ 
    if (dialogName == 'flash'){ 
     var infotab = dialogDefinition.getContents('info'); 
     dialogDefinition.oldOnOk = dialogDefinition.onOk; //change here 
     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); 
      }; 
      dialogDefinition.oldOnOk(ev); //and change here 
     } 
    } 
} 

或者使用Function.apply:

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.apply(this, ev); //change here 
     } 
    } 
} 
+1

f.apply(這一點,[曝光])工作在Firefox和IE,非常感謝:) – Joril 2011-02-16 21:56:17