PluginProbe
Hostinger Tools / 2.2.1
Hostinger Tools v2.2.1
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / src / js / main.js

main.js in Hostinger Tools 2.2.1, at src/js/main.js

189 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import './actions'
2 import './videos'
3
4 ( function ( $ ) {
5 $( document ).on( 'ready', function () {
6 const openClass = 'open';
7 let selectedTab = 'Home';
8 const stepsTitle = $( '.hsr-onboarding-step--title' )
9 const closeBtn = $( '.hsr-close-btn' );
10 const navigationItem = $( '.hsr-list__item' );
11 const knowledgeCard = $( '#card-knowledge' );
12 const helpCard = $( '#card-help' );
13 const adminBarGenerateContent = $( '#wp-admin-bar-create_content_with_ai' );
14
15 stepsTitle.on( 'click', function () {
16 $( this ).find( '.hsr-onboarding-step--expand' ).toggleClass( openClass );
17 $( this ).parent().find( '.hsr-onboarding-step--content' ).slideToggle( 200 );
18 } )
19
20 closeBtn.on( 'click', function () {
21 $( '.hsr-modal' ).removeClass( 'open' );
22 $( 'body' ).removeClass( 'modal-open' );
23 } )
24
25 adminBarGenerateContent.click( function () {
26 $( '.hsr-list__item' ).removeClass( 'hsr-active' );
27 $('.hts-ai-assistant-tab').addClass( 'hsr-active' );
28 $( '.hsr-tab-content' ).hide();
29 $( ".hsr-tab-content[data-name='ai-assistant']" ).show();
30 } );
31
32 navigationItem.click( function () {
33 let clickedItem = $( this );
34
35 $( '.hsr-list__item' ).removeClass( 'hsr-active' );
36
37 clickedItem.addClass( 'hsr-active' );
38 selectedTab = clickedItem.data( 'name' );
39
40 $( '.hsr-tab-content' ).hide();
41 $( '.hsr-tab-content[data-name="' + selectedTab + '"]' ).show();
42
43 add_admin_menu_class();
44 } );
45
46 if( window.location.hash ) {
47 let tab = $( '.hsr-onboarding-navbar .hsr-wrapper__list .hsr-list__item[data-name="' + window.location.hash.split('#')[1] + '"]' )
48
49 if(tab.length > 0) {
50 $( '.hsr-list__item' ).removeClass( 'hsr-active' );
51 tab.addClass( 'hsr-active' );
52
53 $( '.hsr-tab-content' ).hide();
54 $( '.hsr-tab-content[data-name="' + window.location.hash.split('#')[1] + '"]' ).show();
55 }
56 } else {
57
58 $( '.hsr-wrapper__list .hsr-list__item:first-of-type' ).addClass( 'hsr-active' );
59
60 }
61
62 helpCard.click( function () {
63 window.open( 'https://hostinger.com/cpanel-login?r=jump-to/new-panel/section/help', '_blank' );
64 } );
65 knowledgeCard.click( function () {
66 window.open( 'https://support.hostinger.com/en/?q=WordPress', '_blank' );
67 } );
68
69 $('body').on('click', '.hst-open-affiliate-tab', function(e) {
70 e.preventDefault();
71
72 $( 'li.hsr-list__item[data-name="amazon_affiliate"]' ).trigger( 'click' );
73 } );
74
75 $('body').on('click', '#hst-connect_affiliate_settings', function(e) {
76 e.preventDefault();
77
78 $( 'li.hsr-list__item[data-name="amazon_affiliate"]' ).trigger( 'click' );
79
80 document.dispatchEvent(
81 new CustomEvent('scrollToAffiliateSettings', {
82 bubbles: true
83 })
84 );
85 } );
86
87 document.querySelectorAll( '.hsr-playlist-item' ).forEach( function ( item ) {
88 const firstItem = document.querySelector( '.hsr-playlist-item:first-child' );
89 firstItem.classList.add( 'hsr-active-video' );
90 firstItem.querySelector( '.hsr-playlist-item-arrow' ).style.visibility = 'visible';
91 item.addEventListener( 'click', function () {
92 document.querySelectorAll( '.hsr-playlist-item.hsr-active-video' ).forEach( function ( selectedItem ) {
93 selectedItem.classList.remove( 'hsr-active-video' );
94 selectedItem.querySelector( '.hsr-playlist-item-arrow' ).style.visibility = 'hidden';
95 } );
96 this.classList.add( 'hsr-active-video' );
97 this.querySelector( '.hsr-playlist-item-arrow' ).style.visibility = 'visible';
98 } );
99 } );
100
101 function add_admin_menu_class () {
102 const hostingerSubMenu = document.querySelectorAll( '#toplevel_page_hostinger .wp-submenu li' );
103
104 if ( hostingerSubMenu ) {
105 hostingerSubMenu.forEach( item => {
106 item.classList.remove( 'current' );
107 } );
108
109 const tabSelectors = document.querySelectorAll( '.hsr-onboarding-navbar .hsr-wrapper__list .hsr-list__item' );
110
111 tabSelectors.forEach( ( item, index ) => {
112 if ( item.classList.contains( 'hsr-active' ) ) {
113 if ( typeof hostingerSubMenu[ index + 1 ] !== "undefined" ) {
114 hostingerSubMenu[ index + 1 ].classList.add( 'current' );
115 }
116 }
117 } );
118 }
119 }
120
121 add_admin_menu_class();
122
123 // Copy nameservers to clipboard
124 $(document).ready(function() {
125 $('.hts-nameservers svg').click(function() {
126 let textToCopy = $(this).closest('div').find('b').text();
127 copyTextToClipboard(textToCopy);
128 });
129 });
130
131 function copyTextToClipboard(text) {
132 let textArea = document.createElement('textarea');
133 textArea.value = text;
134 document.body.appendChild(textArea);
135 textArea.select();
136 document.execCommand('copy');
137 document.body.removeChild(textArea);
138 }
139
140 //Sidebar menu script
141 window.addEventListener( 'resize', function () {
142
143 var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
144 var navbarWrapper = document.querySelector( '.hsr-wrapper__list' );
145 var mobileSidebar = document.querySelector( '.hsr-mobile-sidebar .hsr-wrapper' );
146 var hpanelLink = document.querySelector( '.hsr-go-to-hpanel' );
147
148
149 if ( windowWidth <= 1000 ) {
150 if ( navbarWrapper && mobileSidebar ) {
151 mobileSidebar.appendChild( navbarWrapper );
152 mobileSidebar.appendChild( hpanelLink );
153 }
154 } else {
155 var originalParent = document.querySelector( '.hsr-onboarding-navbar__wrapper' );
156 if ( navbarWrapper && originalParent ) {
157 originalParent.appendChild( navbarWrapper );
158 originalParent.appendChild( hpanelLink );
159 document.querySelector( '.hsr-mobile-sidebar' ).classList.remove( 'hsr-active' );
160 }
161 }
162 } );
163
164 window.dispatchEvent( new Event( 'resize' ) );
165
166
167 var mobileSidebar = document.querySelector( '.hsr-mobile-sidebar' );
168 var closeButtons = document.querySelectorAll( '.hsr-close, .hsr-mobile-menu-icon' );
169
170 closeButtons.forEach( function ( button ) {
171 button.addEventListener( 'click', function ( event ) {
172 mobileSidebar.classList.toggle( 'hsr-active' );
173 document.querySelector('body').classList.toggle( 'hsr-sidebar-active' );
174 event.stopPropagation();
175 } );
176 } );
177
178 document.addEventListener( 'click', function ( event ) {
179 if ( ! mobileSidebar.contains( event.target ) ) {
180 mobileSidebar.classList.remove( 'hsr-active' );
181 document.querySelector('body').classList.remove( 'hsr-sidebar-active' );
182 }
183 } );
184 } );
185
186
187
188 } )( jQuery );
189