This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Components/BlockWysiwyg): add component (#179)
- Loading branch information
1 parent
650837a
commit 9d08f57
Showing
7 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"layout": { | ||
"name": "blockWysiwyg", | ||
"label": "Block: Wysiwyg", | ||
"sub_fields": [ | ||
{ | ||
"name": "contentHtml", | ||
"label": "Content", | ||
"type": "wysiwyg", | ||
"delay": 1, | ||
"media_upload": 0, | ||
"toolbar": "full", | ||
"required": 1 | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Flynt\Components\BlockWysiwyg; | ||
|
||
use Flynt\Features\Components\Component; | ||
|
||
add_action('wp_enqueue_scripts', function () { | ||
Component::enqueueAssets('BlockWysiwyg'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
# Developer HowTo´s | ||
|
||
### Editor Toolbar | ||
|
||
The MCE Buttons that show up by default are specified in the **TinyMce Feature**, in the `mce_buttons` filter. | ||
|
||
You can either modify that Feature to modify all the wysiwyg toolbars globally (all over your project), or define a specific configuration for one specific wysiwyg field, by using the `acf/fields/wysiwyg/toolbars` acf filter on your `functions.php` file. | ||
|
||
#### To change the Toolbar globally on every TinyMce | ||
Go to the [TinyMce Feature](../../Features/TinyMce/README.md). | ||
|
||
#### To define a specific configuration for one specific Wysiwyg field | ||
Go to the component (`Wysiwyg` here) `functions.php` file, and use the `acf/fields/wysiwyg/toolbars` acf filter: | ||
|
||
```php | ||
<?php | ||
add_filter('acf/fields/wysiwyg/toolbars', function ($toolbars) { | ||
$toolbars['myCustomToolbar'] = []; | ||
$toolbars['myCustomToolbar'][1] = [ | ||
'formatselect', | ||
'styleselect', | ||
'bold', | ||
'italic', | ||
'underline', | ||
'strikethrough', | ||
'|', | ||
'bullist', | ||
'numlist', | ||
'|', | ||
'outdent', | ||
'indent', | ||
'blockquote', | ||
'hr', | ||
'|', | ||
'alignleft', | ||
'aligncenter', | ||
'alignright', | ||
'alignjustify', | ||
'|', | ||
'link', | ||
'unlink', | ||
'|', | ||
'forecolor', | ||
'wp_more', | ||
'charmap', | ||
'spellchecker', | ||
'pastetext', | ||
'removeformat', | ||
'|', | ||
'undo', | ||
'redo', | ||
'wp_help', | ||
'fullscreen', | ||
'wp_adv', // toogle second bar button | ||
]; | ||
return $toolbars; | ||
}); | ||
``` | ||
|
||
In this example, we create a new toolbar called `myCustomToolbar`. You define which buttons show up. Then you need to specify that toolbar on your Wysiwyg field configuration (fields.json): | ||
|
||
```json | ||
{ | ||
"name": "contentHTML", | ||
"label": "Content", | ||
"type": "wysiwyg", | ||
"media_upload": 0, | ||
"required": 1, | ||
"toolbar": "myCustomToolbar" | ||
} | ||
``` | ||
|
||
### Editor Styles | ||
|
||
You can also create new **styles**, globally by modifying the [TinyMce Feature](../../Features/TinyMce/README.md). | ||
|
||
Unfortunately there is no way to have a stylesheet to a specific acf Wysiwyg field as it is possible for toolbars. So your stylesheet will be applied to all TinyMce instances. | ||
|
||
|
||
## Snippets | ||
### Default Theme | ||
|
||
`fields.json` | ||
```json | ||
{ | ||
"layout": { | ||
"name": "blockWysiwyg", | ||
"label": "Block Wysiwyg", | ||
"sub_fields": [ | ||
{ | ||
"name": "settingsTab", | ||
"label": "Settings", | ||
"type": "tab" | ||
}, | ||
{ | ||
"name": "theme", | ||
"label": "Theme", | ||
"type": "select", | ||
"choices": { | ||
"": "---", | ||
"wysiwyg-fullwidth": "Fullwidth", | ||
"wysiwyg-narrow": "Narrow" | ||
}, | ||
"default_value": "" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
`index.twig` | ||
```html | ||
<div class="blockWysiwyg {{ theme }}"></div> | ||
``` | ||
|
||
`style.styl` | ||
```stylus | ||
$containerMaxWidth = lookup('$global-layout-containerMaxWidth') || 1140px | ||
$narrowWidth = lookup('$global-layout-narrowWidth') || 650px | ||
[is='flynt-block-wysiwyg'] | ||
.blockWysiwyg | ||
center($containerMaxWidth, $gutterWidth) | ||
&-fullwidth | ||
center($containerMaxWidth, $gutterWidth) | ||
&-narrow | ||
center($narrowWidth, $gutterWidth) | ||
``` | ||
|
||
## Additional Global Default Theme | ||
|
||
To add an additional Global Default Theme simply add the following code to the Default Theme solution from above. | ||
|
||
`fields.json` | ||
```json | ||
{ | ||
"options": [ | ||
{ | ||
"name": "defaultTheme", | ||
"label": "Default Theme", | ||
"type": "select", | ||
"choices": { | ||
"": "---", | ||
"wysiwyg-fullwidth": "Fullwidth", | ||
"wysiwyg-narrow": "Narrow" | ||
}, | ||
"default_value": "" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
`functions.php` | ||
```php | ||
<?php | ||
add_filter('Flynt/addComponentData?name=BlockWysiwyg', function ($data) { | ||
if (empty($data['theme'])) { | ||
$data['theme'] = get_field('defaultTheme', 'options'); | ||
} | ||
return $data; | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div is="flynt-block-wysiwyg" class="flyntComponent"> | ||
<div class="blockWysiwyg"> | ||
{{ contentHtml }} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Title: Block Wysiwyg | ||
|
||
---- | ||
|
||
Category: Block | ||
|
||
---- | ||
|
||
Tags: wysiwyg, content, html, dom | ||
|
||
---- | ||
|
||
Text: Content Editor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
$rupture.scale = lookup('$global-layout-scale') || (0 576px 768px 992px 1200px) | ||
$rupture.anti-overlap = lookup('$global-layout-overlap') || -1px | ||
$gutterWidth = lookup('$global-layout-gutterWidth') || 15px | ||
$containerMaxWidth = lookup('$global-layout-containerMaxWidth') || 1140px | ||
|
||
[is='flynt-block-wysiwyg'] | ||
*, | ||
*:before, | ||
*:after | ||
box-sizing: border-box | ||
|
||
.blockWysiwyg | ||
center($containerMaxWidth, $gutterWidth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters