editore.js
A magnific javascript editor! Easy to create and valitade fields and get data from them, even better is that you don't need to handle contenteditable yourself :8ball:
install
Available on npm and bower:
npm install editore
, bower install editore
or directly download
basic usage
Load editore.js into your application, create the editor wrapper element, set some fields and instantiate a new Editore.
<div id="editor">
<h1 data-field="title" data-placeholder="Title" data-require="true" data-length="60">Example title</h1>
<h3>Article</h3>
<article data-field="articleBody" data-placeholder="Write here..." data-type="rich" data-require="true">
<p>Lorem lorem lorem!</p>
</article>
</div>
var editore = new Editore(document.getElementById('editor'));
var values = editore.values();
constructor
new Editor(element);
parameters
- element: is the element from where the editor should get its child elements to transform in fields according with their data-attributes. Child elements that don't have the required data-attributes will not be converted into editor fields.
field element
<h1 data-field="title" data-placeholder="Title" data-require="true" data-length="60">
Lorem title!
</h1>
data attributes
- data-field: String (required)
- data-placeholder: String (required)
- data-required: Boolean
- data-length: Number
- data-type: String
- simple (default): It's a single-line field, without any text manipulation
- rich: It's a multi-line field, with text manipulation support
methods
editore.values()
- return a object with all fields values.
editore.values();
editore.fields()
- return a object with all fields internal attributes.
editore.clearFields();
editore.clearFields()
editore.clearFields();
editore.setFieldsValues( fields )
editore.setFieldsValues({
fieldName: 'Value',
richFieldName: '<p>Value</p>'
});
editore.destroy()
- unset editable and remove all fields listeners.
editore.destroy();
editore.subscribeInput( callback )
- parameters
- callback: Function(currentField)
editore.subscribeInput(function(currentField) {
console.log('Current: ', currentField);
});
editore.registerEditionPlugin( Plugin )
- register a new plugin on selection edition component.
- parameters
- Plugin: Plugin Constructor
editore.registerEditionPlugin(EditionPlugin);
editore.registerInsertionPlugin( Plugin )
- register a new plugin on insertion component, which is located between the current block and the next block.
- parameters
- Plugin: Plugin Constructor
editore.registerInsertionPlugin(InsertionPlugin);
Plugins avaliable
Pretty soon we'll have more :pray:
Plugin constructor
- insertion type: A component called on rich fields selection to edit the selection data.
- edition type: A component called on rich fields between the current edit block and the next block, in order to insert new content into the field.
method
- context instance objects
- this.name: String (required)
- editore uses this name to register and manage the plugin, also uses to define the class of the plugin button
- this.button: DOMElement (required)
- Editore get this button and insert into selection component
- this.tag: String (required if is a edition plugin)
- Editore uses this tag to check if the edition plugin is active with current selection element
- injected objects
- this.component: Editore adds in the plugin instance context it's component object, enabling access to it's element, plugins and checkPluginsState method.
- element: DOMElement
- plugins: Array
- checkPluginsState: Function
function EditionPlugin() {
this.name = 'editionPlugin';
this.button = document.createElement('button');
this.button.innerText = 'Edition';
this.tag = 'i'
console.log(this.component)
}
prototype
- action: Function(currentSelectionField, clickEvent) (required)
- method called when plugin button is clicked
- destroy: Function() (required)
- method called before destroy Editore
EditionPlugin.prototype = {
action: function(currentSelectionField, clickEvent) {
e.preventDefault();
},
destroy: function() {
}
};
support
- chrome: ?
- firefox: ?
- safari: ?
- internet explore: ?
contribute
Everyone can contribute! Finding bugs, creating issues, improving documentation, improving editor it self or creating components.
Every contribution will be welcomed! :santa:
Fork it -> Branch it -> Test it -> Push it -> Pull Request it :gem:
Currently development is being maintained by Núcleo Digital Grupo RBS.