Home

Awesome

Editr

About

Editr is a HTML, CSS and JavaScript playground that you can host on your server. it is based on ACE Editor. It’s super easy to setup and supports multiple instances on one page. Configurations are available via JS object or HTML attributes.

You can check demo and read more about features here.

EditrWP - Wordpress Plugin

You can also buy Editr.js as Wordpress plugin here

Files structure

.
|---. editr
|   |--- editr.js
|   |--- editr.css
|   |---. items
|       |--- index.html
|   |---. libs
|       |--- ext.emmet.js
|       |--- parser.coffeescript.js
|       |--- parser.less.js

editr Folder containing Editr script, style and projects folder

editr.js Editr main script. It's quite clean and have some comments so have fun with digging it.

editr.css Editr style, it contains only some basic style so you can easily customize it.

items Folder containing all your projects(can be configured).

index.html Required file with basic html, used as default file when no files were added for html, css or js.

libs Contains preprocessors and emmet extension.

Dependencies

You also have to add parsers if you want to support preprocessors:

Installation

Copy editr folder to root of your website.

Add this in <head>:

<link rel="stylesheet" href="/editr/editr.css">

and this before </body>:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/ace/1.1.01/min/ace.js"></script>
<script src="//cdn.jsdelivr.net/ace/1.1.01/min/ext-emmet.js"></script>
<script src="/editr/libs/ext.emmet.js"></script>
<script src="/editr/editr.js"></script>

Additionally you can add(before Editr script) LESS and CoffeeScript compilers if you're going to use them:

<script src="/editr/libs/parser.coffeescript.js"></script>
<script src="/editr/libs/parser.less.js"></script>

Embed single editor:

<div class="editr" data-item="PROJECT-NAME" data-files-html="index-1.html;index-2.html" data-files-css="!normalize.css;style.css" data-files-js="!jquery.js;script.js"></div>

Run it:

$('.editr').each(function() {
    new Editr({ el: this });
});

This will load project named 'PROJECT-NAME' from 'items/' folder(Editr default value). Files passed in data-files-[html/css/js] will be loaded in a queue. Files with '!' before name will be hidden from Editr navigation bar.

Options

Via HTML data- attribute

NameDefaultDescription
itemnullName of project folder inside projects folder('path' option).
viewsingleEditr layout view. Other options: horizontal, vertical, cartesian.
pathitemsPath to folder with projects.
thememonokaiACE Editor theme. If you want to use light theme then also add class editr--light.
hidenullThis attribute allows you to hide elements from Editr toolbar. Values: all result html css js.
wrapfalseSet to true if you want to wrap lines.
readonlyfalseMake Editr textarea read-only.
files-htmlnullHTML Files. Base64 and Gists are supported.
files-cssnullCSS Files. LESS is supported. Base64 and Gists are supported.
files-jsnullJavaScript Files. CoffeeScript is supported. Base64 and Gists are supported.

Notes:

Valid ways to add files

DesciptionCodeNote
Single fileindex.html
Multiple filesindex.html; other-page.htmlSeparated by ;
Hide file from nav!index.htmlAdd ! before name
Read base64 stringYm9keSB7IHdpZHRoOiA1MCU7IH0=Separate multiple strings like normal files
Hide base64 content from nav!Ym9keSB7IHdpZHRoOiA1MCU7IH0=
Use preprocessor on base64 stringless:Ym9keSB7IHdpZHRoOiA1MCU7IH0=;You can hide it from nav by adding ! before preprocessor name
Github Gist$4631473, jquery.js, script.jsTemplate: $GIST_ID,FILE-1,...,FILE-N. Preceded by $. Files separated by ,. Add ! before file name to hide it, not before GIST_ID.

Via JavaScript

NameDefaultDescription
viewsingleEditr layout view. Other options: horizontal, vertical, cartesian.
pathitemsPath to folder with projects.
gistProxyURL/editr/libs/proxy.gist.phpPath to gist proxy file.
thememonokaiACE Editor theme. If you want to use light theme then also add class editr--light.
wrapfalseSet to true if you want to wrap lines.
readonlyfalseMake Editr textarea read-only.
callbackfunction (editor) {}Callback triggered after all files are loaded and Editr is ready. Editr object is passed as an argument, use wisely.
parsersCheck sourceYou can add custom parsers for preprocessors. Check source for more info.

Load files from Gists

To load files from Gists, you need to configure gist proxy file first, it's really easy.

Go to Authorized Applications page and create new Personal Access Token, name it Editr or whatever you want.

Open editr/libs/proxy.gist.php file, update $username and $api_token variables.

Now make sure that gistProxyURL option is set properly.

API

Please keep in mind that using API functions is most stable in callback which you can configure in JS options. Editr object is passed for it as an argument.

In case, you want to use API functions outside of callback, use them on pure JS objects, not jQuery.

Here's how to make jQuery object a pure js object:

$('.editr')[0]

You can also access all Editr instances using EditrInstances var.

On that object you can use any of API methods:

NameArgumentsDescription
isReadyNoneCheck if Editr is fully loaded
getGistsNoneReturn all gists
getFilestype - html, css, js, nullReturn all files for given type or overall if not passed
getFiletype - html, css, js, null <br> id - File IDReturn single file for given type(extension) and id
setReadOnlyvalue - booleanSet Editr textareas read state

License

The MIT License (MIT)

Copyright (c) 2013 Kasper Mikiewicz

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.