1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-15 09:34:14 +02:00

Flextype Box Plugin: Admin #125 #117

- Entries Controller/Views implementation
This commit is contained in:
Awilum
2019-06-05 11:42:23 +03:00
parent 4e6f55180b
commit 2d4b5bdb56
2 changed files with 45 additions and 18 deletions

View File

@@ -75,6 +75,37 @@
<script src="https://cdn.jsdelivr.net/npm/@editorjs/marker@latest"></script><!-- Marker -->
<script src="https://cdn.jsdelivr.net/npm/@editorjs/inline-code@latest"></script><!-- Inline Code -->
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
<script>
/**
* Module to compose output JSON preview
*/
const cPreview = (function (module) {
/**
* Shows JSON in pretty preview
* @param {object} output - what to show
* @param {Element} holder - where to show
*/
module.show = function(output, holder) {
/** Make JSON pretty */
output = JSON.stringify( output, null, 4 );
/** Encode HTML entities */
output = encodeHTMLEntities( output );
/** Stylize! */
//output = stylize( output );
holder.innerHTML = output;
};
/**
* Converts '>', '<', '&' symbols to entities
*/
function encodeHTMLEntities(string) {
return string.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
return module;
})({});
</script>
{% endif %}
@@ -319,6 +350,10 @@
$("#form" ).submit();
});
$('.js-save-editor-form-submit').click(function() {
$("#form").submit();
});
$('.navbar-toggler').click(function () {
$('.sidebar').addClass('show-sidebar');
$('.sidebar-off-canvas').addClass('show-sidebar-off-canvas');

View File

@@ -1,13 +1,14 @@
<div id="{{ form_element }}" class="editor"></div>
<div class="js-editor">
<div id="{{ form_element }}" class="editor"></div>
<textarea id="textarea_{{ form_element }}" name="{{ form_element }}" rows="8" cols="80" style="display:none;"></textarea>
<a href="javascript:;" id="saveButton{{ form_element }}" class="js-editor-save-button">save</a>
</div>
<script>
{% if is_current_path('admin.entries.edit') %}
/**
* Saving button
*/
//const saveButton = document.getElementById('saveButton');
var saveButton_{{ form_element }} = document.getElementById('saveButton{{ form_element }}');
/**
* To initialize the Editor, create a new instance with configuration object
@@ -83,21 +84,12 @@
*/
data: {},
onReady: function(){
saveButton.click();
},
onChange: function() {
console.log('something changed');
{{ form_element }}.save().then((savedData) => {
cPreview.show(savedData, document.getElementById("textarea_{{ form_element }}"));
});
}
});
/**
* Saving example
*/
saveButton.addEventListener('click', function () {
editor.save().then((savedData) => {
//cPreview.show(savedData, document.getElementById("output"));
});
});
{% endif %}