Skip to content

Instantly share code, notes, and snippets.

View amclean's full-sized avatar

Alan McLean amclean

  • New York Times co.
  • New York
View GitHub Profile
@amclean
amclean / gist:5355611
Created April 10, 2013 15:25
Detecting mobile touch events
(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch)
if(typeof Ink === 'undefined'){
var Ink = {};
Ink.$ = (jQuery) ? jQuery : $;
Ink.isMobile = function(){
return (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
};
}
@amclean
amclean / preloads
Created January 23, 2013 21:24
The right way to preload images that allows for onload event firing even if IE has cached image.
var imageLoadEvent = function(){
console.log('image ready');
}
var $newImg = this.$(new Image()),
src = 'blah.png';
// using onreadstatechange to deal with cached stuff in IE
$newImg.bind('load readystatechange', function(e){
if(this.complete || (this.readyState == 'complete' && e.type == 'readystatechange')) imageLoadEvent();
@amclean
amclean / gist:4411187
Created December 30, 2012 05:48
promo code for a year in graphics
<a href="http://www.nytimes.com/interactive/2012/12/28/multimedia/2012-the-year-in-graphics.html"><div id="nytg-trailer" style="width:337px; height:190px;" data-poster='http://graphics8.nytimes.com/packages/images/newsgraphics/2012/1227-annual/year-in-graphics-poster.jpg' data-mp4='http://graphics8.nytimes.com/packages/video/newsgraphics/2012/1227-annual/year-in-graphics.mp4' data-ogv='http://graphics8.nytimes.com/packages/video/newsgraphics/2012/1227-annual/year-in-graphics.oggtheora.ogv' data-loop="false"></div></a>
<script type="text/javascript" charset="utf-8">
/*
* The New York Times Multimedia Desk.
* Namespace: NYTD.NYTMM
*/
window.NYTD=window.NYTD||{};window.NYTD.NYTMM=window.NYTD.NYTMM||{};if(NYTD.jQuery){$j=NYTD.jQuery.noConflict()}window.NYTD.NYTMM.namespace=function(d){var c=d.split("."),b=NYTD.NYTMM,a;if(c[0]==="NYTD"&&c[1]==="NYTMM"){c=c.slice(2)}for(a=0;a<c.length;a+=1){if(typeof b[c[a]]==="undefined"){b[c[a]]={}}b=b[c[a]]}return b};if(typeof console=="undefined"){window.console={log:func
@amclean
amclean / gist:3978100
Created October 30, 2012 03:08
video code
nytg.gfx = function(){
return{
init: function(){
this.mmVideoPlayerOptions = {
autoPlay : false,
controlsBelow : false,
fullScreen : true,
skin : "light",
autoRewind : true
};
@amclean
amclean / gist:3974326
Created October 29, 2012 15:53
IE Shim for D3
var console = console || {log:function(a){return false}};
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
<script type="text/javascript" charset="utf-8">
nytint.history = {
// The interval at which the window location is polled.
URL_CHECK_INTERVAL : 500,
// We need to use an iFrame to save history if we're in an old version of IE.
USE_IFRAME : jQuery.browser.msie && jQuery.browser.version < 8,
var scrollLoader = function(){
return{
elements: [],
winHeight: window.innerHeight ? window.innerHeight : $(window).height(),
threshHold: 150,
init: function(){
this.setElementsPosition();
$(window).bind('scroll',_.bind(scrollLoader.checkViewPort,this));
this.checkViewPort.lastChecked = 0;
this.checkViewPort.busy = false;
window.Inflector = {
camelize: function(s) {
var parts = s.split('-'), len = parts.length;
if (len == 1) return parts[0];
var camelized = s.charAt(0) == '-'
? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
: parts[0];
// Handles JavaScript history management and callbacks. To use, register a
// regexp that matches the history hash with its corresponding callback:
//
// dc.history.register(/^#search/, controller.runSearch);
//
// And then you can save arbitrary history fragments.
//
// dc.history.save('search/freedom/p3');
//
DV.history = {