Vishwanatha HM
commited on
Commit
·
3968c8b
1
Parent(s):
fa5e8c7
Using event delegation and dataset to reduce the listener to one (#168)
Browse files* added all the possible position options into the demo page
* event listener is reduced to one and data- attribute is used.
- demo/index.html +19 -5
- demo/scripts/demo.js +7 -47
- demo/styles/demo.scss +12 -1
demo/index.html
CHANGED
@@ -142,11 +142,25 @@ driver.highlight({
|
|
142 |
</code></pre>
|
143 |
</div>
|
144 |
<div class="section__example">
|
145 |
-
<div class="top-
|
146 |
-
<a href="#" id="position-btn-left">
|
147 |
-
<a href="#" id="position-btn-
|
148 |
-
<a href="#" id="position-btn-bottom">
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
</div>
|
151 |
<p class="top-20">If you don't specify the position or specify it to be <code>auto</code>, it will automatically
|
152 |
find the suitable position for the popover and show it</p>
|
|
|
142 |
</code></pre>
|
143 |
</div>
|
144 |
<div class="section__example">
|
145 |
+
<div class="top-90 position-btns" id="position-btns">
|
146 |
+
<a href="#" id="position-btn-left" data-alignment="left">Left, Left Top</a>
|
147 |
+
<a href="#" id="position-btn-left-center" data-alignment="left-center">Left Center</a>
|
148 |
+
<a href="#" id="position-btn-left-bottom" data-alignment="left-bottom">Left Bottom</a>
|
149 |
+
|
150 |
+
<a href="#" id="position-btn-right" data-alignment="right">Right, Right Top</a>
|
151 |
+
<a href="#" id="position-btn-right-center" data-alignment="right-center">Right Center</a>
|
152 |
+
<a href="#" id="position-btn-right-bottom" data-alignment="right-bottom">Right Bottom</a>
|
153 |
+
|
154 |
+
<a href="#" id="position-btn-top" data-alignment="top">Top, Top-left</a>
|
155 |
+
<a href="#" id="position-btn-top-center" data-alignment="top-center">Top Center</a>
|
156 |
+
<a href="#" id="position-btn-top-right" data-alignment="top-right">Top Right</a>
|
157 |
+
|
158 |
+
<a href="#" id="position-btn-bottom" data-alignment="bottom">Bottom, Bottom left</a>
|
159 |
+
<a href="#" id="position-btn-bottom-center" data-alignment="bottom-center">Bottom center</a>
|
160 |
+
<a href="#" id="position-btn-bottom-right" data-alignment="bottom-right">Bottom right</a>
|
161 |
+
|
162 |
+
<a href="#" id="position-btn-mid-center" data-alignment="mid-center">Mid Center</a>
|
163 |
+
<!-- <a href="#" id="position-btn-auto" data-alignment="auto">Auto</a> -->
|
164 |
</div>
|
165 |
<p class="top-20">If you don't specify the position or specify it to be <code>auto</code>, it will automatically
|
166 |
find the suitable position for the popover and show it</p>
|
demo/scripts/demo.js
CHANGED
@@ -205,65 +205,25 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
205 |
padding: 0,
|
206 |
});
|
207 |
|
208 |
-
document.querySelector('#position-
|
209 |
.addEventListener('click', (e) => {
|
210 |
e.preventDefault();
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
showButtons: false,
|
215 |
-
popover: {
|
216 |
-
title: 'Did you know?',
|
217 |
-
description: 'You can add HTML in title or description also!',
|
218 |
-
position: 'left'
|
219 |
-
}
|
220 |
-
});
|
221 |
-
});
|
222 |
-
|
223 |
-
document.querySelector('#position-btn-right')
|
224 |
-
.addEventListener('click', (e) => {
|
225 |
-
e.preventDefault();
|
226 |
-
|
227 |
-
positionBtnsDriver.highlight({
|
228 |
-
element: '#position-btn-right',
|
229 |
-
showButtons: false,
|
230 |
-
popover: {
|
231 |
-
title: 'Did you know?',
|
232 |
-
description: 'You can add HTML in title or description also!',
|
233 |
-
position: 'right'
|
234 |
-
}
|
235 |
-
});
|
236 |
-
});
|
237 |
-
|
238 |
-
document.querySelector('#position-btn-bottom')
|
239 |
-
.addEventListener('click', (e) => {
|
240 |
-
e.preventDefault();
|
241 |
-
|
242 |
-
positionBtnsDriver.highlight({
|
243 |
-
element: '#position-btn-bottom',
|
244 |
-
showButtons: false,
|
245 |
-
popover: {
|
246 |
-
title: 'Did you know?',
|
247 |
-
description: 'You can add HTML in title or description also!',
|
248 |
-
position: 'bottom'
|
249 |
-
}
|
250 |
-
});
|
251 |
-
});
|
252 |
|
253 |
-
|
254 |
-
.addEventListener('click', (e) => {
|
255 |
-
e.preventDefault();
|
256 |
|
257 |
positionBtnsDriver.highlight({
|
258 |
-
element:
|
259 |
showButtons: false,
|
260 |
popover: {
|
261 |
title: 'Did you know?',
|
262 |
description: 'You can add HTML in title or description also!',
|
263 |
-
position:
|
264 |
}
|
265 |
});
|
266 |
-
})
|
267 |
|
268 |
/////////////////////////////////////////////////////
|
269 |
// Highlighting single element with popover position
|
|
|
205 |
padding: 0,
|
206 |
});
|
207 |
|
208 |
+
document.querySelector('#position-btns')
|
209 |
.addEventListener('click', (e) => {
|
210 |
e.preventDefault();
|
211 |
|
212 |
+
let id = e.target.id;
|
213 |
+
let alignment = e.target.dataset.alignment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
+
if (!alignment) return;
|
|
|
|
|
216 |
|
217 |
positionBtnsDriver.highlight({
|
218 |
+
element: `#${id}`,
|
219 |
showButtons: false,
|
220 |
popover: {
|
221 |
title: 'Did you know?',
|
222 |
description: 'You can add HTML in title or description also!',
|
223 |
+
position: alignment
|
224 |
}
|
225 |
});
|
226 |
+
})
|
227 |
|
228 |
/////////////////////////////////////////////////////
|
229 |
// Highlighting single element with popover position
|
demo/styles/demo.scss
CHANGED
@@ -108,6 +108,17 @@ section {
|
|
108 |
}
|
109 |
}
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
.position-btns a {
|
112 |
text-decoration: none;
|
113 |
font-size: 13px;
|
@@ -115,4 +126,4 @@ section {
|
|
115 |
background: #f54336;
|
116 |
color: white !important;
|
117 |
border-radius: 6px;
|
118 |
-
}
|
|
|
108 |
}
|
109 |
}
|
110 |
|
111 |
+
.position-btns {
|
112 |
+
display: grid;
|
113 |
+
grid-template-columns: repeat(3,1fr);
|
114 |
+
grid-gap: 8px;
|
115 |
+
text-align: center;
|
116 |
+
|
117 |
+
#position-btn-mid-center{
|
118 |
+
grid-column: 2/ span 1;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
.position-btns a {
|
123 |
text-decoration: none;
|
124 |
font-size: 13px;
|
|
|
126 |
background: #f54336;
|
127 |
color: white !important;
|
128 |
border-radius: 6px;
|
129 |
+
}
|