Giter VIP home page Giter VIP logo

ckeditor-easycontent's Introduction

CKEditor easycontent injector plugin.

Works on CKEditor 4.x and probably others.

The plugin allows you to easily create an editor button that will insert your custom HTML or call your custom function.

View demo

Installation

  1. Download to your plugins folder or use plugins.addExternal to add easycontent plugin.
  2. Add easycontent plugin to your configuration: `editor.config.extraPlugins = 'easycontent';
  3. Define your CKEDITOR.config.easycontent buttons (see configuration below)
  4. Add the buttons to your toolbar: CKEDITOR.config.toolbar = [{name: 'My collection', items : ['Iframe', 'LineBreak', 'CustomHTML']}];

Configuration

You can create an array of buttons to add to the toolbar. Each button has these properties:

  • name: The name of the command and the button (the one to use in the toolbar configuration)
  • icon: The icon to use. Place them in the plugin folder or put an absolute path (starting with '/')
  • html: The HTML to insert or the function to call when the user clicks the button
  • title: Title that appears while hovering the button

Example

    CKEDITOR.replace('editor', {
      // Activate easycontent plugin
      extraPlugins: 'easycontent',
      // Add 'Iframe' button
      toolbar: [['Bold', 'Italic'], ['Iframe']],
      // Define buttons and their action
      easycontent: [
        {
          name: 'Iframe',
          title: 'A simple iframe creator',
          icon: '/my/path/to/my/iframe-icon.png',
          html: function(editor) {
              var source = window.prompt('Insert the source of your iframe');
              if(!source) {
                  return alert("You must specify an URL to create an Iframe");
              }
              return '<iframe src="'+source+'" width="100%" height="300"></iframe>';
          }
        }
      ]
    });

This configuration is simple yet powerful:

Adding the button like CKEDITOR.config.toolbar = [['Iframe']];

You've just created powerful custom Iframe generator buttons!

See the demo page for further examples.

Notes

I am not CKEditor expert (nor actually a user). If anything seems fuzzy in the code, just fork/report/pull-request/email.

Credits

This plugin is strongly inspired from the ckeditor htmlbuttons plugin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.