Customize the HTML tags in the Froala text editor with easy insertion and removal

In my AngularJS project, I am utilizing Froala editor. I want to create a unique functionality where a custom button wraps selected text with <close></close> tags when activated. Moreover, if the selected text is already wrapped with these tags, clicking the button should remove them.

This feature should operate similarly to underlining or bolding text. For example, you can bold an entire word, but upon selecting 'ol' and clicking bold again, you will get a result like this: bold

I have managed to program a button that adds the tags, but I need assistance with removing them as well:

callback: function () {

  var selectedText = this.html.getSelected(),
    firstTag = '<close>',
    lastTag = '</close>';

  // replace selected text with wrapped text
  this.html.insert(firstTag + selectedText + lastTag, true)

}

Answer №1

If you're looking to enhance your Froala editor, check out this resource on creating custom buttons for Froala editor.

$.FroalaEditor.DefineIcon("highlight", { NAME: "exclamation" });
$.FroalaEditor.RegisterCommand("highlight",
{
    title: "Highlight",
    focus: false,
    refreshAfterCallback: false,
    callback: function () {
        //this.html.insert("<span class=\"highlight\">" + this.html.getSelected() + "</span>");
        debugger;
    }
});

Don't overlook adding the button during editor instantiation.

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

Angular directive for resizing C3 charts

I've recently implemented a basic donut chart using C3, which I've enclosed in a directive and everything is functioning smoothly. Below is the code for my directive: angular.module('dashboardApp').directive('donutChart', fu ...

Incorporate geographical data from a JSON file into my Google Maps application

Hey there, I'm a newbie on this forum and could really use your expertise. I've put together an html5 page with Google maps using the API key from Google (My code is shown below), it's working fine with a central marker in place and loads pe ...

Is it possible to retain the model value when clicking the back button in the browser using AngularJS?

I'm new to AngularJS and I have a dropdown along with a link. What I want is for AngularJS to remember the selected value in the dropdown even after clicking the link, and then going back using the browser's back button. Currently, when I click t ...

Angular project icons not displaying in the browser

My current project in Angular was functioning properly until recently. I am facing an issue where the images are not being displayed on the browser when I run ng serve, resulting in a 404 error. Interestingly, everything else seems to be working fine witho ...

Numerous capabilities consolidated into a single platform

Within my innovative MEAN application, the product model is structured as follows : product: { field: //some string value//, reviews: //an array of review objects// } To enforce distinct restrictions when saving field and reviews, I hav ...

Tips for filling jstree with information in Grails

I am currently facing difficulties in populating a jstree within a Grails gsp. Here is what I have attempted so far (rewritten for clarity): <script> $("#treeView").jsTree(); </script> <div id="treeView"> <g:each in="${atomMa ...

Steps to transfer the content of a label when the onclick event occurs

Seeking advice on how to send the dynamically varying value of a label upon clicking an anchor tag. Can anyone recommend the best approach to passing the label value to a JavaScript function when the anchor is clicked? Here is a sample code snippet: < ...

What is the best method to trigger a bootstrap modal window from a separate component in Angular 8?

I have successfully implemented a bootstrap modal window that opens on a button click. However, I am now facing difficulty in opening the same modal window from a different component. Below is the code I have tried: <section> <button type=&quo ...

I want to save the information for "KEY" and "textValue" in JSON format and then return it as a response when I make a request to app.get("/api"). How can I achieve this?

Working with GCP Document AI using Node.js and react.js, I have created a JSON structure (var jsonResult) in the provided code. In the for loop, I am extracting key and text value data by using console.log(key); and console.log(textValue);. However, my g ...

Exploring Angular 6 with Universal Karma for effective module testing

Issue I have been facing challenges while testing my Angular 6 application with Karma. I am encountering errors such as: Can't bind to 'ngModel' since it isn't a known property of 'mat-select'. Although the import works in ...

An elegant approach to converting a JavaScript object containing key-value pairs into an array of objects, each with a single key-value pair

Essentially, I have an enum that represents different statuses status = {1: "new", 2: "working" ... } and my goal is to transform it into something like status = [{1: "new"}, {2: "working"} ...] in a way that is cl ...

Adding data to an AngularJS template

I am encountering an issue with a flag that I am toggling between true and false to alter the display of certain elements on my page. While it works outside of the template, integrating this value into the template itself has proven challenging. restrict: ...

Developing a custom CSS for React using clamp and focus attributes

I'm currently working on creating an object to be used in inline style, but I'm having trouble figuring out how to correctly write `clamp` and `after`. const PhoneInputStyle = { fontSize: clamp("13px", "1.111vw", "16px"), /*this particular ...

Encountered a problem when incorporating delay functions into redux-saga testing using the Redux Saga Test Plan library

I am facing a challenge while trying to test my redux-saga functions using the Redux Saga Test Plan library. The issue arises due to delay functions present in my saga. All tests pass smoothly without any errors when I remove the line containing yield del ...

How can I easily add both horizontal and vertical arrows to components in React?

Creating a horizontal line is as simple as using the following code: <hr style={{ width: "80%", border: "1px solid black" }} /> You can customize the width, length, and other properties as needed. If you want to display an arrow ...

Implement a JavaScript and jQuery code that alternates between fading in and fading out every two items in a

Can someone help me figure out how to create a loop that fades in and out every 2 items from an unordered list using jQuery? I've been trying to do this, but my loop only processes one item at a time. <div> <ul> <li>item1</li ...

Obtain the URL within each promise

I'm currently utilizing Bluebird.js and the request-promise NPM module. My goal is to be able to access the promise URL or item.transactionID as shown in the code snippet below. After numerous attempts, I have not been successful in achieving this. Ho ...

The state returned by React Redux does not meet the expected results

I recently implemented a like function on the backend using Node and MongoDB. This function successfully returns the post with an updated likes counter, which I tested using Postman. The post object contains properties such as likes, _id, by, createdAt, an ...

Ajax script causes error 403 when loading content while scrolling

Currently in the process of creating a blog using the HubSpot platform. The primary goal is to have blog posts load dynamically as users scroll down the page. I came across a script that claims to achieve this functionality and is designed specifically for ...

displaying an AngularJS ng-repeat as empty following the completion of an Ionic loading operation

When using $ionicLoading to load the news page, a message is displayed if no news is found: <div ng-show="!news.length" class="empty"> Nothing to show ! </div> However, there is an issue where the empty div (Nothing to show !) is visible durin ...