Hello!

I've written the counter plugin to count symbols (with and without blank symbols) and words for CKEditor. It uses jQuery so it will be suitable only for the sites with this library included, like Drupal based sites. It is attached to this issue - hope it will be usefull for the community and you might want to include it with the module (and to improve it if possible - for now it refreshes the counter on dataReady, blur and focus events).

counter plugin

Code to include it into the settings of CKEditor profile using custom module would be:

/**
 * Implements hook_ckeditor_plugin().
 */
function MYMODULE_ckeditor_plugin() {
  $path = drupal_get_path('module', 'MYMODULE');
  return array(
    'counter' => array(
      'name' => 'counter',
      'desc' => t('Plugin to count number of words and symbols'),
      'path' => $path . '/plugins/counter/',
    ),
  );
}

Thanks
AndyB

CommentFileSizeAuthor
counter.png37.83 KBduozersk
counter.tar_.gz964 bytesduozersk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dczepierga’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

Really thx for this plugin...
Do u agree to add this to CKEditor module?

I think also what to do with counter refresh when writing... maybe sth like counter update on every 5 seconds when writing or sth like that?

Greetings

duozersk’s picture

Hi,

Sure, let's add it to the CKEditor module - it will be really good addition.

As for the counter refresh - I tried to do it on the 'key' event of CKEditor (then it will update on every new symbol), but it then consumes too much resources. We might want to do the refresh on the 'saveSnapshot' event or smth similar. I don't feel like doing it through setTimeout function will be a good way to go. May be CKEditor experts would suggest some other events to do the refresh.

Thanks
AndyB

dczepierga’s picture

Title: Counter plugin to count symbols and words » [D6] Counter plugin to count symbols and words
Status: Reviewed & tested by the community » Fixed

Ok i add this to GIT and commit all changes.
Again really thx for this great plugin.
I will also add this to Drupal 7 module.

Greetings

duozersk’s picture

Great! Thank you for the module :)

I will let you know if I would have any improvements to it.

AndyB

mkesicki’s picture

Title: [D6] Counter plugin to count symbols and words » [D6] "Counter" plugin to count symbols and words inside CKEditor
Status: Fixed » Closed (fixed)
soulfroys’s picture

Hello! Is it possible to translate the strings?

Like...

          var symbols_wo_blanks = text.length;
          var placeholders = {
            '@symbols': symbols,
            '@symbols_wo_blanks': symbols_wo_blanks,
            '@words': words
          }
          var countOutput = Drupal.t('@symbols / @symbols_wo_blanks symbols; @words words', placeholders);
					space.setHtml( '<span class="cke_counter" style="float: right">' +  countOutput + '</span>' );
				}

Thanks for this great plugin!

playeronee’s picture

Hi,

The plugin is great.
I added it to Liferay 6.1 as CKEditor plugin. It works good on FF but it is problem on IE (7~9)

SCRIPT5007: Unable to get value of the property 'innerHTML': object is null or undefined

Have you got this issue? What could be reason?

Regards,
Michal

playeronee’s picture

Issue summary: View changes

added inline screen shot

saga_shiftyblow’s picture

Issue summary: View changes

Can i suggest to add to the current version of the plugin this line of code?

editor.on( 'key', count );

Having it responding to key pressure make the plugin way more useful.