The Art of Fluid Editing: Froala’s Draggable Plugin

Drag and drop with Froala

Nowadays, users are looking for convenient ways to edit their content. In response to this need, professional WYSIWYG editors with advanced capabilities, such as Froala, have become increasingly popular. For example, the Froala draggable plugin allows moving images and videos within the editor by dragging them, resulting in easily reordering the content and improving the overall content editing experience.

In this article, we will explore the Froala draggable plugin in depth. We will look at setting up the plugin, its options, and different usage examples.

Drag and drop with Froala

What is the Froala Draggable Plugin?

The Froala draggable plugin adds the capability to drag content such as images and videos inside the Froala editor. This allows users to move and rearrange the content using their mouse or touch screen. Using the Froala draggable plugin has several advantages such as

  • Improved user experience:
    Adding a drag-and-drop feature makes your application more user-friendly and improves the overall user experience.
  • Increased productivity
    Dragging content using a mouse or touch screen is much faster than cutting content and re-pasting it. As a result, users will be able to complete more tasks in the same time frame.

Installation and Setup of Froala Draggable Plugin

To set up the Froala Draggable plugin, you have to include its script and stylesheet files alongside the core Froala editor scripts and stylesheet files

<!-- Froala core editor Files -->
<link href='{url_based_on_your_download_option}/css/froala_editor.min.css' rel='stylesheet' type='text/css' />

<script type='text/javascript' src='{url_based_on_your_download_option}/js/froala_editor.min.js'></script>


<!-- Froala Draggable plugin files -->
<link href='{url_based_on_your_download_option}/css/plugins/draggable.min.css' rel='stylesheet' type='text/css' />

<script type='text/javascript' src='{url_based_on_your_download_option}/js/plugins/draggable.min.js'></script>

Note that if we use the .pkgd version of the Froala editor, you do not have to include Draggable plugin scripts and stylesheet files separately. The .pkgd version already includes all Froala’s default plugin files.

Once the plugin files are included, it will be active by default when initializing the editor

new FroalaEditor('#HTMLElement');

However, if you’re customizing the pluginsEnabled option, you must include the Draggable plugin:

new FroalaEditor('#HTMLElement',{

     pluginsEnabled: ['image', 'link', 'video', 'draggable', 'print']

});

Using the Draggable Plugin

If the Draggable plugin is enabled and there are images or videos inside the editor, users can drag these elements as follows:

  • Click on the element.
  • Drag the element into a new position within the editor.
  • Release the element.

Dragging elements as described above is impossible if the Draggable plugin is disabled.

Customizing the Draggable Plugin

Options

The Draggable plugin provides developers with a dragInline API option. This option allows developers to control how the dragged elements are positioned within the editor. When set to true, the dragged items can be placed inside inline elements, such as text. Disabling this option ensures that the dragged elements are positioned between block-level tags. This provides more control over the layout and structure of your content.

new FroalaEditor('#HTMLElement',{
     dragInline: false,
     pluginsEnabled: ['image', 'link', 'video', 'draggable', 'print']

});
draginline
draginline: true

 

draginline-false
draginline: false

 

Events

The plugins register two events:

  • The element.beforeDrop event is fired when the user starts dropping the dragged element into a new or the same position (by releasing a mouse button or hitting the escape key).
  • The element.dropped event is fired when the element is dropped either in a new or the same position.
new FroalaEditor('div#froala-editor', {
  dragInline: false,
  pluginsEnabled: ['image', 'link', 'draggable', 'print'],
  events: {
    "element.beforeDrop": function(element) {
      console.log("beforeDrop");
    },
    "element.dropped": function(element, t) {
      console.log("droppped");
    },

  }
})

Both events pass the dragged element as the first argument of the callback function.

If more control is required over the dragging and dropping process, JavaScript events can be utilized, such as:

  • drag
  • dragend
  • dragenter
  • dragleave
  • dragover
  • dragstart
  • drop

To utilize these events, register an event handler for these events inside the editor’s initialized event using the on method.

new FroalaEditor('div#froala-editor', {
  dragInline: false,
  pluginsEnabled: ['image', 'link', 'draggable', 'print'],
  events: {
    "element.beforeDrop": function(element) {
      console.log("beforeDrop");
    },
    "element.dropped": function(element, t) {
      console.log("droppped");
    },
    'initialized': function() {
      // Do something here.
      var editor = this;

      editor.events.on('drop', function(dropEvent) {
        console.log("drop");
        console.log(dropEvent);

      });
    }
  }
})

Comparison of dragging feature between TinyMCE and Froala

At the time of writing this article, I went to the official TinyMCE full feature example page, I tried to drag the TinyMCE logo image but it didn’t move. Clicking on the image to drag it makes the image selected, but once I try to move it down, it selects the text below instead of dragging the image.

drag-and-drop inTinyMCE

I copied the TinyMCE editor content and pasted it into the Froala editor full-featured example, moving the TinyMCE logo by drag and drop was a piece of cake.

Drag-and-drop in Froala

Moreover, unlike Froala:

  • TinyMCE doesn’t provide options to customize drag-and-drop behavior.
  • TinyMCE only supports browser-native dragging events.

Overall, Froala provides a better user drag-and-drop experience.

Do I need to subscribe to a specific plan for using the Froala Draggable plugin?

The Froala draggable plugin, as well as other Froala plugins, are available in any of the Froala’s plans. Check our pricing page and select the plan that best fits your needs. Froala’s flexible licensing options ensure you can utilize the full capabilities of the draggable plugin, tailored to your specific requirements, without any additional costs or restrictions.

What is the difference between Froala’s annual and perpetual licenses?

Froala’s annual license lets you use the Froala editor for a full calendar year. Within this year, you can update your editor to the new releases. After that, you need to renew your license to continue using the editor in your product.

Froala’s perpetual license lets you use any version of the Froala editor that was released within one year of your license purchase, forever. To use versions that were released after that, you can renew your license at a discounted cost.

Can I test the editor before purchasing a license?

You may download the editor from our download page and test it at any time, without spending money. While testing, an unlicensed message will be displayed, however, it doesn’t limit any of the editor’s features. Once you are ready to use the editor in production, purchase a license to get the API key and remove the unlicensed message.

Conclusion

The Froala draggable plugin offers a seamless and customizable drag-and-drop experience, surpassing the capabilities of TinyMCE’s dragging functionality. With options to control the positioning of dragged elements and events to monitor the dragging process, Froala provides developers with greater control over the content structure. Froala’s flexible licensing, including annual and perpetual options, ensures the draggable plugin can be utilized effectively without additional costs or restrictions, making it a compelling choice for content-rich web.

 

Posted on June 25, 2024

Mostafa Yousef

Senior web developer with a profound knowledge of the Javascript and PHP ecosystem. Familiar with several JS tools, frameworks, and libraries. Experienced in developing interactive websites and applications.

No comment yet, add your voice below!


Add a Comment

Your email address will not be published. Required fields are marked *