diff --git a/src/CKEditorForMendix/CKEditorForMendix.xml b/src/CKEditorForMendix/CKEditorForMendix.xml index 4320101..90f43ac 100644 --- a/src/CKEditorForMendix/CKEditorForMendix.xml +++ b/src/CKEditorForMendix/CKEditorForMendix.xml @@ -188,5 +188,15 @@ Images This constraint might be used to filter the set of browsable images. (not functional right now) + + Count plugin + Count + Enable/disable wordcount plugin. This will have the ability to set a max amount of characters + + + Maximum characters + Count + If the Count plugin is enabled, specifiy the max amount of characters (including HTML). If you set this to 0, it will be unlimited. + diff --git a/src/CKEditorForMendix/widget/CKEditorForMendix.js b/src/CKEditorForMendix/widget/CKEditorForMendix.js index 082ce13..4c14883 100644 --- a/src/CKEditorForMendix/widget/CKEditorForMendix.js +++ b/src/CKEditorForMendix/widget/CKEditorForMendix.js @@ -52,7 +52,8 @@ define([ "maximize", "uploadimage", "simple-image-browser", - "pastebase64" + "pastebase64", + "wordcount" ], // CKEditor instances. @@ -183,7 +184,7 @@ define([ }, _editorChange: function (data) { - logger.debug(this.id + "._editorChange:", data); + logger.debug(this.id + "._editorChange:"); if (this._contextObj !== null) { this._contextObj.set(this.messageString, data); } @@ -331,14 +332,28 @@ define([ } this._settings[this.id].config.imageUploadUrl = "http://localhost/"; // not used + this._settings[this.id].config.extraPlugins = this._getPlugins(); + if (!this._useImageUpload) { - this._settings[this.id].config.extraPlugins = this._getPlugins(false); this._settings[this.id].config.removePlugins = "simple-image-browser,uploadimage"; } else { - this._settings[this.id].config.extraPlugins = this._getPlugins(true); this._settings[this.id].config.removePlugins = "pastebase64"; } + if (!this.countPlugin) { + this._settings[this.id].config.removePlugins = "wordcount"; + } else { + this._settings[this.id].config.wordcount = { + showParagraphs: false, + showWordCount: true, + showCharCount: true, + countSpacesAsChars: true, + countHTML: true, + maxWordCount: -1, + maxCharCount: this.countPluginMaxCount > 0 ? this.countPluginMaxCount : -1 + }; + } + this._settings[this.id].config.extraAllowedContent = "*[data-*]"; // Create a CKEditor from HTML element. @@ -615,6 +630,4 @@ define([ }); }); -require(["CKEditorForMendix/widget/CKEditorForMendix"], function () { - "use strict"; -}); +require(["CKEditorForMendix/widget/CKEditorForMendix"]); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/css/wordcount.css b/src/CKEditorForMendix/widget/lib/plugins/wordcount/css/wordcount.css new file mode 100644 index 0000000..fe72026 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/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 {color:red! important} \ No newline at end of file diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ar.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ar.js new file mode 100644 index 0000000..ef4d8f5 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ar.js @@ -0,0 +1,11 @@ +// Arabic Translation by Amine BENHAMIDA + +CKEDITOR.plugins.setLang('wordcount', 'ar', { + WordCount: 'كلمات:', + CharCount: 'حروف:', + CharCountWithHTML: 'حروف مع إتش تي إم إل', + Paragraphs: 'فقرات', + pasteWarning: 'لا يمكن اضافة هذا المحتوى لانه تجاوز الحد الاقصى', + Selected: 'محدد: ', + title: 'احصائيات' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ca.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ca.js new file mode 100644 index 0000000..5e7ca1f --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ca.js @@ -0,0 +1,13 @@ +/* +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):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Estadístiques' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/da.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/da.js new file mode 100644 index 0000000..b382b18 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/da.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'da', { + WordCount: 'Ord:', + CharCount: 'Karakterer:', + CharCountWithHTML: 'Karakterer (med HTML):', + Paragraphs: 'Afsnit:', + pasteWarning: 'Indholdet kan ikke indsættes da det er længere end den tilladte grænse.', + Selected: 'Markeret: ', + title: 'Statistik' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/de.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/de.js new file mode 100644 index 0000000..462e772 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/de.js @@ -0,0 +1,13 @@ +/* +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):', + Paragraphs: 'Absätze:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statistik' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/el.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/el.js new file mode 100644 index 0000000..58f2222 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/el.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'el', { + WordCount: 'Λέξεις:', + CharCount: 'Χαρακτήρες:', + CharCountWithHTML: 'Χαρακτήρες (μαζί με HTML):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Στατιστικά' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/en.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/en.js new file mode 100644 index 0000000..b46cccc --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/en.js @@ -0,0 +1,13 @@ +/* +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 (with HTML):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statistics' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/es.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/es.js new file mode 100644 index 0000000..c5385d9 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/es.js @@ -0,0 +1,13 @@ +/* +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):', + Paragraphs: 'Párrafos:', + pasteWarning: 'El contenido no se puede pegar, ya que se encuentra fuera del límite permitido', + Selected: 'Seleccionado: ', + title: 'Estadísticas' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/fi.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/fi.js new file mode 100644 index 0000000..444eaf8 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/fi.js @@ -0,0 +1,14 @@ +/** + * Finnish localisation. + * + * @author Joel Posti / Response200.pro + */ +CKEDITOR.plugins.setLang('wordcount', 'fi', { + WordCount: 'Sanoja:', + CharCount: 'Merkkejä:', + CharCountWithHTML: 'Merkkejä (ml. HTML):', + Paragraphs: 'Kappaleita:', + pasteWarning: 'Sisältöä ei voida liittää, koska se ylittää sallitun rajan.', + Selected: 'Valittuna: ', + title: 'Statistiikkaa' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/fr.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/fr.js new file mode 100644 index 0000000..6c1e063 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/fr.js @@ -0,0 +1,11 @@ +// French Translation by Nicolas M. et Pierre-Luc Auclair + +CKEDITOR.plugins.setLang('wordcount', 'fr', { + WordCount: 'Mots :', + CharCount: 'Caractères :', + CharCountWithHTML: 'Caractères (incluant HTML) :', + Paragraphs: 'Paragraphes :', + pasteWarning: 'Le contenu ne peut pas être collé car il dépasse la limite autorisée', + Selected: 'Sélectionné :', + title: 'Statistiques' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/he.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/he.js new file mode 100644 index 0000000..e6080da --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/he.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'he', { + WordCount: 'מילים:', + CharCount: 'תווים:', + CharCountWithHTML: 'תווים (כולל HTML):', + Paragraphs: 'פסקאות:', + pasteWarning: 'לא ניתן להדביק תוכן בשל עודף תווים', + Selected: 'נבחר: ', + title: 'סטטיסטיקות' +}); \ No newline at end of file diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/hr.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/hr.js new file mode 100644 index 0000000..ab9e5fa --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/hr.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'hr', { + WordCount: 'Riječi:', + CharCount: 'Znakova:', + CharCountWithHTML: 'Znakova (uključujući HTML):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statistika' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/it.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/it.js new file mode 100644 index 0000000..dfda23e --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/it.js @@ -0,0 +1,14 @@ +/* +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):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statistiche' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/jp.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/jp.js new file mode 100644 index 0000000..8103881 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/jp.js @@ -0,0 +1,13 @@ +/* +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: '文字数:', + CharCountWithHTML: '文字数 (with HTML):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'ワードカウント' +}); \ No newline at end of file diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/nl.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/nl.js new file mode 100644 index 0000000..0bc069c --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/nl.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'nl', { + WordCount: 'Woorden:', + CharCount: 'Tekens:', + CharCountWithHTML: 'Tekens (inclusief HTML):', + Paragraphs: 'Paragraven:', + pasteWarning: 'De tekst kan niet worden geplakt omdat de limiet is overschreden', + Selected: 'Selected: ', + title: 'Statistieken' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/no.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/no.js new file mode 100644 index 0000000..0932542 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/no.js @@ -0,0 +1,10 @@ +// Norwegian translation by Vegard S. +CKEDITOR.plugins.setLang('wordcount', 'no', { + WordCount: 'Ord:', + CharCount: 'Tegn:', + CharCountWithHTML: 'Tegn (including HTML):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statistikk' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pl.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pl.js new file mode 100644 index 0000000..c7ca3bb --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pl.js @@ -0,0 +1,13 @@ +/* +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):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statystyka' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pt-br.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pt-br.js new file mode 100644 index 0000000..595a354 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pt-br.js @@ -0,0 +1,13 @@ +/* +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 carateres:', + CharCountWithHTML: 'Carateres (incluindo HTML):', + Paragraphs: 'Parágrafos:', + pasteWarning: 'Conteúdo não pode ser colado porque ultrapassa o limite permitido', + Selected: 'Selecionado: ', + title: 'Estatísticas' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pt.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pt.js new file mode 100644 index 0000000..e72908f --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/pt.js @@ -0,0 +1,9 @@ +CKEDITOR.plugins.setLang('wordcount', 'pt', { + WordCount: 'Palavras:', + CharCount: 'Caracteres:', + CharCountWithHTML: 'Carateres (incluindo HTML):', + Paragraphs: 'Parágrafos:', + pasteWarning: 'O conteúdo não pode ser colado porque ultrapassa o limite permitido', + Selected: 'Selecionado: ', + title: 'Estatísticas' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ru.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ru.js new file mode 100644 index 0000000..fd8eb69 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/ru.js @@ -0,0 +1,13 @@ +/* +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 разметку):', + Paragraphs: 'Параграфов:', + pasteWarning: 'Контент не может быть вставлен, т.к. привышает допустимый лимит', + Selected: 'Выделено: ', + title: 'Статистика' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/sv.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/sv.js new file mode 100644 index 0000000..8a48c3f --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/sv.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'sv', { + WordCount: 'Ord:', + CharCount: 'Tecken:', + CharCountWithHTML: 'Tecken (inklusive HTML):', + Paragraphs: 'Paragraphs:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'Statistik' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/tr.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/tr.js new file mode 100644 index 0000000..74ccc92 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/tr.js @@ -0,0 +1,13 @@ +/* +Mesut ÇAKIR +mesut.cakir@hotmail.com.tr +*/ +CKEDITOR.plugins.setLang('wordcount', 'tr', { + WordCount: 'Kelime:', + CharCount: 'Karakter:', + CharCountWithHTML: 'Karakter (HTML dahil):', + Paragraphs: 'Paragraf:', + pasteWarning: 'Content can not be pasted because it is above the allowed limit', + Selected: 'Selected: ', + title: 'İstatistik' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/zh-cn.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/zh-cn.js new file mode 100644 index 0000000..26e4a3e --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/lang/zh-cn.js @@ -0,0 +1,13 @@ +/* +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.html or http://ckeditor.com/license +*/ +CKEDITOR.plugins.setLang('wordcount', 'zh-cn', { + WordCount: '词数:', + CharCount: '字符:', + CharCountWithHTML: '字符 (含HTML)', + Paragraphs: '段落:', + pasteWarning: '由于上限允许,内容不能粘贴', + Selected: '已选择: ', + title: '统计' +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/plugin.js b/src/CKEditorForMendix/widget/lib/plugins/wordcount/plugin.js new file mode 100644 index 0000000..fe79758 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/plugin.js @@ -0,0 +1,407 @@ +/** + * @license Copyright (c) CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.html or http://ckeditor.com/license + */ + +CKEDITOR.plugins.add("wordcount", { + lang: "ar,ca,da,de,el,en,es,fi,fr,he,hr,it,jp,nl,no,pl,pt,pt-br,ru,sv,tr,zh-cn", // %REMOVE_LINE_CORE% + version: 1.15, + 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, + + // Filter + filter: null, + + //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"); + + // Add filter before strip + html = filter(html); + + tmp.innerHTML = html; + + if (tmp.textContent == "" && typeof tmp.innerText == "undefined") { + return ""; + } + + return tmp.textContent || tmp.innerText; + } + + /** + * Implement filter to add or remove before counting + * @param html + * @returns string + */ + function filter(html) { + if(config.filter instanceof CKEDITOR.htmlParser.filter) { + var fragment = CKEDITOR.htmlParser.fragment.fromHtml(html), + writer = new CKEDITOR.htmlParser.basicWriter(); + config.filter.applyTo( fragment ); + fragment.writeHtml( writer ); + return writer.getHtml(); + } + return html; + } + + function countCharacters(text, editorInstance) { + if (config.countHTML) { + return (filter(text).length); + } else { + var normalizedText; + + // strip body tags + if (editor.config.fullPage) { + var i = text.search(new RegExp("", "i")); + if (i != -1) { + var j = text.search(new RegExp("", "i")); + text = text.substring(i + 6, j); + } + + } + + normalizedText = text; + + if (!config.countSpacesAsChars) { + normalizedText = text. + replace(/\s/g, ""). + replace(/ /g, ""); + } + + normalizedText = normalizedText. + replace(/(\r\n|\n|\r)/gm, ""). + replace(/ /gi, " "); + + normalizedText = strip(normalizedText).replace(/^([\t\r\n]*)$/, ""); + + return(normalizedText.length); + } + } + + function countParagraphs(text) { + return (text.replace(/ /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(" ", " "); + + 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.config.wordcount || (editorInstance.config.wordcount = {})).wordCount = wordCount; + (editorInstance.config.wordcount || (editorInstance.config.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 += "
 
"; + } + } else { + if (event.data.space == "bottom") { + event.data.html += "
 
"; + } + } + + }, 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); + } +}); diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/samples/wordcount.html b/src/CKEditorForMendix/widget/lib/plugins/wordcount/samples/wordcount.html new file mode 100644 index 0000000..5649b7f --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/samples/wordcount.html @@ -0,0 +1,61 @@ + + + + + + WordCount — CKEditor Sample + + + + + + + + + +

+ CKEditor Samples » WordCount Plugin +

+ +
+

+ WordCount Plugin for CKEditor that counts the words an shows the word count in the footer of the editor.. +

+

+ In order to use the new plugin, include it in the config.extraPlugins configuration setting. +

+
+CKEDITOR.replace( 'textarea_id', {
+	extraPlugins: 'wordcount'
+} );
+
+
+ + + + + + + diff --git a/src/CKEditorForMendix/widget/lib/plugins/wordcount/samples/wordcountWithMaxCount.html b/src/CKEditorForMendix/widget/lib/plugins/wordcount/samples/wordcountWithMaxCount.html new file mode 100644 index 0000000..dd46ed2 --- /dev/null +++ b/src/CKEditorForMendix/widget/lib/plugins/wordcount/samples/wordcountWithMaxCount.html @@ -0,0 +1,110 @@ + + + + + + WordCount — CKEditor Sample + + + + + + + + + + +

+ CKEditor Samples » WordCount Plugin +

+ +
+

+ WordCount Plugin for CKEditor that counts the words an shows the word count in the footer of the editor.. +

+

+ In order to use the new plugin, include it in the config.extraPlugins configuration setting. +

+
+CKEDITOR.replace( 'textarea_id', {
+	extraPlugins: 'wordcount', 
+                maxWordCount: 4,
+	        maxCharCount: 10,
+                // optional events
+	        paragraphsCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
+	                $("#informationparagraphs").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - paragraphs").show();
+	        },
+	        wordCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
+	                $("#informationword").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - word").show();
+	        },
+	        charCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
+	                $("#informationchar").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - char").show();
+	        },
+	        charCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
+	                $("#informationchar").css("background-color", "white").css("color", "black").hide();
+	        },
+	        paragraphsCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
+	                $("#informationparagraphs").css("background-color", "white").css("color", "black").hide();
+	        },
+	        wordCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
+	                $("#informationword").css("background-color", "white").css("color", "black").hide();
+	        }
+} );
+
+
+ + +
+
+
+ + + + + diff --git a/test/widgets/CKEditorForMendix.mpk b/test/widgets/CKEditorForMendix.mpk index 3ebceab..1562ebf 100644 Binary files a/test/widgets/CKEditorForMendix.mpk and b/test/widgets/CKEditorForMendix.mpk differ