5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 02:06:21 +00:00

eliminar la dependencia en zepto

This commit is contained in:
f 2020-11-19 21:23:23 -03:00
parent 2d46c68904
commit 5e15653b2d
6 changed files with 56 additions and 60 deletions

View file

@ -2,5 +2,4 @@
//= require turbolinks //= require turbolinks
//= require input-tag/input-tag.js //= require input-tag/input-tag.js
//= require input-map/input-map.js //= require input-map/input-map.js
//= require zepto/dist/zepto.min.js
//= require_tree . //= require_tree .

View file

@ -1,11 +1,11 @@
$(document).on('turbolinks:load', function() { document.addEventListener('turbolinks:load', () => {
$('input[type=file]').on('change', function(event) { document.querySelectorAll('input[type=file]').forEach(file => {
if (event.target.files.length == 0) return; if (!file.dataset.preview) return
var input = $(event.target); file.addEventListener('change', event => {
var preview = $(`#${input.data('preview')}`); if (file.files.length === 0) return
preview.attr('src', document.querySelector('#' + file.dataset.preview).src = window.URL.createObjectURL(file.files[0])
window.URL.createObjectURL(event.target.files[0])); })
}); })
}); })

View file

@ -1,19 +1,13 @@
$(document).on('turbolinks:load', function() { document.addEventListener('turbolinks:load', () => {
$('.taggable').each(function() { document.querySelectorAll('.taggable').forEach(target => {
this.innerHTML = ''; target.innerHTML = ''
new InputTag({ new InputTag({ target, props: { ...target.dataset } })
target: this, })
props: { ...this.dataset }
});
});
$('.mapable').each(function() { document.querySelectorAll('.mapable').forEach(target => {
this.innerHTML = ''; target.innerHTML = ''
new InputMap({ new InputMap({ target, props: { ...target.dataset } })
target: this, })
props: { ...this.dataset } })
});
});
});

View file

@ -1,3 +1,3 @@
$(document).on('turbolinks:load', function() { document.addEventListener('turbolinks:load', () => {
$('a[href^="#"]').data('turbolinks', false); document.querySelectorAll('a[href^="#"]').forEach(a => a.data.turbolinks = false)
}); })

View file

@ -1,37 +1,35 @@
$(document).on('turbolinks:load', function() { document.addEventListener('turbolinks:load', () => {
// Al enviar el formulario del artículo, aplicar la validación // Al enviar el formulario del artículo, aplicar la validación
$('.submit-post').click(function(e) { // localmente y actualizar los comentarios para lectores de pantalla.
var form = $(this).parents('form.form'); document.querySelectorAll('.submit-post').forEach(submit => {
var invalid_help = $('.invalid_help'); submit.addEventListener('click', event => {
var sending_help = $('.sending_help'); const form = submit.closest('form')
const invalid_help = form.querySelectorAll('.invalid_help')
const sending_help = form.querySelectorAll('.sending_help')
invalid_help.addClass('d-none'); invalid_help.forEach(i => i.classList.add('d-none'))
sending_help.addClass('d-none'); sending_help.forEach(i => i.classList.add('d-none'))
form.find('[aria-invalid="true"]')
.attr('aria-invalid', false)
.attr('aria-describedby', function() {
return $(this).siblings('.feedback').attr('id');
});
if (form[0].checkValidity() === false) { form.querySelectorAll('[aria-invalid="true"]').forEach(aria => {
e.preventDefault(); aria.setAttribute('aria-invalid', false)
e.stopPropagation(); aria.setAttribute('aria-describedby', aria.parentElement.querySelector('.feedback').id)
invalid_help.removeClass('d-none'); })
form.find(':invalid') if (form.checkValidity() === false) {
.attr('aria-invalid', true) event.preventDefault()
.attr('aria-describedby', function() { event.stopPropagation()
return $(this).siblings('.invalid-feedback').attr('id');
});
} else {
sending_help.removeClass('d-none');
}
form.addClass('was-validated'); invalid_help.forEach(i => i.classList.remove('d-none'))
});
$('.submit-post-incomplete').click(function(e) { form.querySelectorAll(':invalid').forEach(invalid => {
$('.sending_help').removeClass('d-none'); invalid.setAttribute('aria-invalid', true)
}); invalid.setAttribute('aria-describedby', invalid.parentElement.querySelector('.invalid-feedback').id)
}); })
} else {
sending_help.forEach(i => i.classList.remove('d-none'))
}
form.classList.add('was-validated')
})
})
})

View file

@ -10,6 +10,11 @@
.custom-control.custom-switch .custom-control.custom-switch
= check_box_tag "post[#{attribute}][path]", '', false, id: "post_#{attribute}_destroy", class: 'custom-control-input' = check_box_tag "post[#{attribute}][path]", '', false, id: "post_#{attribute}_destroy", class: 'custom-control-input'
= label_tag "post_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label' = label_tag "post_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label'
- else
= image_tag '',
alt: metadata.value['description'],
class: 'img-fluid',
id: "#{attribute}-preview"
.custom-file .custom-file
= file_field(*field_name_for('post', attribute, :path), = file_field(*field_name_for('post', attribute, :path),