Calliope is an extensible rich text editor based on EnyoJS.
Calliope gets it's name from the muse of epic poetry in Greek Mithology, daughter of Zeus and Mnemosyne, and is believed to be Homer's muse, the inspiration for the Odyssey and the Iliad.
Calliope can be used as a standalone Enyo component:
enyo.kind({
name: "CalliopeStandaloneExample",
kind: "newness.Calliope",
style: "width: 100%; height: 400px",
});
or integrated with the Onyx library:
enyo.kind({
name: "CalliopeOnyxExample",
kind: "onyx.InputDecorator",
components: [{
kind: "newness.Calliope",
style: "width: 100%; height: 100%",
}]
});
You can use getValue() to get Calliope's document html content, and setValue() to overwrite it.
Calliope comes with a predefined basic toolbar, that includes commands for font formatting (bold, italic, underline,strikethrough, fontsize), paraghraph alignment and format removing.
You can overwrite the default toolbar with a customized one easily. You just take into account the following
The currently available Toolbar components are:
newness.Calliope.ToolbarRow: Aligns vertically ToolbarGroup or ToolbarButton elements.newness.Calliope.ToolbarGroup: Groups horizontally ToolbarButton components. This is thedefaultKindcomponent forToolbar, if not specified otherwise.newness.Calliope.ToolbarIcon: Default bi-state or single-state button. This is thedefaultKindcomponent forToolbarGroup. More info below.newness.Calliope.ToolbarSelect: A select control for Calliope's Toolbar
But there are more coming:
newness.Calliope.ToolbarButton: A captioned buttonnewness.Calliope.Input: An editable Input for Calliope's Toolbarnewness.Calliope.Label: A label control to show information
With these current three basic elements, you can make your own toolbars easily:
enyo.kind({
name: "CustomCalliopeToolbarSample",
kind: "Onyx.InputDecorator,
tag: "div",
components: [{
kind: "newness.Calliope",
components: [{
kind: "newness.Calliope.ToolbarRow",
components: [{
components: [{
src: "copy.png",
command: "copy",
stateful: false
}, {
src: "paste.png",
command: "paste",
stateful: "false"
}]
}]
}, {
kind: "newness.Calliope.ToolbarRow",
components: [{
components: [{
command: "bold"
}]
}]
}]
}]
});
This code creates a Calliope editor with a toolbar with two ToolbarRow; the first one shows a ToolbarGroup with two custom ToolbarIcon inside for "copy" and "paste" actions, and the second one another ToolbarGroupwith the predefined "bold" ToolbarIcon.
But you don't need to deal with rows, if you don't want to:
enyo.kind({
name: "CustomCalliopeToolbarSample",
kind: "Onyx.InputDecorator,
tag: "div",
components: [{
kind: "newness.Calliope",
components: [{
components: [{
src: "copy.png",
command: "copy",
stateful: false
}, {
src: "paste.png",
command: "paste",
stateful: "false"
}]
}, {
components: [{
command: "bold"
}]
}]
}]
});
This code creates a toolbar with one single ToolbarRow, with two ToolbarGroup inside it with the same ToolbarIcon items setup as the previous example.
Calliope resorts the toolbar structure to match the size, so you don't have to deal with rows if you don't want to.
At this, moment, Calliope comes with a very little predefined set of ToolbarIcon:
bold,italic,underline,strikeThrough: Sets formatting for typing, or applies it to selectionjustifyLeft,justifyCenter,justifyRight,justifyFull: Applies paragraph justification.removeFormat: removes formatting for current selection.
These predefined ToolbarIcon items include their own graphical assets.
There is also a predefined ToolbarSelect:
newness.Calliope.ToolbarSelect.Fontsize: Adjusts fontsize by percentage values.
The plan is to improve the predefined buttons set, but meanwhile, you can enable any of the DOM execCommand command.
To do so, just declare your custom ToolbarIcon with the following properties:
src: the url to the icon graphical assetcommand: the DOM command to execute.- Optional
stateful: set it to true if the button must show the command state (and the command allows it).
Optionaly, you can use the standard ToolbarIcon kind to perform whatever operation you desire it to do, just doesn't specify a command, and listent to the onclick event:
{
onclick: "customClickEvent",
onRefreshButtonState : "customStateRefresh",
stateful : true
}
statefultells the button to fire theonRefreshButtonStateevent, so you can apply your customizations.onclickgets fired whem the user clicks the button, so you can do with it whatever you want it to.
onclick event handling is as follows:
customClicked: function(inSender, inDocument) {
//inDocument is the editable document.
}
Of course, this is the default behaviour... you can create your derived kinds overwriting the default ToolbarIcon click handling, to show a dialog or whatever, and of course, share it ;)
Calliope is released under the Apache 2.0 License.