Skip to content

Commit 3f727a5

Browse files
committed
[PRAC/cont] Delete "bootstrap-tooltips" logic
Returning to tooltips organization by Tippy.js lib's. Worth noting: - difficulties encountered when customizing/positioning "bootstrap-tooltips". core: B-3 / JS-BL
1 parent 8190697 commit 3f727a5

File tree

11 files changed

+115
-84
lines changed

11 files changed

+115
-84
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/css/custom-tooltips.css renamed to core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/css/custom-tippy.css

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
.tooltip {
2-
position: relative;
1+
.tippy-box[data-theme~="main"] {
32
border-radius: 0;
43
padding: 5px 10px;
54
font-family: var(--open-sans), sans-serif;
@@ -11,9 +10,8 @@
1110
will-change: transform;
1211
}
1312

14-
.tooltip .tooltip-inner {
15-
border-radius: 0;
16-
padding: 5px 10px;
17-
color: var(--white);
18-
background-color: var(--black);
13+
.tippy-box[data-theme~="main"] .tippy-arrow {
14+
margin-top: -1px;
15+
margin-right: -1px;
16+
color: var(--main-purple);
1917
}

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
@import url("crm-output.css");
77
@import url("crm-add.css");
88
@import url("modal-add.css");
9-
@import url("custom-tooltips.css");
9+
@import url("custom-tippy.css");

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
<link rel="stylesheet" href="css/normalize.css">
1010
<link rel="stylesheet" href="libs/bootstrap-v5.3.3/bootstrap.min.css">
1111
<link rel="stylesheet" href="libs/bootstrap-icons-v1.11.3/font/bootstrap-icons.css">
12+
<link rel="stylesheet" href="libs/tippy-v6.3.7/tippy.min.css">
13+
<link rel="stylesheet" href="libs/tippy-v6.3.7/animations/scale.css">
1214
<link rel="stylesheet" href="css/style.css">
1315
<script src="libs/jquery-v3.7.1/jquery-3.7.1.min.js" defer></script>
14-
<script src="libs/bootstrap-v5.3.3/bootstrap.bundle.min.js" defer></script>
15-
<script src="js/bootstrapTooltips.js" defer></script>
16+
<script src="libs/bootstrap-v5.3.3/bootstrap.min.js" defer></script>
17+
<script src="libs/tippy-v6.3.7/popper.min.js" defer></script>
18+
<script src="libs/tippy-v6.3.7/tippy.umd.min.js" defer></script>
19+
<script src="js/customTippy.js" defer></script>
1620
<script src="js/index.js" defer></script>
1721
</head>
1822

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js/bootstrapTooltips.js

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
(() => {
2+
// в данной реализации прослушка DOMContentLoaded необходима
3+
document.addEventListener('DOMContentLoaded', () => {
4+
function initTippy(selector, content, side, customOptions = {}) {
5+
if (typeof tippy === 'function') {
6+
const defaultOptions = {
7+
content: content,
8+
theme: 'main',
9+
delay: [50, 0],
10+
offset: [0, 12],
11+
placement: side,
12+
animation: 'scale', // анимация появления/скрытия (через дополнительный файл/подключение)
13+
trigger: 'mouseenter', // только по наведению мыши (исключение вывода по клику, в другом месте)
14+
15+
onShow(instance) {
16+
setTimeout(() => {
17+
instance.hide(); // автоматическое скрытие (по истечению времени)
18+
}, 1000);
19+
},
20+
};
21+
22+
tippy(selector, { ...defaultOptions, ...customOptions }); // применение "общих" настроек с возможностью переопределения/индивидуального изменения, согласно customOptions
23+
} else {
24+
console.error('Tippy.js is not loaded!');
25+
}
26+
}
27+
28+
// инициализация Tippy только/для #search-logo (в зависимости от ширины экрана)
29+
function initTippyForSearchLogo() {
30+
const isSmallWidth = window.matchMedia('(max-width: 320px)').matches; // уточнение ширины
31+
const searchLogo = document.querySelector('#search-logo');
32+
33+
if (isSmallWidth && searchLogo && !searchLogo._tippy) {
34+
initTippy('#search-logo', 'Показать/скрыть..!?', 'top', {
35+
offset: [0, 8],
36+
});
37+
} else if (!isSmallWidth && searchLogo && searchLogo._tippy) {
38+
searchLogo._tippy.destroy(); // исключение всплывающей подсказки, если экран больше 320px
39+
}
40+
}
41+
42+
// инициализация Tippy для/всех "остальных" элементов (без учёта ширины экрана)
43+
function initTippyForOther() {
44+
initTippy('#hash-tag-title', 'сбросить сортировку', 'bottom', {
45+
offset: [0, 2],
46+
});
47+
initTippy('#table-th-id', 'сортировать ⇵', 'bottom', {
48+
offset: [0, 2],
49+
});
50+
initTippy('#table-th-fio', 'сортировать ⇵', 'bottom', {
51+
offset: [0, 2],
52+
});
53+
initTippy('#table-th-dt', 'сортировать ⇵', 'bottom', {
54+
offset: [0, 2],
55+
});
56+
initTippy('#table-th-change', 'сортировать ⇵', 'bottom', {
57+
offset: [0, 2],
58+
});
59+
}
60+
61+
initTippyForSearchLogo();
62+
initTippyForOther();
63+
64+
window.addEventListener('resize', initTippyForSearchLogo); // отслеживание изменения ширины экрана (разрешения)
65+
});
66+
})();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.tippy-box[data-animation="scale"][data-placement^="top"] {
2+
transform-origin: bottom;
3+
}
4+
5+
.tippy-box[data-animation="scale"][data-placement^="bottom"] {
6+
transform-origin: top;
7+
}
8+
9+
.tippy-box[data-animation="scale"][data-placement^="left"] {
10+
transform-origin: right;
11+
}
12+
13+
.tippy-box[data-animation="scale"][data-placement^="right"] {
14+
transform-origin: left;
15+
}
16+
17+
.tippy-box[data-animation="scale"][data-state="hidden"] {
18+
transform: scale(0.5);
19+
opacity: 0;
20+
}

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/libs/tippy-v6.3.7/popper.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/libs/tippy-v6.3.7/popper.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/libs/tippy-v6.3.7/tippy.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/libs/tippy-v6.3.7/tippy.umd.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)