Is there a way to use this with TinyMCE? I mean, add a button to tinymce?

Thanks!

Comments

Zen’s picture

Version: 6.x-1.1-beta2 » 6.x-1.x-dev

I would certainly like to add support for RTEs. Ideally, this would be done via the wysiwyg module, which I'm told provides an API that would allow such features to be added to all supported RTEs across the board in one fell swoop. However, I have also been led to believe that the API is still quite incomplete. In other words, for the time being, the status is "Wait and See".

If you have any other information or want to work on this, please update away :)

Regards,
-K

Fidelix’s picture

http://drupal.org/project/wysiwyg_imageupload
http://drupal.org/project/imce_wysiwyg

These two modules add buttons to the editors through WYSIWYG API.
And they work quite fine, especially the first one.

Fidelix’s picture

WYSIWYG has a button plugin which serves as an example:

Basically, the plugin is just these 2 small files:
break.inc

<?php
function wysiwyg_break_plugin() {
  $plugins['break'] = array(
    'title' => t('Teaser break'),
    'vendor url' => 'http://drupal.org/project/wysiwyg',
    'icon file' => 'break.gif',
    'icon title' => t('Separate the teaser and body of this content'),
    'settings' => array(),
  );
  return $plugins;
}
?>

break.js

(function ($) {
// @todo Array syntax required; 'break' is a predefined token in JavaScript.
Drupal.wysiwyg.plugins['break'] = {

  /**
   * Return whether the passed node belongs to this plugin.
   */
  isNode: function(node) {
    return ($(node).is('img.wysiwyg-break'));
  },

  /**
   * Execute the button.
   */
  invoke: function(data, settings, instanceId) {
    if (data.format == 'html') {
      // Prevent duplicating a teaser break.
      if ($(data.node).is('img.wysiwyg-break')) {
        return;
      }
      var content = this._getPlaceholder(settings);
    }
    else {
      // Prevent duplicating a teaser break.
      // @todo data.content is the selection only; needs access to complete content.
      if (data.content.match(/<!--break-->/)) {
        return;
      }
      var content = '<!--break-->';
    }
    if (typeof content != 'undefined') {
      Drupal.wysiwyg.instances[instanceId].insert(content);
    }
  },

  /**
   * Replace all <!--break--> tags with images.
   */
  attach: function(content, settings, instanceId) {
    content = content.replace(/<!--break-->/g, this._getPlaceholder(settings));
    return content;
  },

  /**
   * Replace images with <!--break--> tags in content upon detaching editor.
   */
  detach: function(content, settings, instanceId) {
    var $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(
    // #404532: document.createComment() required or IE will strip the comment.
    // #474908: IE 8 breaks when using jQuery methods to replace the elements.
    // @todo Add a generic implementation for all Drupal plugins for this.
    $.each($('img.wysiwyg-break', $content), function (i, elem) {
      elem.parentNode.insertBefore(document.createComment('break'), elem);
      elem.parentNode.removeChild(elem);
    });
    return $content.html();
  },

  /**
   * Helper function to return a HTML placeholder.
   */
  _getPlaceholder: function (settings) {
    return '<img src="' + settings.path + '/images/spacer.gif" alt="&lt;--break-&gt;" title="&lt;--break--&gt;" class="wysiwyg-break drupal-content" />';
  }
};

})(jQuery);

Any ideas on what can be done?

Zen’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Assigned: Unassigned » Zen
Status: Active » Fixed

Rudimentary support added to D7. Please test :)

-K

Status: Fixed » Closed (fixed)

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