1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
( function(){
|
5 |
|
|
var emptyHtml = '<span class="cke_empty"> </span>';
|
6 |
|
|
CKEDITOR.plugins.add( 'counter',
|
7 |
|
|
{
|
8 |
|
|
init : function( editor )
|
9 |
|
|
{
|
10 |
|
|
var spaceId = 'cke_counter_' + editor.name;
|
11 |
|
|
var spaceElement;
|
12 |
|
|
var ckeditorEventThemeSpace = 'uiSpace';
|
13 |
|
|
var getSpaceElement = function()
|
14 |
|
|
{
|
15 |
|
|
if ( !spaceElement )
|
16 |
|
|
spaceElement = CKEDITOR.document.getById( spaceId );
|
17 |
|
|
return spaceElement;
|
18 |
|
|
};
|
19 |
|
|
|
20 |
|
|
if (Drupal.ckeditor_ver == 3) {
|
21 |
|
|
ckeditorEventThemeSpace = 'themeSpace';
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
editor.on( ckeditorEventThemeSpace, function( event )
|
25 |
|
|
{
|
26 |
|
|
if ( event.data.space == 'bottom' )
|
27 |
|
|
{
|
28 |
|
|
event.data.html +=
|
29 |
|
|
'<span id="' + spaceId + '_label" class="cke_voice_label">Counter</span>' +
|
30 |
|
|
'<div id="' + spaceId + '" class="cke_counter" role="group" aria-labelledby="' + spaceId + '_label">' + emptyHtml + '</div>';
|
31 |
|
|
}
|
32 |
|
|
});
|
33 |
|
|
|
34 |
|
|
function count( ev )
|
35 |
|
|
{
|
36 |
|
|
var space = getSpaceElement();
|
37 |
|
|
var text = ev.editor.getData();
|
38 |
|
|
|
39 |
|
|
text = jQuery('<div/>').html(text).text();
|
40 |
|
|
|
41 |
|
|
text = text.replace(new RegExp('\\s+', 'g'), ' ');
|
42 |
|
|
|
43 |
|
|
text = text.replace(new RegExp('(^\\s+)|(\\s+$)', 'g'), '');
|
44 |
|
|
var symbols = text.length;
|
45 |
|
|
var words = text.split(' ').length;
|
46 |
|
|
|
47 |
|
|
text = text.replace(new RegExp('\\s+', 'g'), '');
|
48 |
|
|
var symbols_wo_blanks = text.length;
|
49 |
|
|
|
50 |
|
|
space.setHtml( '<span class="cke_counter" style="float: right">' + symbols + ' / ' + symbols_wo_blanks + ' symbols; ' + words + ' words</span>' );
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
editor.on( 'dataReady', count );
|
54 |
|
|
editor.on( 'blur', count );
|
55 |
|
|
editor.on( 'focus', count );
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
}
|
61 |
|
|
});
|
62 |
|
|
})(); |