mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
scroll to tag block, review suggestions, cleanup
This commit is contained in:
parent
4010a8a277
commit
343078678a
1 changed files with 3 additions and 25 deletions
|
@ -2,6 +2,7 @@
|
||||||
* Fetch and display preview images for various image upload forms.
|
* Fetch and display preview images for various image upload forms.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { assertNotNull } from './utils/assert';
|
||||||
import { fetchJson, handleError } from './utils/requests';
|
import { fetchJson, handleError } from './utils/requests';
|
||||||
import { $, $$, clearEl, hideEl, makeEl, showEl } from './utils/dom';
|
import { $, $$, clearEl, hideEl, makeEl, showEl } from './utils/dom';
|
||||||
import { addTag } from './tagsinput';
|
import { addTag } from './tagsinput';
|
||||||
|
@ -173,9 +174,8 @@ function setupImageUpload() {
|
||||||
|
|
||||||
function createTagError(message) {
|
function createTagError(message) {
|
||||||
const buttonAfter = $('#tagsinput-save');
|
const buttonAfter = $('#tagsinput-save');
|
||||||
const errorElement = makeEl('span', { className: 'help-block tag-error' });
|
const errorElement = makeEl('span', { className: 'help-block tag-error', innerText: message });
|
||||||
|
|
||||||
errorElement.innerText = message;
|
|
||||||
buttonAfter.insertAdjacentElement('beforebegin', errorElement);
|
buttonAfter.insertAdjacentElement('beforebegin', errorElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,14 +229,6 @@ function setupImageUpload() {
|
||||||
return errors.length === 0; // true: valid if no errors
|
return errors.length === 0; // true: valid if no errors
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableUploadButton() {
|
|
||||||
const submitButton = $('.input--separate-top');
|
|
||||||
if (submitButton !== null) {
|
|
||||||
submitButton.disabled = false;
|
|
||||||
submitButton.innerText = 'Upload';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function disableUploadButton() {
|
function disableUploadButton() {
|
||||||
const submitButton = $('.button.input--separate-top');
|
const submitButton = $('.button.input--separate-top');
|
||||||
if (submitButton !== null) {
|
if (submitButton !== null) {
|
||||||
|
@ -248,17 +240,6 @@ function setupImageUpload() {
|
||||||
requestAnimationFrame(() => submitButton.setAttribute('disabled', 'disabled'));
|
requestAnimationFrame(() => submitButton.setAttribute('disabled', 'disabled'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollToTags() {
|
|
||||||
const taginputEle = $('#taginput-fancy-tag_input');
|
|
||||||
|
|
||||||
if (!taginputEle) {
|
|
||||||
// default to scroll to top
|
|
||||||
window.scrollTo({ top: 0, left: 0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
taginputEle.scrollIntoView();
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitHandler(event) {
|
function submitHandler(event) {
|
||||||
// Remove any existing tag error elements
|
// Remove any existing tag error elements
|
||||||
clearTagErrors();
|
clearTagErrors();
|
||||||
|
@ -273,10 +254,7 @@ function setupImageUpload() {
|
||||||
// Let the form submission complete
|
// Let the form submission complete
|
||||||
} else {
|
} else {
|
||||||
// Scroll to view validation errors
|
// Scroll to view validation errors
|
||||||
scrollToTags();
|
assertNotNull($('.fancy-tag-upload')).scrollIntoView();
|
||||||
|
|
||||||
// allow users to re-submit the form
|
|
||||||
enableUploadButton();
|
|
||||||
|
|
||||||
// Prevent the form from being submitted
|
// Prevent the form from being submitted
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
Loading…
Reference in a new issue