Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ckeditor字数启用还是禁用?_Javascript_Php_Ckeditor_Ckeditor Wordcount - Fatal编程技术网

Javascript ckeditor字数启用还是禁用?

Javascript ckeditor字数启用还是禁用?,javascript,php,ckeditor,ckeditor-wordcount,Javascript,Php,Ckeditor,Ckeditor Wordcount,我已经为ckeditor安装了ckeditor和wordcount插件,但还没有启用。请给我建议如何在我的ckeditor中启用单词计数 编辑: config.js /** * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ CKEDIT

我已经为ckeditor安装了ckeditor和wordcount插件,但还没有启用。请给我建议如何在我的ckeditor中启用单词计数

编辑:

config.js

/**
 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md or http://ckeditor.com/license
 */

CKEDITOR.editorConfig = function (config) {
    // Define changes to default configuration here.
    // For complete reference see:
    // http://docs.ckeditor.com/#!/api/CKEDITOR.config

    config.enterMode = CKEDITOR.ENTER_BR;
    // 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'}

    ];

    // 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';

//    config.extraPlugins = 'wordcount,notification';

    config.wordcount = {
        // Whether or not you want to show the Paragraphs Count, Default Value: true
        showParagraphs: true,
        // Whether or not you want to show the Word Count, Default Value: true
        showWordCount: true,
        // Whether or not you want to show the Char Count, Default Value: false
        showCharCount: true,
        // Whether or not you want to count Spaces as Chars, Default Value: false
        countSpacesAsChars: false,
        // Whether or not to include Html chars in the Char Count, Default Value: false
        countHTML: true,
        // Maximum allowed Word Count that can be entered in the editor, Default Value: -1 (unlimited)
        maxWordCount: 100,
        // Maximum allowed Chararcater Count entered be in the editor, Default Value: -1 (unlimited)
        maxCharCount: 100,
        // Add filter to add or remove element before counting (see CKEDITOR.htmlParser.filter), Default value : null (no filter)
        filter: new CKEDITOR.htmlParser.filter({
            elements: {
                div: function (element) {
                    if (element.attributes.class == 'mediaembed') {
                        return false;
                    }
                }
            }
        })
    };

};
WordCount:plugin.js

/**
 * @license Copyright (c) CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.html or http://ckeditor.com/license
 */

CKEDITOR.plugins.add("wordcount", {
    lang: "ca,de,el,en,es,fr,he,hr,it,jp,nl,no,pl,pt-br,ru,sv,tr,zh-cn", // %REMOVE_LINE_CORE%
    version: 1.14,
    requires: 'htmlwriter,notification,undo',
    init: function (editor) {
        var defaultFormat = "",
            intervalId,
            lastWordCount = -1,
            lastCharCount = -1,
            limitReachedNotified = false,
            limitRestoredNotified = false,
            snapShot = editor.getSnapshot();

        var dispatchEvent = function (type, currentLength, maxLength) {
            if (typeof document.dispatchEvent == 'undefined') {
                return;
            }

            type = 'ckeditor.wordcount.' + type;

            var cEvent;
            var eventInitDict = {
                bubbles: false,
                cancelable: true,
                detail: {
                    currentLength: currentLength,
                    maxLength: maxLength
                }
            };

            try {
                cEvent = new CustomEvent(type, eventInitDict);
            } catch (o_O) {
                cEvent = document.createEvent('CustomEvent');
                cEvent.initCustomEvent(
                    type,
                    eventInitDict.bubbles,
                    eventInitDict.cancelable,
                    eventInitDict.detail
                );
            }

            document.dispatchEvent(cEvent);
        };

        // Default Config
        var defaultConfig = {
            showParagraphs: true,
            showWordCount: true,
            showCharCount: false,
            countSpacesAsChars: false,
            countHTML: false,
            hardLimit: true,

            //MAXLENGTH Properties
            maxWordCount: -1,
            maxCharCount: -1,

            //DisAllowed functions
            wordCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                dispatchEvent('wordCountGreaterThanMaxLengthEvent', currentLength, maxLength);
            },
            charCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                dispatchEvent('charCountGreaterThanMaxLengthEvent', currentLength, maxLength);
            },

            //Allowed Functions
            wordCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                dispatchEvent('wordCountLessThanMaxLengthEvent', currentLength, maxLength);
            },
            charCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                dispatchEvent('charCountLessThanMaxLengthEvent', currentLength, maxLength);
            }
        };

        // Get Config & Lang
        var config = CKEDITOR.tools.extend(defaultConfig, editor.config.wordcount || {}, true);

        if (config.showParagraphs) {
            defaultFormat += editor.lang.wordcount.Paragraphs + " %paragraphs%";
        }

        if (config.showParagraphs && (config.showWordCount || config.showCharCount)) {
            defaultFormat += ", ";
        }

        if (config.showWordCount) {
            defaultFormat += editor.lang.wordcount.WordCount + " %wordCount%";
            if (config.maxWordCount > -1) {
                defaultFormat += "/" + config.maxWordCount;
            }
        }

        if (config.showCharCount && config.showWordCount) {
            defaultFormat += ", ";
        }

        if (config.showCharCount) {
            var charLabel = editor.lang.wordcount[config.countHTML ? "CharCountWithHTML" : "CharCount"];

            defaultFormat += charLabel + " %charCount%";
            if (config.maxCharCount > -1) {
                defaultFormat += "/" + config.maxCharCount;
            }
        }

        var format = defaultFormat;

        if (config.loadCss === undefined || config.loadCss) {
          CKEDITOR.document.appendStyleSheet(this.path + "css/wordcount.css");
        }

        function counterId(editorInstance) {
            return "cke_wordcount_" + editorInstance.name;
        }

        function counterElement(editorInstance) {
            return document.getElementById(counterId(editorInstance));
        }

        function strip(html) {
            var tmp = document.createElement("div");
            tmp.innerHTML = html;

            if (tmp.textContent == "" && typeof tmp.innerText == "undefined") {
                return "";
            }

            return tmp.textContent || tmp.innerText;
        }

        function countCharacters(text, editorInstance) {
            if (config.countHTML) {
                return (text.length);
            } else {
                var normalizedText;

                // strip body tags
                if (editor.config.fullPage) {
                    var i = text.search(new RegExp("<body>", "i"));
                    if (i != -1) {
                        var j = text.search(new RegExp("</body>", "i"));
                        text = text.substring(i + 6, j);
                    }

                }

                normalizedText = text;

                if (!config.countSpacesAsChars) {
                    normalizedText = text.
                        replace(/\s/g, "").
                        replace(/&nbsp;/g, "");
                }

                normalizedText = normalizedText.
                    replace(/(\r\n|\n|\r)/gm, "").
                    replace(/&nbsp;/gi, " ");

                normalizedText = strip(normalizedText).replace(/^([\t\r\n]*)$/, "");

                return(normalizedText.length);
            }
        }

        function countParagraphs(text) {
            return (text.replace(/&nbsp;/g, " ").replace(/(<([^>]+)>)/ig, "").replace(/^\s*$[\n\r]{1,}/gm, "++").split("++").length);
        }

        function countWords(text) {
            var normalizedText = text.
                replace(/(\r\n|\n|\r)/gm, " ").
                replace(/^\s+|\s+$/g, "").
                replace("&nbsp;", " ");

            normalizedText = strip(normalizedText);

            var words = normalizedText.split(/\s+/);

            for (var wordIndex = words.length - 1; wordIndex >= 0; wordIndex--) {
                if (words[wordIndex].match(/^([\s\t\r\n]*)$/)) {
                    words.splice(wordIndex, 1);
                }
            }

            return (words.length);
        }

        function limitReached(editorInstance, notify) {
            limitReachedNotified = true;
            limitRestoredNotified = false;

            if (config.hardLimit) {
                editorInstance.loadSnapshot(snapShot);
                // lock editor
                editorInstance.config.Locked = 1;
            }

            if (!notify) {
                counterElement(editorInstance).className = "cke_path_item cke_wordcountLimitReached";
                editorInstance.fire("limitReached", {}, editor);
            }
        }

        function limitRestored(editorInstance) {
            limitRestoredNotified = true;
            limitReachedNotified = false;
            editorInstance.config.Locked = 0;
            snapShot = editor.getSnapshot();

            counterElement(editorInstance).className = "cke_path_item";
        }

        function updateCounter(editorInstance) {
            var paragraphs = 0,
                wordCount = 0,
                charCount = 0,
                text;

            if (text = editorInstance.getData()) {
                if (config.showCharCount) {
                    charCount = countCharacters(text, editorInstance);
                }

                if (config.showParagraphs) {
                    paragraphs = countParagraphs(text);
                }

                if (config.showWordCount) {
                    wordCount = countWords(text);
                }
            }

            var html = format.replace("%wordCount%", wordCount).replace("%charCount%", charCount).replace("%paragraphs%", paragraphs);

            editorInstance.plugins.wordcount.wordCount = wordCount;
            editorInstance.plugins.wordcount.charCount = charCount;

            if (CKEDITOR.env.gecko) {
                counterElement(editorInstance).innerHTML = html;
            } else {
                counterElement(editorInstance).innerText = html;
            }

            if (charCount == lastCharCount && wordCount == lastWordCount) {
                return true;
            }

            //If the limit is already over, allow the deletion of characters/words. Otherwise,
            //the user would have to delete at one go the number of offending characters
            var deltaWord = wordCount - lastWordCount;
            var deltaChar = charCount - lastCharCount;

            lastWordCount = wordCount;
            lastCharCount = charCount;

            if (lastWordCount == -1) {
                lastWordCount = wordCount;
            }
            if (lastCharCount == -1) {
                lastCharCount = charCount;
            }

            // Check for word limit and/or char limit
            if ((config.maxWordCount > -1 && wordCount > config.maxWordCount && deltaWord > 0) ||
                (config.maxCharCount > -1 && charCount > config.maxCharCount && deltaChar > 0)) {

                limitReached(editorInstance, limitReachedNotified);
            } else if ((config.maxWordCount == -1 || wordCount < config.maxWordCount) &&
            (config.maxCharCount == -1 || charCount < config.maxCharCount)) {

                limitRestored(editorInstance);
            } else {
                snapShot = editorInstance.getSnapshot();
            }

            // Fire Custom Events
            if (config.charCountGreaterThanMaxLengthEvent && config.charCountLessThanMaxLengthEvent) {
                if (charCount > config.maxCharCount && config.maxCharCount > -1) {
                    config.charCountGreaterThanMaxLengthEvent(charCount, config.maxCharCount);
                } else {
                    config.charCountLessThanMaxLengthEvent(charCount, config.maxCharCount);
                }
            }

            if (config.wordCountGreaterThanMaxLengthEvent && config.wordCountLessThanMaxLengthEvent) {
                if (wordCount > config.maxWordCount && config.maxWordCount > -1) {
                    config.wordCountGreaterThanMaxLengthEvent(wordCount, config.maxWordCount);

                } else {
                    config.wordCountLessThanMaxLengthEvent(wordCount, config.maxWordCount);
                }
            }

            return true;
        }

        editor.on("key", function (event) {
            if (editor.mode === "source") {
                updateCounter(event.editor);
            }
        }, editor, null, 100);

        editor.on("change", function (event) {
            updateCounter(event.editor);
        }, editor, null, 100);

        editor.on("uiSpace", function (event) {
            if (editor.elementMode === CKEDITOR.ELEMENT_MODE_INLINE) {
                if (event.data.space == "top") {
                    event.data.html += "<div class=\"cke_wordcount\" style=\"\"" +
                        " title=\"" +
                        editor.lang.wordcount.title +
                        "\"" +
                        "><span id=\"" +
                        counterId(event.editor) +
                        "\" class=\"cke_path_item\">&nbsp;</span></div>";
                }
            } else {
                if (event.data.space == "bottom") {
                    event.data.html += "<div class=\"cke_wordcount\" style=\"\"" +
                        " title=\"" +
                        editor.lang.wordcount.title +
                        "\"" +
                        "><span id=\"" +
                        counterId(event.editor) +
                        "\" class=\"cke_path_item\">&nbsp;</span></div>";
                }
            }

        }, editor, null, 100);

        editor.on("dataReady", function (event) {
            updateCounter(event.editor);
        }, editor, null, 100);

        editor.on("paste", function(event) {
            if (config.maxWordCount > 0 || config.maxCharCount > 0) {

                // Check if pasted content is above the limits
                var wordCount = -1,
                    charCount = -1,
                    text = event.editor.getData() + event.data.dataValue;


                if (config.showCharCount) {
                    charCount = countCharacters(text, event.editor);
                }

                if (config.showWordCount) {
                    wordCount = countWords(text);
                }

                var notification = new CKEDITOR.plugins.notification(event.editor, { message: event.editor.lang.wordcount.pasteWarning, type: 'warning' });

                if (config.maxCharCount > 0 && charCount > config.maxCharCount && config.hardLimit) {
                    notification.show();
                    event.cancel();
                }

                if (config.maxWordCount > 0 && wordCount > config.maxWordCount && config.hardLimit) {
                    notification.show();
                    event.cancel();
                }
            }
        }, editor, null, 100);

        editor.on("afterPaste", function (event) {
            updateCounter(event.editor);
        }, editor, null, 100);

        editor.on("blur", function () {
            if (intervalId) {
                window.clearInterval(intervalId);
            }
        }, editor, null, 300);
    }
});
/**
*@license版权所有(c)CKSource-Frederico Knabben。版权所有。
*有关许可,请参阅LICENSE.html或http://ckeditor.com/license
*/
CKEDITOR.plugins.add(“字数”{
lang:“ca、de、el、en、es、fr、he、hr、it、jp、nl、no、pl、pt br、ru、sv、tr、zh cn”、//%删除行/核心%
版本:1.14,
要求:“htmlwriter,通知,撤消”,
init:函数(编辑器){
var defaultFormat=“”,
有效期,
lastWordCount=-1,
lastCharCount=-1,
limitReachedNotified=false,
limitRestoredNotified=false,
snapShot=editor.getSnapshot();
var dispatchEvent=函数(类型、currentLength、maxLength){
if(document.dispatchEvent的类型==“未定义”){
返回;
}
type='ckeditor.wordcount.'+type;
var cEvent;
var eventInitDict={
泡泡:错,
可取消:对,
详情:{
currentLength:currentLength,
maxLength:maxLength
}
};
试一试{
cEvent=新的CustomEvent(类型,eventInitDict);
}捕获(o_o){
cEvent=document.createEvent('CustomEvent');
cEvent.initCustomEvent(
类型,
eventInitDict.bubbles,
eventInitDict.cancelable,
eventInitDict.detail
);
}
文件调度事件(cEvent);
};
//默认配置
var defaultConfig={
是的,
showWordCount:没错,
showCharCount:false,
萨沙:错,
countHTML:false,
硬限制:是的,
//最大长度属性
maxWordCount:-1,
maxCharCount:-1,
//不允许的功能
大于maxLength的WordCounter事件:函数(currentLength,maxLength){
dispatchEvent('字数大于MaxLengtheEvent',currentLength,maxLength);
},
CharCountGreater大于maxLength事件:函数(currentLength,maxLength){
dispatchEvent('字符数大于MaxLengtheEvent',currentLength,maxLength);
},
//允许的函数
wordCountLessThanMaxLengthEvent:函数(currentLength,maxLength){
dispatchEvent('WordCountlessthanMaxLengtheEvent',currentLength,maxLength);
},
maxLength事件:函数(currentLength,maxLength){
dispatchEvent('MaxLengtheEvent'上的无字符数sthan',currentLength,maxLength);
}
};
//获取配置文件(&Lang)
var config=CKEDITOR.tools.extend(defaultConfig,editor.config.wordcount | |{},true);
if(config.showPages){
defaultFormat+=editor.lang.wordcount.Pages+%Pages%”;
}
if(config.showParents&&(config.showWordCount | | config.showCharCount)){
defaultFormat+=“,”;
}
if(config.showWordCount){
defaultFormat+=editor.lang.wordcount.wordcount+%wordcount%”;
如果(config.maxWordCount>-1){
defaultFormat+=“/”+config.maxWordCount;
}
}
if(config.showCharCount&&config.showWordCount){
defaultFormat+=“,”;
}
if(config.showCharCount){
var charLabel=editor.lang.wordcount[config.countHTML?“CharCountWithHTML”:“CharCount”];
defaultFormat+=charLabel+%charCount%;
如果(config.maxCharCount>-1){
defaultFormat+=“/”+config.maxCharCount;
}
}
var格式=defaultFormat;
if(config.loadCss==未定义| | config.loadCss){
CKEDITOR.document.appendStyleSheet(this.path+“css/wordcount.css”);
}
函数计数器ID(editorInstance){
返回“cke_wordcount_”+editorInstance.name;
}
函数计数器元素(editorInstance){
return document.getElementById(counterId(editorInstance));
}
功能条(html){
var tmp=document.createElement(“div”);
tmp.innerHTML=html;
if(tmp.textContent==“和&typeof tmp.innerText==“未定义”){
返回“”;
}
返回tmp.textContent | | tmp.innerText;
}
函数计数字符(文本、编辑实例){
if(config.countHTML){
返回(文本长度);
}否则{
var规范化文本;
//带体标签
if(editor.config.fullPage){
var i=text.search(newregexp(“,”i”);
如果(i!=-1){
var j=text.search(newregexp(“,”i”);
text=text.子字符串(i+6,j);
}
}
normalizedText=文本;
如果(!config.countSpacesAsChars){
normalizedText=文本。
替换(/\s/g,“”)。
替换(//g,“”);
}
normalizedText=normalizedText。
替换(/(\r\n |\n |\r)/gm“”)。
替换(//gi,“”);
normalizedText=strip(normalizedText)。替换(/^([\t\r\n]*)$/,“”);
返回(标准化文本长度);
}
}
功能段(文本){
返回(text.replace(//g,“”)。replace(/(
    config.wordcount = {  
// Whether or not you want to show the Paragraphs Count  
 showParagraphs: true,   

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

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

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

// 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: -1,

// Add filter to add or remove element before counting (see CKEDITOR.htmlParser.filter), Default value : null (no filter)
filter: new CKEDITOR.htmlParser.filter({
    elements: {
        div: function( element ) {
            if(element.attributes.class == 'mediaembed') {
                return false;
            }
        }
    }
}) };