Skip to content

Instantly share code, notes, and snippets.

@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 / 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-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 / 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 / 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 / video-preview.js
Last active December 16, 2015 06:58
Video from URL Preview
/*
* Requires : underscore.js
uploader = file[type=text]
output = output element
E.G
uploader = document.getElementById("file_url"),
output = document.getElementById('preview_image'),
valid :
@stugoo
stugoo / inView.js
Created April 16, 2013 10:46
Detects if an element is in the viewport and then displays it
/*
requires :
underscore js
event subscriber
*/
inView = function (element) {
var self = this,
type,
@stugoo
stugoo / text-preview.js
Created April 16, 2013 10:50
Simple text input > preview
var textPreview = function (el) {
var self = this,
input,
output,
initialise = function() {
input = el.querySelector('input') || el.querySelector('textarea'),
target = el.getAttribute('data-textPreview-output-element'),
@stugoo
stugoo / arc.svg
Last active December 16, 2015 06:58
SVG Arc drawing, pass in a CFG and allow it to draw an arc
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stugoo
stugoo / script.js
Created May 2, 2013 16:56
window resize listener used to sort out flex slider
var listItems = $('.project_list > li')
$(window).bind('resize',function() {
var ww = $(window).width();
listItems.each(function() {
$(this).width(ww);
});
});