Skip to content

Commit

Permalink
[4.2] article status script (#38154)
Browse files Browse the repository at this point in the history
* [4.2] article status script

Completes an `@todo` by moving an inline script to a standaloine script using webassetmanager.

* Phase 1 convert BRANCH to PSR-12
  • Loading branch information
brianteeman authored Jun 30, 2022
1 parent 958669b commit cadcf98
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
17 changes: 1 addition & 16 deletions administrator/components/com_content/tmpl/articles/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,9 @@
$workflow_featured = false;

if ($workflow_enabled) :
// @todo move the script to a file
$js = <<<JS
(function() {
document.addEventListener('DOMContentLoaded', function() {
var elements = [].slice.call(document.querySelectorAll('.article-status'));
elements.forEach(function (element) {
element.addEventListener('click', function(event) {
event.stopPropagation();
});
});
});
})();
JS;

$wa->getRegistry()->addExtensionRegistryFile('com_workflow');
$wa->useScript('com_workflow.admin-items-workflow-buttons')
->addInlineScript($js, [], ['type' => 'module']);
->useScript('com_content.articles-status');

$workflow_state = Factory::getApplication()->bootComponent('com_content')->isFunctionalityUsed('core.state', 'com_content.article');
$workflow_featured = Factory::getApplication()->bootComponent('com_content')->isFunctionalityUsed('core.featured', 'com_content.article');
Expand Down
17 changes: 1 addition & 16 deletions administrator/components/com_content/tmpl/featured/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,9 @@
$workflow_featured = false;

if ($workflow_enabled) :
// @todo move the script to a file
$js = <<<JS
(function() {
document.addEventListener('DOMContentLoaded', function() {
var elements = [].slice.call(document.querySelectorAll('.article-status'));
elements.forEach(function (element) {
element.addEventListener('click', function(event) {
event.stopPropagation();
});
});
});
})();
JS;

$wa->getRegistry()->addExtensionRegistryFile('com_workflow');
$wa->useScript('com_workflow.admin-items-workflow-buttons')
->addInlineScript($js, [], ['type' => 'module']);
->useScript('com_content.articles-status');

$workflow_state = Factory::getApplication()->bootComponent('com_content')->isFunctionalityUsed('core.state', 'com_content.article');
$workflow_featured = Factory::getApplication()->bootComponent('com_content')->isFunctionalityUsed('core.featured', 'com_content.article');
Expand Down
23 changes: 23 additions & 0 deletions build/media_source/com_content/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@
"attributes": {
"type": "module"
}
},
{
"name": "com_content.articles-status.es5",
"type": "script",
"uri": "com_content/articles-status-es5.min.js",
"dependencies": [
"core"
],
"attributes": {
"nomodule": true,
"defer": true
}
},
{
"name": "com_content.articles-status",
"type": "script",
"uri": "com_content/articles-status.min.js",
"dependencies": [
"com_content.articles-status.es5"
],
"attributes": {
"type": "module"
}
}
]
}
18 changes: 18 additions & 0 deletions build/media_source/com_content/js/articles-status.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

(function () {
'use strict';

document.addEventListener('DOMContentLoaded', () => {
const elements = [].slice.call(document.querySelectorAll('.article-status'));

elements.forEach((element) => {
element.addEventListener('click', (event) => {
event.stopPropagation();
});
});
});
}());

0 comments on commit cadcf98

Please sign in to comment.