一些CKEditor定制問題


 

 

調整CKEditor的basePath

使用base標簽,或者項目文件結構的原因,我們可能需要調整CKEditor的basePath。

basePath: (function() {
                // ATTENTION: fixes to this code must be ported to
                // var basePath in "core/loader.js".

                // Find out the editor directory path, based on its <script> tag.
                var path = window.CKEDITOR_BASEPATH || '';

                if ( !path ) {
                    var scripts = document.getElementsByTagName( 'script' );

                    for ( var i = 0; i < scripts.length; i++ ) {
                        var match = scripts[ i ].src.match( /(^|.*[\\\/])ckeditor(?:_basic)?(?:_source)?.js(?:\?.*)?$/i );

                        if ( match ) {
                            path = match[ 1 ];
                            break;
                        }
                    }
                }

                // In IE (only) the script.src string is the raw value entered in the
                // HTML source. Other browsers return the full resolved URL instead.
                if ( path.indexOf( ':/' ) == -1 ) {
                    // Absolute path.
                    if ( path.indexOf( '/' ) === 0 )
                        path = location.href.match( /^.*?:\/\/[^\/]*/ )[ 0 ] + path;
                    // Relative path.
                    else
                        path = location.href.match( /^[^\?]*\/(?:)/ )[ 0 ] + path;
                }

                if ( !path )
                    throw 'The CKEditor installation path could not be automatically detected. Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.';

                return path;
            })()

可見,我們可以通過設置window.CKEDITOR_BASEPATH來調整CKEditor的basePath。

 

自定義CKEditor的語言

CKEditor可以根據瀏覽器來自動選擇語言,但可能我們需要其和UI統一語言,而不是自動選擇,這時候我們就需要自定義其語言。

我們需要給Config的language屬性定義成相應的語言。

  • 在repalce時傳入config
var idSelector = "editor1"; 

CKEDITOR.replace(idSelector, {language: 'zh-cn'}); //設置成簡體中文
  • 在editor實例生成時自動設置
CKEDITOR.on('instanceCreated', function(event){ // 當editor實例創建時
  var editor = event.editor;

  editor.on('configLoaded', function(){ // 當實例載入config時
    editor.config.language = "zh-cn"; // 修改成簡體中文
  });

};

 

Advanced Content Filter

CKEditor會自動開啟內容過濾器,其會對節點的屬性進行過濾,可是我們可能不希望其過濾,可以通過設置config.allowedContent為true,來關閉該功能。

這樣CKEditor就僅僅是富文本編輯器了。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM