Skip to content

Commit 20cec45

Browse files
authored
Refactored messages.js (#1852)
* 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
1 parent 4fbcf7d commit 20cec45

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

djangoproject/scss/_style.scss

+5
Original file line numberDiff line numberDiff line change
@@ -3427,6 +3427,11 @@ ul.corporate-members li {
34273427
margin-right: 10px;
34283428
}
34293429

3430+
&.fade-out {
3431+
opacity: 0;
3432+
transition: opacity 400ms;
3433+
}
3434+
34303435
&.info {
34313436
&::before {
34323437
content: $fa-var-info-circle;

djangoproject/static/js/djangoproject.js

+11
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ document.querySelectorAll('#doc-versions a').forEach(function (el) {
1111
this.href = this.href.split('#')[0] + window.location.hash;
1212
});
1313
});
14+
15+
// Fade out and remove message elements when close icon is clicked
16+
document.querySelectorAll('.messages li .close').forEach(function (el) {
17+
el.addEventListener('click', function (e) {
18+
this.parentElement.addEventListener('transitionend', function (e) {
19+
this.style.display = 'none';
20+
});
21+
22+
this.parentElement.classList.add('fade-out');
23+
});
24+
});

djangoproject/static/js/main.js

-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ define(function () {
5757
mods.push('mod/corporate-member-join');
5858
}
5959

60-
if (hasClass('messages')) {
61-
mods.push('mod/messages');
62-
}
63-
6460
if (hasClass('code-block-caption') || hasClass('snippet')) {
6561
mods.push('mod/clippify');
6662
}

djangoproject/static/js/mod/messages.js

-7
This file was deleted.

0 commit comments

Comments
 (0)