Skip to content

Instantly share code, notes, and snippets.

@amclean
Created December 30, 2012 05:48
Show Gist options
  • Save amclean/4411187 to your computer and use it in GitHub Desktop.
Save amclean/4411187 to your computer and use it in GitHub Desktop.
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:function(){},warn:function(){},error:function(){}}}window.NYTD.NYTMM.debugLevel=1;(function(a){a.extend({log:function(){if(arguments.length>0){var b=(arguments.length>1)?Array.prototype.join.call(arguments," "):arguments[0];if(NYTD.NYTMM.debugLevel==1){if(window.console){if(console.dirxml&&b instanceof HTMLElement){console.dirxml(b)}else{if(window.console&&console.log){console.log(b)}}}}else{if(NYTD.NYTMM.debugLevel==2){alert(b)}}}}})})(NYTD.jQuery||NYTD.jQuery||jQuery);(function(a){a.fn.videoBG=function(b,d){var d={};if(typeof b=="object"){d=a.extend({},a.fn.videoBG.defaults,b)}else{if(!b){d=a.fn.videoBG.defaults}else{return a(b).videoBG(d)}}var c=a(this);if(!c.length){return}if(c.css("position")=="static"||!c.css("position")){c.css("position","relative")}if(d.width==0){d.width=c.width()}if(d.height==0){d.height=c.height()}var e=a.fn.videoBG.wrapper();e.height(d.height).width(d.width);if(d.textReplacement){d.scale=true;c.width(d.width).height(d.height).css("text-indent","-9999px")}else{e.css("z-index",d.zIndex+1)}e.html(c.html());var f=a.fn.videoBG.video(d);if(d.scale){e.height(d.height).width(d.width);f.height(d.height).width(d.width)}c.html(e);c.append(f);return this};a.fn.videoBG.setFullscreen=function(f){var e=a(window).width(),h=a(window).height();f.css("min-height",0).css("min-width",0);f.parent().width(e).height(h);if(e/h>f.aspectRatio){f.width(e).height("auto");var b=f.height();var c=(b-h)/2;if(c<0){c=0}f.css("top",-c)}else{f.width("auto").height(h);var g=f.width();var c=(g-e)/2;if(c<0){c=0}f.css("left",-c);if(c===0){var d=setTimeout(function(){a.fn.videoBG.setFullscreen(f)},500)}}a("body > .videoBG_wrapper").width(e).height(h);return f};a.fn.videoBG.video=function(f){a("html, body").scrollTop(-1);var c=a("<div/>");c.addClass("videoBG").css("position",f.position).css("z-index",f.zIndex).css("top",0).css("left",0).css("height",f.height).css("width",f.width).css("opacity",f.opacity).css("overflow","hidden");var e=a("<video/>");e.css("position","absolute").css("z-index",f.zIndex).attr("poster",f.poster).css("top",0).css("left",0).css("min-width","100%").css("min-height","100%");var b=a.fn.videoBG.supportsVideo();if(f.autoplay!==undefined){e.attr("autoplay",f.autoplay)}if(f.preload){e.attr("preload",f.preload)}if(f.fullscreen){e.bind("canplay",function(){e.aspectRatio=e.width()/e.height();a.fn.videoBG.setFullscreen(e)});var i;a(window).resize(function(){clearTimeout(i);i=setTimeout(function(){a.fn.videoBG.setFullscreen(e)},100)});a.fn.videoBG.setFullscreen(e)}var d=e[0];var h=f.loop;e.bind("ended",function(){if(f.loop){if(h){d.play()}if(h!==true){h--}}else{d.pause()}});e.bind("canplay",function(){if(f.autoplay){d.play()}});if(b){if(a.fn.videoBG.supportType("mp4")&&f.mp4){e.attr("src",f.mp4)}else{if(a.fn.videoBG.supportType("webm")&&f.webm){e.attr("src",f.webm)}else{if(a.fn.videoBG.supportType("ogv")&&f.ogv){e.attr("src",f.ogv)}else{b=false}}}}var g=a("<img/>");g.attr("src",f.poster).css("position","absolute").css("z-index",f.zIndex).css("top",0).css("left",0).css("min-width","100%").css("min-height","100%");if(b){c.html(e);e.attr("controls","controls");setTimeout(function(){e.removeAttr("controls")},0)}else{c.html(g)}if(f.textReplacement){c.css("min-height",1).css("min-width",1);e.css("min-height",1).css("min-width",1);g.css("min-height",1).css("min-width",1);c.height(f.height).width(f.width);e.height(f.height).width(f.width);g.height(f.height).width(f.width)}if(b){d.play()}return c};a.fn.videoBG.supportsVideo=function(){return(document.createElement("video").canPlayType)};a.fn.videoBG.supportType=function(c){if(!a.fn.videoBG.supportsVideo()){return false}var b=document.createElement("video");switch(c){case"webm":return(b.canPlayType('video/webm; codecs="vp8, vorbis"'));break;case"mp4":return(b.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'));break;case"ogv":return(b.canPlayType('video/ogg; codecs="theora, vorbis"'));break}return false};a.fn.videoBG.wrapper=function(){var b=a("<div/>");b.addClass("videoBG_wrapper").css("position","absolute").css("top",0).css("left",0);return b};a.fn.videoBG.defaults={mp4:"",ogv:"",webm:"",poster:"",autoplay:true,loop:true,scale:false,position:"absolute",opacity:1,textReplacement:false,zIndex:0,width:0,height:0,fullscreen:false,imgFallback:true}})(NYTD.jQuery);(function(b,c){var a=navigator.userAgent.match(/iPad|iPhone/i);b.simpleVideoDiv=function(g,e){var d=c(g).empty();if(!e){e=d.data()}if(a){delete e.mp4;delete e.ogv;delete e.webm}var f=c.extend({poster:"http://graphics8.nytimes.com/packages/flash/multimedia/ICONS/grey9.png",width:d.width(),height:d.height(),mp4:undefined,ogv:undefined,webm:undefined,poster:undefined,autoplay:"autoplay",loop:true,scale:false,position:"absolute",opacity:1,textReplacement:false,zIndex:0,fullscreen:false,imgFallback:true,preload:"auto"},e);d.css({width:f.width+"px",height:f.height+"px"}).videoBG(f).addClass("nytmm_simpleVideoDiv")}})(NYTD.NYTMM,NYTD.jQuery);
</script>
<script type="text/javascript">
NYTD.NYTMM.simpleVideoDiv('#nytg-trailer');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment