Skip to content

Instantly share code, notes, and snippets.

@nathanaelnsmith
nathanaelnsmith / betterPlacehold.js
Created November 19, 2012 19:49
Small plugin to hide placeholder text on focus.
$.fn.betterPlacehold = function() {
$.each($(this), function(){
var text = $(this).attr('placeholder');
$(this).focusin(function(){
$(this).attr('placeholder','');
});
$(this).focusout(function(){
if ($(this).val() == '') {
$(this).attr('placeholder', text);
}
@nathanaelnsmith
nathanaelnsmith / brackets.css
Created November 20, 2012 23:16
A Mixin for generating tournament bracket spacing.
.brackets-wrapper {
width: 980px;
margin: 0 auto;
position: relative;
float: left;
z-index: 2;
}
.brackets-wrapper ul {
position: relative;
float: left;
@nathanaelnsmith
nathanaelnsmith / triangles.less
Last active October 13, 2015 15:47
A Less / Sass Mixin that creates triangles for :before and :after pseudo elements
#triangle {
.bottom(@color:#5c82bb,@height:5px,@width:4px) {
width: 0;
height: 0;
border-top: @height solid @color;
border-left: @width solid transparent;
border-right: @width solid transparent;
}
.bottom-right(@color:#5c82bb,@height:5px,@width:4px) {
width: 0;
@nathanaelnsmith
nathanaelnsmith / bgScrollFix.js
Created December 5, 2012 19:53
A jQuery plugin that changes a background images position to fixed once you've scrolled the page to the bottom of the image
$.fn.bgScrollFix = function() {
var imageSrc = this.css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "").split(',')[0];
var image = new Image();
image.src = imageSrc;
$(window).scroll(function(){
if((image.height - $(window).height()) <= $(window).scrollTop()) {
$('body').addClass('fixed');
} else {
$('body').removeClass('fixed');
}
@nathanaelnsmith
nathanaelnsmith / horz-center.less
Created December 5, 2012 20:03
A Mixin for horizontally centering a dynamic element
// The element the mixin is applied to must be a wrapper for the dynamic element
.horz-center(){
*text-align: center;
> * {
display: table;
margin: 0px auto;
*display: inline;
*zoom: 1;
}
}
@nathanaelnsmith
nathanaelnsmith / custom-upload.html
Last active December 10, 2015 21:58
Hide the file input using css, create a disabled text input to display file name once selected, use custom button to trigger file browse click. After file is selected, JS grabs value and inserts into text field.
<span class="custom-upload">
<i class="icomoon-upload"></i>
<input type="file" name="receipt" id="receipt" class="in-lrg">
<input type="text" name="file-name" id="file-name" class="in-lrg" disabled>
</span>
@nathanaelnsmith
nathanaelnsmith / speedbump.js
Created January 11, 2013 00:35
External Link Speedbump
// external link speedbump
$.expr[":"].external = function (a) {
// DO NOT INCLUDE THE FOLLOWING MATCHES: EMAIL LINKS, TELEPHONE LINKS, HOSTNAME
return !a.href.match(/^mailto\:/) && !a.href.match(/^tel\:/) && a.hostname != location.hostname
};
$('a:external').click(function(e){
e.preventDefault();
href = $(this).attr('href');
$.colorbox({
href: '/_diffs/templates/portal_pop_up-speedbump.html',
@nathanaelnsmith
nathanaelnsmith / blocks-equalize.js
Last active December 16, 2015 17:18
Match all blocks in a set to the same height.
$(function(){
$('.block-grid').each(function(index){
var blocks = $.makeArray($(this).find('.block')).sort(sortByHeight)[0];
$(this).find('.block').height($(blocks).height());
});
});
function sortByHeight(a,b) {
return ($(b).height() - $(a).height());
}
// Normalize & Layout
article, aside, details, figcaption, figure, footer,
header, hgroup, nav, section, summary { display: block; }
audio, canvas, video {
display: inline-block;
*display: inline;
*zoom: 1;
}
audio:not([controls]) { display: none; }
[hidden] { display: none; }
@nathanaelnsmith
nathanaelnsmith / autoTab.js
Created June 13, 2013 23:24
Auto Tab Form fields with maxlength set
(function(){
var autoTab = {
keysPressed : 0,
init : function () {
this.keyEvents();
},
keyEvents : function () {
var self = this; self.keyEvents.validKey = false;
$('input[maxlength]').on('keypress', function(e){
self.keyEvents.validKey = true;