Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions build/media_source/system/js/showon.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
if (this.showonFields.length) {
// @todo refactor this, dry
this.showonFields.forEach((field) => {
// Set up only once
if (field.hasAttribute('data-showon-initialised')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to field.dataset.hasOwnProperty('showonInitialised')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the end it the same, but use the attribute is more clear for "visual debuging" ;)

return;
}
field.setAttribute('data-showon-initialised', '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field.dataset.showonInitialised = '';


const jsondata = field.getAttribute('data-showon') || '';
const showonData = JSON.parse(jsondata);
let localFields;
Expand Down Expand Up @@ -204,12 +210,20 @@
}
}

// Provide a public API
window.Joomla = window.Joomla || {};

if (!Joomla.Showon) {
Joomla.Showon = {
initialise: (container) => new Showon(container),
};
}

/**
* Initialize 'showon' feature at an initial page load
*/
document.addEventListener('DOMContentLoaded', () => {
// eslint-disable-next-line no-new
new Showon(document);
Joomla.Showon.initialise(document);
});

/**
Expand All @@ -229,7 +243,6 @@
});
}

// eslint-disable-next-line no-new
new Showon(target);
Joomla.Showon.initialise(target);
});
})(document);