diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/css/wordcount.css b/main/inc/lib/javascript/ckeditor/plugins/wordcount/css/wordcount.css new file mode 100644 index 0000000000..7154b35977 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/css/wordcount.css @@ -0,0 +1,3 @@ +.cke_wordcount {display:block;float:right;margin-top:-2px;margin-right:3px;color:black;} + +.cke_wordcountLimitReached span {color:red! important} \ No newline at end of file diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/ca.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/ca.js new file mode 100644 index 0000000000..80f8fb7226 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/ca.js @@ -0,0 +1,11 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'ca', { + WordCount: 'Paraules:', + CharCount: 'Caràcters:', + CharCountWithHTML: 'Caràcters (including HTML):', + limit: 'Límit:', + title: 'Estadístiques' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/de.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/de.js new file mode 100644 index 0000000000..6bcf6b5f6c --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/de.js @@ -0,0 +1,11 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'de', { + WordCount: 'Wörter:', + CharCount: 'Zeichen:', + CharCountWithHTML: 'Zeichen (inkl. HTML):', + limit: 'Limit:', + title: 'Statistik' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/en.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/en.js new file mode 100644 index 0000000000..51c8523797 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/en.js @@ -0,0 +1,11 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'en', { + WordCount: 'Words:', + CharCount: 'Characters:', + CharCountWithHTML: 'Characters (including HTML):', + limit: 'Limit:', + title: 'Statistics' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/es.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/es.js new file mode 100644 index 0000000000..980e9aaf28 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/es.js @@ -0,0 +1,11 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'es', { + WordCount: 'Palabras:', + CharCount: 'Caràcteres:', + CharCountWithHTML: 'Caràcteres (con HTML):', + limit: 'Límite:', + title: 'Estadísticas' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/fr.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/fr.js new file mode 100644 index 0000000000..d55f54bb4d --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/fr.js @@ -0,0 +1,9 @@ +// French Translation by Nicolas M. + +CKEDITOR.plugins.setLang('wordcount', 'fr', { + WordCount: 'Mots:', + CharCount: 'Caractères:', + CharCountWithHTML: 'Caractères (including HTML):', + limit: 'Limite:', + title: 'Statistiques' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/it.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/it.js new file mode 100644 index 0000000000..c15370a522 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/it.js @@ -0,0 +1,12 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +@author translation: Davide Montorio +*/ +CKEDITOR.plugins.setLang('wordcount', 'it', { + WordCount: 'Parole:', + CharCount: 'Caratteri:', + CharCountWithHTML: 'Caratteri (HTML incluso):', + limit: 'Limite:', + title: 'Statistiche' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/jp.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/jp.js new file mode 100644 index 0000000000..300e55b16b --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/jp.js @@ -0,0 +1,10 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'jp', { + WordCount: '単語数:', + CharCount: '文字数:', + limit: '上限:', + title: 'ワードカウント' +}); \ No newline at end of file diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/no.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/no.js new file mode 100644 index 0000000000..0615d90c22 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/no.js @@ -0,0 +1,8 @@ +// Norwegian translation by Vegard S. +CKEDITOR.plugins.setLang('wordcount', 'no', { + WordCount: 'Ord:', + CharCount: 'Tegn:', + CharCountWithHTML: 'Tegn (including HTML):', + limit: 'Grense:', + title: 'Statistikk' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/pl.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/pl.js new file mode 100644 index 0000000000..8a2703fcec --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/pl.js @@ -0,0 +1,11 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'pl', { + WordCount: 'Słów:', + CharCount: 'Znaków:', + CharCountWithHTML: 'Znaków (wraz z kodem HTML):', + limit: 'Limit:', + title: 'Statystyka' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/pt-BR.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/pt-BR.js new file mode 100644 index 0000000000..89ea1cc92f --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/pt-BR.js @@ -0,0 +1,10 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'pt-BR', { + WordCount: 'Contagem de palavras:', + CharCount: 'Contagem de caracteres:', + limit: 'Limit:', + title: 'Estatísticas' + }); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/ru.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/ru.js new file mode 100644 index 0000000000..d1520c5b12 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/lang/ru.js @@ -0,0 +1,11 @@ +/* +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'ru', { + WordCount: 'Слов:', + CharCount: 'Символов:', + CharCountWithHTML: 'Символов (включая HTML):', + limit: 'Лимит:', + title: 'Статистика' +}); diff --git a/main/inc/lib/javascript/ckeditor/plugins/wordcount/plugin.js b/main/inc/lib/javascript/ckeditor/plugins/wordcount/plugin.js new file mode 100644 index 0000000000..e22fbb73e3 --- /dev/null +++ b/main/inc/lib/javascript/ckeditor/plugins/wordcount/plugin.js @@ -0,0 +1,211 @@ +/** + * @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', 'en', 'es', 'fr', 'it', 'jp', 'no', 'pl', 'pt-BR'], + version : 1.08, + init: function (editor) { + if (editor.elementMode === CKEDITOR.ELEMENT_MODE_INLINE) { + return; + } + + var defaultFormat = '', + intervalId, + lastWordCount, + lastCharCount = 0, + limitReachedNotified = false, + limitRestoredNotified = false; + + // Default Config + var defaultConfig = { + showWordCount: true, + showCharCount: false, + charLimit: 'unlimited', + wordLimit: 'unlimited', + countHTML: false + }; + + // Get Config & Lang + var config = CKEDITOR.tools.extend(defaultConfig, editor.config.wordcount || {}, true); + + if (config.showCharCount) { + var charLabel = editor.lang.wordcount[config.countHTML ? 'CharCountWithHTML' : 'CharCount']; + + defaultFormat += charLabel + ' %charCount%'; + + if (config.charLimit != 'unlimited') { + defaultFormat += ' (' + editor.lang.wordcount.limit + ' ' + config.charLimit + ')'; + } + } + + if (config.showCharCount && config.showWordCount) { + defaultFormat += ', '; + } + + if (config.showWordCount) { + defaultFormat += editor.lang.wordcount.WordCount + ' %wordCount%'; + + if (config.wordLimit != 'unlimited') { + defaultFormat += ' (' + editor.lang.wordcount.limit + ' ' + config.wordLimit + ')'; + } + } + + defaultFormat += ''; + + var format = defaultFormat; + + 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 '0'; + } + return tmp.textContent || tmp.innerText; + } + + function updateCounter(editorInstance) { + var wordCount = 0, + charCount = 0, + normalizedText, + text; + + if (text = editorInstance.getData()) { + if (config.showCharCount) { + if (config.countHTML) { + charCount = text.length; + } else { + normalizedText = text. + replace(/(\r\n|\n|\r)/gm, ""). + replace(/^\s+|\s+$/g, ""). + replace(" ", ""). + replace(" ", ""); + normalizedText = strip(normalizedText); + + charCount = normalizedText.length; + } + } + + if (config.showWordCount) { + normalizedText = text. + replace(/(\r\n|\n|\r)/gm, " "). + replace(/^\s+|\s+$/g, ""). + replace(" ", " "); + + normalizedText = strip(normalizedText); + + wordCount = normalizedText.split(/\s+/).length; + } + } + + var html = format.replace('%wordCount%', wordCount).replace('%charCount%', charCount); + + counterElement(editorInstance).innerHTML = html; + + if (charCount == lastCharCount) { + return true; + } + + lastWordCount = wordCount; + lastCharCount = charCount; + + // Check for word limit + if (config.showWordCount && wordCount > config.wordLimit) { + limitReached(editor, limitReachedNotified); + } else if (config.showWordCount && wordCount == config.wordLimit) { + // create snapshot to make sure only the content after the limit gets deleted + editorInstance.fire('saveSnapshot'); + } else if (!limitRestoredNotified && wordCount < config.wordLimit) { + limitRestored(editor); + } + + // Check for char limit + if (config.showCharCount && charCount > config.charLimit) { + limitReached(editor, limitReachedNotified); + } else if (config.showCharCount && charCount == config.charLimit) { + // create snapshot to make sure only the content after the limit gets deleted + editorInstance.fire('saveSnapshot'); + } else if (!limitRestoredNotified && charCount < config.charLimit) { + limitRestored(editor); + } + + return true; + } + + function limitReached(editorInstance, notify) { + limitReachedNotified = true; + limitRestoredNotified = false; + + editorInstance.execCommand('undo'); + + if (!notify) { + //counterElement(editorInstance).className = "cke_wordcount cke_wordcountLimitReached"; + + editorInstance.fire('limitReached', {}, editor); + } + + // lock editor + editorInstance.config.Locked = 1; + } + + function limitRestored(editorInstance) { + + limitRestoredNotified = true; + limitReachedNotified = false; + editorInstance.config.Locked = 0; + + counterElement(editorInstance).className = "cke_wordcount"; + } + + editor.on('key', function (event) { + + updateCounter(event.editor); + }, editor, null, 100); + + editor.on('uiSpace', function (event) { + if (event.data.space == 'bottom') { + event.data.html += '