Skip to content

Commit

Permalink
Merge pull request #18 from Samuell1/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Samuell1 authored Apr 16, 2017
2 parents 850ce2f + 9507e89 commit 8357382
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,50 @@ http://octobercms.com/plugin/samuell-contenteditor

<img src="http://octobercms.com/storage/app/uploads/public/572/dfc/ec4/572dfcec4d675487425233.png">

### How to use it? It's simple. ###
### How to use it? It`s simple.

* Drop the Content Editor component to a CMS page.
* Check if you have `{% framework %}` and `{% scripts %}` inside layout for working ajax requests
* Use this code in your page code and link the editor to a content file or set name to autocreate new file

*Simple example:*
```
{% component 'contenteditor' file="filename_in_content.htm" %}
```

##### Properties

* file - Content block filename to edit, optional. If doesnt exists it will autocreate
* fixture - Fixed name for content block, useful for inline texts (headers, spans...)
* tools - List of enabled tools, comma separated (for all use *)

*Example:*
```
{% component 'contenteditor' file="filename_in_content.htm" fixture="h3" tools="bold,italic" %}
```

##### Tools list

* `bold` => Bold (b)
* `italic` => Italic (i)
* `link` => Link (a)
* `align-left` => Align left
* `align-center` => Align center
* `align-right` => Align right
* `heading` => Heading (h1)
* `subheading` => Subheading (h2)
* `subheading3` => Subheading3 (h3)
* `subheading4` => Subheading4 (h4)
* `subheading5` => Subheading5 (h5)
* `paragraph` => Paragraph (p)
* `unordered-list` => Unordered list (ul)
* `ordered-list` => Ordered list (ol)
* `table` => Table
* `indent` => Indent
* `unindent` => Unindent
* `line-break` => Line-break (br)
* `image` => Image upload
* `video` => Video
* `preformatted` => Preformatted (pre)

*Inspired by [Editable plugin](http://octobercms.com/plugin/rainlab-editable) and using Content tools editor http://getcontenttools.com.*
12 changes: 11 additions & 1 deletion assets/contenteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

var editor = ContentTools.EditorApp.get();
editor.init('*[data-editable]', 'data-file');
editor.init('[data-editable], [data-fixture]', 'data-file');

/*
* Save event
Expand Down Expand Up @@ -34,6 +34,16 @@ editor.addEventListener('saved', function (ev) {

});

/*
* Fixture focus
*/
ContentEdit.Root.get().bind('focus', function(element) {
var dataTools = element._parent._domElement.dataset.tools
var tools = (dataTools === '*' ? ContentTools.DEFAULT_TOOLS : [element._parent._domElement.dataset.tools.split(',')]);
if (element.isFixed()) tools = dataTools !== '*' ? tools : [['undo', 'redo', 'remove']];
if (editor.toolbox().tools() !== tools) editor.toolbox().tools(tools);
});

/*
* Predefined tools
*/
Expand Down
13 changes: 13 additions & 0 deletions components/ContentEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ContentEditor extends ComponentBase
{
public $content;
public $file;
public $fixture;
public $tools;
public $buttons;
public $palettes;

Expand All @@ -31,6 +33,15 @@ public function defineProperties()
'description' => 'Content block filename to edit, optional',
'default' => '',
'type' => 'dropdown',
],
'fixture' => [
'title' => 'Content block tag with disabled toolbox',
'description' => 'Fixed name for content block, useful for inline texts (headers, spans...)',
],
'tools' => [
'title' => 'List of enabled tools',
'description' => 'List of enabled tools for selected content (for all use *)',
'default' => '*',
]
];
}
Expand Down Expand Up @@ -58,6 +69,8 @@ public function onRender()
{

$this->file = $this->property('file');
$this->fixture = $this->property('fixture');
$this->tools = $this->property('tools');

// Compatability with RainLab.Translate
if (class_exists('\RainLab\Translate\Classes\Translator')) {
Expand Down
9 changes: 5 additions & 4 deletions components/contenteditor/default.htm
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<div
data-editable
<{% if __SELF__.fixture %}{{ __SELF__.fixture }}{% else %}div{% endif %}
{% if __SELF__.fixture %}data-fixture{% else %}data-editable{% endif %}
data-component="{{ __SELF__ }}::onSave"
data-file="{{ __SELF__.file }}">
data-file="{{ __SELF__.file }}"
data-tools="{{ __SELF__.tools }}">
{{ __SELF__.content|raw }}
</div>
</{% if __SELF__.fixture %}{{ __SELF__.fixture }}{% else %}div{% endif %}>

{% put scripts %}
<script type="text/javascript">
Expand Down
20 changes: 20 additions & 0 deletions lang/sk/lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

return [
'plugin' => [
'name' => 'Content Editor',
'description' => 'Front-end content editor'
],
'settings' => [
'main_settings' => 'Hlavné nastavenia',
'style_palettes' => 'Palety štýlov',
'buttons' => 'Tlačidlá',
'permissions' => 'Práva',
'permissions_comment' => 'Zobraziť Content editor iba pre',
'image_folder' => 'Zložka pre obrázky',
'image_folder_comment' => 'Upload obrázkov do priečinku v MediaLibrary',
'name' => 'Názov',
'class' => 'Trieda',
'allowed_tags' => 'Povolené tagy',
]
];
6 changes: 5 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
- Settings in backend
1.0.4:
- Enabled taglist input for selecting tags
- Fixed some bugs
- Fixed some bugs
1.0.5:
- Added fixture option
- Added tools option
- Added Slovak translation

0 comments on commit 8357382

Please sign in to comment.