IMPR: minor updates

This commit is contained in:
Tony Air 2022-08-14 22:29:09 +02:00
parent 3693b9a9ca
commit 700c2771a6
6 changed files with 52 additions and 24 deletions

View File

@ -13,8 +13,8 @@ const CarouselUI = ((window) => {
interval, interval,
}) })
el.ui = carousel el.ui = carousel
const items = el.querySelectorAll('.carousel-item') let items = el.querySelectorAll('.carousel-item')
const numberOfItems = parseInt(items.length) let numberOfItems = parseInt(items.length)
// create next/prev arrows // create next/prev arrows
if (el.dataset.bsArrows) { if (el.dataset.bsArrows) {
@ -89,12 +89,21 @@ const CarouselUI = ((window) => {
if (el.classList.contains('carousel-multislide')) { if (el.classList.contains('carousel-multislide')) {
const inner = el.querySelector('.carousel-inner') const inner = el.querySelector('.carousel-inner')
const items = el.querySelectorAll('.carousel-item')
// add next elements by cloning originals
items.forEach((el, i) => {
const newItem = el.cloneNode(true);
newItem.classList.remove('active');
inner.appendChild(newItem);
});
items = el.querySelectorAll('.carousel-item')
numberOfItems = parseInt(items.length)
// fix animation glitch // fix animation glitch
inner.style.left = '0px' inner.style.left = '0px'
const calculate = new window.ResizeObserver((entries) => { const calculate = (entries) => {
const entry = entries[0] const entry = entries[0]
const el = entry.target const el = entry.target
const rect = entry.contentRect const rect = entry.contentRect
@ -106,7 +115,7 @@ const CarouselUI = ((window) => {
el.dataset.itemWidth = itemWidth el.dataset.itemWidth = itemWidth
el.dataset.numToDisplay = numToDisplay el.dataset.numToDisplay = numToDisplay
el.querySelector('.carousel-inner').style.width = `${numberOfItems * itemWidth}px` inner.style.width = `${numberOfItems * itemWidth}px`
items.forEach((el, i) => { items.forEach((el, i) => {
el.style.width = `${itemWidth}px` el.style.width = `${itemWidth}px`
}) })
@ -115,28 +124,38 @@ const CarouselUI = ((window) => {
el.classList.add('js-carousel-no-slide') el.classList.add('js-carousel-no-slide')
carousel.pause() carousel.pause()
} }
}) };
calculate.observe(el) const calcResize = new window.ResizeObserver(calculate)
el.addEventListener('slide.bs.carousel', (e) => { calcResize.observe(el)
// infinite scroll const resetPosition = () => {
const numToDisplay = Math.min(parseInt(el.dataset.length), numberOfItems)
if(numberOfItems - numToDisplay < e.to) {
// disable transition // disable transition
//inner.style.transition = 'none' inner.style.transition = 'none'
inner.classList.add('no-transition')
inner.style.left = '0px'
// enable transition
setTimeout(() => {
inner.style.transition = ''
inner.classList.remove('no-transition')
inner.querySelectorAll('.carousel-item').forEach((el) => { inner.querySelectorAll('.carousel-item').forEach((el) => {
el.classList.remove('active') el.classList.remove('active')
}) })
inner.querySelector('.carousel-item:first-child').classList.add('active') inner.querySelector('.carousel-item:first-child').classList.add('active')
inner.style.left = '0px' }, 1000);
};
el.addEventListener('slide.bs.carousel', (e) => {
// infinite scroll
const numToDisplay = Math.min(parseInt(el.dataset.length), numberOfItems)
console.log(`.${NAME}: ${e.to} ${numberOfItems / 2}`);
if(numberOfItems - numToDisplay < e.to){
e.preventDefault(); e.preventDefault();
resetPosition();
// enable transition
//inner.style.transition = ''
return; return;
} }
// //
@ -149,6 +168,10 @@ const CarouselUI = ((window) => {
inner.style.left = `${-(e.to * el.dataset.itemWidth)}px` inner.style.left = `${-(e.to * el.dataset.itemWidth)}px`
break break
} }
if(numberOfItems / 2 === e.to){
resetPosition();
}
}) })
el.classList.add(`${NAME}-multislide-active`) el.classList.add(`${NAME}-multislide-active`)

View File

@ -38,6 +38,7 @@ const DatetimeUI = (($) => {
const defaultDate = const defaultDate =
$el.attr('name').toLowerCase().indexOf('end') !== -1 ? '+4d' : '+3d' $el.attr('name').toLowerCase().indexOf('end') !== -1 ? '+4d' : '+3d'
$el.attr('type', 'text')
$el.attr('readonly', 'true') $el.attr('readonly', 'true')
$el.datepicker( $el.datepicker(
$.extend( $.extend(

View File

@ -2,7 +2,7 @@
import $ from 'jquery' import $ from 'jquery'
import select2 from 'select2/dist/js/select2.js' import 'select2/dist/js/select2.js'
import Events from '../_events' import Events from '../_events'
const FormSelect2 = (($) => { const FormSelect2 = (($) => {

View File

@ -46,14 +46,15 @@ const FormValidate = (($) => {
ui.validate(true, () => { ui.validate(true, () => {
e.preventDefault() e.preventDefault()
const $el = $element.find('.error').first()
// switch to step // switch to step
if (ui._stepped_form) { if (ui._stepped_form) {
const $el = $element.find('.error').first()
if ($el.length) { if ($el.length) {
ui._stepped_form.step($el.parents('.step')) ui._stepped_form.step($el.parents('.step'))
} }
} }
// scroll to error
$el[0].scrollIntoView()
$element.trigger(Events.FORM_VALIDATION_FAILED) $element.trigger(Events.FORM_VALIDATION_FAILED)
}) })

View File

@ -45,3 +45,7 @@
overflow: visible; overflow: visible;
} }
} }
.no-transition {
transition: none!important;
}

View File

@ -1,7 +1,6 @@
// Bootstrap // Bootstrap
// Configuration // Configuration
@import "~bootstrap/scss/functions"; @import "~bootstrap/scss/functions";
@import "~bootstrap/scss/maps";
@import "~bootstrap/scss/variables"; @import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins"; @import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/utilities"; @import "~bootstrap/scss/utilities";