Skip to content

Commit

Permalink
[MAT-7230] refactor jquery once usages
Browse files Browse the repository at this point in the history
  • Loading branch information
dlariono committed Oct 14, 2024
1 parent 9d0d25a commit 26cbcd2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
Drupal.behaviors.externalLink = {
attach: function(context, settings) {

$(document).once('mat-external-link').each(function() {

$(once(
'mat-external-link',
document
)).each(function () {
if (drupalSettings.data.extlink.extAlertText) {
$('#js-extlink-alert-text').html(drupalSettings.data.extlink.extAlertText);
}
Expand Down

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

2 changes: 1 addition & 1 deletion html/themes/custom/madie/madie.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ external-link:
dist/02-molecules/extlink/external-link.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/once

countdown:
js:
Expand Down
17 changes: 17 additions & 0 deletions html/themes/custom/madie/minify-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Source and destination directories
SRC_DIR="components/_patterns"
DEST_DIR="dist"

# Find all .js files in the source directory
find $SRC_DIR -name '*.js' | while read jsfile; do
# Create the same folder structure in the destination directory
destfile="$DEST_DIR/${jsfile#$SRC_DIR/}"

# Create the destination directory if it doesn't exist
mkdir -p "$(dirname "$destfile")"

# Minify and write to the destination directory
npx uglifyjs "$jsfile" --compress --mangle --output "${destfile%.js}.js"
done
16 changes: 15 additions & 1 deletion html/themes/custom/madie/package-lock.json

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

4 changes: 3 additions & 1 deletion html/themes/custom/madie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"name": "madie",
"private": true,
"scripts": {
"build-js": "./minify-js.sh",
"sass-watch": "node-sass -w --output-style expanded scss -o css",
"sass-compile": "node-sass --importer node_modules/node-sass-glob-importer/dist/cli.js components/_patterns/style.scss dist/style.css"
},
"devDependencies": {
"node-sass": "^9.0.0"
"node-sass": "^9.0.0",
"uglify-js": "^3.19.3"
},
"dependencies": {
"breakpoint-sass": "^2.7.1",
Expand Down

0 comments on commit 26cbcd2

Please sign in to comment.