Skip to content

Commit

Permalink
Refactored messages.js
Browse files Browse the repository at this point in the history
- Simplified code using a combination of CSS and JavaScript
- Stopped using jQuery
- Moved refactored code to `djangoproject.js`

This patch should bring no user-facing changes.

Refs django#1827
  • Loading branch information
adamzap committed Dec 28, 2024
1 parent d068670 commit ffef477
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions djangoproject/scss/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3416,6 +3416,8 @@ ul.corporate-members li {
color: $green-dark;
border: 1px solid $green-dark;
border-radius: 4px;
opacity: 1;
transition: opacity 400ms;

&::before {
@include fa-icon();
Expand All @@ -3427,6 +3429,10 @@ ul.corporate-members li {
margin-right: 10px;
}

&.fade-out {
opacity: 0;
}

&.info {
&::before {
content: $fa-var-info-circle;
Expand Down
11 changes: 11 additions & 0 deletions djangoproject/static/js/djangoproject.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ document.querySelectorAll('#doc-versions a').forEach(function (el) {
this.href = this.href.split('#')[0] + window.location.hash;
});
});

// Fade out and remove message elements when close icon is clicked
document.querySelectorAll('.messages li .close').forEach(function (el) {
el.addEventListener('click', function (e) {
this.parentElement.classList.add('fade-out');

setTimeout(function () {
el.parentElement.style.display = 'none';
}, 400);
});
});
4 changes: 0 additions & 4 deletions djangoproject/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ define(function () {
mods.push('mod/corporate-member-join');
}

if (hasClass('messages')) {
mods.push('mod/messages');
}

if (hasClass('code-block-caption') || hasClass('snippet')) {
mods.push('mod/clippify');
}
Expand Down
7 changes: 0 additions & 7 deletions djangoproject/static/js/mod/messages.js

This file was deleted.

0 comments on commit ffef477

Please sign in to comment.