Skip to content

Instantly share code, notes, and snippets.

View stephenscaff's full-sized avatar

Stephen Scaff stephenscaff

View GitHub Profile
@stephenscaff
stephenscaff / Web Font Async Loader
Created January 16, 2014 09:12
Webfont Loader for Google fonts. (just swapping the: WebFontConfig={ typekit: {id: 'myKitId'} };
WebFontConfig={
google:{families:["Lato:400,700,300,100:latin"]}
};
(function(){
var wf = document.createElement("script");
wf.src = ("https:" == document.location.protocol ? "https":"http") +
"://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js";
wf.type="text/javascript";
wf.async="true";
@stephenscaff
stephenscaff / img to background-image
Last active August 29, 2015 13:57
Turn img to a background-image of it's parent div. Great for accessing the proportional cropping of bgs while still droppin some meaningful markup.
//Parent div
$('.js-tobg').each(function() {
//Hunt down img in parent div and snag its src
var imageUrl = $(this).find('img').attr('src');
//Now add inline style with backgroud-image to div
$(this).css('background-image', 'url(' + imageUrl + ')');
//Maybe cover the badboy?
@stephenscaff
stephenscaff / gist:6736c564ca3e66404ff7
Last active August 29, 2015 14:01
Updates Styles for chefn - 5-15 1:34pm
/*----------------------------------------------
--Vendor Prefix
----------------------------------------------- */
/*----------------------------------------------
--Transition
----------------------------------------------- */
/*----------------------------------------------
--Translate
----------------------------------------------- */
/*----------------------------------------------
@stephenscaff
stephenscaff / PureJS-AddClass
Created June 28, 2014 11:15
Add Class with Pure Javascript
//Fade in page all sexy like with a css opaicty keyframe
document.getElementsByTagName('html')[0].className+=' fade-in-page'
@stephenscaff
stephenscaff / findpageurltoaddclass
Created June 30, 2014 10:15
Find page url to add class
$(function(){
//If the url contains foo
if (window.location.href.indexOf('foo') >= 0) {
//add a class on specified div
$('.myclass').addClass('myaddedclass') ;
}
});
@stephenscaff
stephenscaff / AddPlaceholders.js
Created July 5, 2014 10:26
Add global placeholders with Jquery
$(document).ready(function(){
$('form').find("input[type=textarea], input[type=password], textarea").each(function(ev)
{
if(!$(this).val()) {
$(this).attr("placeholder", "Here goes your placeholder);
}
});
});
@stephenscaff
stephenscaff / DropKickJs-remove-prompt-after-change.js
Created July 5, 2014 10:33
Remove placeholder/ first option from a DropKick.js select and corresponding unordered list output. Using DropKick in a rails app featuring a filter bar, needed to ensure select placeholders via 'prompt" would not be selectable. Since Dropkick.js makes an unordered list from selects, have to ensure that both the first select option and ul list i…
/*----------------------------------------------
--Remove Prompt after change
----------------------------------------------- */
//target all styled selects and their generated unordered list
$('.dk-drops').change(function(){
//Remove the first select option & it's corresponding generated list item
$(".dk_options_inner li:first-child").remove();
$(this).find('option:first').remove();
});
@stephenscaff
stephenscaff / Wordpress-Next-and-Previous-Posts
Created October 7, 2014 15:41
Snags next and previous posts in Wordpress. Intended for a single.php template. Can also pull images with a <?php the_post_thumbnail('thumbnail'); ?> or a catch first img function.
<!-- Single Next/Last Post nav
================================================== -->
<section class="post-nav">
<div class="row">
<?php $prevPost = get_previous_post(true);
if($prevPost) {
$args = array(
'posts_per_page' => 1,
'include' => $prevPost->ID
);
@stephenscaff
stephenscaff / Wordpress: Next and Last Post
Created December 18, 2014 16:13
Get next and last post in Wordpress, using first image from post (catch_that_image) instead of a featured image, styled as background-image for container-less half grid.
<!-- Single Next/Last Post nav
================================================== -->
<section class="sect-posts post-nav cf">
<?php $prevPost = get_previous_post(true);
if($prevPost) {
$args = array(
'posts_per_page' => 1,
'include' => $prevPost->ID
);
@stephenscaff
stephenscaff / wordpress-sql-url-search-replace
Created January 1, 2015 18:11
Search and replace SQL query for Wordpress migration. In phpMyAdmin, select database, go to SQL tab... click, click boom.
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');