PageSourceSearch

https://exploringsecularism.org/custom/javascript/cp.js?1

js exploringsecularism.org collected 2026-10-08 13:58:51 UTC 5,515 bytes, 178 lines download raw bytes

1/***** Functions *****/
2// Remove the link from around an image (useful to stop redundant link warning when accessibility testing)
3export const removeImgLink = (item, imgPath, imgParent) => {
4	$(item).find(imgParent).replaceWith(function() {
5		return imgPath;
6	});
7}
8
9// Remove links from element move them to the start of the parent element so they can be positioned across the entire box
10export const blockStyling = (items, path, type = null, wrapInner = true) => {
11	$(items).map(function() {
12		let theLink = $(this).find(path);
13		let titleText = $(this).find(path).text();
14		let image;
15		if(path == '.doc-info > a') {
16			theLink.replaceWith(function() {
17				return `<p class="title">${$(this).text()}</p>`;
18			});
19		} else {
20			theLink.parent().replaceWith(function() {
21				// if(type != 'a') {
22					// return $(this).text();
23				// } else {
24					return `<p class="title">${$(this).text()}</p>`;
25				// }
26			});
27		}
28		if(wrapInner) {
29			if($(this).find('.highlight').length < 1) {
30				$(this).find('> *:not(.image)').wrapAll('<div class="inner-content"></div>');
31			} else {
32				$(this).find('.highlight > *:not(.image)').wrapAll('<div class="inner-content"></div>');
33			}
34		}
35		if($(this).find('img').length > 0) {
36			image = $(this).find('.image');
37			$(this).prepend(image);
38			
39		}
40		if($(this).find('.image a').length > 0) {
41			removeImgLink($(this), $(this).find('.image a img'), $(this).find('.image a'));
42		}
43		if($(this).find('.tags').length > 0) {
44			let tagContainer = $(this).find('.tags');
45			tagContainer.find('.label').remove();
46			$(this).find('.image').append(tagContainer);
47		}
48		if($(this).find('.read-more').length > 0) {
49			$(this).find('.read-more').remove();
50		}
51		noImgCheck($(this), $(this).find('.image a img'), $(this).find('.image a'));
52		$(this).prepend(theLink.text('').attr('title', titleText));
53	});
54}
55
56// Map across all links and apply external class if the window.location.origin doesn't match that of the site.
57export const checkExternal = (item) => {
58	const baseURL = window.location.origin;
59	console.log(baseURL)
60	$(item).map(function() {
61		const aLink = $(this).attr('href');
62		if(!aLink.includes(window.location.origin) || aLink.hasClass('external')) {
63			$(this).addClass('external');
64		}
65	});
66}
67
68// Self explanatory, checks with width of the page and applies classes/adds elements/runs functions needed for smaller views
69export const checkWidth = (mobileThreshold) => {
70	var windowSize = $(window).width();
71	if(windowSize <= 1260) {
72		$('body').addClass('mobile');
73		if($('.mob-menu').length === 0) {
74			let mobMenu = $('.header > .wrap nav').clone();
75			console.log(mobMenu)
76			mobMenu.addClass('mob-menu');
77			mobMenu.insertAfter($('.side-menu .top-bar'));
78			$('.header .side-menu .mob-menu, .header .side-menu > ul').wrapAll('<div class="mob-inner"></div>');
79		}
80		if($('.mobile').length > 0) {
81			var dropdownTrigger = $('.dropdown-trigger');
82			if(dropdownTrigger.length === 0) {
83				// $('li.has-submenu > a').wrap('<span class="link-wrp"></span>');
84				// $('li.has-submenu > span').append('<span class="dropdown-trigger"></span>');
85				$('.dropdown-trigger').click(function() {
86					$(this).parent('span').siblings('div').slideToggle();
87				});
88			}
89		}
90	} else {
91		$('body').removeClass('mobile');
92		$('.header').removeClass('show-menu');
93		$('li.has-submenu').find('.dropdown-trigger').remove();
94		if($('.mob-menu').length > 0) {
95			$('.mob-menu').remove();
96		}
97	}
98}
99
100// Check if specified element contains an image and adds the 'no-image' div if not
101export const noImgCheck = (elemnt) => {
102	if(elemnt.find('img').length < 1 && elemnt.find('.image').length < 1) {
103		elemnt.prepend('<div class="image no-image"></div>');
104	}
105}
106
107export const slideRestruc = () => {
108	$('.home-slider .item').map(function() {
109		
110		$(this).find('.heading, .description').wrapAll('<div class="content-wrap"></div>');
111		$(this).find('.clear').remove();
112		
113		cp.removeImgLink($(this), $(this).find('.image a img'), $(this).find('.image a'));
114		
115		if($(this).find('.heading a').length > 0) {
116			let headLink = $(this).find('.heading a').clone();
117			
118			$(this).find('.content-wrap').append(headLink.text('Read More').addClass('button'));
119			
120			$(this).find('.heading a').replaceWith(function() {
121				return `<h2 class="heading">${$(this).text()}</h2>`;
122			})
123		}
124	
125	});
126}
127
128export const removeRedundantTitles = () => {
129	$('a').map(function() {
130		if($(this).text() > 0 && $(this).attr('title')) {
131			// $(this).removeAttribute('title');
132		}
133	});
134}
135
136export const removeImageTitles = () => {
137	$('img').map(function() {
138		if($(this).attr('title') && $(this).attr('alt')) {
139			$(this).removeAttr('title');
140		} else if($(this).attr('title') && !$(this).attr('alt')) {
141			$(this).attr('alt', $(this).attr('title'));
142			$(this).removeAttr('title');
143		}
144	});
145}
146
147export const applyImageDimensions = () => {
148	$('img').map(function() {
149		let theWidth = $(this).outerWidth();
150		let theHeight = $(this).outerHeight();
151		
152		$(this).attr({
153			'width': theWidth,
154			'height': theHeight
155		})
156		
157	})
158}
159
160// TODO - Find way to allow stacking of alerts
161export const flashBehaviour = () => {
162	if($('#flash:not(.flash-persist)').length > 0) {
163		setTimeout(() => {
164			$('#flash:not(.flash-persist)').addClass('flash-shown');
165		}, 4000);
166		setTimeout(() => {
167			$('#flash:not(.flash-persist)').remove();
168		}, 5000)
169	}
170}
171
172export const itemEditFormat = () => {
173	$('.item.slide-down').map(function() {
174		if($(this).find('.editbuttons').length > 0) {
175			$(this).find('.editbuttons').insertBefore($(this));
176		}
177	});
178}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.