Skip to content

Commit

Permalink
Merge branch 'dev' into remove_some_jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen authored Jul 1, 2021
2 parents e423d78 + 3b26ab5 commit 6191302
Show file tree
Hide file tree
Showing 43 changed files with 2,065 additions and 2,068 deletions.
1 change: 0 additions & 1 deletion Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ function jsLint() {
function jsPackages() {
return gulp.src([
require.resolve('jquery/dist/jquery.min.js'),
require.resolve('cookies-eu-banner/dist/cookies-eu-banner.min.js'),
require.resolve('moment/min/moment.min.js'),
require.resolve('moment/locale/fr.js'),
require.resolve('chart.js/dist/Chart.min.js'),
Expand Down
41 changes: 18 additions & 23 deletions assets/js/accordeon.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
/* ===== Zeste de Savoir ====================================================
Accordeon for sidebar
---------------------------------
Author: Alex-D
Author: Alex-D, firm1
========================================================================== */

(function($) {
'use strict'
(function() {
function accordeon(element) {
const nextSearchElt = ['OL', 'UL']

function accordeon($elem) {
$('h4 + ul, h4 + ol', $elem).each(function() {
if (!$(this).hasClass('unfolded')) {
if ($('.current', $(this)).length === 0) { $(this).hide() }
}
})
Array.from(element.querySelectorAll('h4 + ul:not(.unfolded), h4 + ol:not(.unfolded)'))
.filter(item => item.querySelectorAll('.current').length === 0)
.forEach(item => item.classList.add('hidden'))

$('h4', $elem).click(function(e) {
$('+ ul, + ol', $(this)).slideToggle(100)

e.preventDefault()
e.stopPropagation()
})
Array.from(element.querySelectorAll('h4'))
.filter(item => nextSearchElt.includes(item.nextElementSibling.nodeName))
.forEach(item => item.addEventListener('click', (e) => {
item.nextElementSibling.classList.toggle('hidden')

e.preventDefault()
e.stopPropagation()
}))
}

$(document).ready(function() {
$('.main .sidebar.accordeon, .main .sidebar .accordeon')
.each(function() {
accordeon($(this))
})
.on('DOMNodeInserted', function(e) {
accordeon($(e.target))
})
window.addEventListener('DOMContentLoaded', () => {
Array.from(document.querySelectorAll('.main .sidebar.accordeon, .main .sidebar .accordeon')).forEach(item => accordeon(item))
})
})(jQuery)
})()
81 changes: 51 additions & 30 deletions assets/js/compare-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,62 @@
* Allow the user to compare two commits
*/

(function($) {
'use strict'

function toogleRadioInput($radioInput) {
var $row = $radioInput.parent().parent()
(function() {
function prevAll(element) {
const result = []
while (element) {
result.push(element)
element = element.previousElementSibling
}
return result
}

if ($radioInput.attr('name') === 'compare-from') {
$row.prevAll().find("[name='compare-to']").prop('disabled', false)
$row.nextAll().find("[name='compare-to']").prop('disabled', true)
$row.find("[name='compare-to']").prop('disabled', true)
} else {
$row.prevAll().find("[name='compare-from']").prop('disabled', true)
$row.nextAll().find("[name='compare-from']").prop('disabled', false)
$row.find("[name='compare-from']").prop('disabled', true)
function nextAll(element) {
const result = []
while (element) {
result.push(element)
element = element.nextElementSibling
}
return result
}

$(".commits-list input[name^='compare']").on('change', function() {
toogleRadioInput($(this))
})
function toogleRadioInput(radioInput) {
const row = radioInput.parentNode.parentNode

$(document).ready(function() {
$(".commits-list input[name^='compare']:checked").each(function() {
toogleRadioInput($(this))
})
})
if (radioInput.getAttribute('name') === 'compare-from') {
prevAll(row).forEach(
r => Array.prototype.forEach.call(r.querySelectorAll('[name="compare-to"]'), elem => elem.removeAttribute('disabled'))
)
nextAll(row).forEach(
r => Array.prototype.forEach.call(r.querySelectorAll('[name="compare-to"]'), elem => elem.setAttribute('disabled', true))
)
Array.prototype.forEach.call(row.querySelectorAll('[name="compare-to"]'), elem => elem.setAttribute('disabled', true))
} else {
prevAll(row).forEach(
r => Array.prototype.forEach.call(r.querySelectorAll('[name="compare-from"]'), elem => elem.setAttribute('disabled', true))
)
nextAll(row).forEach(
r => Array.prototype.forEach.call(r.querySelectorAll('[name="compare-from"]'), elem => elem.removeAttribute('disabled'))
)
Array.prototype.forEach.call(row.querySelectorAll('[name="compare-from"]'), elem => elem.setAttribute('disabled', true))
}
}

$('.commits-compare-form').on('submit', function() {
var $form = $(this)
var $fromInput = $form.find("input[name='from']")
var $toInput = $form.find("input[name='to']")
var compareFrom = $(".commits-list input[name='compare-from']:checked").val()
var compareTo = $(".commits-list input[name='compare-to']:checked").val()
window.addEventListener('DOMContentLoaded', () => {
Array.prototype.forEach.call(document.querySelectorAll('.commits-list input[name^="compare"]:checked'), elem => toogleRadioInput(elem))
Array.prototype.forEach.call(document.querySelectorAll('.commits-list input[name^="compare"]'), elem =>
elem.addEventListener('change', function() {
toogleRadioInput(this)
})
)
Array.prototype.forEach.call(document.querySelectorAll('.commits-compare-form'), elem =>
elem.addEventListener('submit', function(e) {
const compareFrom = document.querySelector(".commits-list input[name='compare-from']:checked").value
const compareTo = document.querySelector(".commits-list input[name='compare-to']:checked").value

$fromInput.val(compareFrom)
$toInput.val(compareTo)
this.querySelector("input[name='from']").value = compareFrom
this.querySelector("input[name='to']").value = compareTo
})
)
})
})(jQuery)
})()
Loading

0 comments on commit 6191302

Please sign in to comment.