oboe.js-demo
Version:
A website for Oboe.js
2 lines • 53.6 kB
JavaScript
!function(a,b){function c(){L=$("main h2").map(function(a,b){return{top:$(b).offset().top,id:b.id}})}function d(){for(var a,b=K.scrollTop()+100,c=L.length;c--;)if(a=L[c],b>=a.top)return a}function e(){if(0!=L.length){var a=d();a||(a=L.first()[0]),H&&H.removeClass("active");var b=$('a[href="#'+a.id+'"]');b.addClass("active"),H=b}}function f(){console.log("handling stickying");var a=$("#siteNav");a.sticky(K.width()>J?M:"unstick"),$(".internalNav").sticky(K.width()>I?{topSpacing:28,getWidthFrom:".col1"}:"unstick")}function g(a){return new Function("o",'return o["'+a+'"]')}function h(a,b){return b.apply(void 0,a)}function i(a){var b=a.length-1,c=Array.prototype.slice;if(0==b)return function(){return a.call(this,c.call(arguments))};if(1==b)return function(){return a.call(this,arguments[0],c.call(arguments,1))};var d=Array(a.length);return function(){for(var e=0;b>e;e++)d[e]=arguments[e];return d[b]=c.call(arguments,b),a.apply(this,d)}}function j(a){return function(b,c){return a(c,b)}}function k(){}function l(){return!0}function m(a){return function(){return a}}function n(a,b){return Object.freeze([a,b])}function o(a){return s(a.reduce(j(n),N))}function p(a,b,c){return c?a(p(a,b,P(c)),O(c)):b}function q(a,b,c){function d(a,c){return a?b(O(a))?(c(O(a)),P(a)):n(O(a),d(P(a),c)):N}return d(a,c||k)}function r(a,b){a&&(O(a).apply(null,b),r(P(a),b))}function s(a){function b(a,c){return a?b(P(a),n(O(a),c)):c}return b(a,N)}function t(a,b){return b&&(a(O(b))?O(b):t(a,P(b)))}function u(a,b,c){function d(a){return function(b){return b.id==a}}var e,f;return{on:function(c,d){var g={listener:c,id:d||c};return b&&b.emit(a,c,g.id),e=n(g,e),f=n(c,f),this},emit:function(){r(f,arguments)},un:function(b){var g;e=q(e,d(b),function(a){g=a}),g&&(f=q(f,function(a){return a==g.listener}),c&&c.emit(a,g.listener,g.id))},listeners:function(){return f},hasListener:function(a){var b=a?d(a):l;return defined(t(b,e))}}}function v(){function a(a){return c[a]=u(a,d,e)}function b(b){return c[b]||a(b)}var c={},d=a("newListener"),e=a("removeListener");return["emit","on","un"].forEach(function(a){b[a]=i(function(c,d){h(d,b(c)[a])})}),b}function w(a,b){return b.prototype=Object.create(a.prototype),b.prototype.constructor=b,b}function x(a){switch(a){case"upstream":return"downstream";case"downstream":return"upstream"}throw new Error("unknown direction"+a)}function y(a){return a}function z(a,b,c){function d(a){g.push(a),a.ordering.isFirst&&e(0)}function e(d){var f=g.shift();if(f&&b.call(c,f),!f||!f.ordering.isLast){var h=a(d);c.schedule(function(){e(d+1)},h)}}function f(){g=[]}if(!a)throw new Error("no timing given");var g=[];return{read:d,reset:f}}function A(a){var b,c=v();switch(a){case"progressive":b=function(a){c("packetParsed").emit(a)};break;case"discrete":var d=[];b=function(a){d.push(a),a.ordering.isLast&&d.forEach(function(a){c("packetParsed").emit(a)})};break;default:throw Error("wtf is "+a+"?")}return{read:b,events:c}}function B(a,b){for(var c in b)a.attr("data-"+c,b[c])}function C(a,b){var c=a[0],d=c.hasAttribute("class")?c.getAttribute("class")+" "+b:b;c.setAttribute("class",d)}function D(a,b){var c=a[0];c.setAttribute("class",c.getAttribute("class").split(" ").filter(function(a){return a!=b}).join(" "))}function E(a,b){var c;if(!a.length)throw new Error("nothing in the template");return c=a[0].content?$(document.importNode(a[0].content.querySelector("*"),!0)):a.children().clone(),b&&C(c,b),c}function F(a){return"unit-"+a.ordering.i%10}function G(a,b){function c(a){var b=g[a.type];return new b(a.name,a.locations||{},a.options||{})}function d(a,b){var c=b.relationships||{};for(var d in c){var e=c[d],f=i[e];a.with[d].call(a,f)}}function e(a){var b=a.script||[];return c(a).inDemo(j).followingScript(b)}function f(a){i[a.name]=e(a)}var g={originServer:bb,wire:fb,client:gb,aggregatingServer:cb,barrier:Y,relay:hb,cache:ib,narrativeItem:X},h=R(a);if(!h)return void console.warn("no scenario for "+a);var i={},j=i.demo=new _(a,h.options||{}),k=new nb(j);k.withNarrativeView(new kb(j,k)),h.items.forEach(f),h.items.forEach(function(a){var b=i[a.name];a.next.forEach(function(c){if(!i[c])throw new Error("no such item as "+c+" given as downstream of "+a.name);b.withDownstream(i[c])})}),h.items.forEach(function(a){var b=i[a.name];d(b,a)}),(h.narrative||[]).forEach(function(a){var b=e(a);d(b,a),b.announce()}),h.items.forEach(function(a){i[a.name].announce()}),j.startSimulation=function(){h.options.startSimulation.call(j,i)},b&&j.start()}b.enclose=a,function(a){var b={topSpacing:0,bottomSpacing:0,className:"is-sticky",wrapperClassName:"sticky-wrapper",center:!1,getWidthFrom:""},c=a(window),d=a(document),e=[],f=c.height(),g=function(){for(var b=c.scrollTop(),g=d.height(),h=g-f,i=b>h?h-b:0,j=0;j<e.length;j++){var k=e[j],l=k.stickyWrapper.offset().top,m=l-k.topSpacing-i;if(m>=b)null!==k.currentTop&&(k.stickyElement.css("position","").css("top",""),k.stickyElement.parent().removeClass(k.className),k.currentTop=null);else{var n=g-k.stickyElement.outerHeight()-k.topSpacing-k.bottomSpacing-b-i;0>n?n+=k.topSpacing:n=k.topSpacing,k.currentTop!=n&&(k.stickyElement.css("position","fixed").css("top",n),"undefined"!=typeof k.getWidthFrom&&k.stickyElement.css("width",a(k.getWidthFrom).width()),k.stickyElement.parent().addClass(k.className),k.currentTop=n)}}},h=function(){f=c.height()},i={init:function(c){var d=a.extend(b,c),f=this.each(function(){var b=a(this),c=e.some(function(a){return a.stickyElement[0]==b[0]});if(!c){var f=b.attr("id"),g=a("<div></div>").attr("id",f+"-sticky-wrapper").addClass(d.wrapperClassName);b.wrapAll(g),d.center&&b.parent().css({width:b.outerWidth(),marginLeft:"auto",marginRight:"auto"}),"right"==b.css("float")&&b.css({"float":"none"}).parent().css({"float":"right"});var h=b.parent();h.css("height",b.outerHeight()),e.push({topSpacing:d.topSpacing,bottomSpacing:d.bottomSpacing,stickyElement:b,currentTop:null,stickyWrapper:h,className:d.className,getWidthFrom:d.getWidthFrom})}});return g(),f},unstick:function(){return this.each(function(){var b=a(this),c=b.parent().hasClass("sticky-wrapper");c&&b.unwrap(),b.attr("style",""),e=e.filter(function(a){return a.stickyElement[0]!=b[0]})})},restick:function(){i.unstick.apply(this),i.init.apply(this,arguments),g()},update:g};window.addEventListener?(window.addEventListener("scroll",g,!1),window.addEventListener("resize",h,!1)):window.attachEvent&&(window.attachEvent("onscroll",g),window.attachEvent("onresize",h)),a.fn.sticky=function(b){return i[b]?i[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?void a.error("Method "+b+" does not exist on jQuery.sticky"):i.init.apply(this,arguments)},a(function(){setTimeout(g,0)})}(jQuery),jQuery.easing.easeOutBounce=function(a,b,c,d,e){return(b/=e)<1/2.75?7.5625*d*b*b+c:2/2.75>b?d*(7.5625*(b-=1.5/2.75)*b+.75)+c:2.5/2.75>b?d*(7.5625*(b-=2.25/2.75)*b+.9375)+c:d*(7.5625*(b-=2.625/2.75)*b+.984375)+c},function(){function a(){return(new Date).getTime()}var b=jQuery,c="jQuery.pause",d=1,e=b.fn.animate,f={};b.fn.animate=function(g,h,i,j){var k=b.speed(h,i,j);return k.complete=k.old,this.each(function(){this[c]||(this[c]=d++);var h=b.extend({},k);e.apply(b(this),[g,b.extend({},h)]),f[this[c]]={run:!0,prop:g,opt:h,start:a(),done:0}})},b.fn.pause=function(){return this.each(function(){this[c]||(this[c]=d++);var e=f[this[c]];e&&e.run&&(e.done+=a()-e.start,e.done>e.opt.duration?delete f[this[c]]:(b(this).stop(),e.run=!1))})},b.fn.resume=function(){return this.each(function(){this[c]||(this[c]=d++);var g=f[this[c]];g&&!g.run&&(g.opt.duration-=g.done,g.done=0,g.run=!0,g.start=a(),e.apply(b(this),[g.prop,b.extend({},g.opt)]))})}}();var H,I=950,J=600,K=$(window),L=[],M={getWidthFrom:"#pageArea",topSpacing:0};K.resize(function(){c(),e(),f()}),$(function(){var a=$(window),b=$(".reducedLogo"),d=$("#siteNav");if($("svg.menuButton").click(function(){d.toggleClass("open"),d.sticky("restick",M)}),a.scroll(function(){var c=a.scrollTop();b.toggleClass("show",c>240)}),f(),a.width()>I){c(),e(),L.length&&($(document).scroll(e),e());var g=$("html,body");$("ul.sections a").click(function(){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var a=$(this.hash);if(a=a.length?a:$("[name="+this.hash.slice(1)+"]"),a.length)return g.animate({scrollTop:a.offset().top-70},500),!1}})}}),function(a){var b=a.isFinite;Object.defineProperty(Number,"isFinite",{value:function(a){return"number"==typeof a&&b(a)},configurable:!0,enumerable:!1,writable:!0})}(this),function(){function a(a){return{get:function(b){return b.getAttribute(a)},set:function(b,c){b.setAttribute(a,c)}}}var b=$.cssHooks,c=$.cssNumber;b.translateX={get:function(a){var b=a.transform.baseVal;return b.numberOfItems?b.getItem(0).matrix.e:0},set:function(a,b){var c=a.transform.baseVal;c.numberOfItems||a.setAttribute("transform","translate(0,0)"),c.getItem(0).matrix.e=b}},b.translateY={get:function(a){var b=a.transform.baseVal;return b.numberOfItems?b.getItem(0).matrix.f:0},set:function(a,b){var c=a.transform.baseVal;c.numberOfItems||a.setAttribute("transform","translate(0,0)"),c.getItem(0).matrix.f=b}},jQuery.extend(b,{lineX1:a("x1"),lineY1:a("y1"),lineX2:a("x2"),lineY2:a("y2"),circleX:a("cx"),circleY:a("cy"),circleRadius:a("r")}),c.translateX=c.translateY=c.lineX1=c.lineY1=c.lineX2=c.lineY2=c.circleX=c.circleY=c.circleRadius=!0}();i(function(a,b){var c=b.length;return i(function(d){for(var e=0;e<d.length;e++)b[c+e]=d[e];return b.length=c+d.length,a.apply(this,b)})}),i(function(a){function b(a,b){return[h(a,b)]}var c=o(a);return i(function(a){return p(b,a,c)[0]})});lazyUnion=i(function(a){return i(function(b){for(var c,d=0;d<len(a);d++)if(c=h(b,a[d]))return c})});var N=null,O=g(0),P=g(1),Q=(i(o),function(){function a(a){switch(a){case 0:case 1:case 5:case 6:return 75}return 600}function b(){return c(75,1500)}function c(a,b){var c=b-a;return a+Math.random()*c}function d(a){return 6>a?100:c(750,2500)}function e(a){return 6>a?"historic":"live"}function f(a){return-1===a?0:a+=2}function g(a){return-1===a?1:a+=2}function h(a){return 1e3*a}return{blank:{options:{startSimulation:function(){}},items:[]},"2-node-layout":{items:[{name:"sever",type:"originServer",options:{timeBetweenPackets:0,messageSize:10,label:"Server"},locations:{where:{x:65,y:70}}},{name:"internet",type:"wire",options:{bandwidth:100,latency:1500}},{name:"client",type:"client",options:{label:"Client"},locations:{where:{x:415,y:130}}}]},"fast-ajax-discrete":{baseOn:"2-node-layout",narrative:[{type:"narrativeItem",script:[{eventName:"client_requestAttempt_0",delay:h(.35)}],relationships:{topic:"client"},options:{text:"Our client makes a GET request for a page-worth of data",locationOnTopic:"upstream"}},{type:"narrativeItem",script:[{eventName:"client_accepted_response5"}],relationships:{topic:"client"},options:{text:"Without streaming nothing is shown until everything is downloaded",locationOnTopic:"where"}}],extensions:{items:[,,{options:{parseStrategy:"discrete"}}]}},"fast-ajax-progressive":{baseOn:"2-node-layout",narrative:[{type:"narrativeItem",script:[{eventName:"client_accepted_response0"}],relationships:{topic:"client"},options:{text:"Because it uses a streaming parser the webapp can render progressively",locationOnTopic:"where"}}],extensions:{items:[,,{options:{parseStrategy:"progressive"}}]}},"streaming-ajax-progressive":{baseOn:"fast-ajax-progressive",extensions:{items:[{options:{timeBetweenPackets:b}}]}},"mobile-layout":{items:[{name:"sever",type:"originServer",options:{timeBetweenPackets:0,packetMode:"historic"},locations:{where:{y:93}}},{name:"internet-wire",type:"wire",options:{bandwidth:50,latency:800}},{name:"tower",type:"relay"},{name:"internet-gsm",type:"wire",options:{medium:"mobile",bandwidth:a,latency:800}},{name:"client",type:"client",options:{page:"map",deviceType:"mobile",zoom:1.25},locations:{where:{x:415,y:135}},next:[]}]},"mobile-discrete":{baseOn:"mobile-layout",extensions:{items:[,,,,{options:{parseStrategy:"discrete"}}]},narrative:[{type:"narrativeItem",script:[{eventName:"tower_accepted_response9",delay:h(.2)}],relationships:{topic:"tower"},options:{text:"On mobile networks the traffic often arrives in bursts.",locationOnTopic:"upstream"}},{type:"narrativeItem",script:[{eventName:"client_accepted_response6",delay:h(.2)}],relationships:{topic:"client"},options:{text:"By now the webapp has already received most of the data but the user won't be shown anything until the last bit arrives..."}},{type:"narrativeItem",script:[{eventName:"client_accepted_response9",delay:h(.5)}],relationships:{topic:"client"},options:{text:"The user didn't see anything until all the data was downloaded."}}]},"mobile-progressive":{baseOn:"mobile-layout",extensions:{items:[,,,,{options:{parseStrategy:"progressive"}}]},narrative:[{type:"narrativeItem",script:[{eventName:"client_accepted_response2",delay:h(.2)}],relationships:{topic:"client"},options:{text:"The client has only downloaded some of the JSON but we're displaying useful content."}},{type:"narrativeItem",script:[{eventName:"client_accepted_response9",delay:h(.5)}],relationships:{topic:"client"},options:{text:"The time taken to display the data completely is the same but the display started much earlier."}}]},"mobile-fail":{baseOn:"mobile-layout",extensions:{items:[,,{locations:{where:{x:190,y:80}}},{relationships:{blockedBy:"tunnel"}},{options:{failAfter:h(4),retryAfter:h(2)}},{name:"tunnel",type:"barrier",options:{startHidden:!0},script:[{eventName:"client_accepted_response6",action:function(){this.activateIfNeverShownBefore()}},{eventName:"client_requestAttempt_1",delay:h(2),action:function(){this.deactivate()}}]}]}},"mobile-fail-discrete":{baseOn:"mobile-fail",extensions:{items:[,,,,{options:{parseStrategy:"discrete"}}]},narrative:[{type:"narrativeItem",script:[{eventName:"tunnel_activated"}],relationships:{topic:"client"},options:{text:"At this point the phone loses sight of the tower and the connection goes down."}},{type:"narrativeItem",script:[{eventName:"client_requestFail_1"}],relationships:{topic:"client"},options:{text:"When the request times out the data received so far is discarded."}},{type:"narrativeItem",script:[{eventName:"tunnel_deactivated"}],relationships:{topic:"client"},options:{text:"Some time later the signal returns."}}]},"mobile-fail-progressive":{baseOn:"mobile-fail",extensions:{items:[,,,,{options:{parseStrategy:"progressive"}}]},narrative:[{type:"narrativeItem",script:[{eventName:"tunnel_activated"}],relationships:{topic:"client"},options:{text:"When the connection goes down the user can already see most of the data."}},{type:"narrativeItem",script:[{eventName:"client_requestAttempt_2",delay:h(.2)}],relationships:{topic:"client"},options:{text:"Now that signal has returned the client is smart enough to only re-request the data that it missed the first time."}}]},"aggregated-layout":{options:{height:257,colors:"twoSeries"},items:[{name:"origin-slow",type:"originServer",options:{timeBetweenPackets:2e3,messageSize:9,packetSequence:f,label:"Origin 1"},locations:{where:{x:60,y:50}}},{name:"origin-slow-wire",type:"wire",next:["aggregator"],options:{latency:1200}},{name:"origin-fast",type:"originServer",options:{timeBetweenPackets:750,initialDelay:250,packetSequence:g,label:"Origin 2"},locations:{where:{x:120,y:160}}},{name:"origin-fast-wire",type:"wire",options:{latency:800}},{name:"aggregator",type:"aggregatingServer",options:{timeBetweenPackets:0,messageSize:Number.POSITIVE_INFINITY,label:"Aggregator"},locations:{where:{x:265,y:115}}},{name:"client-internet",type:"wire",options:{bandwidth:500,latency:1e3}},{name:"client",type:"client",options:{parseStrategy:"progressive",page:"graph",aspect:"landscape",showProgress:!1},locations:{where:{x:420,y:115}}}]},"aggregated-discrete":{baseOn:"aggregated-layout",extensions:{items:[,,,,{options:{parseStrategy:"discrete"}},,{options:{parseStrategy:"discrete"}}]}},"aggregated-progressive":{baseOn:"aggregated-layout",extensions:{items:[,,,,{options:{parseStrategy:"progressive"}},,{options:{parseStrategy:"progressive"}}]}},"big-small":{options:{startSimulation:function(a){this.schedule(function(){a.client1.makeRequest()},250),this.schedule(function(){a.client2.makeRequest()},125),a.client3.makeRequest()},endSimulationEvent:"client2_accepted_response9",height:257},items:[{name:"server",type:"originServer",options:{zoom:"0.85"},next:["wire1","wire2","wire3"],locations:{where:{x:110,y:150}}},{name:"wire1",type:"wire",options:{latency:1500}},{name:"client1",type:"client",options:{zoom:"0.85",page:"map"},locations:{where:{x:310,y:40}},next:[]},{name:"wire2",type:"wire",options:{latency:1500}},{name:"client2",type:"client",options:{zoom:"0.85",page:"map",maxRequestSize:5},locations:{where:{x:320,y:130}},next:[],script:[{eventName:"client2_accepted_response4",delay:h(.5),action:function(){this.makeRequest()}}]},{name:"wire3",type:"wire",options:{latency:1500}},{name:"client3",type:"client",options:{zoom:"0.85",page:"map",parseStrategy:"progressive"},locations:{where:{x:300,y:220}},next:[]}]},"historic-and-live":{narrative:[{type:"narrativeItem",script:[{eventName:"server_sent_response6",delay:h(.15)}],relationships:{topic:"server"},options:{text:"Now the historic messages have been sent the server keeps the connection open, writing out new messages as they happen."}},{type:"narrativeItem",script:[{eventName:"client_accepted_response6",delay:h(.2)}],relationships:{topic:"client"},options:{text:"The client handles live messages the same as historic, displaying them as HTML."}}],items:[{name:"server",type:"originServer",options:{timeBetweenPackets:d,packetMode:e,messageSize:Number.POSITIVE_INFINITY,label:"Message server"},locations:{where:{x:95,y:70}}},{name:"internet",type:"wire",options:{latency:1e3}},{name:"client",type:"client",options:{parseStrategy:"progressive",page:"twitter",showProgress:!1},locations:{where:{x:400,y:130}}}]},caching:{options:{height:257,startSimulation:function(a){a.client1.makeRequest()},colors:"political",endSimulationEvent:"client3_acceptedAll"},narrative:[{type:"narrativeItem",script:[{eventName:"cache_requestOff_cache-to-client1"}],relationships:{topic:"cache"},options:{text:"This is the first client to request election results so it is a cache miss. The cache propagates the request as per usual."}},{type:"narrativeItem",script:[{eventName:"server_gotRequest",delay:h(.1)}],relationships:{topic:"server"},options:{text:"As usual, the results server doesn't care that it is talking to a cache. It proceeds to serve the results as they are announced."}},{type:"narrativeItem",script:[{eventName:"client2_requestAttempt_0",delay:h(.18)}],relationships:{topic:"client2"},options:{text:"A second client comes online and requests the results."}},{type:"narrativeItem",script:[{eventName:"cache_requestOff_cache-to-client2"}],relationships:{topic:"cache"},options:{text:"The http cache already has a connection to the server for this URL and is partially populated. It doesn't need to hit the server again and can send what it has already."}},{type:"narrativeItem",script:[{eventName:"cache_accepted_response19",delay:.2}],relationships:{topic:"cache"},options:{text:"As streaming data arrives the cache treats it like normal traffic by propagating to all requesters."}},{type:"narrativeItem",script:[{eventName:"server_sent_response50",delay:h(.1)}],relationships:{topic:"server"},options:{text:"The server sends the last result and closes the JSON normally. The content ultimately forms a valid JSON document."}},{type:"narrativeItem",script:[{eventName:"client3_requestAttempt_0",delay:h(.3)}],relationships:{topic:"client3"},options:{text:"Now a third client comes online after all the results have been announced.",locationOnTopic:"upstream"}},{type:"narrativeItem",script:[{eventName:"cache_requestOff_cache-to-client3"}],relationships:{topic:"cache"},options:{text:"This request can be served from cache. At this time it is essentially a static resource."}}],items:[{name:"server",type:"originServer",locations:{where:{x:60,y:100}},options:{payloads:"2012UsElection",timeBetweenPackets:b,packetMode:"live",label:"Results Server"}},{name:"server-to-cache-wire",type:"wire",options:{latency:400,bandwidth:100}},{name:"cache",type:"cache",locations:{where:{x:180,y:55}},next:["cache-to-client1","cache-to-client2","cache-to-client3"],options:{label:"HTTP cache"}},{name:"cache-to-client1",type:"wire",options:{latency:800,bandwidth:100}},{name:"client1",type:"client",options:{parseStrategy:"progressive",page:"cartogram",aspect:"landscape",zoom:1.5},locations:{where:{x:375,y:185}},next:[]},{name:"cache-to-client2",type:"wire",options:{latency:600,bandwidth:20,startHidden:!0}},{name:"client2",type:"client",options:{parseStrategy:"progressive",page:"cartogram",aspect:"landscape",startHidden:!0,zoom:1.15},locations:{where:{x:430,y:60}},script:[{eventName:"client1_accepted_response12",delay:h(.5),action:function(){this.activate(),this.adjacents.upstream.forEach(function(a){a.activate()})}},{eventName:"client1_accepted_response12",delay:h(1),action:function(){this.makeRequest()}}],next:[]},{name:"cache-to-client3",type:"wire",options:{latency:800,bandwidth:20,startHidden:!0}},{name:"client3",type:"client",options:{parseStrategy:"progressive",page:"cartogram",aspect:"landscape",startHidden:!0,zoom:1.15},locations:{where:{x:235,y:205}},script:[{eventName:"client1_accepted_response50",delay:h(.5),action:function(){this.activate(),this.adjacents.upstream.forEach(function(a){a.activate()})}},{eventName:"client1_accepted_response50",delay:h(2),action:function(){this.makeRequest()}}]}]}}}()),R=function(){function a(a){var c=a.locations,d=c.where,e=a.options&&a.options.zoom||1;switch(a.type){case"relay":c.upstream=b(d,{x:0,y:40});break;case"client":switch(a.options.deviceType){case"mobile":c.upstream=b(d,{x:30*e,y:-53*e});break;case"desktop":default:c.upstream=b(d,{x:-18,y:0})}}}function b(a,b){return{x:a.x+b.x,y:a.y+b.y}}function c(a){return jQuery.extend(!0,{},a)}function d(a,b){return f(a,b,!1)}function e(a,b){return f(a,b,!0)}function f(a,b,c){a||(a={});for(var d in b)b[d]instanceof Function?(c||void 0===a[d])&&(a[d]=b[d]):b[d]instanceof Object?(a[d]||(a[d]=new b[d].constructor),f(a[d],b[d],c)):(c||void 0===a[d])&&(a[d]=b[d]);return a}function g(a,b){var d=c(a),f=e(d,b);return f}function h(a){var b=Q[a],c=b.baseOn;if(c){var d=g(h(c),b.extensions);return d.narrative=b.narrative,d}return b}function i(b){var c=h(b);d(c,j.demo);var e={};return c.name=b,c.items.forEach(function(a){e[a.name]=a}),c.items.forEach(function(b,c,e){b.next||(b.next=c<e.length-1?[e[c+1].name]:[]),j[b.type]&&d(b,j[b.type]),a(b)}),(c.narrative||[]).forEach(function(a){d(a,j[a.type])}),c}var j={demo:{options:{colors:"categorical",width:500,height:200,startSimulation:function(a){a.client.makeRequest()},endSimulationEvent:"client_acceptedAll"}},wire:{options:{bandwidth:0,latency:1e3,medium:"cable"},locations:{}},relay:{options:{timeBetweenPackets:500,zoom:1},locations:{where:{x:235,y:90}}},cache:{options:{timeBetweenPackets:500,zoom:1},locations:{where:{x:235,y:90}}},client:{options:{retryAfter:Number.POSITIVE_INFINITY,failAfter:Number.POSITIVE_INFINITY,aspect:"portrait",page:"singlePageSite",deviceType:"desktop",showProgress:!0,parseStrategy:"discrete",zoom:1},locations:{where:{x:430,y:145}}},barrier:{locations:{where:{x:410,y:145}}},originServer:{options:{packetSequence:function(a){return a+1},timeBetweenPackets:500,initialDelay:500,messageSize:10,packetMode:"live",zoom:1},locations:{where:{x:40,y:55}}},narrativeItem:{script:[{delay:0,action:function(){this.popUp()}}],options:{locationOnTopic:"where"}}};return function(a){return Q[a]&&i(a)}}(),S={"2012UsElection":[{state:"in",wonBy:"rep",votes:11},{state:"ky",wonBy:"rep",votes:8},{state:"fl",wonBy:"dem",votes:29},{state:"ga",wonBy:"rep",votes:16},{state:"nh",wonBy:"dem",votes:4},{state:"sc",wonBy:"rep",votes:9},{state:"vt",wonBy:"dem",votes:3},{state:"va",wonBy:"dem",votes:13},{state:"nc",wonBy:"rep",votes:15},{state:"oh",wonBy:"dem",votes:18},{state:"wv",wonBy:"rep",votes:5},{state:"al",wonBy:"rep",votes:9},{state:"ct",wonBy:"dem",votes:7},{state:"de",wonBy:"dem",votes:3},{state:"dc",wonBy:"dem",votes:3},{state:"il",wonBy:"dem",votes:20},{state:"ks",wonBy:"rep",votes:6},{state:"me",wonBy:"dem",votes:4},{state:"md",wonBy:"dem",votes:10},{state:"ma",wonBy:"dem",votes:11},{state:"mi",wonBy:"dem",votes:16},{state:"ms",wonBy:"rep",votes:6},{state:"mo",wonBy:"rep",votes:10},{state:"nj",wonBy:"dem",votes:14},{state:"nd",wonBy:"rep",votes:3},{state:"ok",wonBy:"rep",votes:7},{state:"pa",wonBy:"dem",votes:20},{state:"ri",wonBy:"dem",votes:4},{state:"tn",wonBy:"rep",votes:11},{state:"tx",wonBy:"rep",votes:38},{state:"ar",wonBy:"rep",votes:6},{state:"co",wonBy:"dem",votes:9},{state:"la",wonBy:"rep",votes:8},{state:"mn",wonBy:"dem",votes:10},{state:"ne",wonBy:"rep",votes:5},{state:"nm",wonBy:"dem",votes:5},{state:"ny",wonBy:"dem",votes:29},{state:"sd",wonBy:"rep",votes:3},{state:"wi",wonBy:"dem",votes:10},{state:"wy",wonBy:"rep",votes:3},{state:"az",wonBy:"rep",votes:11},{state:"ia",wonBy:"dem",votes:6},{state:"mt",wonBy:"rep",votes:3},{state:"nv",wonBy:"dem",votes:6},{state:"ut",wonBy:"rep",votes:6},{state:"ca",wonBy:"dem",votes:55},{state:"hi",wonBy:"dem",votes:4},{state:"id",wonBy:"rep",votes:4},{state:"or",wonBy:"dem",votes:7},{state:"wa",wonBy:"dem",votes:12},{state:"ak",wonBy:"rep",votes:3}]},T={upstream:"upstream",downstream:"downstream"},U=function(){function a(a){var b=0,c=!1;return function(d){var e=d.copy();return d.done(),d.ordering.isLast&&b++,e.ordering.isFirst=!c,e.ordering.isLast=b==a,c=!0,e}}function b(a,b){for(var c in a)a[c].events("packetParsed").on(b)}function c(a,b){function c(a){a.ordering.isLast&&e++,f.push(a),e==d&&f.forEach(function(a){b(a)})}var d=0,e=0,f=[];for(var g in a)d++,a[g].events("packetParsed").on(c)}return function(d,e,f){function g(a){f(i(a))}var h=Object.keys(e).length,i=a(h);"progressive"==d?b(e,g):c(e,g)}}(),V=function(){"use strict";function a(a,b){this.tasks=[],this.subject=a,b("paused").on(this._pause.bind(this)),b("unpaused").on(this._unpause.bind(this))}var b=500;return a.prototype._pause=function(){this.tasks.forEach(this._pauseTask)},a.prototype._unpause=function(){this.tasks.forEach(this._scheduleTask)},a.prototype._removeTask=function(a){this.tasks=this.tasks.filter(function(b){return b!==a})},a.prototype.cancelTimeouts=function(){this.tasks.forEach(function(a){window.clearTimeout(a.timeout)}),this.tasks=[]},a.prototype.schedule=function(a,c,d){if(c==Number.POSITIVE_INFINITY)return void 0;var e=void 0===c?b:c,f=function(){this._removeTask(g),a()}.bind(this),g={performTask:f,wait:e};return d||this._scheduleTask(g),this.tasks.push(g),g},a.prototype._pauseTask=function(a){window.clearTimeout(a.timeout),a.timeout=void 0,a.wait=a.performTime-Date.now()},a.prototype._scheduleTask=function(a){if(a.timeout)throw Error("task already scheduled");return a.timeout=window.setTimeout(a.performTask,a.wait),a.performTime=Date.now()+a.wait,a},a.prototype.unschedule=function(a){a&&(window.clearTimeout(a.timeout),a.timeout=void 0,this._removeTask(a))},a}(),W=function(){"use strict";function a(a,b,c){this.name=a,this.events=v(),this.locations=b||{},this.scheduler=new V(this,this.events),c&&(this.label=c.label,this.startHidden=c.startHidden,this.zoom=c.zoom),this.events("reset").on(function(){this.scheduler.cancelTimeouts()}.bind(this))}function b(a,b,c){function d(a){return a&&(a.name||a.toString())}return[a,b,c].map(d).filter(function(a){return void 0!==a}).join("_")}return a.newEvent="Thing",a.prototype.with={},a.prototype.inDemo=function(a){this.demo=a;var b=this.events,c=a.events;return c("reset").on(b("reset").emit),c("paused").on(b("paused").emit),c("unpaused").on(b("unpaused").emit),this},a.prototype.done=function(){this.events("done").emit();var a=this.events,b=this.demo.events;return b("reset").un(a("reset").emit),b("paused").un(a("paused").emit),b("unpaused").un(a("unpaused").emit),this},a.prototype.followingScript=function(a){var b=this,c=this.demo.script;return a.forEach(function(a){var d=a.action,e=a.delay?function(){b.schedule(d,a.delay)}:d.bind(b);c(a.eventName).on(e)}),this},a.prototype.announce=function(){if(!this.constructor.newEvent)throw new Error("cannot announce type without .newEvent set");return this.demo.events(this.constructor.newEvent).emit(this),this},a.prototype.addToScript=function(a,c){var d=b(this,a,c);this.demo.script(d).emit()},a.prototype.cancelTimeouts=function(){return this.scheduler.cancelTimeouts()},a.prototype.schedule=function(a,b){return this.scheduler.schedule(a.bind(this),b,this.demo.paused)},a.prototype.unschedule=function(a){return this.scheduler.unschedule(a)},a.asFunction=function(a,b){if("function"==typeof a)return a;var c=void 0!==a?a:b;return function(){return c}},a.prototype.activate=function(){this.addToScript("activated"),this.events("activated").emit()},a.prototype.deactivate=function(){this.addToScript("deactivated"),this.events("deactivated").emit()},a}(),X=function(){var a=w(W,function(a,b,c){W.apply(this,arguments),this.text=c.text,this.locationOnTopic=c.locationOnTopic});return a.prototype.with={topic:function(a){this.topic=a}},a.newEvent="NarrativeItem",a.prototype.popUp=function(){this.demo.pause(),this.events("activated").emit(this)},a.prototype.dismiss=function(){this.demo.unpause(),this.events("deactivated").emit(this)},a}(),Y=function(){var a=w(W,function(){W.apply(this,arguments),this.events("reset").on(function(){this.hasBeenShown=!1}.bind(this))});return a.newEvent="Barrier",a.prototype.activateIfNeverShownBefore=function(){this.hasBeenShown||this.activate(),this.hasBeenShown=!0},a}(),Z=function(){"use strict";var a=W,b=w(a,function(b,c){if(!c)throw new Error("don't know where "+b+" is");if(a.apply(this,arguments),!c)throw new Error("don't know where "+b+" is");this.latency=0,this.adjacents={downstream:[],upstream:[]}});return b.newEvent="PacketHolder",b.prototype.accept=b.prototype.acceptFromDownstream=b.prototype.acceptFromUpstream=function(){},b.prototype.withDownstream=function(a){return this.adjacents.downstream.push(a),this.listenToAdjacentForPackets(a,"downstream"),a._withUpstream(this),this},b.prototype._withUpstream=function(a){this.adjacents.upstream.push(a),this.listenToAdjacentForPackets(a,"upstream")},b.prototype.listenToAdjacentForPackets=function(a,b){var c=x(b),d="upstream"==b?"acceptFromUpstream":"acceptFromDownstream",e=this[d],f=function(c){var d=c.copy().announce();e.call(this,d,a),this.accept(d,a),this.events("acceptedFrom"+b).emit(d)}.bind(this),g=this.inputThrottle(f),h=function(a,b){b&&-1==b.indexOf(this)||g(a)}.bind(this);a.events(c).on(h)},b.prototype.inputThrottle=function(a){return a},b.prototype.propagate=function(a,b){this.events(a.direction).emit(a,b),a.done()},b.prototype.movePacket=function(a){var b=x(a.direction),c=a.direction,d=this.locations[b],e=this.locations[c];a.move(d,e,this.latency)},b}(),_=function(){var a=4500,b=750,c=w(W,function(b,c){W.apply(this,arguments),this.height=c.height,this.width=c.width,this.script=v(),this.colors=c.colors,this.paused=!1,this.inProgress=!1,c.endSimulationEvent&&this.script(c.endSimulationEvent).on(function(){this.schedule(this.reset.bind(this),a)}.bind(this)),this.demo=this});return c.newEvent="Demo",c.prototype.start=function(){this.inProgress||(this.inProgress=!0,this.events("started").emit(),this.schedule(function(){this.startSimulation()}.bind(this),b))},c.prototype.reset=function(){this.inProgress&&(this.events("reset").emit(),this.inProgress=!1,this.paused=!1)},c.prototype.pause=function(){this.paused=!0,this.events("paused").emit()},c.prototype.unpause=function(){if(!this.paused)throw new Error("unpausing but not paused");this.paused=!1,this.events("unpaused").emit()},c}(),ab=function(){var a=w(W,function(a){W.call(this,"responseGenerator");var b=S[a.payloads];this.timeBetweenPackets=W.asFunction(a.timeBetweenPackets),this.initialDelay=a.initialDelay,this.messageSize=b?b.length:a.messageSize,this.packetNumberAfter=a.packetSequence,this.packetMode=W.asFunction(a.packetMode),this.packetPayloads=b
});return a.prototype.packetGenerator=function(a){var b=!1;return function(c){var d={i:c,isFirst:!b,isLast:c>=a};d.isFirst&&Number.isFinite(this.messageSize)&&(d.expectedSize=a+1);var e=new db("response"+c,"JSON","downstream",d,this.packetMode(c)).inDemo(this.demo);return e.payload=this.packetPayloads&&this.packetPayloads[c],b=!0,e}.bind(this)},a.prototype.generateResponse=function(a,b,c){function d(a){var b=this.packetNumberAfter(a),g=b>=e;if(this.events("packetGenerated").emit(f(b),c),!g){var h=this.packetNumberAfter(b);this.schedule(d.bind(this,b,c),this.timeBetweenPackets(h))}}var e=Math.min(this.messageSize-1,b),f=this.packetGenerator(e);this.schedule(d.bind(this,a-1),this.initialDelay)},a}(),bb=function(){var a=Z,b=w(a,function(b,c,d){a.apply(this,arguments),this.responseGenerator=new ab(d),this.responseGenerator.events("packetGenerated").on(function(a,b){this.addToScript("sent",a),this.propagate(a,[b])}.bind(this))});return b.newEvent="OriginServer",b.prototype.acceptFromDownstream=function(a,b){this.addToScript("gotRequest"),this.responseGenerator.generateResponse(a.gotAlreadyUpTo,a.requestingUpto,b),a.done()},b.prototype.inDemo=function(b){return a.prototype.inDemo.apply(this,arguments),this.responseGenerator.inDemo(b),this},b}(),cb=function(){var a=Z,b=w(a,function(b,c,d){a.apply(this,arguments),this.parseStrategyName=d.parseStrategy});return b.newEvent="AggregatingServer",b.prototype.acceptFromDownstream=function(a){this.propagate(a),this.setupResponse()},b.prototype.acceptFromUpstream=function(a,b){this.parsers[b.name].read(a)},b.prototype.setupResponse=function(){this.parsers=this.createInputParsersForEachUpstreamNode(this.parseStrategyName),U(this.parseStrategyName,this.parsers,this.propagate.bind(this))},b.prototype.createInputParsersForEachUpstreamNode=function(a){var b={},c=this.adjacents.upstream,d=this.events("packetParsed").emit;return c.forEach(function(c){b[c.name]=A(a,d)}),b},b}(),db=function(){var a=W,b=w(a,function(b,c,d,e,f){a.apply(this,arguments),this.direction=d,this.ordering=e,this.type=c,this.mode=f,this.gotAlreadyUpTo=0,this.events("reset").on(this.done.bind(this))});return b.newEvent="Packet",b.prototype.copy=function(){var a={i:this.ordering.i,isFirst:this.ordering.isFirst,isLast:this.ordering.isLast,expectedSize:this.ordering.expectedSize};return new b(this.name,this.type,this.direction,a,this.mode).inDemo(this.demo).startingAt(this.gotAlreadyUpTo).endingAt(this.requestingUpto).withPayload(this.payload)},b.prototype.replayedCopy=function(){var a=this.copy();return a.mode=m("historic"),a},b.prototype.startingAt=function(a){return this.gotAlreadyUpTo=a,this},b.prototype.endingAt=function(a){return this.requestingUpto=a,this},b.prototype.withPayload=function(a){return this.payload=a,this},b.prototype.startsRequest=function(){return this.direction==T.upstream&&this.ordering.isFirst},b.prototype.closesResponse=function(){return this.direction==T.downstream&&this.ordering.isLast},b.prototype.move=function(a,b,c){this.events("move").emit(a,b,c)},b.prototype.isOn=function(a){this.events("isOn").emit(a)},b}(),eb=w(W,function(){W.apply(this,arguments),this.events("reset").on(this.done.bind(this))});eb.newEvent="Message",eb.prototype.transmittedOver=function(a){return this.holder=a,this},eb.prototype._withRequestStart=function(a){return a.events("move").on(function(){this.events("requestStartMove").emit.apply(this,arguments)}.bind(this)),this},eb.prototype._withResponseClose=function(a){return a.events("move").on(function(){this.events("responseCloseMove").emit.apply(this,arguments)}.bind(this)),a.events("done").on(function(){this.done()}.bind(this)),this},eb.prototype.includes=function(a){return a.startsRequest()&&this._withRequestStart(a),a.closesResponse()&&this._withResponseClose(a),this};var fb=function(){var a=Z,b=w(a,function(b,c,d){if(a.apply(this,arguments),this.latency=d.latency,this.bandwidth=W.asFunction(d.bandwidth),this.medium=d.medium,!d.medium)throw new Error("no medium for wire "+b);this.events("reset").on(function(){this.blockage=void 0}.bind(this))});return b.newEvent="Wire",b.prototype.accept=function(a){a.isOn(this),a.startsRequest()&&(this.message=(new eb).inDemo(this.demo).transmittedOver(this).announce()),this.message.includes(a),a.closesResponse()&&(this.message=null),this.events("deliveryStarted").emit(a),this.movePacket(a),this.blockage||this.propagateAfterLatency(a)},b.prototype.inputThrottle=function(a){var b=z(this.bandwidth,a,this);return this.events("reset").on(b.reset),b.read},b.prototype.withDownstream=function(b){a.prototype.withDownstream.call(this,b);var c=b.locations;return this.locations.downstream=c.upstream||c.where,this},b.prototype._withUpstream=function(b){a.prototype._withUpstream.call(this,b);var c=b.locations;return this.locations.upstream=c.downstream||c.where,this},b.prototype.with={blockedBy:function(a){a.events("activated").on(function(){this.blockage=a}.bind(this)),a.events("deactivated").on(function(){this.blockage=null}.bind(this))}},b.prototype.propagateAfterLatency=function(a){this.schedule(function(){this.blockage||(this.propagate(a),this.events("delivered").emit(a))}.bind(this),this.latency)},b}(),gb=w(Z,function(a,b,c){"use strict";Z.apply(this,arguments),this.page=c.page,this.failAfter=c.failAfter,this.retryAfter=c.retryAfter,this.aspect=c.aspect,this.showProgress=c.showProgress,this.maxRequestSize=c.maxRequestSize||Number.POSITIVE_INFINITY,this.parseStrategy=c.parseStrategy,this.attemptNumber=0,this.receivedUpTo=-1,this.events("reset").on(function(){this.attemptNumber=0,this.receivedUpTo=-1}.bind(this))});gb.newEvent="Client",gb.prototype.makeRequest=function(){this.parser=A(this.parseStrategy),this.parser.events("packetParsed").on(function(a){this.events("gotData").emit(a),this.receivedUpTo=a.ordering.i}.bind(this)),this.events("request").emit(),this.addToScript("requestAttempt",this.attemptNumber);var a=this.receivedUpTo+1,b=a+this.maxRequestSize-1,c=new db("request","GET","upstream",{isFirst:!0,isLast:!0,i:0}).inDemo(this.demo).startingAt(a).endingAt(b).announce();this.scheduleFail(),this.propagate(c),this.attemptNumber++},gb.prototype.scheduleFail=function(){this.giveUpTimeout=this.schedule(function(){this.addToScript("requestFail",this.attemptNumber),this.events("requestFail").emit(),this.schedule(this.makeRequest.bind(this),this.retryAfter)}.bind(this),this.failAfter)},gb.prototype.acceptFromUpstream=function(a){this.addToScript("accepted",a),this.parser.read(a),this.unschedule(this.giveUpTimeout),a.ordering.isLast?(this.addToScript("acceptedAll"),this.events("requestComplete").emit()):this.scheduleFail(),a.done()};var hb=function(){var a=w(Z,function(){Z.apply(this,arguments)});return a.newEvent="Relay",a.prototype.accept=function(a){this.addToScript("accepted",a),this.propagate(a)},a}(),ib=function(){var a=Z,b=w(Z,function(b,c,d){a.apply(this,arguments),this.timeBetweenPackets=W.asFunction(d.timeBetweenPackets),this.cacheContents=[],this.requestors=[],this.upstreamRequestOngoing=!1,this.events("reset").on(function(){this.cacheContents=[],this.requestors=[],this.upstreamRequestOngoing=!1}.bind(this))});return b.prototype.acceptFromDownstream=function(a,b){this.addToScript("requestOff",b),this.requestors.push(b),this.cacheContents.forEach(function(a){this.propagate(a,[b])}.bind(this)),this.upstreamRequestOngoing?a.done():(this.propagate(a),this.upstreamRequestOngoing=!0)},b.prototype.acceptFromUpstream=function(a){this.addToScript("accepted",a);var b=a.replayedCopy().done();this.cacheContents.push(b),this.propagate(a,this.requestors)},b.newEvent="Cache",b}(),jb=function(){"use strict";function a(a,b){this.subject=a,this.demoView=b;var c=this.subject.demo.events;c("paused").on(this.pause.bind(this)),c("unpaused").on(this.unpause.bind(this))}var b=200;return a.prototype.writeLabel=function(){this.subject.label&&this.jDom.find(".label").text(this.subject.label)},a.prototype.find=function(a){return this.demoView.jDom.find(a)},a.prototype.pause=function(){this.jPausibleElements&&this.jPausibleElements.pause()},a.prototype.unpause=function(){this.jPausibleElements&&this.jPausibleElements.resume()},a.prototype.setZoom=function(a){this.jDom.find(".zoom").attr("transform","scale("+a+")")},a.prototype.stampContentsFromTemplate=function(a,b,c){var d=E($("#"+b),c),e=this.find(a);if(1!=e.length)throw new Error("no one place to put the thing");return e.append(d),d},a.prototype.initHiding=function(){this.subject.startHidden&&(this.hide(),this.subject.events("reset").on(this.hide.bind(this))),this.subject.events("activated").on(this.fadeIn.bind(this)),this.subject.events("deactivated").on(this.fadeOut.bind(this))},a.prototype.initDomFromTemplate=function(a,b,c){return this.jDom=this.stampContentsFromTemplate("."+a,b,c),this.jPausibleElements=this.jDom,this.jDom},a.prototype.moveTo=function(a){return this.jDom.css({translateX:a.x,translateY:a.y}),this},a.prototype.putAtXy=function(a,b,c,d){var e={};e[b]=d.x,e[c]=d.y,a.css(e)},a.flash=function(a,c){C(a,c),window.setTimeout(function(){D(a,c)},b)},a.prototype.flash=function(b){a.flash(this.jDom,b)},a.prototype.goToXy=function(a,b,c){this.putAtXy(this.jDom,a,b,c)},a.prototype.animateXy=function(a,b,c,d,e){this.goToXy(a,b,c);var f={};f[a]=d.x,f[b]=d.y,this.jDom.animate(f,{duration:e,queue:!1}),this.pauseAnimationIfDemoPaused(this.jDom)},a.prototype.pauseAnimationIfDemoPaused=function(a){this.subject.demo.paused&&a.pause()},a.prototype.hide=function(){this.jDom.hide()},a.prototype.fadeIn=function(){this.jDom.fadeIn()},a.prototype.fadeOut=function(){this.jDom.fadeOut()},a}(),kb=function(){var a=w(jb,function(a,b){jb.apply(this,arguments),this.jDom=b.jDom.find(".narrative").add(b.jDom.filter(".narrative")).hide()});return a.prototype.scaleAt=function(a){return a.parents("[data-scale]").attr("data-scale")},a.prototype.captionPositionOnSmall=function(a){var b=this.subject.demo.width,c=.5*b,d=a.x>c;return{x:0,y:0,verticalSide:"top",horizontalSide:d?"left":"right"}},a.prototype.captionPosition=function(a){var b,c=this.subject.demo.width,d=this.subject.demo.height,e=.5*c,f=100,g=a.x,h=a.x>e,i=a.y>d/2,j=!1,k={};if(h){var l=c-a.x;b=l+f,k.horizontalSide="right"}else b=g+f,k.horizontalSide="left";var m=.45*c;b>m&&(b=m,j=!0),k.x=b,k.y="15";var n=j?i:!i;return k.verticalSide=n?"top":"bottom",k},a.prototype.positionLightboxHighlightAt=function(a,b){var c=this.jDom.filter(".lightbox");this.putAtXy(c,"translateX","translateY",b);var d=this.scaleAt(c),e=1>d,f=e?this.captionPositionOnSmall(b):this.captionPosition(b);this.jDom.filter("div.narrative").css({left:"",right:"",top:"",bottom:""}).css("text-align",f.horizontalSide).css(f.horizontalSide,f.x*d*a.zoom).css(f.verticalSide,f.y*d*a.zoom)},a.prototype.showText=function(a){this.jDom.find(".label").text(a)},a.prototype.showItem=function(a){var b=a.text,c=a.topic,d=a.locationOnTopic,e=c.locations[d];this.showText(b),this.positionLightboxHighlightAt(c,e),this.setZoom(c.zoom),this.jDom.fadeIn(),this.jDom.filter(".demoCaption").one("click",function(){return a.dismiss(),!1})},a.prototype.hideItem=function(){this.jDom.filter(".demoCaption").off(),this.jDom.fadeOut()},a.prototype.displayItem=function(a){a.events("activated").on(this.showItem.bind(this)),a.events("reset").on(this.hideItem.bind(this)),a.events("deactivated").on(this.hideItem.bind(this))},a.newEvent="NarrativeView",a}(),lb=w(jb,function(a){jb.apply(this,arguments),this.initDomFromTemplate("barriers","barrier",a.name),this.moveTo(a.locations.where);var b=this.jDom.find("clipPath").children();this.putAtXy(b,"translateX","translateY",a.locations.where),a.events("activated").on(this.fadeIn.bind(this)),a.events("deactivated").on(this.fadeOut.bind(this)),this.initHiding()}),mb=function(){var a=w(jb,function(a){jb.apply(this,arguments);var b=this.initDomFromTemplate("places","client-"+a.aspect,a.name),c="."+a.name+" .browserContents",d="client-"+a.page;this.stampContentsFromTemplate(c,d),C(b,a.page),this.moveTo(a.locations.where);var e=this.showSpinner.bind(this),f=this.hideSpinner.bind(this);a.events("request").on(e),a.events("requestFail").on(f),a.events("requestComplete").on(f),a.events("reset").on(f),b.click(function(){a.demo.paused?a.demo.unpause():a.demo.pause()}),this.setZoom(a.zoom),this.manageProgressBar(),this.initHiding(),this.writeLabel()});a.factory=function(a,f){function g(a){switch(a){case"singlePageSite":case"graph":return b;case"map":return c;case"cartogram":return d;case"twitter":return e;default:throw Error("unknown page type "+a)}}var h=g(a.page);return new h(a,f)},a.prototype.manageProgressBar=function(){function a(){if(b){var a=e/b,c=Math.round(100*a)/100;d.attr("width",c)}}if(!this.subject.showProgress)return void this.jDom.find(".progressBar").remove();var b,c=this.jDom.find(".progressBar"),d=c.find(".bar"),e=0,f=function(){e=0,a(),D(c,"complete")}.bind(this);this.subject.events("reset").on(f),"discrete"==this.subject.parseStrategy&&this.subject.events("requestFail").on(f),this.subject.events("acceptedFromupstream").on(function(d){e++,d.ordering.expectedSize&&(b=d.ordering.expectedSize),a(),d.ordering.isLast&&C(c,"complete"),d.ordering.isFirst&&D(c,"complete")}.bind(this))},a.prototype.showSpinner=function(){C(this.jDom,"requesting");var a=E($("#rotateAnimation"));this.jDom.find(".spinner")[0].appendChild(a[0])},a.prototype.hideSpinner=function(){D(this.jDom,"requesting"),this.jDom.find(".spinner .rotate").remove()};var b=w(a,function(b){a.apply(this,arguments),b.events("gotData").on(this.newData.bind(this)),b.events("reset").on(function(){var a=this.jDom[0],b=a.getAttribute("class"),c=b.replace(/received-\d/g,"");a.setAttribute("class",c)}.bind(this))});b.prototype.newData=function(a){C(this.jDom,"received-"+a.ordering.i)};var c=w(b,function(){b.apply(this,arguments)});c.prototype.newData=function(a){var c="discrete"==this.subject.parseStrategy?20*a.ordering.i:0;b.prototype.newData.apply(this,arguments);var d=this.jDom.find(".unit-"+a.ordering.i);d.css({opacity:0}).delay(c).animate({opacity:1}),d.find(".pointer").css({translateY:-20}).delay(c).animate({translateY:0},{easing:"easeOutBounce"})};var d=w(a,function(b){a.apply(this,arguments),this.runningTotals={dem:0,rep:0},b.events("gotData").on(function(a){var b=a.payload;B(this.stateElement(b.state),b),this.updateTotals(b)}.bind(this)),b.events("reset").on(function(){this.jDom.find(".states [data-state]").each(function(){$(this).attr("data-wonby","")}),this.jDom.find(".pie path").each(function(){$(this).attr("d","")}),this.runningTotals={dem:0,rep:0}}.bind(this))});d.prototype.stateElement=function(a){var b=".states [data-state="+a+"]";return this.jDom.find(b)},d.prototype.updateTotals=function(a){var b=538,c=a.wonBy,d=this.runningTotals[c]+=a.votes;proportion=d/b,selector=".pie [data-wonby="+c+"]";var e=this.jDom.find(selector);e.attr("d",this.pieWedge(proportion,.5))},d.prototype.pieWedge=function(a,b){function c(a){return Math.round(100*a)/100}var d=b+2*a,e=c(Math.cos(Math.PI*b)),f=c(Math.sin(Math.PI*b)),g=c(Math.cos(Math.PI*d)),h=c(Math.sin(Math.PI*d)),i=a>.5?1:0;return"M0 0 L"+e+" "+f+" A1 1 0 "+i+" 1 "+g+" "+h+" z"};var e=w(a,function(b){a.apply(this,arguments);var c=$("#tweet"),d=this.jDom.find(".tweetsScroll"),e=0,f=0,g=5;b.events("gotData").on(function(a){e++,"live"==a.mode&&f++;var b=E(c,F(a)),h=22*(e-1);scrollOffset=22*f,"live"==a.mode?(d.append(b),b.css({translateY:-scrollOffset}),d.animate({translateY:scrollOffset})):(d.prepend(b),b.css({translateY:h})),e>g&&d.find(".tweet:first-child").remove()}),b.events("reset").on(function(){e=0,f=0,d.stop(!0).css({translateY:0}).empty()})});return a}(),nb=w(jb,function(a){jb.apply(this,arguments);var b=$("[data-demo="+a.name+"]");this.jDom=E($("#demo"),a.colors).add(E($("#demoCaption"))),b.append(this.jDom),this.baseWidth=a.width,this.baseHeight=a.height,this.setDimensions(this.baseHeight,this.scalingFactor()),this.initSubviewCreation(),this.resizeWithWindow(),this.setupControls(),this.showNewNarrativeItems(),a.events("started").on(function(){C(this.jDom,"playing")}.bind(this)),a.events("reset").on(function(){D(this.jDom,"playing")}.bind(this)),a.events("paused").on(function(){C(this.jDom,"paused")}.bind(this)),a.events("unpaused").on(function(){D(this.jDom,"paused")}.bind(this))});nb.prototype.withNarrativeView=function(a){this.narrativeView=a},nb.prototype.resizeWithWindow=function(){$(window).resize(function(){this.setDimensions(this.baseHeight,this.scalingFactor())}.bind(this))},nb.prototype.showNewNarrativeItems=function(){this.subject.events("NarrativeItem").on(function(a){this.narrativeView.displayItem(a)}.bind(this))},nb.prototype.initSubviewCreation=function(){this.createNewViewsForNewModelItems(db,rb),this.createNewViewsForNewModelItems(eb,ob),this.createNewViewsForNewModelItems(cb,pb),this.createNewViewsForNewModelItems(bb,pb),this.createNewViewsForNewModelItems(fb,qb),this.createNewViewsForNewModelItems(gb,mb),this.createNewViewsForNewModelItems(hb,sb),this.createNewViewsForNewModelItems(Y,lb),this.createNewViewsForNewModelItems(ib,pb)},nb.prototype.createNewViewsForNewModelItems=function(a,b){if(!a.newEvent)throw new Error("constructors must have .newEvent set to be listened to");var c=this.subject;c.events(a.newEvent).on(function(a){b.factory?b.factory(a,this):new b(a,this)}.bind(this))},nb.prototype.setupControls=function(){function a(){e.one("click",function(){g.start()})}function b(){f.one("click",function(){g.reset()})}var c=this.jDom,d=c.find(".controls"),e=d.find(".fadeControls"),f=d.find(".reset").hide(),g=this.subject,h=g.events;h("started").on(function(){e.fadeOut(),f.fadeIn(),b()}),h("reset").on(function(){e.off(),f.off(),e.fadeIn(),f.fadeOut(),a()}),a()},nb.prototype.scalingFactor=function(){var a=this.jDom.parents("main").width();return a/this.baseWidth},nb.prototype.setDimensions=function(a,b){var c=this.jDom.filter("svg");c.attr("height",a*b),c.attr("data-scale",b),c.find(".scaling").attr("transform","scale("+b+")"),c.find(".fade").attr("height",a+1),c.find(".reset").css("translateY",a),c.find(".play").attr("y",a/2)};var ob=w(jb,function(a){"use strict";jb.apply(this,arguments);var b=this.find(".messages");this.jDom=E($("#message"),a.name),this.jPausibleElements=this.jDom,b.find(".inners").append(this.jDom.filter(".messageInner")),b.find(".outers").append(this.jDom.filter(".messageOuter")),this.jDom.hide(),a.events("requestStartMove").on(function(a,b,c){this.jDom.show(),this.goToXy("lineX1","lineY1",a),this.animateXy("lineX2","lineY2",a,b,c)}.bind(this)),a.events("responseCloseMove").on(function(a,b,c){this.animateXy("lineX2","lineY2",a,b,c)}.bind(this));var c=function(){this.jDom.remove()}.bind(this);a.events("done").on(c)});ob.factory=function(a,b){return"cable"==a.holder.medium?new ob(a,b):void 0};var pb=w(jb,function(a){jb.apply(this,arguments),this.initDomFromTemplate("places","server",a.name),this.moveTo(a.locations.where),this.writeLabel()}),qb=w(jb,function(a){"use strict";jb.apply(this,arguments),this.initDomFromTemplate("wires","wire-"+a.medium,a.name);var b={cable:function(a,b,c){a.css({lineX1:c.x,lineY1:c.y,lineX2:b.x,lineY2:b.y})},mobile:function(a,b,c){a.find(".upstream").css({translateX:b.x,translateY:b.y}),a.find(".downstream").css({translateX:c.x,translateY:c.y})}},c=b[a.medium];c(this.jDom,a.locations.upstream,a.locations.downstream),"mobile"==a.medium&&this.flashOnMessageStartAndEnd(),this.initHiding()});qb.prototype.flashOnMessageStartAndEnd=function(){function a(a,c){var d=F(a),e=a.name;jb.flash(b[c(a.direction)],d),jb.flash(b[c(a.direction)],e)}var b={upstream:this.jDom.find(".upstream"),downstream:this.jDom.find(".downstream")};this.subject.events("deliveryStarted").on(function(b){a(b,x)}),this.subject.events("delivered").on(function(b){a(b,y)})};var rb=function(){"use strict";var a=1.66,b=w(jb,function(a,b){jb.apply(this,arguments),a.events("isOn").on(function(c){var f="mobile"==c.medium?e:d;new f(a,b,c)}.bind(this))}),c=w(jb,function(a,b){var c=a.events;jb.call(this,a,b),this.initDomFromTemplate("packets",this.templateName(a),this.className(a)),a.payload&&B(this.jDom,a.payload),c("move").on(this.animateMove.bind(this)),c("done").on(this.done.bind(this))});c.prototype.className=function(a){return a.name+" "+F(a)},c.prototype.done=function(){this.jDom.remove()};var d=w(c,function(){c.apply(this,arguments)});d.prototype.animateMove=function(a,b,c){this.animateXy("translateX","translateY",a,b,c)},d.prototype.templateName=function(a){switch(a.type){case"GET":return"getRequest";case"JSON":return a.ordering.isFirst?"firstPacket":a.ordering.isLast?"lastPacket":"packet"}};var e=w(c,function(a,b,d){if(c.apply(this,arguments),d.blockage){var e=x(a.direction)+"-clip";this.jDom[0].setAttribute("clip-path","url(#"+e+")")}});return e.prototype.animateMove=function(b,c,d){function e(a,b){function c(a){return Math.pow(a,2)}return Math.sqrt(c(b.x-a.x)+c(b.y-a.y))}var f=(this.subject,e(b,c)),g=this.jDom.find(".packet");this.jPausibleElements=g,this.putAtXy(g,"circleX","circleY",b),g.animate({circleRadius:f*a,opacity:0},{duration:d*a,queue:!1,complete:function(){this.jDom.remove()}.bind(this)}),this.pauseAnimationIfDemoPaused(g)},c.prototype.done=function(){window.setTimeout(function(){this.jDom.remove()}.bind(this),500)},e.prototype.templateName=function(){return"airwavePacket"},b}(),sb=w(jb,function(a){jb.apply(this,arguments),this.initDomFromTemplate("places","tower",a.name),this.moveTo(a.locations.where)});$(function(){$("[data-demo]").each(function(a,b){G(b.getAttribute("data-demo"),b.hasAttribute("data-autoplay"))}),c(),e()})}({},function(){return this}());