Skip to content

Commit

Permalink
Remove jQuery from modal fields JS file (#22308)
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo authored and wilsonge committed Sep 23, 2018
1 parent f1e9fa2 commit ad6d622
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ protected function getInput()
$modalId = 'Category_' . $this->id;

// Add the modal field script to the document head.
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'system/fields/modal-fields.min.js', array('version' => 'auto', 'relative' => true));

// Script to proxy the select modal function to the modal-fields.js file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected function getInput()
$modalId = 'Contact_' . $this->id;

// Add the modal field script to the document head.
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'system/fields/modal-fields.min.js', array('version' => 'auto', 'relative' => true));

// Script to proxy the select modal function to the modal-fields.js file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected function getInput()
$modalId = 'Article_' . $this->id;

// Add the modal field script to the document head.
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'system/fields/modal-fields.min.js', array('version' => 'auto', 'relative' => true));

// Script to proxy the select modal function to the modal-fields.js file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ function (Toolbar $childBar) use ($checkedOut, $itemEditable, $canDo)
ToolbarHelper::modal('ModalNewItem_' . $modalId, 'icon-new', 'COM_CONTENT_ADD_NEW_MENU_ITEM');

// Add the modal field script to the document head.
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'system/fields/modal-fields.min.js', array('version' => 'auto', 'relative' => true));

// Load the language files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ protected function getInput()
$modalId = 'Item_' . $this->id;

// Add the modal field script to the document head.
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'system/fields/modal-fields.min.js', array('version' => 'auto', 'relative' => true));

// Script to proxy the select modal function to the modal-fields.js file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected function getInput()
$modalId = 'Newsfeed_' . $this->id;

// Add the modal field script to the document head.
HTMLHelper::_('jquery.framework');
HTMLHelper::_('script', 'system/fields/modal-fields.min.js', array('version' => 'auto', 'relative' => true));

// Script to proxy the select modal function to the modal-fields.js file.
Expand Down
17 changes: 9 additions & 8 deletions build/media/system/js/fields/modal-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,29 @@
titleFieldId = titleFieldId || 'jform_title';

var modalId = element.parentNode.parentNode.parentNode.parentNode.id, submittedTask = task;
var iframe = document.getElementById(modalId + ' iframe');

// Set frame id.
jQuery('#' + modalId + ' iframe').get(0).id = 'Frame_' + modalId;
iframe.id = 'Frame_' + modalId;

var iframeDocument = jQuery('#Frame_' + modalId).contents().get(0);
var iframeDocument = iframe.firstChild;

// If Close (cancel task), close the modal.
if (task === 'cancel')
{
// Submit button on child iframe so we can check out.
document.getElementById('Frame_' + modalId).contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + task);
iframe.contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + task);

Joomla.Modal.getCurrent().close();
}
// For Save (apply task) and Save & Close (save task).
else
{
// Attach onload event to the iframe.
jQuery('#Frame_' + modalId).on('load', function()
iframe.addEventListener('load', function()
{
// Reload iframe document var value.
iframeDocument = jQuery(this).contents().get(0);
iframeDocument = this.firstChild;

// Validate the child form and update parent form.
if (iframeDocument.getElementById(idFieldId) && iframeDocument.getElementById(idFieldId).value != '0')
Expand All @@ -146,7 +147,7 @@
}

// Show the iframe again for future modals or in case of error.
jQuery('#' + modalId + ' iframe').removeClass('sr-only');
iframe.classList.remove('sr-only');
});

// Submit button on child iframe.
Expand All @@ -156,10 +157,10 @@
if (task === 'save')
{
submittedTask = 'apply';
jQuery('#' + modalId + ' iframe').addClass('sr-only');
iframe.classList.add('sr-only');
}

document.getElementById('Frame_' + modalId).contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + submittedTask);
iframe.contentWindow.Joomla.submitbutton(itemType.toLowerCase() + '.' + submittedTask);
}
}

Expand Down

0 comments on commit ad6d622

Please sign in to comment.