forked from zendesk/copenhagen_theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
356 lines (305 loc) · 14.3 KB
/
script.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/* eslint-disable */
document.addEventListener('DOMContentLoaded', function() {
function closest (element, selector) {
if (Element.prototype.closest) {
return element.closest(selector);
}
do {
if (Element.prototype.matches && element.matches(selector)
|| Element.prototype.msMatchesSelector && element.msMatchesSelector(selector)
|| Element.prototype.webkitMatchesSelector && element.webkitMatchesSelector(selector)) {
return element;
}
element = element.parentElement || element.parentNode;
} while (element !== null && element.nodeType === 1);
return null;
}
// social share popups
Array.prototype.forEach.call(document.querySelectorAll('.share a'), function(anchor) {
anchor.addEventListener('click', function(e) {
e.preventDefault();
window.open(this.href, '', 'height = 500, width = 500');
});
});
// In some cases we should preserve focus after page reload
function saveFocus() {
var activeElementId = document.activeElement.getAttribute("id");
sessionStorage.setItem('returnFocusTo', '#' + activeElementId);
}
var returnFocusTo = sessionStorage.getItem('returnFocusTo');
if (returnFocusTo) {
sessionStorage.removeItem('returnFocusTo');
var returnFocusToEl = document.querySelector(returnFocusTo);
returnFocusToEl && returnFocusToEl.focus && returnFocusToEl.focus();
}
// show form controls when the textarea receives focus or backbutton is used and value exists
var commentContainerTextarea = document.querySelector('.comment-container textarea'),
commentContainerFormControls = document.querySelector('.comment-form-controls, .comment-ccs');
if (commentContainerTextarea) {
commentContainerTextarea.addEventListener('focus', function focusCommentContainerTextarea() {
commentContainerFormControls.style.display = 'block';
commentContainerTextarea.removeEventListener('focus', focusCommentContainerTextarea);
});
if (commentContainerTextarea.value !== '') {
commentContainerFormControls.style.display = 'block';
}
}
// Expand Request comment form when Add to conversation is clicked
var showRequestCommentContainerTrigger = document.querySelector('.request-container .comment-container .comment-show-container'),
requestCommentFields = document.querySelectorAll('.request-container .comment-container .comment-fields'),
requestCommentSubmit = document.querySelector('.request-container .comment-container .request-submit-comment');
if (showRequestCommentContainerTrigger) {
showRequestCommentContainerTrigger.addEventListener('click', function() {
showRequestCommentContainerTrigger.style.display = 'none';
Array.prototype.forEach.call(requestCommentFields, function(e) { e.style.display = 'block'; });
requestCommentSubmit.style.display = 'inline-block';
if (commentContainerTextarea) {
commentContainerTextarea.focus();
}
});
}
// Mark as solved button
var requestMarkAsSolvedButton = document.querySelector('.request-container .mark-as-solved:not([data-disabled])'),
requestMarkAsSolvedCheckbox = document.querySelector('.request-container .comment-container input[type=checkbox]'),
requestCommentSubmitButton = document.querySelector('.request-container .comment-container input[type=submit]');
if (requestMarkAsSolvedButton) {
requestMarkAsSolvedButton.addEventListener('click', function () {
requestMarkAsSolvedCheckbox.setAttribute('checked', true);
requestCommentSubmitButton.disabled = true;
this.setAttribute('data-disabled', true);
// Element.closest is not supported in IE11
closest(this, 'form').submit();
});
}
// Change Mark as solved text according to whether comment is filled
var requestCommentTextarea = document.querySelector('.request-container .comment-container textarea');
if (requestCommentTextarea) {
requestCommentTextarea.addEventListener('input', function() {
if (requestCommentTextarea.value === '') {
if (requestMarkAsSolvedButton) {
requestMarkAsSolvedButton.innerText = requestMarkAsSolvedButton.getAttribute('data-solve-translation');
}
requestCommentSubmitButton.disabled = true;
} else {
if (requestMarkAsSolvedButton) {
requestMarkAsSolvedButton.innerText = requestMarkAsSolvedButton.getAttribute('data-solve-and-submit-translation');
}
requestCommentSubmitButton.disabled = false;
}
});
}
// Disable submit button if textarea is empty
if (requestCommentTextarea && requestCommentTextarea.value === '') {
requestCommentSubmitButton.disabled = true;
}
// Submit requests filter form on status or organization change in the request list page
Array.prototype.forEach.call(document.querySelectorAll('#request-status-select, #request-organization-select'), function(el) {
el.addEventListener('change', function(e) {
e.stopPropagation();
saveFocus();
closest(this, 'form').submit();
});
});
// Submit requests filter form on search in the request list page
var quickSearch = document.querySelector('#quick-search');
quickSearch && quickSearch.addEventListener('keyup', function(e) {
if (e.keyCode === 13) { // Enter key
e.stopPropagation();
saveFocus();
closest(this, 'form').submit();
}
});
function toggleNavigation(toggle, menu) {
var isExpanded = menu.getAttribute('aria-expanded') === 'true';
menu.setAttribute('aria-expanded', !isExpanded);
toggle.setAttribute('aria-expanded', !isExpanded);
}
function closeNavigation(toggle, menu) {
menu.setAttribute('aria-expanded', false);
toggle.setAttribute('aria-expanded', false);
toggle.focus();
}
var burgerMenu = document.querySelector('.header .menu-button');
var userMenu = document.querySelector('#user-nav');
burgerMenu.addEventListener('click', function(e) {
e.stopPropagation();
toggleNavigation(this, userMenu);
});
userMenu.addEventListener('keyup', function(e) {
if (e.keyCode === 27) { // Escape key
e.stopPropagation();
closeNavigation(burgerMenu, this);
}
});
if (userMenu.children.length === 0) {
burgerMenu.style.display = 'none';
}
// Toggles expanded aria to collapsible elements
var collapsible = document.querySelectorAll('.collapsible-nav, .collapsible-sidebar');
Array.prototype.forEach.call(collapsible, function(el) {
var toggle = el.querySelector('.collapsible-nav-toggle, .collapsible-sidebar-toggle');
el.addEventListener('click', function(e) {
toggleNavigation(toggle, this);
});
el.addEventListener('keyup', function(e) {
if (e.keyCode === 27) { // Escape key
closeNavigation(toggle, this);
}
});
});
// Show the webinar bar on some whole sections and some specific articles
var checkSectionEl = document.querySelector('.js-check-section');
var webinarWhitelist = [
'360000372333', // Get Started category
'360000883273', // What do you need help with section
'115001334107', // Settings category
'115002622868', // Company Settings section
'115001335727', // Videos category
'115002328508', // Videos section
'115004125828', // Getting Started Videos section
'115001344107', // Glossary
'115009450867', // Client basics
'360034980534', // Import your clients
'115009378727', // Quote basics
'115009379027', // Job basics
'115009685047', // Invoice Basics
'360052416073', // Import your calendar
'115009233447', // Calendar overview
'115009571387', // Jobber payments basics
'115009786848' // Setting up QuickBooks Online Sync
]
if (checkSectionEl) {
var currentSection = checkSectionEl.dataset.section;
var articleID = checkSectionEl.dataset.id;
// var banner = document.querySelector('#jobbar-banner');
// if (webinarWhitelist.includes(currentSection) || webinarWhitelist.includes(articleID)){
// banner.style.display = "flex";
// }
}
// display a message if jobberstatus.net is reporting maintenance or an outage
var sp = new StatusPage.page({ page : '7qns4hqkcjx5' });
// var sp = new StatusPage.page({ page : 'p2lpv5tmvf9q' }); //'Statusbar Test' dev account
sp.summary({
success: function (data) {
var statusIndicator = data.status.indicator;
if(data.incidents.length || statusIndicator === 'maintenance'){
var maintenance_component_name;
if (statusIndicator === 'maintenance'){
data.components.forEach(component => {
if (component.status == 'under_maintenance') {
maintenance_component_name = component.name;
}
});
}
var statusTitle = (data.incidents.length) ? 'SERVICE DISRUPTION' : 'SCHEDULED MAINTENANCE';
var maintenance_message = typeof maintenance_component_name !== 'undefined' ? 'We’re doing scheduled maintenance on our ' + maintenance_component_name + ' right now. Thank you for your patience.' : 'Jobber is undergoing scheduled maintenance right now. Thank you for your patience. '
var statusBody = (data.incidents.length) ? 'Some parts of Jobber are currently down. We’re sorry for the inconvenience, and we’re working to get things back up and running ASAP.' : maintenance_message;
document.getElementById("jobbar-banner").innerHTML = '<div class="container jobbar-banner__container"><div class="jobbar-banner__content"><div>'+statusTitle+'</div><div class="jobbar-banner__subtitle">'+statusBody+'</div></div><a href="https://www.jobberstatus.net/" class="button">LEARN MORE</a></div>';
document.getElementById("jobbar-banner").style.display = "flex";
}
}
});
// Submit organization form in the request page
var requestOrganisationSelect = document.querySelector('#request-organization select');
if (requestOrganisationSelect) {
requestOrganisationSelect.addEventListener('change', function() {
closest(this, 'form').submit();
});
}
// If a section has more than 6 subsections, we collapse the list, and show a trigger to display them all
const seeAllTrigger = document.querySelector("#see-all-sections-trigger");
const subsectionsList = document.querySelector(".section-list");
if (subsectionsList && subsectionsList.children.length > 6) {
seeAllTrigger.setAttribute("aria-hidden", false);
seeAllTrigger.addEventListener("click", function(e) {
subsectionsList.classList.remove("section-list--collapsed");
seeAllTrigger.parentNode.removeChild(seeAllTrigger);
});
}
// If multibrand search has more than 5 help centers or categories collapse the list
const multibrandFilterLists = document.querySelectorAll(".multibrand-filter-list");
Array.prototype.forEach.call(multibrandFilterLists, function(filter) {
if (filter.children.length > 6) {
// Display the show more button
var trigger = filter.querySelector(".see-all-filters");
trigger.setAttribute("aria-hidden", false);
// Add event handler for click
trigger.addEventListener("click", function(e) {
e.stopPropagation();
trigger.parentNode.removeChild(trigger);
filter.classList.remove("multibrand-filter-list--collapsed")
})
}
});
//HIGHLIGHT TEXT
function isInView( elm ) {
const topBoundary = window.innerHeight / 5;
const bottomBoundary = window.innerHeight - topBoundary;
const elementRect = elm.getBoundingClientRect();
return ( elementRect.top >= topBoundary ) && ( elementRect.bottom <= bottomBoundary );
};
const HIGHLIGHT_TEXT = $( '.highlight-text' );
document.addEventListener( 'DOMContentLoaded', function() {
for( var i = 0; i < HIGHLIGHT_TEXT.length; i++ ) {
if ( isInView( HIGHLIGHT_TEXT[i] ) ) {
HIGHLIGHT_TEXT[i].classList.add( 'highlight-text--in-view' );
}
}
} );
window.addEventListener( 'scroll', function() {
for( var i = 0; i < HIGHLIGHT_TEXT.length; i++ ) {
if ( isInView( HIGHLIGHT_TEXT[i] ) ) {
HIGHLIGHT_TEXT[i].classList.add( 'highlight-text--in-view' );
}
};
} );
function centerWistiaVids() {
window._wq = window._wq || [];
const wistiaIds = window.wistiaEmbeds && window.wistiaEmbeds.map(({ _hashedId }) => _hashedId);
wistiaIds.forEach(HashId => {
_wq.push({
id: HashId,
onReady: video => {
const videoContainer = document.querySelector(`.wistia_async_${HashId}`);
const grandParent = videoContainer.parentNode.parentNode;
const aspect = video.aspect();
if (aspect < 1) {
grandParent.classList.add("this-is-a-vertical-video");
}
}
});
});
}
var numVideos = document.getElementsByClassName("wistia_embed").length;
if( numVideos > 0 ) {
function tryPageLoad() {
if(window.wistiaEmbeds) {
if( window.wistiaEmbeds.length === numVideos ) {
centerWistiaVids();
} else {
setTimeout(tryPageLoad, 100);
}
}
else {
setTimeout(tryPageLoad, 100);
}
}
tryPageLoad();
}
});
// redirects
var oldIds = ["360019766773", "115009518827", "115009727208", "360021265374", "360007324274", "115009727668", "115009560387", "115011697807", "360046288634", "115009519087", "360033659193", "115009730468", "115009560687", "115009730148", "360042930793", "8420210943767", "360023027673", "115010546447", "360051851213", "1500001840841", "360021573434", "360029029913"];
var newIds = ["360056046054", "7061327071639", "8196953752855", "7448087796631", "8195739126039", "7760313735575", "8185260991127", "8196925335575", "8196961124887", "7447835963159", "8185260991127", "8508884808599", "7447924360855", "8354601698583", "7453632138391", "7061327071639", "15594265901591", "15594265901591", "23846836592023", "23846836592023", "24244124296471", "24244124296471"];
for (var i = 0; i < oldIds.length; i++){
if (window.location.href.indexOf(oldIds[i]) > -1) {
window.location.href = 'https://help.getjobber.com/hc/en-us/articles/' + newIds[i];
}
}
//billing redirect
if (window.location.href.indexOf('115001334127-Billing-Add-ons') > -1) {
window.location.href = 'https://help.getjobber.com/hc/en-us/sections/360005048253-Billing';
}
// video redirect
if (window.location.href.indexOf('360021749753') > -1) {
window.location.href = 'https://www.youtube.com/channel/UCE_6hSXDXbyz1r9uoh6hv5w';
}