Skip to content

Instantly share code, notes, and snippets.

View jeremypage's full-sized avatar

Jeremy Page jeremypage

  • Trafford Council
  • UK
View GitHub Profile
@jeremypage
jeremypage / more-less.js
Created October 17, 2017 13:42
JavaScript / jQuery: Add 'Show more / show less' link at bottom of block to show/hide more content
$(function () {
// Hide the extra content initially (or could be done using css / inline style attribute)
$('.more-content').hide();
// Add 'show more' text beneath the main content
$(".more-less").append('<div class="adjust" style="cursor:pointer">Show more \u25bc</div>');
// Show hidden content when 'show more' selected
$('.more-less').on('click', '.adjust', function (e) {
$(this).siblings('.more-content').slideToggle();
// Change to 'show less' when extra content is visible
($(this).text() === 'Show more \u25bc') ? $(this).text('Show less \u25b2') : $(this).text('Show more \u25bc');
@jeremypage
jeremypage / jQuery-noConflicy.md
Last active December 28, 2020 07:37
jQuery: Using noConflict() to use multiple versions of jQuery on the same page

How to use multiple versions of jQuery on the same page

First, reference 'legacy' jQuery version:

<script src="jquery.1.10.2.js"></script>

Do any necessary legacy jQuery stuff, and anything that is not version-dependent:

@jeremypage
jeremypage / responsive-square-tiles.html
Created November 14, 2018 21:42
HTML/CSS: Responsive square tiles with text overlay
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- Enable responsive view on mobile devices -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Responsive tiled photo gallery in pure CSS</title>
@jeremypage
jeremypage / chrome-date-validation-fix.js
Last active February 9, 2019 08:09
jQuery Validate: Custom unobtrusive date validator (fixes Chrome date validation bug)
// Handle Chrome date validation 'bug'
jQuery.validator.addMethod('date', function (value, element) {
jQuery.culture = Globalize.culture("en-GB");
var date = Globalize.parseDate(value, "dd/MM/yyyy", "en-GB");
return this.optional(element) || !/Invalid|NaN/.test(new Date(date).toString());
});
@jeremypage
jeremypage / dynamic-content-filtering.js
Created January 31, 2019 12:10
JavaScript: Dynamic filtering of page content using search box. Optionally send search term to analytics.
// Dynamic filtering of page content
// Wrap content to be filtered in #contentToFilterContainer element
// Add data-filter attributes with keywords for each (child) item to be filtered
var contentToFilterContainer = jQuery('#contentToFilterContainer');
var keyupTimer;
var filterCaption = (!!contentToFilterContainer.data('filtercaption') ? contentToFilterContainer.data('filtercaption') : 'Search page');
contentToFilterContainer.before('<label for="filterText">' +
filterCaption +
'</label><input type="text" id="filterText" class="content-filter" title="start typing here to filter content on the page" data-tooltip />'
@jeremypage
jeremypage / jstree-sort.js
Last active April 24, 2019 06:03
jsTree: Custom sort - Specify priority entries that must always be listed first, and the order they must appear
// Example usage:
// $("#EstablishmentTree").jstree({
// // other jstree properties ...
// "sort": // function sort(a, b) { ... }
// });
function sort(a, b) {
// For jsTree, use get_text() to get node text:
// var textA = this.get_text(a), textB = this.get_text(b);
@jeremypage
jeremypage / add-external-link-annotation.js
Created April 17, 2019 13:19
JavaScript: Add 'external link' annotation to specific (external) links
@jeremypage
jeremypage / big-number-list.css
Last active April 2, 2020 11:01
CSS: Ordered list with bigger numbers
/* Creates extra-large ordered list numbering */
.bignum {
margin-left: 0;
counter-reset: listItem;
}
.bignum>li {
list-style: none;
position: relative;
@jeremypage
jeremypage / hidden-text.css
Created July 21, 2020 08:03
CSS: Hidden text (when content is hidden, but still present for screen readers)
.hidden-text {
position: absolute;
left: -10000px;
height: 1px;
width: 1px;
}
@jeremypage
jeremypage / skip-to-content.md
Created July 21, 2020 14:41
HTML/CSS: Skip to content link
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Skip to content</title>
	<style>
		#skiptocontent a {
 padding: 6px;