Skip to content

Instantly share code, notes, and snippets.

View spsaucier's full-sized avatar

Stephen Saucier spsaucier

View GitHub Profile
@spsaucier
spsaucier / gist:6044067
Created July 20, 2013 06:24
Form with jQuery Number Verification
<div id="MyForm">
<form method="POST" name="info-form">
<input type="hidden" value="/form-sent" name="returnURL" />
<label for="First Name">First Name: </label>
<input type="text" name="First Name" maxlength="40" />
<label for="Last Name">Last Name: </label>
<input type="text" name="Last Name" maxlength="80" />
<label>Enter the below number: </label>
<input type="hidden" value="701469" id="verifyNumHidden" name="verifyNumHidden" />
<input type="text" id="enterVerify" name="enterVerify" />
@spsaucier
spsaucier / gist:6044068
Created July 20, 2013 06:25
Check Delivery Postcode JS
$('#checkDelivery').submit(function() {
var data = $(this).serializeArray(),
postcodes = [2015,2019,2015,2018,2011];
jQuery.each(data, function(i, field){
if ( $.inArray(parseInt(field.value), postcodes) != -1 ) {
$('#delivery_options').html('<p>Yes, we deliver to your area!</p>');
}
else {
$('#delivery_options').html('<p>Unfortunately, we do not deliver to your area.</p>');
}
@spsaucier
spsaucier / gist:6044069
Created July 20, 2013 06:25
Include jQuery through Console
var jq = document.createElement('script');
jq.src = "http://code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
@spsaucier
spsaucier / gist:6044070
Created July 20, 2013 06:25
Wordpress - Import Posts - Assign to Author
$('#authors > li').each(function(){
var textstring = $(this).find('strong').text().split(" (");
console.info(textstring[0]);
$(this).find('select[name^=user_map] option').filter(function() {
return $(this).text() == textstring[0];
}).prop('selected', true);
});
@spsaucier
spsaucier / gist:6044072
Last active December 20, 2015 00:48
Disallow large file uploads
// Disallows uploads over 2Mb
$(document).on('change', 'input[type=file]', function() {
//this.files[0].size gets the size of your file.
if (this.files[0].size > 2097152 || this.files[0].filesize > 2097152) {
alert('Your file is too large (over 2Mb). Please use a smaller file.')
$(this).wrap('<form>').closest('form').get(0).reset();
$(this).unwrap();
}
});
@spsaucier
spsaucier / gist:6044073
Created July 20, 2013 06:26
Preload images
// Preload images, append, & hide
$("a").has('img').each(function() {
$('<img />').attr('src',$(this).data("large-image")).appendTo('body').hide();
});
// Inline Labels
// -------------------------------------------------- //
$('input, textarea').each(function() {
var self = $(this),
label = $("label[for='" + self.attr("id") + "']").hide().text();
// Replace initial values
if (!self.val().replace(/^\s+/g, "").length) {
@spsaucier
spsaucier / gist:7190181
Created October 28, 2013 01:41
Easily fade-out/truncate content & enable Read More button to expand content (white background).
<div class="truncate">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex, error, magni dicta fugit delectus nobis harum! Temporibus, ipsam, sequi nam ullam praesentium doloribus quis necessitatibus error molestias natus non eaque. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus, accusamus, cumque, adipisci modi officiis magnam eaque aspernatur recusandae accusantium aliquam debitis explicabo dolores ratione labore nulla similique consequuntur sapiente saepe!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex, error, magni dicta fugit delectus nobis harum! Temporibus, ipsam, sequi nam ullam praesentium doloribus quis necessitatibus error molestias natus non eaque. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus, accusamus, cumque, adipisci modi officiis magnam eaque aspernatur recusandae accusantium aliquam debitis explicabo dolores ratione labore nulla similique consequuntur sapiente saepe!</p>
<p>Lorem ipsum dolor sit amet, consec
@spsaucier
spsaucier / equalHeights.js
Last active December 29, 2015 09:39
jQuery function to equalize heights of a set of elements. HTML structure for example call: div.equalize>div*4
$(window).on('load resize', function(){
$('.equalize > *').equalHeights();
});
$.fn.equalHeights = function() {
var maxHeight = 0,
$this = $(this);
$this.each( function() {
$(this).css('min-height', 'none');
var height = $(this).outerHeight();

Keybase proof

I hereby claim:

  • I am spsaucier on github.
  • I am spsaucier (https://keybase.io/spsaucier) on keybase.
  • I have a public key whose fingerprint is AAFF 2A5B E4F6 D5ED 7BC0 943A 8EB0 4B9D EC54 9A68

To claim this, I am signing this object: