在CKeditor网页表单中完全禁用粘贴选项

时间:2017-11-07 12:04:51

标签: php codeigniter ckeditor

我无法在CKeditor中禁用粘贴(CTRL + V)选项。虽然现在禁用了右键单击粘贴选项。

以下是CKeditor的config.js文件

CKEDITOR.editorConfig = function( config ) {
config.extraPlugins = 'wordcount,notification';

config.wordcount = {

    // Whether or not you want to show the Paragraphs Count
    showParagraphs: false,

    // Whether or not you want to show the Word Count
    showWordCount: true,

    // Whether or not you want to show the Char Count
    showCharCount: true,

    // Whether or not you want to count Spaces as Chars
    countSpacesAsChars: true,

    // Whether or not to include Html chars in the Char Count
    countHTML: false,

    // Maximum allowed Word Count, -1 is default for unlimited
    maxWordCount: -1,

    // Maximum allowed Char Count, -1 is default for unlimited
    maxCharCount: 2000
};
// The toolbar groups arrangement, optimized for a single toolbar row.
config.toolbarGroups = [
    { name: 'document',    groups: [ 'mode', 'document', 'doctools' ] },
    { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
    { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
    { name: 'forms' },
    { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
    { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
    { name: 'links' },
    { name: 'insert' },
    { name: 'styles' },
    { name: 'colors' },
    { name: 'tools' },
    { name: 'others' },
    { name: 'about' }
];
CKEDITOR.config.toolbar = [
   ['Format','FontSize'],

   ['Bold','Italic','Underline','StrikeThrough','-','Undo','Redo','-','Cut','Copy','Paste','Find','Replace','-','Outdent','Indent','-','Print'],

   ['NumberedList','BulletedList','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
   ['-','Link']
] ;
// The default plugins included in the basic setup define some buttons that
// are not needed in a basic editor. They are removed here.
config.removeButtons = 'Cut,Copy,Paste,Undo,Redo,Anchor,Underline,Strike,Subscript,Superscript';

// Dialog windows are also simplified.
config.removeDialogTabs = 'link:advanced';

};

This is how the editor looks like

加载此编辑器的控制器功能是 -

public function edit_cv(){
$user_id= $this->CI->session->userdata('id');
$this->addJS("tnpcell/edit.js");
$this->addJS("ckeditor/ckeditor.js");
$this->addJS("ckeditor/samples/js/sample.js");
$data['cv_data'] = $this->cv_model->get_achievements($user_id);
foreach ($data['cv_data'] as $row){
      $row->editor_content = urldecode($row->editor_content);
      $row->skype_id = urldecode($row->skype_id);
      $row->shoe_size = urldecode($row->shoe_size);
      $row->blood_group = urldecode($row->blood_group);
      $row->specialization = urldecode($row->specialization);
      $row->editor_content = str_replace('$.ol.$', '<ol>', $row->editor_content);
      $row->editor_content = str_replace('$.ul.$', '<ul>', $row->editor_content);
      $row->editor_content = str_replace('$.li.$', '<li>', $row->editor_content);
      $row->editor_content = str_replace('$./ol.$', '</ol>', $row->editor_content);
      $row->editor_content = str_replace('$./ul.$', '</ul>', $row->editor_content);
      $row->editor_content = str_replace('$./li.$', '</li>', $row->editor_content);
      $row->editor_content = str_replace('$.nbsp.$', '&nbsp;', $row->editor_content);
}
$data['project_data'] = $this->cv_model->get_project($user_id);
foreach ($data['project_data'] as $row) {
      $row->title = urldecode($row->title);
      $row->role = urldecode($row->role);
}
$this->load->model('course_structure/basic_model','',TRUE);
$this->load->model('student/student_academic_model','',TRUE);
$data['student_academic']=$this->student_academic_model->get_stu_academic_details_by_id($user_id);
$data['branch_name']=$this->basic_model->get_branch_details_by_id($data['student_academic']->branch_id)[0]->name;

$this->drawHeader("Edit Your CV");
$this->load->view('tnpcell/edit_cv',$data);
$this->drawFooter();

}

我希望用户不能在编辑器字段中粘贴任何文本(如上图所示)。但目前使用ctrl + V粘贴一些文本已启用。

1 个答案:

答案 0 :(得分:2)

您可以取消paste活动。

CKEDITOR.instances.editor1.on('paste', function(evt) {
    evt.cancel();
});