Giter VIP home page Giter VIP logo

fondant's Introduction

Fondant v0.6.2

The icing on the cake for user input. A simple jQuery HTML5 WYSIWYG editor using contenteditable.

© 2013 Phillip Ridlen & Oven Bits, LLC

Requirements

  • A recent jQuery (tested with 1.9.1)
  • A modern-ish browser (IE9+)

Usage

Instantiation

To launch the editor on a block element or a text area:

$('div.editable').fondant({
  // Default options
  prefix: 'fondant'   // prefix for all css classes and ids added to elements generated by Fondant

  toolbar: true,      // If set to `true`, Fondant will generate a generic toolbar. If set to a
                      // string or a function, it will use the value or return value of it for the
                      // toolbar html

  buttons: [          // You can pass in a subset of these buttons to only show certain ones. Will
    'bold',           // only work if `toolbar` is `true`. Otherwise the toolbar will not be
    'italic',         // generated or will use the custom string or function.
    'p',
    'h1',
    'h2',
    'h3',
    'h4',
    'blockquote',
    'ol',
    'ul',
    'indent',
    'outdent',
    'remove',
    'unlink',
    'undo',
    'redo'
  ]
});

Commands

Formatting

If you choose to build your own toolbar, here are the commands to use. Note that because of the nature of document.execCommand() these actions will apply to the currently selected text of any contenteditable block element.

// Insert Custom HTML (replaces currently selected text)
$('.fondant-editor').fondant('custom', html_string);

// Remove Formatting
$('.fondant-editor').fondant('remove');

// Font Style
$('.fondant-editor').fondant('bold');
$('.fondant-editor').fondant('italic');

// Block elements
$('.fondant-editor').fondant('p');
$('.fondant-editor').fondant('h1');
$('.fondant-editor').fondant('h2');
$('.fondant-editor').fondant('h3');
$('.fondant-editor').fondant('h4');
$('.fondant-editor').fondant('blockquote');

// Lists
$('.fondant-editor').fondant('ol');
$('.fondant-editor').fondant('ul');
$('.fondant-editor').fondant('indent');
$('.fondant-editor').fondant('outdent');

// Links
$('.fondant-editor').fondant('link', href);
$('.fondant-editor').fondant('unlink');

Fondant

// Focus the editor
$('.fondant-editor').fondant('focus');

// Get or set the editor html
$('.fondant-editor').fondant('value');
$('.fondant-editor').fondant('value', html_string);

// Get the currently selected text
$('.fondant-editor').fondant('getSelection');

Testing

To run the tests, first start CoffeScript watching and compiling:

coffee --watch --compile src/*.coffee spec/*.coffee

Then open SpecRunner.html in your browser to run the tests.

fondant's People

Contributors

philtr avatar

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.