Simplified collapse.js with Element.closest().
This commit is contained in:
parent
290eb98764
commit
0f2885e3f6
|
@ -1,16 +1,6 @@
|
|||
/*global gettext*/
|
||||
(function() {
|
||||
'use strict';
|
||||
var closestElem = function(elem, tagName) {
|
||||
if (elem.nodeName === tagName.toUpperCase()) {
|
||||
return elem;
|
||||
}
|
||||
if (elem.parentNode.nodeName === 'BODY') {
|
||||
return null;
|
||||
}
|
||||
return elem.parentNode && closestElem(elem.parentNode, tagName);
|
||||
};
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
// Add anchor tag for Show/Hide link
|
||||
var fieldsets = document.querySelectorAll('fieldset.collapse');
|
||||
|
@ -35,7 +25,7 @@
|
|||
if (ev.target.matches('.collapse-toggle')) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var fieldset = closestElem(ev.target, 'fieldset');
|
||||
var fieldset = ev.target.closest('fieldset');
|
||||
if (fieldset.classList.contains('collapsed')) {
|
||||
// Show
|
||||
ev.target.textContent = gettext('Hide');
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
(function(){var e=function(b,a){return b.nodeName===a.toUpperCase()?b:"BODY"===b.parentNode.nodeName?null:b.parentNode&&e(b.parentNode,a)};window.addEventListener("load",function(){for(var b=document.querySelectorAll("fieldset.collapse"),a=0;a<b.length;a++){var c=b[a];if(0===c.querySelectorAll("div.errors, ul.errorlist").length){c.classList.add("collapsed");c=c.querySelector("h2");var d=document.createElement("a");d.id="fieldsetcollapser"+a;d.className="collapse-toggle";d.href="#";d.textContent=gettext("Show");
|
||||
c.appendChild(document.createTextNode(" ("));c.appendChild(d);c.appendChild(document.createTextNode(")"))}}b=function(a){if(a.target.matches(".collapse-toggle")){a.preventDefault();a.stopPropagation();var b=e(a.target,"fieldset");b.classList.contains("collapsed")?(a.target.textContent=gettext("Hide"),b.classList.remove("collapsed")):(a.target.textContent=gettext("Show"),b.classList.add("collapsed"))}};c=document.querySelectorAll("fieldset.module");for(a=0;a<c.length;a++)c[a].addEventListener("click",
|
||||
b)})})();
|
||||
(function(){window.addEventListener("load",function(){for(var d=document.querySelectorAll("fieldset.collapse"),b=0;b<d.length;b++){var a=d[b];if(0===a.querySelectorAll("div.errors, ul.errorlist").length){a.classList.add("collapsed");a=a.querySelector("h2");var c=document.createElement("a");c.id="fieldsetcollapser"+b;c.className="collapse-toggle";c.href="#";c.textContent=gettext("Show");a.appendChild(document.createTextNode(" ("));a.appendChild(c);a.appendChild(document.createTextNode(")"))}}d=function(a){if(a.target.matches(".collapse-toggle")){a.preventDefault();
|
||||
a.stopPropagation();var b=a.target.closest("fieldset");b.classList.contains("collapsed")?(a.target.textContent=gettext("Hide"),b.classList.remove("collapsed")):(a.target.textContent=gettext("Show"),b.classList.add("collapsed"))}};a=document.querySelectorAll("fieldset.module");for(b=0;b<a.length;b++)a[b].addEventListener("click",d)})})();
|
||||
|
|
Loading…
Reference in New Issue