-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions,js
78 lines (73 loc) · 4.01 KB
/
functions,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
// Copy this into ACP->admin/appearance/customise#custom-js
function threaded() {
$(document).ready(function () {
// Check if the screen width is 1200px or more
if ($(window).width() >= 1200) {
// Check if the dropdown already exists
if ($('#enableThreading').length === 0) {
var threadView = $('<div class="threads-wrapper"><i class="fa fa-fw fa-bars left"></i><form class="form"><div class="form-check form-switch sticky-tools-bar"> \
<input class="form-check-input" id="enableThreading" type="checkbox" data-field="enableThreading"> \
<label class=" d-none d-md-inline fw-semibold" for="enableThreading"><i class="fa fa-fw fa-bars-staggered right"></i></label> \
</div></form></div>');
$('.topic .sticky-tools .thread-tools').append(threadView);
// If you have browsing users plugin, comment out the above line and uncomment the one below
//$('.topic .sticky-tools ul [component="topic/browsing-users"]:last-of-type').append(threadView);
// Check if there's a stored state for the checkbox and update it
var storedState = localStorage.getItem('enableThreadingState');
if (storedState === 'true') {
$('#enableThreading').prop('checked', true);
}
}
// Toggle the class 'threaded' on or off when the checkbox changes state
$('#enableThreading').on('change', function () {
var isChecked = $(this).is(':checked');
var theTooltip = isChecked ? "Disable Threading" : "Enable Threading"; // Update tooltip message
if (isChecked) {
console.log('Thread view is active.');
$('ul[component="topic"]').addClass('threaded');
$('.posts-container').addClass('threaded')
$('ul[component="topic"]').addClass('threaded')
$('.post-container').addClass('threaded')
$('.timeline-event').addClass('threaded')
$('[component="post/footer"]').addClass('threaded');
$('[component="post"]').each(function () {
// Add the 'threaded' class to matching elements
if ($(this).hasClass('pt-4') || $(this).hasClass('self-post')) {
$(this).addClass('threaded');
$('.topic .sticky-tools').addClass('threaded');
}
});
} else {
console.log('Thread view is inactive.');
$('[component="post"]').removeClass('threaded');
$('ul[component="topic"]').removeClass('threaded');
$('.posts-container').removeClass('threaded')
$('ul[component="topic"]').removeClass('threaded')
$('.post-container').removeClass('threaded')
$('.timeline-event').removeClass('threaded')
$('[component="post/footer"]').removeClass('threaded');
$('.topic .sticky-tools').removeClass('threaded');
}
// Store the checkbox state in localStorage
localStorage.setItem('enableThreadingState', isChecked);
// Update the tooltip title
$(this).attr('data-original-title', theTooltip).tooltip('dispose').tooltip({
placement: 'bottom',
title: theTooltip,
trigger: 'hover'
});
});
// Check for changes in the checkbox state when the page loads
$('#enableThreading').trigger('change');
}
});
}
$(window).on('action:ajaxify.end', function (data) {
threaded();
});
$(window).on('action:posts.edited', function (data) {
threaded();
});
$(window).on('action:posts.loaded', function (data) {
threaded();
});