Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live preview #2462

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions assets/js/app/editor/Components/LivePreview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<transition name="card">
<iframe name="preview_area"></iframe>
</transition>
</template>

<script>
export default {
name: 'LivePreview',
mounted() {
$(document.getElementById('editcontent').elements).change(function(){
// Submit the live preview
$("#live_preview").click();
})
},
}
</script>

<style scoped>
iframe[name="preview_area"] {
width: 100%;
height: 100%;
min-height: 70vh;
border: none;
}
</style>
2 changes: 2 additions & 0 deletions assets/js/app/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Filelist from './Components/Filelist';
import Collection from './Components/Collection';
import Checkbox from './Components/Checkbox';
import UnsavedChangesWarning from './unsavedchanges';
import LivePreview from './Components/LivePreview';

Vue.component('editor-checkbox', Checkbox);
Vue.component('editor-date', Date);
Expand All @@ -45,6 +46,7 @@ Vue.component('editor-text', Text);
Vue.component('editor-textarea', Textarea);
Vue.component('editor-collection', Collection);
Vue.component('editor-set', Set);
Vue.component('editor-live-preview', LivePreview);
Vue.component('general-language', Language);
Vue.component('theme-select', ThemeSelect);

Expand Down
12 changes: 12 additions & 0 deletions templates/content/_buttons.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
'btn- dropdown-button mb-0',
{ 'target': '_blank' }
) }}

{{ macro.button(
'action.live_preview',
'fa-tablet',
'primary mb-0',
{
'id': 'live_preview',
'type': 'submit',
'form': 'editcontent',
'formtarget': 'preview_area',
'formaction': path('bolt_content_edit_preview', {'id': record.id|default(0) })
}) }}
</div>
</div>
{% endif %}
Expand Down
65 changes: 38 additions & 27 deletions templates/content/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,60 @@

{% block main %}

{% if record.definition.virtual|default(false) %}
<div class="alert alert-danger" role="alert">
{{ 'content.edit_missing_definition'|trans({'%contenttype%': record.definition.name}) }}
</div>
{% endif %}

{% if errors is defined %}
{%for error in errors %}
<div style="display: flex; gap: 5%;">
<div style="flex: 1;">
{% if record.definition.virtual|default(false) %}
<div class="alert alert-danger" role="alert">
{{ error.propertyPath }}: {{error.message}}
{{ 'content.edit_missing_definition'|trans({'%contenttype%': record.definition.name}) }}
</div>
{%endfor%}
{% endif %}
{% endif %}

{% if errors is defined %}
{%for error in errors %}
<div class="alert alert-danger" role="alert">
{{ error.propertyPath }}: {{error.message}}
</div>
{%endfor%}
{% endif %}

<form method="post" id="editcontent">

<form method="post" id="editcontent">
<input type="hidden" name="_csrf_token" value="{{ csrf_token('editrecord') }}">
<input type="hidden" name="_edit_locale" value="{{ currentlocale }}">
{# To prevent confusion in browsers about which submit to use when pressing 'enter', we
provide this _input_ here. All browsers will use this as a default. See #454 on Github. #}
<input type="submit" form="editcontent" style="display: none;" value="__('action.save')">

<input type="hidden" name="_csrf_token" value="{{ csrf_token('editrecord') }}">
<input type="hidden" name="_edit_locale" value="{{ currentlocale }}">
{# To prevent confusion in browsers about which submit to use when pressing 'enter', we
provide this _input_ here. All browsers will use this as a default. See #454 on Github. #}
<input type="submit" form="editcontent" style="display: none;" value="__('action.save')">
{% set groups = record.definition.groups|default([]) %}

{% set groups = record.definition.groups|default([]) %}
{% include '@bolt/content/_tabs.html.twig' %}

{% include '@bolt/content/_tabs.html.twig' %}
<div class="tab-content" id="nav-tabContent">

<div class="tab-content" id="nav-tabContent">
{% include '@bolt/content/_fields.html.twig' %}

{% include '@bolt/content/_fields.html.twig' %}
<div class="tab-pane" id="relations" role="tabpanel" aria-labelledby="relations-tab">

<div class="tab-pane" id="relations" role="tabpanel" aria-labelledby="relations-tab">
{% include '@bolt/content/_relationships.html.twig' %}

{% include '@bolt/content/_relationships.html.twig' %}
{% include '@bolt/content/_taxonomies.html.twig' %}
</div>

{% include '@bolt/content/_taxonomies.html.twig' %}
</div>

<hr>
{% include '@bolt/content/_buttons.html.twig' with {'hide_on_mobile': true} %}

</form>

</div>

<hr>
{% include '@bolt/content/_buttons.html.twig' with {'hide_on_mobile': true} %}
<div style="flex: 1;">
<editor-live-preview></editor-live-preview>
{# <iframe style="width: 100%; height: 100%;" name="preview" src=""></iframe>#}
</div>

</form>
</div>

{% endblock %}

Expand Down
6 changes: 6 additions & 0 deletions translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2613,5 +2613,11 @@
<target>Refresh</target>
</segment>
</unit>
<unit id="a6WWRhQ" name="action.live_preview">
<segment>
<source>action.live_preview</source>
<target>Live preview</target>
</segment>
</unit>
</file>
</xliff>