Skip to content

Instantly share code, notes, and snippets.

@bspingarn
bspingarn / gist:2002644
Created March 8, 2012 18:49
Detect click outside element
$("body").click(function(e){
if(e.target.className !== "foo"){
$(".foo").hide();
}
}
);
@bspingarn
bspingarn / gist:2125777
Created March 19, 2012 19:49
Javascript - mobile phone detection excluding tablets
//this 100% isnt accurate due to android browser unreliably reporting width.. use at your own risk
// Note - requires Modernizr touch detection build
if (Modernizr.touch && window.innerWidth < 768) {
// mobile user (if a touch screen and the window is smaller than tablet sized)
alert('Mobile Phone');
}
else {
alert('Desktop or Tablet Browser');
@bspingarn
bspingarn / gist:2370313
Created April 12, 2012 19:23
Shorten each link text of a class name on pageload
function shortenLink(){
var screenWidth = $(window).width();
var f = function(){
var linkTextURL = $(this).text();
if (screenWidth < 450) linkTextURL = linkTextURL.substring(0,40) + "...";
$(this).text(linkTextURL);
}
$('a.resultLink').each(f);
@bspingarn
bspingarn / gist:2788452
Created May 25, 2012 14:33
jQuery UI Range Slider Loader
// Allows sliders to be dynamically initiated more easily
// Adds validation for min and max number input boxes
// Minimizes code if many sliders are on a page
var searchSlider = {
init: function(selector, range_min, range_max){
var input_min = $(selector).parents('.slider-wrapper').find('.min'),
input_max = $(selector).parents('.slider-wrapper').find('.max');
@bspingarn
bspingarn / charts.js
Created November 15, 2012 17:39
Google Charts API - chart loader module
// This is a chart loading module to simply initializing charts that use a custom API to populate the data tables
google.load('visualization', '1', {'packages': ['corechart','geochart']});
google.setOnLoadCallback(function(){
coCharts.init();
});
var coCharts = (function(){
var colors = {
@bspingarn
bspingarn / gist:4225600
Created December 6, 2012 16:04
SublimeText2 snippet for JS comment box
<snippet>
<content><![CDATA[
/* ----------------------------------------------------
${1:Message text...}
---------------------------------------------------- */
@bspingarn
bspingarn / jquery.bootstrap.confirm.popover.js
Last active December 11, 2015 21:58
Modified options to accept a continue handler (continueFn) rather than following the selector's href attribute. Also accepts continueText (string) in options.
/*
Copyright (c) 2011 Damien Antipa, http://www.nethead.at/, http://damien.antipa.at
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@bspingarn
bspingarn / gist:5007267
Created February 21, 2013 19:13
Sort of array of object literals based on a key value
myArray.sort(function(a,b){
return a.propertyName - b.propertyName;
});
@bspingarn
bspingarn / gist:5256286
Created March 27, 2013 17:25
Newegg does the right thing
Blake: Hi, my name is Blake. How may I help you?
Bill Spingarn: I ordered a hard drive that I didn't end up needing, but it's past 30 days. I was wondering if I could still return it for a store credit.
Bill Spingarn: Invoice #98272107
Blake: Hi Bill, I am happy to assist you with that. May I please have a moment to look into this for you?
Bill Spingarn: It was purchased just last month, 2/18
Bill Spingarn: sure
Blake: Thank you for holding. We are sorry for the unfavorable situation. The item is beyond our warranty for 6 days, and it can no longer be returned to us. However, you can still contact the manufacturer of the item for direct warranty support. Their contact information is 1-800-726-7864.
Bill Spingarn: I don't need warranty support. I haven't even used it. I can't believe there is nothing you guys can do.
Blake: Is it unopened?
Bill Spingarn: It was just a bare hard drive
@bspingarn
bspingarn / gist:5437840
Created April 22, 2013 19:37
Problem: IE rotate animation acting unpredictable Solution: animate something else just for IE
.rotating {
-webkit-animation: rotating 2s linear infinite;
-moz-animation: rotating 2s linear infinite;
-ms-animation: rotating 1s linear infinite;
}
@-webkit-keyframes rotating {
from{
-webkit-transform: rotate(360deg);
-webkit-transform-origin: 50% 50%;