Skip to content

Commit ec9034a

Browse files
authored
[5.4] Cleanup short and sweet script (joomla#45017)
- Use the JS ESM module instead of the iife - Drop the patches in the build tools
1 parent 72e1102 commit ec9034a

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

build/build-modules-js/init/minify-vendor.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ const folders = [
1313
'media/vendor/diff/js',
1414
'media/vendor/es-module-shims/js',
1515
'media/vendor/qrcode/js',
16-
'media/vendor/short-and-sweet/js',
1716
'media/vendor/webcomponentsjs/js',
1817
];
1918

2019
let allFiles = [];
2120

22-
const noMinified = ['accessibility.min.js', 'short-and-sweet.min.js'];
21+
const noMinified = ['accessibility.min.js'];
2322

2423
const alreadyMinified = [
2524
'media/vendor/webcomponentsjs/js/webcomponents-bundle.js',

build/build-modules-js/init/patches.mjs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const patchPackages = async (options) => {
1515

1616
// Joomla's hack to expose the chosen base classes so we can extend it ourselves
1717
// (it was better than the many hacks we had before. But I'm still ashamed of myself).
18-
let dest = join(mediaVendorPath, 'chosen');
18+
const dest = join(mediaVendorPath, 'chosen');
1919
const chosenPath = `${dest}/${options.settings.vendors['chosen-js'].js['chosen.jquery.js']}`;
2020
let ChosenJs = await readFile(chosenPath, { encoding: 'utf8' });
2121
ChosenJs = ChosenJs.replace(
@@ -26,17 +26,6 @@ export const patchPackages = async (options) => {
2626
);
2727
await writeFile(chosenPath, ChosenJs, { encoding: 'utf8', mode: 0o644 });
2828

29-
// Append initialising code to the end of the Short-and-Sweet javascript
30-
dest = join(mediaVendorPath, 'short-and-sweet');
31-
const shortandsweetPath = `${dest}/${options.settings.vendors['short-and-sweet'].js['dist/short-and-sweet.min.js']}`;
32-
let ShortandsweetJs = await readFile(shortandsweetPath, { encoding: 'utf8' });
33-
ShortandsweetJs = ShortandsweetJs.concat(`
34-
shortAndSweet('textarea.charcount,input.charcount', {counterClassName: 'small text-muted'});
35-
/** Repeatable */
36-
document.addEventListener("joomla:updated", (event) => [].slice.call(event.target.querySelectorAll('textarea.charcount,input.charcount')).map((el) => shortAndSweet(el, {counterClassName: 'small text-muted'})));
37-
`);
38-
await writeFile(shortandsweetPath, ShortandsweetJs, { encoding: 'utf8', mode: 0o644 });
39-
4029
// Include the v5 shim for Font Awesome
4130
const faPath = join(mediaVendorPath, 'fontawesome-free/scss/fontawesome.scss');
4231
const newScss = (await readFile(faPath, { encoding: 'utf8' })).concat(`

build/build-modules-js/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,16 +704,13 @@
704704
"short-and-sweet": {
705705
"name": "short-and-sweet",
706706
"licenseFilename": "LICENSE",
707-
"js": {
708-
"dist/short-and-sweet.min.js": "js/short-and-sweet.min.js"
709-
},
710707
"provideAssets": [
711708
{
712709
"name": "short-and-sweet",
713710
"type": "script",
714711
"uri": "short-and-sweet.min.js",
715712
"attributes": {
716-
"defer": true
713+
"type": "module"
717714
}
718715
}
719716
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import shortAndSweet from 'short-and-sweet/dist/short-and-sweet.module.js';
2+
3+
shortAndSweet('textarea.charcount,input.charcount', { counterClassName: 'small text-muted' });
4+
5+
/** Repeatable */
6+
document.addEventListener('joomla:updated', (event) => {
7+
event.target.querySelectorAll('textarea.charcount,input.charcount')
8+
.forEach((el) => shortAndSweet(el, { counterClassName: 'small text-muted' }));
9+
});

0 commit comments

Comments
 (0)