2012年10月31日

Wysiwyg与CKEditor

在Drupal中,Wysiwyg与CKEditor是很好的搭配。

 

安装

  • Instal the WYSIWYG module and enable
  • Download the latest CKEditor and unzip it in sites/all/libraries
  • Go to configuration => wysiwyg and choose the editor for the input format (use it on the full HTML or PHP)
  • Now you can edit and there you can choose under buttons and plugins what buttons appear
  • When you create a content type don't forget to set the correct text format

 

配置

由于默认的配置文件【sites/all/libraries/ckeditor/config.js】不起作用,需要变通的方法,大致如下

   (具体请参考: http://fuseinteractive.ca/blog/wysiwyg-module-ckeditor-taming-beast

 

1.制作一个Module

     创建目录【sites/all/modules/custom】,在该目录下建立2个文件(类型为info和module)

      ckeditor_custom.info    

name = CKEditor Custom

description = Custom configuration for CKEditor

core = 7.x

      ckeditor_custom.module

<?php

/**
* Implements hook_wysiwyg_editor_settings_alter()
*/
function ckeditor_custom_wysiwyg_editor_settings_alter(&$settings, $context) {

  // The $context variable contains information about the wysiwyg profile we're using
  // In this case we just need to check that the editor being used is ckeditor

  if ($context['profile']->editor == 'ckeditor') {
     $settings['customConfig'] = base_path() . drupal_get_path('module', 'ckeditor_custom') .
'/ckeditor_custom_config.js';
   }
}

 

2.创建配置文件

跟上面两个文件在同一目录下创建文件【ckeditorcustomconfig.js

CKEDITOR.on( 'dialogDefinition', function( ev )
{
  // Take the dialog name and its definition from the event data.
  var dialogName = ev.data.name;
  var dialogDefinition = ev.data.definition;

  if ( dialogName == 'link' )
  {
    var targetTab = dialogDefinition.getContents( 'target' );
    // Set the default value for the URL field.
    var targetField = targetTab.get( 'linkTargetType' );
    targetField[ 'default' ] = '_blank';
  }
});

 

3.将刚制作的Module启用

 

下面的链接是Dialog的定制示例

http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Dialog_Customization

没有评论:

发表评论