Skip to content

Instantly share code, notes, and snippets.

View spsaucier's full-sized avatar

Stephen Saucier spsaucier

View GitHub Profile
@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();
});
@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: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: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: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: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:6044024
Created July 20, 2013 05:53
Delivery Form with jQuery
<form id="checkDelivery">
<label for="postcode">Enter your postcode</label>
<input type="text" required name="postcode"/>
<button class="button">Submit</button>
</form>
<div id="delivery_options"></div>
<script>
$('#checkDelivery').submit(function() {
var data = $(this).serializeArray(),
@spsaucier
spsaucier / gist:6044023
Created July 20, 2013 05:52
jQuery - Form Validation without PHP
jQuery(document).ready(function(){
function randomgen()
{
var rannumber='';
for(ranNum=1; ranNum<=6; ranNum++){
rannumber+=Math.floor(Math.random()*10).toString();
}
$('#verifyNum').html(rannumber);
$('#verifyNumHidden').val(rannumber);
}
@spsaucier
spsaucier / gist:6044020
Created July 20, 2013 05:50
Table to Divs - HTML
<table class="productTable ">
<tbody>
<tr>
<td class="productItem">
<div class="product_item">
Product 1
</div>
</td>
<td class="productItem">
<div class="product_item">
@spsaucier
spsaucier / gist:6044018
Created July 20, 2013 05:50
Convert Table to Divs with jQuery
$(".productTable").after("<div id='product-container'></div>");
$(".productTable .product_item").appendTo("#product-container").each(function() {});
$('.productTable').remove();