Skip to content

Instantly share code, notes, and snippets.

//From test-cors.org
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// IE8 & IE9
@zolitch
zolitch / Background image with overlay
Last active August 29, 2015 14:12
Background image with overlay in one declaration
.darken {
background-image:
linear-gradient(
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)
),
url(image.jpg);
}
/*
Also see: http://dabblet.com/gist/a8be0d5d5731023f9c1a for color blend option.
@zolitch
zolitch / Videoplayer require js module
Last active August 29, 2015 14:11
Videoplayer require js module to leverage Youtube api
/*
Videoplayer
Author: Stephen Zsolnai (http://www.zolla.co.uk)
Decription: Youtube api video module.
This module will wait for the global callback from Youtube API if it is requested.
That is the trigger to set up the necessary video players.
Events will be fired to send tracking data and the video data is pulled from embedded iframes like so:
<iframe id="competitionVideo"
@zolitch
zolitch / GA event tracking module with share tracking
Created October 29, 2014 13:31
GA event tracking module with share tracking
define([
'jquery',
'jquery.cookie'
], function($) {
'use strict';
var $body = $('body'),
sendEvent = function(category, action, label) {
ga('send', 'event', {
'eventCategory': category,
@zolitch
zolitch / gist:7875660
Created December 9, 2013 16:50
Disable hover onscroll to speed up painting
function scrollListener(){
$window.scroll(function() {
//disable hover onscroll to speed up painting
$body.css({'pointer-events':'none'});
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
// do something
$body.css({'pointer-events':'inherit'});
}, 100));
});
@zolitch
zolitch / UMD module skeleton
Created April 26, 2013 09:29
UMD module skeleton
/*jshint laxcomma : true */
var BaseModuleConstructor
, NewClass = require('./newclass')
, _newClassInstance
, $ = $ || window.jQuery
;
@zolitch
zolitch / Date Formatter (javascript)
Last active December 16, 2015 14:59
Date Formatter (javascript) using "/Date(1366743323000)/"
formatDate = function( timestamp ){
/*
Could be either date type : /Date(1397397600000)/
Or : 2014-03-18T20:45:00
*/
var newDate = timestamp.indexOf('T') > -1 ? timestamp : parseInt(timestamp.split('(')[1])
, d = new Date(newDate)
, time
, minutes = (d.getMinutes() === 0) ? '00' : d.getMinutes()
;
@zolitch
zolitch / Facebook link share
Created April 3, 2013 09:18
Facebook link share
@zolitch
zolitch / loading
Last active December 14, 2015 06:29
loading css
.loading {
background: url(/images/rfulive/loading.gif) no-repeat center center;
width: 100%;
height: 100%;
z-index: 20;
position: absolute;
text-indent: -999em;
overflow: hidden;
top: 0;
left: 0;
@zolitch
zolitch / log (Paul Irish version)
Created January 28, 2013 21:52
// usage: log('inside coolFunc', this, arguments); // paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console) {
arguments.callee = arguments.callee.caller;
console.log( Array.prototype.slice.call(arguments) );
}
};