Skip to content

Instantly share code, notes, and snippets.

View jonkemp's full-sized avatar

Jonathan Kemp jonkemp

View GitHub Profile
@jonkemp
jonkemp / jQuery Checkbox Shortcut
Created March 14, 2011 18:41
An alias or shortcut for selecting checkboxes quickly in jQuery.
$.fn.checkbox = function () {
return this.find('input[type="checkbox"]');
};
@jonkemp
jonkemp / query.js
Last active September 25, 2015 06:17
A simple function for getting parameters from a query string.
function query( key ) {
if ( location.href.indexOf("?") !== -1 ) {
var q = location.search,
p = [],
i, val;
q = q.slice(1);
if ( q.indexOf("&") !== -1 ) {
q = q.split("&");
for ( i=0; i < q.length; i++ ) {
p.push( q[i].split("=") );
@jonkemp
jonkemp / Clear localStorage Bookmarklet
Created March 31, 2011 21:14
A bookmarklet for clearing data saved to localStorage in whatever domain you are on.
<a href="javascript:(function(){localStorage.clear();})();">Clear localStorage</a>
@jonkemp
jonkemp / Check localStorage
Last active July 10, 2024 21:06
This code will log key/value pairs saved in localStorage to your console for whatever domain you are on.
if ( localStorage.length > 0 ) {
for ( let i=0; i < localStorage.length; i++ ) {
console.log( `${localStorage.key(i)}:${localStorage.getItem( localStorage.key(i) )}` );
}
}
@jonkemp
jonkemp / Check localStorage Bookmarklet
Created March 31, 2011 21:29
A bookmarklet for viewing localStorgage key/value pairs in your console.
<a href="javascript:(function(){if(localStorage.length){for(var i=0;i<localStorage.length;i++){console.log(localStorage.key(i)+':'+localStorage.getItem(localStorage.key(i)));}}})();">Check localStorage</a>
@jonkemp
jonkemp / prepopulate.html
Created April 5, 2011 15:11
Pre-populate your forms with random data. For testing forms. Requires jQuery. Includes a bookmarklet.
<!-- include jQuery -->
<script>
$('form').find('input:text').val( function(i, val) {
return $(this).attr('name');
});
$('form').find('select').each( function(a) {
$(this).find('option').each( function(b) {
if ( $(this).val() !== '' ) {
$(this).parent().val( $(this).val() );
@jonkemp
jonkemp / ago.js
Created June 5, 2011 21:32 — forked from gf3/ago.js
Super small relative dates
module.exports = (function(){
const MS =
{ seconds: 1000
, minutes: 60 * 1000
, hours: 60 * 60 * 1000
, days: 24 * 60 * 60 * 1000
, weeks: 7 * 24 * 60 * 60 * 1000
, months: 30 * 7 * 24 * 60 * 60 * 1000
, years: 365 * 24 * 60 * 60 * 1000 }
@jonkemp
jonkemp / futon.js
Created August 28, 2011 04:07
Simple object oriented script for creating a global namespace and then extending via the prototype.
/*
Ex:
ftn.extend({
foo: function() {
console.log( "foo" );
}
});
ftn.foo();
@jonkemp
jonkemp / snippet.js
Created March 8, 2012 16:29 — forked from necolas/snippet.js
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@jonkemp
jonkemp / css-calc.css
Created April 2, 2012 04:17
Cross Browser CSS Calc()
/* 1. write it out for older browsers */
/* 2. use the vendor prefix for webkit */
/* 3. use the vendor prefix for moz */
/* 4. include the un-prefixed version last */
#foo {
width: 200px;
width: -webkit-calc(50% - 100px);
width: -moz-calc(50% - 100px);
width: calc(50% - 100px);