What is the best way to incorporate custom styles in CKEditor with the help of the Custom drop

I recently implemented a plugin that provides me with the code needed to create a dropdown menu on my CKeditor toolbar. This dropdown menu contains various styles that can be applied by clicking on them. Here is the code snippet:

CKEDITOR.plugins.add( 'tokens',
{   
   requires : ['richcombo'],
   init : function( editor )
   {
      var config = editor.config,
         lang = editor.lang.format;

      // List of tags for the dropdown.
      var tags = [];
      tags[0]=["[contact_name]", "Name", "Name"];
      tags[1]=["[contact_email]", "email", "email"];
      tags[2]=["[contact_user_name]", "User name", "User name"];

      // Function to create style objects for all defined styles.

      editor.ui.addRichCombo( 'tokens',
         {
            label : "Insert tokens",
            title :"Insert tokens",
            voiceLabel : "Insert tokens",
            className : 'cke_format',
            multiSelect : false,

            panel :
            {
               css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
               voiceLabel : lang.panelVoiceLabel
            },

            init : function()
            {
               this.startGroup( "Tokens" );
               for (var this_tag in tags){
                  this.add(tags[this_tag][0], tags[this_tag][1], tags[this_tag][2]);
               }
            },

            onClick : function( value )
            {         
               editor.focus();
               editor.fire( 'saveSnapshot' );
               editor.insertHtml(value);
               editor.fire( 'saveSnapshot' );
            }
         });
   }
});

The purpose of this code is to insert the corresponding tag when a style is selected from the dropdown menu. I am interested in customizing each tag to perform specific functions, such as adding CSS styles to the selected text in the editor. For example, having a function named 'Red Font' that changes the font color of any existing <p> element to red.

Answer №1

Let's enhance your editor by adding this code snippet:
CKEDITOR.replace( 'editorId', {
    extraPlugins: 'tokens'
});

Make sure to replace 'editorId' with the ID of your editor. You're all set!

Answer №2

CKEDITOR.replace( 'editor', { 
    extraPlugins: 'tokens' // explanation for using tokens provided below
});

this is utilized because

CKEDITOR.plugins.add( 'tokens',
{   
    requires : ['richcombo']
    ..

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve and showcase JSON data with the help of jQuery

I'm trying to display a specific variable (Date) from a JSON file, but it doesn't seem to be working. Can anyone help me figure out what I'm doing wrong? <script type="text/javascript"> $(document).ready(function() { $. ...

Sending a directive as an argument to a parent directive function

edit: I made adjustments to the code based on stevuu's recommendation and included a plunkr link here Currently, my goal is to make a child directive invoke a method (resolve) through another directive all the way up to a parent directive. However, I ...

What is the best way to add HTML formatted text into Outlook?

In my Emacs, I've generated this syntax-highlighted code snippet and now want to paste it into an Outlook email with rendered HTML (without the actual HTML code). <pre> <span style="color: #a020f0; background-color: gtk_selection_bg_color;"& ...

CSS: Continuous Automated Slide Transitions

What CSS code do I need to incorporate into my code to create a continuous Slider Animation? I want the pictures to slide automatically one by one, with a specified time interval between each slide when not on hover. The hover function is already included ...

Unable to open new tab using target _blank in React js production build

After attempting to access the link, a 404 error appeared in the live version of react js and triggered an error on the firebase hosting platform. <Link target='_blank' to={'/property-details?id='some_id'}/> ...

How can an external style sheet be inserted into an iframe?

My website features an editor on one side and an iframe on the other. Currently, anytime HTML code is entered into the editor and a keyup event occurs, the iframe updates automatically. I am looking to add default styling to the code entered in the editor ...

What is the best way to manage two buttons within a single form?

<input type="submit" value="" id="button1"/> <input type="submit" value="" id="button2" /> In a single form, I have two buttons. Only one button appears at a time on the client side thanks to jQuery magic. The issue is that when using the &ap ...

What is the functionality behind this unique SCSS mixin that combines flexbox and grid layouts?

Discover a SCSS mixin for creating flexbox/grid layouts HERE. Take a look at the complete mixin code below: @mixin grid-col( $col: null, $grid-columns: 12, $col-offset: null, $gutter: null, $condensed: false, ...

Utilizing Django's jQuery Ajax form functionality to either download a file or display the incorrect form

Is there a way to make a Django-created form jQuery/Ajax-submitted and download a file upon successful submission, while returning the Django form if it's invalid? I experimented with modifying the Django form for jQuery/Ajax functionality like this: ...

Bootstrap modal with autocomplete feature

How can I display the last entered data by the user in a bootstrap modal? I attempted to use the HTML autocomplete="on" attribute but it did not work, similar to what is shown in this fiddle. After the user submits, on the subsequent attempt, it should pr ...

Only two options available: validate and hide; no additional options necessary

Having some trouble understanding the logic behind a JavaScript script that is meant to display select options based on another select option. Any tips on how to hide unused options? For example: If TV is selected, only show options for device, tsignal, b ...

Trouble with Hero Unit Styles not being implemented

Looking to convert a PSD design to HTML using Bootstrap, but the hero unit is not displaying its default style as expected. <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> ...

What might be causing issues with the functionality of my user registration form?

I have been working on creating a registration form for users using PHP and MySQL. However, I'm facing an issue where no new records are added to the database when I submit the form. It's strange because the database has worked perfectly fine wit ...

What is the best approach for running a database query using the value selected from a form dropdown?

Currently, my application server is ColdFusion and I am using SQL Server for the database. Within a select form element on my webpage, users can choose from a list of vehicles such as Volvo S60, BMW M6, and VW Jetta. Once a user selects a vehicle, I need ...

Trouble with Bootstrap 5 Dropdown Functionality

Currently, I am using Bootstrap 5 in conjunction with Django to create a website and I'm encountering difficulties with getting a dropdown feature to work properly. Despite copying the code directly from w3schools, it fails to function when I load the ...

Adjusting the Image Width in React to Match Bootstrap Column Width

Exploring the capabilities of the react-image-mapper library, I stumbled upon an interesting feature: the ImageMapper component offers a prop called width, representing the image width in pixels. Integrating this component into my application based on the ...

When I click the confirm button on Sweet Alert, I would like to update the database status from the default (pending) to confirmed

When I click on the confirm button in this sweetalert, I need assistance with updating the STATUS column in my database. Thank you for your help. swal({ title: 'Are you sure?', text: "You won't be able to revert this!", type: &a ...

What is the process for selecting a radio button using Selenium WebDriver?

I am trying to select the radio button in this HTML code, but I'm having trouble. Here is the snippet of my HTML: <div class="appendContent"> <div> id="contentContainer" class="grid_list_template"> <div id="routeMonitor ...

how to target the last child element using CSS commands

<a><div class="myDiv"></div></a> <a><div class="myDiv"></div></a> <a><div class="myDiv"></div></a> <a><div class="myDiv"></div></a> // This specific one is what ...

I want to use React Bootstrap and Next.js to retrieve the text from a textbox in a React Component and then send it back to my Index.js file. How can I accomplish this task?

I need some assistance. Currently, I am facing a challenge. I am trying to retrieve data from one of my React Components named ParameterList. This component contains a React-Bootstrap Form.Control element for numerical input. My goal is to take the value ...