提交 3968c8b0 编写于 作者: V Vishwanatha HM 提交者: Kamran Ahmed

Using event delegation and dataset to reduce the listener to one (#168)

* added all the possible position options into the demo page

* event listener is reduced to one and data- attribute is used.
上级 fa5e8c7a
...@@ -142,11 +142,25 @@ driver.highlight({ ...@@ -142,11 +142,25 @@ driver.highlight({
</code></pre> </code></pre>
</div> </div>
<div class="section__example"> <div class="section__example">
<div class="top-20 position-btns"> <div class="top-90 position-btns" id="position-btns">
<a href="#" id="position-btn-left">On my Left</a> <a href="#" id="position-btn-left" data-alignment="left">Left, Left Top</a>
<a href="#" id="position-btn-top">On my Top</a> <a href="#" id="position-btn-left-center" data-alignment="left-center">Left Center</a>
<a href="#" id="position-btn-bottom">On my Bottom</a> <a href="#" id="position-btn-left-bottom" data-alignment="left-bottom">Left Bottom</a>
<a href="#" id="position-btn-right">On my Right</a>
<a href="#" id="position-btn-right" data-alignment="right">Right, Right Top</a>
<a href="#" id="position-btn-right-center" data-alignment="right-center">Right Center</a>
<a href="#" id="position-btn-right-bottom" data-alignment="right-bottom">Right Bottom</a>
<a href="#" id="position-btn-top" data-alignment="top">Top, Top-left</a>
<a href="#" id="position-btn-top-center" data-alignment="top-center">Top Center</a>
<a href="#" id="position-btn-top-right" data-alignment="top-right">Top Right</a>
<a href="#" id="position-btn-bottom" data-alignment="bottom">Bottom, Bottom left</a>
<a href="#" id="position-btn-bottom-center" data-alignment="bottom-center">Bottom center</a>
<a href="#" id="position-btn-bottom-right" data-alignment="bottom-right">Bottom right</a>
<a href="#" id="position-btn-mid-center" data-alignment="mid-center">Mid Center</a>
<!-- <a href="#" id="position-btn-auto" data-alignment="auto">Auto</a> -->
</div> </div>
<p class="top-20">If you don't specify the position or specify it to be <code>auto</code>, it will automatically <p class="top-20">If you don't specify the position or specify it to be <code>auto</code>, it will automatically
find the suitable position for the popover and show it</p> find the suitable position for the popover and show it</p>
......
...@@ -205,65 +205,25 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -205,65 +205,25 @@ document.addEventListener('DOMContentLoaded', function () {
padding: 0, padding: 0,
}); });
document.querySelector('#position-btn-left') document.querySelector('#position-btns')
.addEventListener('click', (e) => { .addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
positionBtnsDriver.highlight({ let id = e.target.id;
element: '#position-btn-left', let alignment = e.target.dataset.alignment;
showButtons: false,
popover: {
title: 'Did you know?',
description: 'You can add HTML in title or description also!',
position: 'left'
}
});
});
document.querySelector('#position-btn-right')
.addEventListener('click', (e) => {
e.preventDefault();
positionBtnsDriver.highlight({
element: '#position-btn-right',
showButtons: false,
popover: {
title: 'Did you know?',
description: 'You can add HTML in title or description also!',
position: 'right'
}
});
});
document.querySelector('#position-btn-bottom')
.addEventListener('click', (e) => {
e.preventDefault();
positionBtnsDriver.highlight({
element: '#position-btn-bottom',
showButtons: false,
popover: {
title: 'Did you know?',
description: 'You can add HTML in title or description also!',
position: 'bottom'
}
});
});
document.querySelector('#position-btn-top') if (!alignment) return;
.addEventListener('click', (e) => {
e.preventDefault();
positionBtnsDriver.highlight({ positionBtnsDriver.highlight({
element: '#position-btn-top', element: `#${id}`,
showButtons: false, showButtons: false,
popover: { popover: {
title: 'Did you know?', title: 'Did you know?',
description: 'You can add HTML in title or description also!', description: 'You can add HTML in title or description also!',
position: 'top' position: alignment
} }
}); });
}); })
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// Highlighting single element with popover position // Highlighting single element with popover position
......
...@@ -108,6 +108,17 @@ section { ...@@ -108,6 +108,17 @@ section {
} }
} }
.position-btns {
display: grid;
grid-template-columns: repeat(3,1fr);
grid-gap: 8px;
text-align: center;
#position-btn-mid-center{
grid-column: 2/ span 1;
}
}
.position-btns a { .position-btns a {
text-decoration: none; text-decoration: none;
font-size: 13px; font-size: 13px;
...@@ -115,4 +126,4 @@ section { ...@@ -115,4 +126,4 @@ section {
background: #f54336; background: #f54336;
color: white !important; color: white !important;
border-radius: 6px; border-radius: 6px;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册