Medium.js

Taking control of content editable


This is Medium.js. It keeps HTML code within contenteditable semantic, simple, and clean. It also allows for placeholders, automatic HR creation, events, hotkeys, and more.

This script is inspired by Medium's beautiful content editor, something I have aspired to emulate since its inception.

Medium.js has been tested in Firefox 17+ (No Placeholders), Safari 5+, IE 10+, and Opera 11+ (No placeholders and no hotkeys). Hopefully, browser support (through abstraction), can be improved upon in the near future.

This code is brought to you by jakiestfu, author of Snap.js and Behave.js. Please share!


Features


Usage


            

Simply include the Medium JS library and CSS, and you are ready to rock. No dependencies


Semantic


            

The code within Medium.js editors are very semantic and organized, giving you peace of mind with using contenteditable.


Options


            

All options (excluding modifiers, tags, and cssClasses) may be overridden with data-medium-* attributes on the element.

Common Questions

What is the purpose of Medium.js?

Medium.js overrides many default keyboard events and substitutes a more cross-browser compliant way to interact with contenteditable elements. This means that you can use contenteditable without fearing your user is going to enter poor or invalid HTML. It keeps things tight, organized, and semantic.

Does this give me the cool highlighting toolbar like Medium's editor

No, it does not. If you're looking for a script that adds support for Medium's toolbar, take a look at ZenPen.io

There are weird style issues when inserting empty tags. What gives?

Empty tags do not have what is called layout, a sort of property of an element. You need to set a min-height on the paragraph element you specify.

Medium.js does not work in all browsers!

Please fork Medium.js and contribute, wide support is so close!


Demos

Below each code block is a demo for inline, partial, and rich editors. On the rich editor, try using hotkeys like cmd+b or ctrl+i, etc.

Inline


            

Partial


            

Rich


            

Licensing

MIT Licensing

Copyright (c) 2013 Jacob Kelley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.