-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathquickview.js
More file actions
51 lines (45 loc) · 1.49 KB
/
Copy pathquickview.js
File metadata and controls
51 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function closest(el, selector) {
var matchesFn;
// find vendor prefix
[ 'matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector', 'oMatchesSelector' ].some( function( fn ) {
if ( typeof document.body[ fn ] == 'function' ) {
matchesFn = fn;
return true;
}
return false;
} );
var parent;
// traverse parents
while ( el ) {
parent = el.parentElement;
if ( parent && parent[ matchesFn ]( selector ) ) {
return parent;
}
el = parent;
}
return null;
}
document.addEventListener( 'DOMContentLoaded', function () {
// Get all document sliders
var showQuickview = document.querySelectorAll( '[data-show="quickview"]' );
[].forEach.call( showQuickview, function ( show ) {
var quickview = document.getElementById( show.dataset[ 'target' ] );
if ( quickview ) {
// Add event listener to update output when slider value change
show.addEventListener( 'click', function( event ) {
quickview.classList.add( 'is-active' );
} );
}
} );
// Get all document sliders
var dismissQuickView = document.querySelectorAll( '[data-dismiss="quickview"]' );
[].forEach.call( dismissQuickView, function ( dismiss ) {
var quickview = closest( dismiss, '.quickview' );
if ( quickview ) {
// Add event listener to update output when slider value change
dismiss.addEventListener( 'click', function( event ) {
quickview.classList.remove( 'is-active' );
} );
}
} );
} );