Skip to content

Instantly share code, notes, and snippets.

View megantaylor's full-sized avatar

Megan Taylor megantaylor

View GitHub Profile
@megantaylor
megantaylor / urlParam
Created July 18, 2014 21:33
Get URL parameters
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results) { return 0; }
return results[1] || 0;
}
//http://snipplr.com/view/26662
@megantaylor
megantaylor / scrollAnchor
Created July 18, 2014 21:30
The following snippet will create a smooth sliding effect when a link with the topLink class is clicked.
$(document).ready(function() {
$("a.topLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 500,
easing: "swing"
});
return false;
});
@megantaylor
megantaylor / colHeight
Created July 18, 2014 21:32
Calculate the height of the higher column and automatically adjust all other columns to this height.
var max_height = 0;
$("div.col").each(function(){
if ($(this).height() > max_height) { max_height = $(this).height(); }
});
$("div.col").height(max_height);
//http://web.enavu.com/tutorials/top-10-jquery-snippets-including-jquery-1-4/
@megantaylor
megantaylor / fadeHover
Created July 18, 2014 21:31
Fade in/fade out on hover. The code below set opacity to 100% on hover, and to 60% on hover.
$(document).ready(function(){
$(".thumbs img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads
$(".thumbs img").hover(function(){
$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout
});
});
@megantaylor
megantaylor / blankLinks
Created July 18, 2014 21:29
The following snippet will open all links with the rel="external" attribute in a new tab/window. The code can be easily customized to only open links with a specific class.
@megantaylor
megantaylor / imagePreload.js
Created July 18, 2014 21:28
Preloading images is useful: Instead of loading an image when the user request it, we preload them in the background so they are ready to be displayed.
(function($) {
var cache = [];
// Arguments are image paths relative to the current page.
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}
@megantaylor
megantaylor / hmph.php
Last active August 29, 2015 14:05
exclude categories from WP home page
in functions.php file
<?php
add_filter( 'pre_get_posts', function ( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$example_term = get_term_by( 'name', 'featured', 'category' );
$example_term_2 = get_term_by( 'name', 'Featured Post', 'category' );
$example_term_3 = get_term_by( 'name', '1,000 Stories', 'category' );
$example_term_4 = get_term_by( 'name', '1,000 Stories Spotlight', 'category' );
$query->set( 'category__not_in', $example_term->term_id, $example_term_2->term_id, $example_term_3->term_id, $example_term_4->term_id );
@megantaylor
megantaylor / ChangeTextFieldCharacterLength.js
Created June 10, 2011 17:22
Javascript to change character length of fields
document.getElementById("").onkeyup = function() { limitArea(this, '60', ''); }
@megantaylor
megantaylor / original Boyle Address class
Created July 13, 2011 01:03
original Boyle Address class for Firetracker
class Address(models.Model):
street = models.CharField(max_length=150)
street_slug = models.SlugField()
city = models.ForeignKey(City)
property_value = models.IntegerField(max_length=12, blank=True, null=True)
owner = models.ManyToManyField(Person, blank=True, null=True)
def __unicode__(self):
return self.street