I have been having a tough time installing a plugin for CKEditor, and wanted to ask if anyone has experience with the "lite" plugin, aka change tracking. At this point, the plugin partially works, and I wanted to ask for help writing the needed code to load the buttons from the plugin.

I downloaded a 4.x version of CKEditor with lite rolled up in it, dropped it in to WYSIWYG, and got some strange results. The editor tracks changes, and when you right click on the changed text you have the option to accept or reject that change, but the buttons that com with the plugin do not appear. This is true even if you follow the instructions from the lite page on the CKEditor site.

I've read the documentation for WYSIWYG, and it looks like I need to write a custom module that passes the button information to WYSIWYG. At this point I've gotten a "track changes" checkbox to show up as a button option, but I do not understand what I need to do to load the lite libraries, or add the 5 buttons that come with the plugin.

If anyone has experience with this, any code examples or links to websites would be appreciated. I have been searching and experimenting for days, as this is holding up a project.

----

Updated hook implementation

/**
 * Implements hook_wysiwyg_plugin().
 */
function track_changes_wysiwyg_plugin($editor, $version) {
  switch ($editor) {
   case 'ckeditor':
    return array(
     'lite' => array(
      'path' => drupal_get_path('module', 'track_changes') . '/lite',
      'buttons' => array(
          'lite_AcceptAll' => t('LITE: Accept all changes'),
          'lite_AcceptOne' => t('LITE: Accept one change'),
          'lite_RejectAll' => t('LITE: Reject all changes'),
          'lite_RejectOne' => t('LITE: Reject one changes'),
          'lite_ToggleShow' => t('LITE: Show hide'),
          'lite_ToggleTracking' => t('LITE: Track changes on off'),
      ),
      'load' => TRUE,
     ),
    );
    break;
  }
}

Note: The LITE plugin currently has a bug which causes errors when the editor is removed, see TwoD's comment below on fixing it.

Comments

CarlHinton’s picture

Try

            'buttons' => array(
              'accept_all' => t('Accept all changes'),
              'accept_one' => t('Accept one change'),
              'reject_all' => t('Reject all changes'),
              'reject_one' => t('Reject one changes'),
              'show_hide' => t('Show hide'),
              'track_changes_on_off' => t('Track changes on off'),
            ),

You'll need to switch them on at /admin/config/content/wysiwyg/profile/{profile}/edit - under buttons

TwoD’s picture

Issue summary: View changes
Status: Active » Fixed

I've updated the original post with the correct button names (this plugin made it unnecessarily difficult to figure out that part).

You will need to install jquery_update module and configure it to use at least jQuery 1.7 because it needs the jQuery.on() method not available in the version shipped with D7.

You will also need to fix the plugin itself, since there's a critical bug in its destroy event handler. The error thrown there will prevent Wysiwyg from detaching the editor correctly.
You can fix this by editing LITE's plugin.js on line 104.
Change

var ind = this._findPluginIndex(editor);

to

var ind = _findPluginIndex(editor);
TwoD’s picture

Issue summary: View changes

Added bug note to original post.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

laboratory.mike’s picture

Carl, TwoD,

Thank you very much for your input! I've tried the recommended changes out on my project site, and after I've finished figuring out exactly what needs to go where I will have to come back and write this up as a small module. I'm surprised no one else has committed a feature of this type; this seems like a must for any collaborative writing/publishing site.

LabMike

TwoD’s picture

Sounds like a great sandbox project!

laboratory.mike’s picture

Indeed! I am starting work on it now actually:

https://drupal.org/sandbox/laboratorymike/2221911

Let me know how I can/should credit you. If you would like, I will let you know when I am getting close to a full module.

ibakayoko’s picture

I had to work on the same feature i posted the 1st version of the module on github

https://github.com/ibakayoko/ckeditor_track_changes

Lite plugin got a function setUserInfo i could not find where or how to call it to set the current user info. Any help will be appreciated this way we will not need to alter the lite plugin library.

duozersk’s picture

Here is the module that actually works, either through WYSIWYG or CKEditor module - https://www.drupal.org/project/ckeditor_lite

AndyB

TwoD’s picture

@ibakayoko, a quick tip: I would not create global values like that, there's a risk other modules expose a $settings variable which gets overwritten by your code. Calling drupal_add_js() there will also make Drupal add the script file as soon as the plugin file is loaded, regardless of the reason why it's being included (maybe someone just wants to check which plugins are available, like on the admin pages).
Move them inside the function and you'll be good for now (Btw, use at least a check_plain() for the username!).

However, Wysiwyg module will later cache the return value from that function to increase performance and not always have to load the plugin file. That means your drupal_add_js() line won't run when the plugin data is fetched from the cache. When that happens, you'll be able to include scripts via the metadata, and possibly define a "load callback" for adding dynamic content.
Keep eyes on #841794: Cache wysiwyg_load_includes() and #1039076: Allow plugins to specify libraries and multiple javascript files for more on that.
You could also do it like the ckeditor_lite module, mentioned above, does it. They implement hook_wysiwyg_editor_settings_alter() and inject the dynamic data that way. That completely avoids potential caching issues in the future.
(Adding "namespaced" plugin settings using the hook like this is a fine use case, but I would not recommend most modules to implement it for modifying any existing edit settings, as this is mostly for site-specific custom modules).

@duozersk, for your hook_wysiwyg_plugin() implementation you can skip the 'path' and 'file' keys and just set 'internal' => TRUE instead, since you're relying on the user to install the plugin into the CKEditor library's plugin folder. Then you could make the Libraries API dependency optional if you add a module_exists('libraries') check and fall back to a hardcoded path for hook_ckeditor_plugin().

duozersk’s picture

TwoD,

Thank you for your time to review the code, really appreciate your efforts on developing and supporting the WYSIWYG module.
I also plan to implement the block to toggle the changes highlighting when you view the node with changes.

AndyB

laboratory.mike’s picture

duozersk,

Thank you for your work in developing this module. And for TwoD for getting us started.

If you don't mind, I'm going to try your module on my site and see if I need additional features. I'm teaching myself PHP right now so I'll try writing and sending patches as needed.

Mike

duozersk’s picture

Michael,

Sure, will wait for your review and suggestions/patches in the issue queue.

AndyB