Sounds great!
Any plans on a d7 version?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geerlingguy’s picture

Subs.

David_Rothstein’s picture

I haven't had a chance to try this in D7 yet, but my guess (hope?) would be that literally the only change needed would be to change "6.x" to "7.x" in the info file... The rest of the code is hopefully version agnostic.

If anyone wants to try that and report back here if it works, that would be great, and I could commit a D7 version shortly thereafter :)

tinkalink’s picture

I've tried the D6 version on a D7 site by changing the .info as David suggested. It doesn't seem to work. Once the module is activated the editor is gone and there is no way of entering any text in the text field.

Worth investigating?

TimelessDomain’s picture

Status: Active » Needs work
markabur’s picture

Status: Needs work » Needs review
FileSize
3.55 KB

I was able to get it working in D7 with a couple of changes.

Safari was showing a js error about not finding a file '.../ckeditor/plugin.jsplugin.js', which the following change fixes:

-          'path' => drupal_get_path('module', 'wysiwyg_code_button') . '/ckeditor/plugin.js',
+          'path' => drupal_get_path('module', 'wysiwyg_code_button') . '/ckeditor/',

I still had problems until I got rid of the dash in the plugin name, e.g.

-        'code-button' => array(
+        'codebutton' => array(

And this change lets the button label show in skins other than the default "kama":

-.cke_skin_kama .cke_button_code-button span.cke_icon {
+.cke_button_codebutton span.cke_icon {

-.cke_skin_kama .cke_button_code-button span.cke_label {
-  display: inline;
+.cke_button_codebutton span.cke_label {
+  display: inline !important;

Also, the info file is updated and my editor caught a crlf problem, which is fixed too.

bleen’s picture

sub

andris_b’s picture

Patch worked like a charm for me, thanks!

Panthrax’s picture

Patch worked for me as well, thanks!

TimelessDomain’s picture

Status: Needs review » Reviewed & tested by the community

!

j0rd’s picture

I was looking for a module like this to add H2 and H3 buttons to my CKEditor.

I've created a slightly more generic version of this module to include header tags. I'm hoping someone else will take this even a step further and create generic buttons for all reasonable HTML elements.

This works with D7.

UPDATE: Looks like I left two dpm()'s in there. You'll need to remove them.

korzh-nick’s picture

Hi, there is a patch for the current version?

j0rd’s picture

@kolebas nope, WYSIWYG

gbangban’s picture

FileSize
9.41 KB

I can't create a full patch with netbeans, so here is a zip of the module for a D7 compatible release. It looks like its working for me, but ymmv. This was updated from the 6.x-1.0-rc1 release.

sneyerst’s picture

I have installed the patch from #13.

  • I can select the pre and/or code-button under appearances in wysiwyg configuration screen
  • I can click the code-button when editing a node field and text is marked correctly

There is only one problem; my button doesn't have any label.
I'm not familiar with this module, but I guess this happens in wysiwyg_code_button_form_wysiwyg_profile_form_alter(&$form, $form_state).
The $profile variable in this function is a string (in my case 'ckeditor') but is treated later on in the function as an object (presumably a context object, like in wysiwyg_code_button_wysiwyg_editor_settings_alter(&$settings, $context)).

// ...
  $profile = $form['editor']['#value'];
  switch ($profile) {
    case 'ckeditor':
      $form['appearance']['code_button_pre_label'] = array(
        '#type' => 'textfield',
        '#size' => 6,
        '#title' => t('Label for the %button button', array('%button' => t('Preformatted text'))),
     // Start 
        '#default_value' => isset($profile->settings['code_button_pre_label']) ? $profile->settings['code_button_pre_label'] : t('PRE'),
        '#access' => !empty($profile->settings['buttons']['code-button']['code-button-pre']),
     // End
      );
//..
leanderl’s picture

@sneyerst: Did you ever find out how to solve this?

sneyerst’s picture

Unfortunately not.. I hope someone with a better insight in this module may be able to fix this.

hatul’s picture

The icons is missed.
plugin.js

(function($) {

  /**
   * Adds a CKEditor plugin to insert <pre> and <code> tags.
   *
   * Based on blog posts by:
   *
   * Nikolay Ulyanitsky
   * http://blog.lystor.org.ua/2010/11/ckeditor-plugin-and-toolbar-button-for.html
   *
   * and
   *
   * Peter Petrik
   * http://peterpetrik.com/blog/ckeditor-and-geshi-filter
   */
  CKEDITOR.plugins.add('code-button', {
    init: function (editor) {
      var buttons = {
        'code-button-pre': ['pre', editor.config['code-button-pre'].label, this.path + 'images/pre.png'],
        'code-button-code': ['code', editor.config['code-button-code'].label, this.path + 'images/code.png']
      };
      for (var buttonName in buttons) {
        var format = {'element': buttons[buttonName][0]};
        var style = new CKEDITOR.style(format);

        // Allow the button's state to be toggled.
        // @see http://drupal.org/node/1025626 for a standardized solution to
        //   the closure context late binding problem.
        (function(buttonName, style) {
          editor.attachStyleStateChange(style, function (state) {
            editor.getCommand(buttonName).setState(state);
          });
        })(buttonName, style);

        // Add the command and button to the editor.
        editor.addCommand(buttonName, new CKEDITOR.styleCommand(style));
        editor.ui.addButton(buttonName, {command: buttonName, label: buttons[buttonName][1],icon: buttons[buttonName][2]});
      }
    }
  });

})(jQuery);

I also added icons in ckeditor/images.

You also remove display: none from wysiwyg_code_editor_ckeditor.css

cke_button_code-button-code span.cke_icon {
  /*display: none !important;*/
}
JohnnyX’s picture

Is a release planned?