| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 /** 2 * @file Plugin to count symbols, symbols without blanks and words 3 */ 4 5 (function() 6 { 7 var emptyHtml = '<span class="cke_empty"> </span>'; 8 9 CKEDITOR.plugins.add( 'counter', 10 { 11 init : function( editor ) 12 { 13 var spaceId = 'cke_counter_' + editor.name; 14 var spaceElement; 15 var getSpaceElement = function() 16 { 17 if ( !spaceElement ) 18 spaceElement = CKEDITOR.document.getById( spaceId ); 19 return spaceElement; 20 }; 21 22 editor.on( 'themeSpace', function( event ) 23 { 24 if ( event.data.space == 'bottom' ) 25 { 26 event.data.html += 27 '<span id="' + spaceId + '_label" class="cke_voice_label">Counter</span>' + 28 '<div id="' + spaceId + '" class="cke_counter" role="group" aria-labelledby="' + spaceId + '_label">' + emptyHtml + '</div>'; 29 } 30 }); 31 32 function count( ev ) 33 { 34 var space = getSpaceElement(); 35 var text = ev.editor.getData(); 36 // decode HTML entities; it also removes HTML tags, but works only if jQuery is available 37 text = jQuery('<div/>').html(text).text(); 38 // remove all redundant blank symbols 39 text = text.replace(new RegExp('\\s+', 'g'), ' '); 40 // remove all blank symbols at the start and at the end 41 text = text.replace(new RegExp('(^\\s+)|(\\s+$)', 'g'), ''); 42 var symbols = text.length; 43 var words = text.split(' ').length; 44 //remove all blank symbols 45 text = text.replace(new RegExp('\\s+', 'g'), ''); 46 var symbols_wo_blanks = text.length; 47 48 space.setHtml( '<span class="cke_counter" style="float: right">' + symbols + ' / ' + symbols_wo_blanks + ' symbols; ' + words + ' words</span>' ); 49 } 50 51 editor.on( 'dataReady', count ); 52 editor.on( 'blur', count ); 53 editor.on( 'focus', count ); 54 // Almost useless 55 //editor.on( 'saveSnapshot', count ); 56 // Requires too much resources 57 //editor.on( 'key', count ); 58 } 59 }); 60 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |