global.js
2.23 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
jQuery( function($){
$(function(){
ULT_Sidebar.init();
new ULT_ReviewsBanner();
});
var ULT_Sidebar = {
init: function(){
// Get elements
this.getElements();
// Add class to the container of the featured item
this.addClassToContainerOfFeaturedItems();
},
getElements: function(){
this.$elements = {
featuredItems: $( '.ult-sidebar-featured-item' )
}
},
addClassToContainerOfFeaturedItems: function(){
$.each( this.$elements.featuredItems, function( index, featuredItem ){
// Get featured item
let $featuredItem = $( featuredItem );
// Get container
let $container = $featuredItem.closest( 'a' );
// Add class to the container
$container.addClass( 'ult-sidebar-featured-item-container' );
// Open that link on a new tab
//$container.prop( 'target', '_blank' );
});
}
}
});
/**
* Hides the review banner when one of the buttons is clicked
*/
class ULT_ReviewsBanner {
constructor() {
// Check if the banner exists
if ( ! this.$banner ) {
return;
}
// Listen clicks to the buttons
this.listenClickToButtons();
}
/**
* Listen to clicks to all the buttons that perform an action
*/
listenClickToButtons() {
this.$buttons.forEach( ( $button ) => {
$button.addEventListener( 'click', ( e ) => {
// Remove the banner
this.removeBanner();
} );
} );
}
/**
* Removes the banner
*/
removeBanner() {
this.$banner.parentNode.removeChild( this.$banner );
}
/**
* Returns the banner
*
* @return {Node} The banner
*/
get $banner() {
return document.getElementById( 'ult-review-banner' );
}
/**
* Returns the action buttons
*
* @return {NodeList} A NodeList with all the buttons that perform an action
*/
get $buttons() {
return this.$banner.querySelectorAll( '[data-action="hide-banner"]' );
}
}