Skip to content

Instantly share code, notes, and snippets.

View natedoesweb's full-sized avatar

Nate Smith natedoesweb

View GitHub Profile
@natedoesweb
natedoesweb / 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',
@natedoesweb
natedoesweb / 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>
@natedoesweb
natedoesweb / 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;
}
}
@natedoesweb
natedoesweb / 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');
}
@natedoesweb
natedoesweb / 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;
@natedoesweb
natedoesweb / 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;
@natedoesweb
natedoesweb / 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);
}