Skip to content

Commit

Permalink
Refactored messages.js (#1852)
Browse files Browse the repository at this point in the history
* Refactored `messages.js`

- 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 #1827

* Use `transitionend` event instead of `setTimeout`

* Remove default `opacity` value

* Move `transition` rule to `fade-out` class
  • Loading branch information
adamzap authored Jan 18, 2025
1 parent 4fbcf7d commit 20cec45
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions djangoproject/scss/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3427,6 +3427,11 @@ ul.corporate-members li {
margin-right: 10px;
}

&.fade-out {
opacity: 0;
transition: opacity 400ms;
}

&.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.addEventListener('transitionend', function (e) {
this.style.display = 'none';
});

this.parentElement.classList.add('fade-out');
});
});
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 20cec45

Please sign in to comment.