diff --git a/app/escriptorium/templates/core/document_form.html b/app/escriptorium/templates/core/document_form.html index c6cb28d666d63a1c89d28614d54c6a430688aad3..baaf9abf1a7800e52d5d28bdbb5248ad876f6e8b 100644 --- a/app/escriptorium/templates/core/document_form.html +++ b/app/escriptorium/templates/core/document_form.html @@ -1,5 +1,5 @@ {% extends 'core/document_nav.html' %} -{% load i18n staticfiles bootstrap %} +{% load i18n staticfiles bootstrap json %} {% block head_title %}{% if object %}{% trans "Update a Document" %}{% else %}{% trans "Create a new Document" %}{% endif %}{% endblock %} {% block nav-doc-active %}active{% endblock %} @@ -173,9 +173,11 @@ </script> {{ block.super }} <script type="text/javascript"> - $(document).ready(function(){ - bootDocumentForm(); - bootHelp(); - }); + $(document).ready(function(){ + var scripts = { {% for script in form.fields.main_script.queryset %} + '{{script.pk}}':'{{script.text_direction}}',{% endfor %} }; + bootDocumentForm(scripts); + bootHelp(); + }); </script> {% endblock %} diff --git a/front/src/document_form.js b/front/src/document_form.js index 20d352c7312ac10395e7f1dae68c0c3bc9f7bab3..a4461987d3cfb63acb7a495ec7596732cfb1c1aa 100644 --- a/front/src/document_form.js +++ b/front/src/document_form.js @@ -1,6 +1,6 @@ 'use strict'; /**** Metadata stuff ****/ -export function bootDocumentForm() { +export function bootDocumentForm(scripts) { // delete a metadata row $('.js-metadata-delete').click(function(ev) { var btn = ev.target; @@ -119,4 +119,19 @@ export function bootDocumentForm() { window.location.hash = this.hash; } }); + + // When selecting a rtl script, select rtl read direction + // flash shortly the read direction to tell the user when it changed + $('#id_main_script').on('change', function(ev) { + let dir = scripts[ev.target.value]; + if (dir=='horizontal-rl') { + if ($('#id_read_direction').val() !== 'rtl') { + $('#id_read_direction').val('rtl').addClass('is-valid').removeClass('is-valid', 1000); + } + } else { + if ($('#id_read_direction').val() !== 'ltr') { + $('#id_read_direction').val('ltr').addClass('is-valid').removeClass('is-valid', 1000); + } + } + }); }