Skip to content

Instantly share code, notes, and snippets.

@mattjstrauss
mattjstrauss / gist:e2adca3d9eb61343cd6a
Created November 19, 2014 14:59
JS: Smart resize with on window resize debounce
// Smartresize
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
@mattjstrauss
mattjstrauss / gist:a04a346ee1dc0f683008
Created November 19, 2014 14:56
JS: scrollTo on page load
// Menu linking to sections on the home page with click triggers
if(window.location.hash) {
var hash = window.location.hash;
$(hash+' a' ).trigger('click');
$("html, body").animate({scrollTop: $(hash).offset().top - 100}, 1000);
}
@mattjstrauss
mattjstrauss / gist:5af689fdad5e0825a35b
Created October 9, 2014 21:27
SERVER: .htaccess password
AuthUserFile /var/www/vhosts/160over90.com/park.160over90.com/httpdocs/.htpasswd
AuthGroupFile /dev/null
AuthName "Password Protected Area"
AuthType Basic
<limit GET POST>
require valid-user
</limit>
@mattjstrauss
mattjstrauss / gist:3e5de5d578e045517a6b
Created September 26, 2014 15:47
JS: Subtle Parallax Effect
$window.bind('scroll', function(e) {
parallax();
});
// Subtle Parallax Function
function parallax() {
$scrollPosition = $window.scrollTop();
$windowHeight = (( $window.height() ));
$('body').css('background-position-y', (0 - ($scrollPosition * .2)) + 'px');
};
@mattjstrauss
mattjstrauss / gist:cf6d0ffba7429e2427c4
Created September 23, 2014 17:59
WP: Featured Image URL and Alt text
<?php
$image_id = get_post_thumbnail_id();
$alt_text = get_post_meta($image_id , '_wp_attachment_image_alt', true);
$image_url = wp_get_attachment_image_src($image_id, true);
?>
<?php echo $image_url[0]; ?>
<?php echo $alt_text; ?>
@mattjstrauss
mattjstrauss / gist:940fe366d9b1ade97bfb
Created September 16, 2014 19:21
CSS: Visually Hidden
.visuallyhidden {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px; width: 1px;
margin: -1px; padding: 0; border: 0;
}
@mattjstrauss
mattjstrauss / gist:1be6c858e71e094923c5
Created August 26, 2014 20:51
WP: Post Type Post Navigation
<?php if ( 'stories' == get_post_type() ) { ?>
<div id="post-nav">
<div class="next">
<?php
$next_post = get_next_post();
$nextId = $next_post->ID;
$nextthumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($nextId), 'thumbnail');
if (!empty( $next_post )): ?>
<a href="<?php echo get_permalink( $nextId ); ?>"><span class="arrow">Next &raquo;</span><img src="<?php echo $nextthumbnail[0]; ?>" style="background: <?php the_field('thumbnail_background_color', $nextId );?>"><?php echo $next_post->post_title; ?>
@mattjstrauss
mattjstrauss / gist:34bb758a257fba556f75
Created July 9, 2014 13:41
JS: SVG replacement using Modernizr
if( !$('html').hasClass('no-svg') ) {
$('img[src*="png"]').attr('src', function() {
return $(this).attr('src').replace('.png', '.svg');
});
}
$('#main-nav li').on('click', function(){
$this = $(this);
var category = $this.attr('data-category');
$('#events li').removeClass('hide').css({'display':'block'});
// Checks if li has selected class
if( !$this.hasClass('selected') ) {
// Finds li that has the the data-category
$('#events li:not(.' + category + ')').addClass('hide').css({'display':'none'});
}
$this.toggleClass('selected').siblings().removeClass('selected');
var maxHeight = -1;
$('.three-column .nav-ad').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.three-column .nav-ad').each(function() {
$(this).height(maxHeight);
});