1

Is there a possibility to ad a 'superscript' button to redactor?

Edit: I found an explanation here: How can I use <small> <sub> <sub> within a redactor/rich-text field?

But I can't get it to work.

I copy this snippet form: http://imperavi.com/redactor/examples/buttons-sup-and-sub/ to craft/app/resources/lib/redactor/plugins/subsup.js

if (!RedactorPlugins) var RedactorPlugins = {};

RedactorPlugins.scriptbuttons = function()
{
    return {
        init: function()
        {
            var sup = this.button.add('superscript', 'Superscript');
            var sub = this.button.add('subscript', 'Subscript');

            // make your added buttons as Font Awesome's icon
            this.button.setAwesome('superscript', 'fa-superscript');
            this.button.setAwesome('subscript', 'fa-subscript');

            this.button.addCallback(sup, this.scriptbuttons.formatSup);
            this.button.addCallback(sub, this.scriptbuttons.formatSub);
        },
        formatSup: function()
        {
            this.inline.format('sup');
        },
        formatSub: function()
        {
            this.inline.format('sub');
        }
    };
}; 

Then I call the plugin in a custom.json file like this:

{
    buttons: ['link','bold', 'italic','unorderedlist','orderedlist','image','html'],
    plugins: ['fullscreen', 'subsup'],
    toolbarFixedBox: true
}

But that results in nothing. What do I miss?

  • Nobody knows this? :( – KSPR Oct 29 '14 at 15:06
  • Is this now a thing? now that Redactor has been updated as well? – KSPR Dec 22 '15 at 8:31
4

I had a similar problem so created a plugin to add some of these extras to Redactor.

Redactor Extras for Craft

https://github.com/elliotlewis/Redactor-Extras Available plugin are:

  • Superscript and Subscript
  • Word count
  • Alignment
  • Custom plugin
  • Works like a charm. – KSPR Feb 17 '16 at 14:00
1

I had a similar problem and ended up creating my own fieldtype that extended a RichText field.

I think there is an oversight in Craft, where additional Redactor plugins aren't loaded even if they are specified in the config.json. But perhaps I'm missing something too?

A simple solution would be to hardcode the loading of the plugin in craft/app/fieldtypes/RichTextFieldType.php.

Within the function _includeFieldResources():

add the line:

craft()->templates->includeJsResource('lib/redactor/plugins/subsup.js');

after the default plugins specified.

Obviously modifying a core file is not recommended, but this should enable a temporary fix. I have built a plugin which autoloads js/css depending on what is specified in the config, but this isn't currently ready for general release. Let me know if your interested.

1

This isn't an answer, but I can't comment yet.

Craft is out-of-sync with the current version of the Redactor docs. Redactor is on version 10, while the latest Craft build is still on version 9.2.6.

There were a number of breaking changes and additions to version 10 of Redactor, but for some reason Redactor does not maintain a docs archive. So for the moment, we don't have a reliable source for Redactor docs.

See this answer for more from Craft on this.

  • Thanks for your hints. I guess I'll wait then. I don't want to alter core files. – KSPR Dec 2 '14 at 9:02
  • Okay, so now redactor is on v10 within craft 2.3 Ist there a possible solution now without corefile editing? – KSPR Dec 3 '14 at 11:28
1

I made another pretty easy solution:

{{ entry.redactor | nl2br | replace({'/m3': '/m<sup>3</sup>'}) | raw }}

It just replaces the units with the coresponding html markup. It works nice :) But you need to know which units are used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.