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 / 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 / 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 / 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 / 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 / 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 / web.config
Created October 16, 2017 10:42
web.config: Force browsers to re-validate redirects (HTTP 301 and HTTP 302). Useful when a redirect has changed or been removed.
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Require clients to re-validate redirects">
<match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{RESPONSE_STATUS}" pattern="301" />
<add input="{RESPONSE_STATUS}" pattern="302" />
</conditions>
@jeremypage
jeremypage / contensis-atom-reader-config.xml
Last active August 31, 2019 16:31
Contensis: RSS and Atom feed readers
<control name="Atom feed reader" category="Trafford controls" showInMenu="true" viewingGroup="1">
<properties>
<text name="FeedUrl" required="true" label="Feed URL">
<parameters>
<parameter name="FeedUrl" value="http://intranet.trafford.gov.uk/Forum/feed.php" />
</parameters>
</text>
</properties>
</control>
@jeremypage
jeremypage / extract-image-colours.js
Last active June 29, 2017 15:22
Use Vibrant.js to extract foreground and background colours from images (uses http://jariz.github.io/vibrant.js/)
(function ($) {
$(document).ready(function () {
$('.image-to-colour').each(function (index, element) {
var images = $(this).find('img');
if (images.length == 1) {
var imageColours = getImageColours(images[0]);
element.style.color = imageColours.textColour;
element.style.backgroundColor = imageColours.backgroundColour;
}
});
@jeremypage
jeremypage / google-search-widget.js
Last active September 4, 2017 09:42
Embed-able Google search widget
(function($){
$('#internet-search-control').before('<div class="internet-search" style="min-height:64px;width:400px;margin:1em auto 1em auto;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAAsCAYAAACue3wzAAAACXBIWXMAAC4jAAAuIwF4pT92AAAZ+klEQVR42u1cd1wU97b/qdGbdhNza+7Leze3pFqwIFKWXTpYULFjxYJKkQ7L1umzhWKwxxqNiV1jrsaoIGhM9N4YTTPGVH2WWEBROgSZd87s7FKkeUu87z3+OJ/dnfnNML/f93fO+Z4yEIZhSHtCy8ISnjaQLDqB2OjkdsVOJxKRTleua//e/1+FZmjC0Mw9Ih//J/+tDoBlCEubiYVOI2aWJ0nsusfmM6f9RnHfpI7hv1wTwX+5ewz35T74viWCO2cLt343cT6/4zk9lS1fw9P6LqDbAJinOCKaeZcIZu6nA9gJiEBrCU1TJJrd/VKIcG2ZjyhdUAs/SmqxbVGJDVX+fPnBKcz7o3VMDgCdDruT6gK5iYgmnkQujVH7bZxSEPzajP0BG6YWjF41ZyVHsQ5t/lcC7NBaE7FSySSe3dQ7WLi+2EdoqPMTaqVAoVwKFCs6kHLJX6ySVIIk+QlVhyKZEy/wdCbhaGMXyIpYjQIZsTpq2ou7Rkj9t4+RXt4ZLqk2Tb7EgxYz1L8QYBp2D8/oCUvRZALzuadaqPkWtRJBcwEogDDVkq/YAHK3mSCwjWMBaKFK8hKkion8qdloCRgw910AA8AmgYDGTuq/Y7TkvnW8NGB7hOS/ceoXaLb/ZRrs1FyGMpNR3FfhPoJUGyBWKoCVSwEAGoLtY7n7vdeqWxsmsqdiJ3CfhE/gPwmDzykTuFP2AOHOB76i1ARouA42hIco3Yim9z4pUBldAD9IgG1gliOZT31B6+421UQ/s

API workthough

  1. Open a browser

    # start an instance of firefox with selenium-webdriver
    driver = Selenium::WebDriver.for :firefox
    # :chrome -> chrome
    # :ie     -> iexplore
    
  • Go to a specified URL