GithubHelp home page GithubHelp logo

isabella232 / editr.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stackato-apps/editr.js

0.0 0.0 0.0 1.08 MB

HTML, CSS and JavaScript playground

Home Page: http://lab.idered.pl/editr/

JavaScript 96.28% PHP 0.31% CoffeeScript 0.01% CSS 2.32% HTML 1.08%

editr.js's Introduction

Editr

Gittip

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.

Deploying to HPE Helion Stackato

stackato push -n

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

  • jQuery //ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  • ACE Editor //cdn.jsdelivr.net/ace/1.1.01/min/ace.js
  • Emmet extension for ACE //cdn.jsdelivr.net/ace/1.1.01/min/ext-emmet.js
  • Emmet core /editr/libs/ext.emmet.js

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

  • Coffescript /editr/libs/parser.coffeescript.js
  • LESS /editr/libs/parser.less.js

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

Name Default Description
item null Name of project folder inside projects folder('path' option).
view single Editr layout view. Other options: horizontal, vertical, cartesian.
path items Path to folder with projects.
theme monokai ACE Editor theme. If you want to use light theme then also add class editr--light.
hide null This attribute allows you to hide elements from Editr toolbar. Values: all result html css js.
wrap false Set to true if you want to wrap lines.
readonly false Make Editr textarea read-only.
files-html null HTML Files. Base64 and Gists are supported.
files-css null CSS Files. LESS is supported. Base64 and Gists are supported.
files-js null JavaScript Files. CoffeeScript is supported. Base64 and Gists are supported.

Notes:

  • data- attributes overwrites options passed via JS.
  • Files passed in files-[html,css,js] should be separated by ;.

Valid ways to add files

Desciption Code Note
Single file index.html
Multiple files index.html; other-page.html Separated by ;
Hide file from nav !index.html Add ! before name
Read base64 string Ym9keSB7IHdpZHRoOiA1MCU7IH0= Separate multiple strings like normal files
Hide base64 content from nav !Ym9keSB7IHdpZHRoOiA1MCU7IH0=
Use preprocessor on base64 string less:Ym9keSB7IHdpZHRoOiA1MCU7IH0=; You can hide it from nav by adding ! before preprocessor name
Github Gist $4631473, jquery.js, script.js Template: $GIST_ID,FILE-1,...,FILE-N. Preceded by $. Files separated by ,. Add ! before file name to hide it, not before GIST_ID.

Via JavaScript

Name Default Description
view single Editr layout view. Other options: horizontal, vertical, cartesian.
path items Path to folder with projects.
gistProxyURL /editr/libs/proxy.gist.php Path to gist proxy file.
theme monokai ACE Editor theme. If you want to use light theme then also add class editr--light.
wrap false Set to true if you want to wrap lines.
readonly false Make Editr textarea read-only.
callback function (editor) {} Callback triggered after all files are loaded and Editr is ready. Editr object is passed as an argument, use wisely.
parsers Check source You 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:

Name Arguments Description
isReady None Check if Editr is fully loaded
getGists None Return all gists
getFiles type - html, css, js, null Return all files for given type or overall if not passed
getFile type - html, css, js, null
id - File ID
Return single file for given type(extension) and id
setReadOnly value - boolean Set 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.

editr.js's People

Contributors

idered avatar niceue 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.