Skip to content
Merged
Show file tree
Hide file tree
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
74 changes: 50 additions & 24 deletions media/jui/js/cms-uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ Joomla = window.Joomla || {};
}

/**
* Method for setup the 'showon' feature, for the fields in given container
* Method for setup the 'showon' feature, for the fields in given container. Add it to Joomla object
* so it can be called when adding a container to the DOM.
*
* @param {HTMLElement} container
*/
function setUpShowon(container) {
Expand All @@ -178,9 +180,16 @@ Joomla = window.Joomla || {};
// Setup each 'showon' field
for (var is = 0, ls = $showonFields.length; is < ls; is++) {
// Use anonymous function to capture arguments
(function() {
var $target = $($showonFields[is]), jsondata = $target.data('showon') || [],
field, $fields = $();
(function($target) {
// Set up only once
if ($target[0].hasAttribute('data-showon-initialised')) {
return;
}

$target[0].setAttribute('data-showon-initialised', '');

var jsondata = $target.data('showon') || [],
field, $fields = $();

// Collect an all referenced elements
for (var ij = 0, lj = jsondata.length; ij < lj; ij++) {
Expand All @@ -195,35 +204,52 @@ Joomla = window.Joomla || {};
$fields.on('change keyup', function() {
linkedoptions($target, true);
});
})();

})($($showonFields[is]));
}
}

// Provide a public API
if (!Joomla.Showon) {
Joomla.Showon = {
initialise: setUpShowon
}
}

/**
* Initialize 'showon' feature
*/
$(document).ready(function() {
setUpShowon();

// Setup showon feature in the subform field
$(document).on('subform-row-add', function(event, row) {
var $row = $(row),
$elements = $row.find('[data-showon]'),
baseName = $row.data('baseName'),
group = $row.data('group'),
search = new RegExp('\\[' + baseName + '\\]\\[' + baseName + 'X\\]', 'g'),
replace = '[' + baseName + '][' + group + ']',
$elm, showon;

// Fix showon field names in a current group
for (var i = 0, l = $elements.length; i < l; i++) {
$elm = $($elements[i]);
showon = $elm.attr('data-showon').replace(search, replace);

$elm.attr('data-showon', showon);
Joomla.Showon.initialise(document);

// Setup showon feature in the modified container
$(document).on('subform-row-add joomla:updated', function(event, row) {

// Check for target
var target = row;
if (event.type === 'joomla:updated') {
target = event.target;
}

if ($(target).hasClass('subform-repeatable-group')) {
var $row = $(target),
$elements = $row.find('[data-showon]'),
baseName = $row.data('baseName'),
group = $row.data('group'),
search = new RegExp('\\[' + baseName + '\\]\\[' + baseName + 'X\\]', 'g'),
replace = '[' + baseName + '][' + group + ']',
$elm, showon;

// Fix showon field names in a current group
for (var i = 0, l = $elements.length; i < l; i++) {
$elm = $($elements[i]);
showon = $elm.attr('data-showon').replace(search, replace);

$elm.attr('data-showon', showon);
}
}

setUpShowon(row);
Joomla.Showon.initialise(target);
});
});

Expand Down
2 changes: 1 addition & 1 deletion media/jui/js/cms.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.