diff --git a/wordcount/css/wordcount.css b/wordcount/css/wordcount.css new file mode 100644 index 00000000000..6700dc154fb --- /dev/null +++ b/wordcount/css/wordcount.css @@ -0,0 +1 @@ +.cke_wordcount {display:block;float:right;margin-top:-1px;margin-right:3px;color:black;} \ No newline at end of file diff --git a/wordcount/plugin.js b/wordcount/plugin.js index 800042fdad0..f09c1212190 100644 --- a/wordcount/plugin.js +++ b/wordcount/plugin.js @@ -3,9 +3,9 @@ * For licensing, see LICENSE.html or http://ckeditor.com/license */ - CKEDITOR.plugins.add('wordcount', { +CKEDITOR.plugins.add('wordcount', { lang: ['de', 'en'], - init: function (editor) { + init: function (editor) { var defaultLimit = 'unlimited'; var defaultFormat = '' + editor.lang.wordcount.WordCount + ' %count%'; var limit = defaultLimit; @@ -14,81 +14,91 @@ var lastCount = 0; var limitReachedNotified = false; var limitRestoredNotified = false; - if (true) { - function counterId(editor) { - return 'cke_wordcount_' + editor.name + + CKEDITOR.document.appendStyleSheet(this.path + 'css/wordcount.css'); + + function counterId(editor) { + return 'cke_wordcount_' + editor.name + } + + function counterElement(editor) { + return document.getElementById(counterId(editor)) + } + + function strip(html) { + var tmp = document.createElement("div"); + tmp.innerHTML = html; + return tmp.textContent || tmp.innerText + } + + function updateCounter(editor) { + var count = 0; + if (editor.getData()) { + count = strip(editor.getData()).trim().split(/\s+/).length; } - function counterElement(editor) { - return document.getElementById(counterId(editor)) + var html = format.replace('%count%', count); + counterElement(editor).innerHTML = html + if (count == lastCount) { + return true + } else { + lastCount = count } - function strip(html) { - var tmp = document.createElement("DIV"); - tmp.innerHTML = html; - return tmp.textContent || tmp.innerText + if (count > limit) { + limitReached(editor, limitReachedNotified) + } else if (!limitRestoredNotified && count < limit) { + limitRestored(editor) } - function updateCounter(editor) { - var count = 0; - if (editor.getData() != undefined) { - count = strip(editor.getData()).trim().split(/\s+/).length; - } - if (count == lastCount) { - return true - } else { - lastCount = count - } - if (!limitReachedNotified && count > limit) { - limitReached(editor) - } else if (!limitRestoredNotified && count < limit) { - limitRestored(editor) - } - var html = format.replace('%count%', count); - counterElement(editor).innerHTML = html + } + + function limitReached(editor, notify) { + limitReachedNotified = true; + limitRestoredNotified = false; + editor.execCommand('undo'); + if (!notify) { + editor.fire('limitReached', {}, editor); } - function limitReached(editor) { - limitReachedNotified = true; - limitRestoredNotified = false; - editor.execCommand( 'undo' ); - // lock editor - editor.config.Locked = 1; + // lock editor + editor.config.Locked = 1; + editor.fire("change"); + } + + function limitRestored(editor) { + limitRestoredNotified = true; + limitReachedNotified = false; + editor.config.Locked = 0; + } + editor.on('uiSpace', function (event) { + if (event.data.space == 'bottom') { + event.data.html += '