Merged in feature/editor-plugins (pull request #53)
Add additional editor plugins for instrument WYSIWYG editor Approved-by: Christian Cueni
This commit is contained in:
commit
e9d1552505
|
|
@ -2,15 +2,15 @@
|
||||||
<div class="instrument">
|
<div class="instrument">
|
||||||
<h1 class="instrument__title">{{instrument.title}}</h1>
|
<h1 class="instrument__title">{{instrument.title}}</h1>
|
||||||
|
|
||||||
<content-component v-for="component in instrument.contents"
|
<content-component v-for="component in instrument.contents"
|
||||||
:key="component.id"
|
:key="component.id"
|
||||||
:component="component"
|
:component="component"
|
||||||
:root="instrument.slug"
|
:root="instrument.slug"
|
||||||
:parent="instrument"
|
:parent="instrument"
|
||||||
:bookmarks="instrument.bookmarks"
|
:bookmarks="instrument.bookmarks"
|
||||||
:notes="instrument.notes"
|
:notes="instrument.notes"
|
||||||
>
|
>
|
||||||
</content-component>
|
</content-component>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -59,19 +59,32 @@
|
||||||
& p {
|
& p {
|
||||||
margin-bottom: 40px;
|
margin-bottom: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
& ul {
|
& ul {
|
||||||
padding-left: 25px;
|
padding-left: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
& p + ul {
|
& p + ul {
|
||||||
margin-top: -30px;
|
margin-top: -30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
& li {
|
& li {
|
||||||
list-style: disc;
|
list-style: disc;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
& b {
|
& b {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
color: $color-brand;
|
color: $color-brand;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary {
|
||||||
|
color: $color-accent-2;
|
||||||
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ from wagtail.snippets.blocks import SnippetChooserBlock
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
from surveys.models import Survey
|
from surveys.models import Survey
|
||||||
|
|
||||||
DEFAULT_RICH_TEXT_FEATURES = ['ul']
|
DEFAULT_RICH_TEXT_FEATURES = ['ul', ]
|
||||||
INSTRUMENTS_RICH_TEXT_FEATURES = ['bold', 'ul']
|
INSTRUMENTS_RICH_TEXT_FEATURES = ['bold', 'ul', 'brand', 'secondary']
|
||||||
|
|
||||||
|
|
||||||
# link_block
|
# link_block
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
|
||||||
|
from wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandler
|
||||||
|
from wagtail.core import hooks
|
||||||
|
|
||||||
|
# 1. Use the register_rich_text_features hook.
|
||||||
|
@hooks.register('register_rich_text_features')
|
||||||
|
def register_brand_feature(features):
|
||||||
|
"""
|
||||||
|
Registering the feature, which uses the `BRAND` Draft.js inline style type,
|
||||||
|
and is stored as HTML with a `<span class="brand">` tag.
|
||||||
|
"""
|
||||||
|
feature_name = 'brand'
|
||||||
|
type_ = 'BRAND'
|
||||||
|
|
||||||
|
# 2. Configure how Draftail handles the feature in its toolbar.
|
||||||
|
control = {
|
||||||
|
'type': type_,
|
||||||
|
'label': 'Grün',
|
||||||
|
'description': 'Grün',
|
||||||
|
'style': {
|
||||||
|
'color': '#17A887',
|
||||||
|
'font-weight': '600'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# 3. Call register_editor_plugin to register the configuration for Draftail.
|
||||||
|
features.register_editor_plugin(
|
||||||
|
'draftail', feature_name, draftail_features.InlineStyleFeature(control)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 4.configure the content transform from the DB to the editor and back.
|
||||||
|
db_conversion = {
|
||||||
|
'from_database_format': {'span[class="brand"]': InlineStyleElementHandler(type_)},
|
||||||
|
'to_database_format': {'style_map': {type_: 'span class="brand""'}},
|
||||||
|
}
|
||||||
|
|
||||||
|
# 5. Call register_converter_rule to register the content transformation conversion.
|
||||||
|
features.register_converter_rule('contentstate', feature_name, db_conversion)
|
||||||
|
|
||||||
|
# 6. (optional) Add the feature to the default features list to make it available
|
||||||
|
# on rich text fields that do not specify an explicit 'features' list
|
||||||
|
features.default_features.append(feature_name)
|
||||||
|
|
||||||
|
@hooks.register('register_rich_text_features')
|
||||||
|
def register_secondary_feature(features):
|
||||||
|
"""
|
||||||
|
Registering the feature, which uses the `SECONDARY` Draft.js inline style type,
|
||||||
|
and is stored as HTML with a `<span class="secondary">` tag.
|
||||||
|
"""
|
||||||
|
feature_name = 'secondary'
|
||||||
|
type_ = 'SECONDARY'
|
||||||
|
|
||||||
|
# 2. Configure how Draftail handles the feature in its toolbar.
|
||||||
|
control = {
|
||||||
|
'type': type_,
|
||||||
|
'label': 'Blau',
|
||||||
|
'description': 'Blau',
|
||||||
|
'style': {
|
||||||
|
'color': '#078CC6',
|
||||||
|
'font-weight': '600'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# 3. Call register_editor_plugin to register the configuration for Draftail.
|
||||||
|
features.register_editor_plugin(
|
||||||
|
'draftail', feature_name, draftail_features.InlineStyleFeature(control)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 4.configure the content transform from the DB to the editor and back.
|
||||||
|
db_conversion = {
|
||||||
|
'from_database_format': {'span[class="secondary"]': InlineStyleElementHandler(type_)},
|
||||||
|
'to_database_format': {'style_map': {type_: 'span class="secondary"'}},
|
||||||
|
}
|
||||||
|
|
||||||
|
# 5. Call register_converter_rule to register the content transformation conversion.
|
||||||
|
features.register_converter_rule('contentstate', feature_name, db_conversion)
|
||||||
|
|
||||||
|
# 6. (optional) Add the feature to the default features list to make it available
|
||||||
|
# on rich text fields that do not specify an explicit 'features' list
|
||||||
|
features.default_features.append(feature_name)
|
||||||
Loading…
Reference in New Issue