Skip to content

Instantly share code, notes, and snippets.

@robertcdawson
robertcdawson / add_char_limit.js
Created June 12, 2014 19:50
Add a character count below any input field
function setCount(source, target, limit)
{
var chars = source.val().length;
if (chars > limit)
{
// Disable submit button
jQuery("input#submit").attr('disabled', 'disabled');
source.css("background", "#fee");
target.css("color", "red");
if ((chars - limit) > 1)
@robertcdawson
robertcdawson / simplify_words.js
Last active August 29, 2015 14:02
Simplify words on web pages
// This script replaces harder words with easier ones for faster reading.
jQuery('p,li,blockquote').each(function() {
var text = jQuery(this).html();
jQuery(this).html(
text.replace(/\baccompanying\b/, 'going with')
.replace(/\baccompanied\b/, 'went with')
.replace(/\baccompanies\b/, 'goes with')
.replace(/\baccompany\b/, 'go with')
.replace(/\baccomplishing\b/, 'doing')
.replace(/\baccomplished\b/, 'did')
@robertcdawson
robertcdawson / gallery_arrows.js
Last active August 29, 2015 13:59
This function allows users to navigate a photo gallery with left and right arrow keys if that functionality does not exist.
@robertcdawson
robertcdawson / is_today.js
Created December 13, 2013 22:12
This function compares a parameter, a string formatted in a valid date format (.e.g., 01/01/2014) to today's date and returns true or false, accordingly.
function isToday(d)
{
var date_param = new Date(d).toDateString();
var date_today = new Date().toDateString();
var is_today = (date_today == date_param);
return is_today;
}
// Example use: console.log(isToday("01/01/2014"));
@robertcdawson
robertcdawson / get_url_params.js
Created October 17, 2013 01:05
This function returns an array of URL parameters.
/**
* Get URL parameters
* @return array of URL parameters
*/
function getUrlParams()
{
var params = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{