Skip to content

Instantly share code, notes, and snippets.

View johnpolacek's full-sized avatar

John Polacek johnpolacek

View GitHub Profile
@johnpolacek
johnpolacek / lazyloadimages.js
Last active December 17, 2015 14:59
Lazy Load Images
// <a href="product.html" data-lazy-image="product.jpg" data-lazy-image-alt="The Product"></a>
;(function($) {
$('*[data-lazy-image]').each(function() {
var alt = $(this).attr('data-lazy-image-alt') === undefined ? '' : 'alt="'+$(this).attr('data-lazy-image-alt')+'"';
$(this).append($('<img src="'+$(this).attr('data-lazy-image')+'" '+alt+'" />'));
});
}(jQuery));
@johnpolacek
johnpolacek / gist:5526773
Last active December 17, 2015 01:10
Simple Facebook Share
<a href="#" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=yoursite.com', 'sharer', 'width=626,height=436'); return false;">Share on Facebook</a>
<!--
Get a facebook like button: http://developers.facebook.com/docs/reference/plugins/like/
Sign out of facebook to get a snippet with no app id
-->
@johnpolacek
johnpolacek / scss-project-structure
Last active December 16, 2015 12:59
SCSS Code Organization
00._global.scss <-- imports vars, mixins & 3rd party libs (grid, etc.)
01._typography.scss
02._elements.scss
02.element.form.scss
02.element.form.entry.scss
02.element.callout.scss
02.element.media.scss
03._pages.scss
03.page.landing.scss
03.page.detail.scss
@johnpolacek
johnpolacek / main.css
Last active December 15, 2015 15:08
starter main.css w/minification on styles, from h5bp
/* normalize 3.0.3 + h5bp 5.2 */
html {-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}dfn{font-style:italic}mark{background:#ff0;color:#000}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-ap
@johnpolacek
johnpolacek / Form Input - No Letters
Created January 3, 2013 21:03
Block letter entry on number fields
// Block letter entry on numeric only fields
$('.controls').on('keyup','.numeric-only',function() {
var alphabet = /[A-z]/g;
if (alphabet.test($(this).val())) {
$(this).val($(this).val().replace(alphabet,''));
}
});
@johnpolacek
johnpolacek / gist:4319877
Last active December 9, 2015 19:49
Add Google Analytics tracking to outbound links
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@johnpolacek
johnpolacek / gist:4197322
Created December 3, 2012 19:28
Get Random Array Item
var item = items[Math.floor(Math.random()*items.length)];
@johnpolacek
johnpolacek / responsive-viewport
Created November 16, 2012 18:57
Responsive Viewport
<script language="javascript">
// set viewport to zoom to 1200px wide on viewports > 640px wide
var viewPortTag = document.createElement('meta');
viewPortTag.id = 'viewport';
viewPortTag.name = 'viewport';
if (screen.width > 640) {
viewPortTag.content = 'width=1200';
} else {
viewPortTag.content = 'width=device-width';
}
@johnpolacek
johnpolacek / gist:3945823
Created October 24, 2012 12:32
Basic HTML5 Page
<!doctype html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Default Page Title</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="styles.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<!--[if lt IE 9]>
@johnpolacek
johnpolacek / gist:3899699
Created October 16, 2012 14:42
IE8 Transparent PNG Background Fix
#thing-with-transparent-png-bgr {
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF, endColorstr=#00FFFFFF);
}
/* via http://www.jacklmoore.com/notes/ie-transparency-problems */