Skip to content

Instantly share code, notes, and snippets.

@stugoo
stugoo / scroll.js
Created April 16, 2013 10:31
Infinite scroll
var NS = NS || {};
/*
requires
- underscore js
- external event subscriber
- external AJAX Hanlder
*/
NS.infiniteScroll = function (target,callback) {
@stugoo
stugoo / de-dupe.js
Created March 15, 2013 16:06
remove duplicates
function eliminateDuplicates(arr) {
var i,
len=arr.length,
out=[],
obj={};
for (i=0;i<len;i++) {
obj[arr[i]]=0;
}
for (i in obj) {
@stugoo
stugoo / event-tracker-modernizr.js
Last active December 14, 2015 01:09
Event tracking that also logs modernizr tests. - splits tests into passes & fails, with a variable to test if you want to track passes and/or fails
var SDM = SDM || {};
SDM.track = function (args) {
args = args || {};
var category = args.category,
action = args.action,
label = args.label,
value = args.value || null;
@stugoo
stugoo / ajax-request.js
Created February 20, 2013 11:10
Raw JS Ajax handler with response time in success
fireAJAXRequest = function(method, url, async, callback) {
var httpRequest,
start= new Date().getTime(),
end;
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// Internet Explorer is stupid
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
@stugoo
stugoo / event-tracker.js
Last active April 4, 2023 18:36
Google analytics custom event tracker
var track = function (args) {
args = args || {};
var category = args.category,
action = args.action,
label = args.label,
value = args.value || null;
if (_gaq) {
_gaq.push(['_trackEvent', category, action, label, value]);
@stugoo
stugoo / gist:4754905
Created February 11, 2013 14:59
get value from a querystring
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
@stugoo
stugoo / markup.html
Last active December 12, 2015 06:58
vanilla JS tabbed content
<h2>Tabs</h2>
<ul id="tab_list">
<li><a href="#tab01">tab 01</a></li>
<li><a href="#tab02">tab 02</a></li>
<li><a href="#tab03">tab 03</a></li>
</ul>
<div id="tab_content_container">
<div id="tab01" class="tab_content">
<h1>tab 01</h1>
<br>
@stugoo
stugoo / gist:4731031
Created February 7, 2013 13:49
Get src attribute from string
var input = '<iframe width="560" height="315" src="http://www.youtube.com/embed/_QtoHqZPkk0" frameborder="0" allowfullscreen></iframe>',
rawurl = new String(input).match(/src=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/)[1];
@stugoo
stugoo / gist:4724127
Last active December 12, 2015 05:48
File upload Preview // single file
fileUploadPreview = function () {
var self = this,
uploader = document.getElementById("files"),
output = document.getElementById('preview_image'),
initialise = function() {
uploader.addEventListener('change', handleFileSelect, false);
@stugoo
stugoo / index.html
Created October 12, 2012 16:38
simple jquery overlay
<body>
<a href="#linkToTsnCs" class="showTerms">terms &amp; conditions</a>
<body>