Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

settings issue on server

  • Loading branch information...
commit b17dcf58458b307e8ecf7da6dd7584e66e5ca560 1 parent 50fbb64
@enjalot authored
View
1  example-settings.js
@@ -2,6 +2,7 @@ var settings = module.exports;
settings.port = 8888;
settings.hostname = "localhost";
+//on port 80 you don't want to specify the port, so settings.origin would be "http://tributary.io" for example
settings.origin = "http://" + settings.hostname + ":" + settings.port;
settings.sandboxOrigin = "http://sandbox." + settings.hostname + ":" + settings.port;
View
2  src/ui.js
@@ -9,7 +9,7 @@ var parentWindow;
window.addEventListener("message", recieveMessage, false)
function recieveMessage(event) {
- console.log(event.origin, tributary._origin, event.data);
+ //console.log(event.origin, tributary._origin, event.data);
if(event.origin !== tributary._origin || !event.data) return;
var data = event.data;
View
1  static/tributary.js
@@ -1192,7 +1192,6 @@ var Tributary = function() {
var parentWindow;
window.addEventListener("message", recieveMessage, false);
function recieveMessage(event) {
- console.log(event.origin, tributary._origin, event.data);
if (event.origin !== tributary._origin || !event.data) return;
var data = event.data;
if (data.request === "load") {
View
2  static/tributary.min.js
@@ -1,2 +1,2 @@
//(function(){
-var Tributary=function(){function recieveMessage(a){console.log(a.origin,tributary._origin,a.data);if(a.origin!==tributary._origin||!a.data)return;var b=a.data;if(b.request==="load")parentWindow=a.source,tributary.loadGist(b.gist,_assemble);else if(b.request==="save"){var c=serializeGist();a.source.postMessage({request:"save",config:c,salt:b.salt},a.origin)}else if(b.request==="description")tributary.__config__.set("description",b.description);else if(b.request==="exitfullscreen")$("#container").removeClass("fullscreen"),tributary.events.trigger("resize");else if(b.request==="thumbnail"){var d=b.image;d3.select("#trib-thumbnail").attr("src",d.data.link),d3.select("#trib-thumbnail").style("display",""),tributary.__config__.set("thumbnail",d.data.link)}}function goFullscreen(){parentWindow.postMessage({request:"fullscreen"},tributary._origin)}function _assemble(a,b){if(a){console.log("error!",a);return}var c=b.config;tributary.__config__=c,c.contexts=[];var d,e,f,g,h=c.get("endpoint");tributary.endpoint&&(h=tributary.endpoint),h==="delta"?(c.set("display","svg"),c.set("play",!0),c.set("loop",!0),c.set("autoinit",!0)):h==="cypress"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!0)):h==="hourglass"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!0)):h==="curiosity"?(c.set("display","webgl"),c.set("play",!0),c.set("autoinit",!0)):h==="bigfish"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="fly"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="ocean"&&c.set("display","div"),c.get("display")||c.set("display","svg"),c.set("endpoint","");var i=d3.select("#code");tributary.edit=i,b.models.each(function(a){g=a.get("type"),d=tributary.make_context({config:c,model:a,display:d3.select("#display")}),d&&(c.contexts.push(d),d.render(),mainfiles.indexOf(a.get("filename"))<0&&d.execute(),d.editor=tributary.make_editor({model:a,parent:i}),a.trigger("hide"))}),c.contexts.forEach(function(a){mainfiles.indexOf(a.model.get("filename"))>=0&&(a.model.trigger("show"),tributary.autoinit=!0,a.execute(),tributary.autoinit=c.get("autoinit"))});var j=new tributary.FilesView({el:"#file-list",model:c});j.render();var k=new tributary.ConfigView({el:"#config",model:c});k.render();var l=new tributary.ControlsView({el:"#controls",model:c});l.render(),$("#config-toggle").on("click",function(){$("#config-content").toggle(),$("#config-toggle").text()=="Config"?$("#config-toggle").text("Close Config"):$("#config-toggle").text("Config")}),$("#library-toggle").on("click",function(){$("#library-content").toggle(),$("#library-toggle").text()=="Add libraries"?$("#library-toggle").text("Close libraries"):$("#library-toggle").text("Add libraries")}),$("#fullscreen").on("click",function(){$("#container").addClass("fullscreen"),goFullscreen(),tributary.events.trigger("resize")})}function serializeGist(){var a=tributary.__config__,b={description:a.get("description"),"public":a.get("public"),files:{}},c="";return a.contexts.forEach(function(a){c=a.model.get("code"),c===""&&(c="{}"),b.files[a.model.get("filename")]={content:c}}),a.todelete&&a.todelete.forEach(function(a){b.files[a]=null}),b.files["config.json"]={content:JSON.stringify(a.toJSON())},b}var tributary={};tributary.events=_.clone(Backbone.Events),tributary.data={},window.trib={},window.trib_options={},window.addEventListener("resize",function(a){tributary.events.trigger("resize",a)});var mainfiles=["inlet.js","inlet.coffee","sinwaves.js","squarecircle.js"];tributary.displays=[{name:"svg",description:"creates an <svg> element for you to use"},{name:"canvas",description:"creates a <canvas> element and gives you a Context for the canvas"},{name:"webgl",description:"gives you a Three.js WebGLRenderer scene"},{name:"html",description:"gives you <div id=display>"}],tributary.time_controls=[{name:"play",description:"gives you a play button, and tributary.t. if you provide tributary.run(g,t) it will be executed in a run loop"},{name:"loop",description:"gives you a loop where tributary.t goes from 0 to 1."},{name:"restart",description:"assumes you only want tributary.init(g) to be run when the restart button is clicked"}],tributary.make_context=function(a){var b,c,d,e,f=a.config;if(a.model)c=a.model,g=c.get("filename"),e=c.get("type");else{var g,h;a.filename?g=a.filename:g="inlet.js",a.content?h=a.content:h="";var i=g.split(".");e=i[i.length-1],c=new tributary.CodeModel({name:i[0],filename:g,code:h})}return a.display?d=a.display:d=d3.select("#display"),c.set("type",e),mainfiles.indexOf(g)>=0?(e==="coffee"&&c.set("mode","coffeescript"),b=new tributary.TributaryContext({config:f,model:c,el:d.node()})):e==="json"?(c.set("mode","json"),b=new tributary.JSONContext({config:f,model:c})):e==="csv"?(c.set("mode","text"),b=new tributary.CSVContext({config:f,model:c})):e==="tsv"?(c.set("mode","text"),b=new tributary.TSVContext({config:f,model:c})):e==="js"?b=new tributary.JSContext({config:f,model:c}):e==="coffee"?(c.set("mode","coffeescript"),b=new tributary.CoffeeContext({config:f,model:c})):e==="css"?(c.set("mode","css"),b=new tributary.CSSContext({config:f,model:c})):e==="html"?(c.set("mode","text/html"),b=new tributary.HTMLContext({config:f,model:c,el:d.node()})):e==="svg"&&g!=="inlet.svg"&&(c.set("mode","text/html"),b=new tributary.SVGContext({config:f,model:c,el:d.node()})),b},d3.selection.prototype.moveToFront=function(){return this.each(function(){this.parentNode.appendChild(this)})},tributary.appendSVGFragment=function(a,b){var c="<svg xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink>",d="</svg>",e=document.createRange();e.selectNode(a);var f=e.createContextualFragment(c+b+d),g=f.childNodes[0].childNodes;for(var h=0,i=g.length;h<i;h++)a.appendChild(g[0])},tributary.getContext=function(a){var b=_.find(tributary.__config__.contexts,function(b){return b.model.get("filename")===a});return b},tributary.getCodeEditor=function(a){var b=tributary.getContext(a);if(!b||!b.editor)return;return b.editor.cm},tributary.getModel=function(a){var b=tributary.getContext(a);if(!b||!b.model)return;return b.model},Handlebars.getTemplate=function(a,b){(Handlebars.templates===undefined||Handlebars.templates[a]===undefined)&&$.ajax({url:"/static/templates/"+a+".handlebars",success:function(c){Handlebars.templates===undefined&&(Handlebars.templates={}),Handlebars.templates[a]=Handlebars.compile(c),b&&b(template)}})},tributary.CodeModel=Backbone.Model.extend({defaults:{code:"",filename:"inlet.js",name:"inlet",type:"js",mode:"javascript"},initialize:function(){this.binder()},binder:function(){this.on("error",this.handle_error)},handle_error:function(a){tributary.trace&&(console.trace(),console.log(a))},handle_coffee:function(){var a=this.get("code");return this.get("mode")==="coffeescript"&&(a=CoffeeScript.compile(a,{bare:!0})),a},local_storage:function(a){a||(a="");var b=this.get("filename")+"/code/"+a;return localStorage[b]},set_local_storage:function(a,b){var c=this.get("filename")+"/code/"+b;localStorage[c]=a}}),tributary.CodeModels=Backbone.Collection.extend({model:tributary.CodeModel}),tributary.Config=Backbone.Model.extend({defaults:{description:"Tributary inlet",endpoint:"tributary",display:"svg","public":!0,require:[],fileconfigs:{},play:!1,loop:!1,restart:!1,autoinit:!0,pause:!0,loop_type:"period",bv:!1,nclones:15,clone_opacity:.4,duration:3e3,ease:"linear",dt:.01},require:function(a){var b=this.get("require"),c=_.pluck(b,"url"),d=function(){return a(null,arguments)};require(c,d)},initialize:function(){this.on("hide",function(){this.contexts.forEach(function(a){a.model.trigger("hide")})},this)}}),tributary.ConfigView=Backbone.View.extend({initialize:function(){},render:function(){function c(){var a=d3.event.target.files;for(var c=0,d;d=a[c];c++){if(!d.type.match("image.*")){console.log("not an image");continue}b.onload=function(a){return function(a){var b="data:image/png;base64,".length,c=a.target.result.substring(b);tributary.events.trigger("imgur",c)}}(d),b.readAsDataURL(d)}}function m(){var b={name:k.node().value,url:l.node().value},c=a.model.get("require");c.push(b),a.model.require(function(a,b){}),a.model.set("require",c),o(i.selectAll("li.lib").data(c).enter())}function o(b){var c=b.append("li").classed("lib",!0);c.append("input").attr("type","checkbox").attr("checked",!0).on("change",function(b){var c=a.model.get("require"),d=c.indexOf(b);d>=0?(c.splice(d,1),a.model.set("require",c)):(c.push(b),a.model.set("require",c))}),c.append("span").text(function(a){return a.name})}var a=this,b=new FileReader;d3.select("#thumbnail-content").select("input").on("change",c);var d=this.model.get("thumbnail");d&&d3.select("#thumbnail-content").select("img").attr("src",d).style("display","");var e=d3.select(this.el).select("#config-content select").on("change",function(){var b=this.selectedOptions[0].value;a.model.set("display",b),tributary.events.trigger("execute")}),f=this.model.get("display");e.selectAll("option").each(function(a,b){this.value===f&&(e.node().value=this.value)});var g=d3.select("#timecontrols").selectAll("button");g.datum(function(){return this.dataset}),g.filter(function(b){return a.model.get(b.name)}).classed("active",!0),g.on("click",function(b){var c=!a.model.get(b.name);d3.select(this).classed("active",c),a.model.set(b.name,c)});var h=d3.select(this.el).select("#logerrors").on("click",function(a){var b=d3.select(this);$(this).attr("data-name")==="log-errors"&&(b.classed("active")?(console.log("Error logging disabled"),tributary.hint=!1,tributary.trace=!1,tributary.events.trigger("execute"),b.classed("active",!1)):(console.log("Error logging initiated"),tributary.hint=!0,tributary.trace=!0,tributary.events.trigger("execute"),b.classed("active",!0)))}),i=d3.select(this.el).select("#library-checklist"),j=d3.select(this.el).select("#library-links"),k=j.select("input.library-title"),l=j.select("input.library-url"),n=j.select(".add-library").on("click",m);k.on("keypress",function(){d3.event.charCode===13&&m()}),l.on("keypress",function(){d3.event.charCode===13&&m()});var p=i.selectAll("li.lib").data(this.model.get("require")).enter();o(p)}}),tributary.Context=Backbone.View.extend({initialize:function(){},execute:function(){},render:function(){}}),tributary.TributaryContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("execute",this.execute,this),tributary.__config__||(tributary.__config__=this.options.config),this.model.on("change:code",function(){tributary.events.trigger("warnchanged")},this),this.config=this.options.config,this.config.on("change:display",this.set_display,this);var a=this.config;tributary.init=undefined,tributary.run=undefined,tributary.loop=a.get("loop"),tributary.autoinit=a.get("autoinit"),tributary.pause=a.get("pause"),tributary.loop_type=a.get("loop_type"),tributary.bv=a.get("bv"),tributary.nclones=a.get("nclones"),tributary.clone_opacity=a.get("clone_opacity"),tributary.duration=a.get("duration"),tributary.ease=d3.ease(a.get("ease")),tributary.t=0,tributary.dt=a.get("dt"),tributary.reverse=!1,tributary.useThreejsControls=!0,tributary.render=function(){},tributary.execute=function(){if(tributary.run!==undefined){var a=tributary.t;tributary.loop&&(a=tributary.ease(tributary.t)),tributary.run(tributary.g,a,0)}},tributary.timer={then:new Date,duration:tributary.duration,ctime:tributary.t},d3.timer(function(){tributary.render();if(tributary.pause)return!1;var b=new Date,c=b-tributary.timer.then,d;if(tributary.loop){tributary.reverse?d=tributary.timer.ctime*c/tributary.timer.duration*-1:d=(1-tributary.timer.ctime)*c/tributary.timer.duration,tributary.t=tributary.timer.ctime+d;if(tributary.t>=1||tributary.t<=0||tributary.t==="NaN")tributary.loop_type==="period"?(tributary.t=0,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!1):tributary.loop_type==="pingpong"?(tributary.t=!tributary.reverse,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!tributary.reverse):tributary.t!==0&&(tributary.t=1,tributary.pause=!0);tributary.t===!0&&(tributary.t=1),tributary.t===!1&&(tributary.t=0)}else tributary.t+=tributary.dt;tributary.execute(),a.trigger("tick",tributary.t)})},execute:function(){var a=this.model.handle_coffee();if(a.length>0&&this.model.get("type")!=="coffee"){var b=JSHINT(a,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});b?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{tributary.initialize=new Function("g","tributary",a)}catch(c){return this.model.trigger("error",c),!1}try{window.trib={},window.trib_options={},trib=window.trib,trib_options=window.trib_options,tributary.autoinit&&(tributary.clear(),tributary.events.trigger("prerender")),this.clones&&$(this.clones.node()).empty(),tributary.bv&&this.make_clones(),tributary.initialize(tributary.g,tributary),tributary.autoinit&&tributary.init!==undefined&&tributary.init(tributary.g,0),tributary.execute()}catch(d){return this.model.trigger("error",d),!1}return this.model.trigger("noerror"),!0},render:function(){this.set_display()},set_display:function(){var a=this;this.$el.empty();var b=this.config.get("display");b==="svg"?this.make_svg():b==="canvas"?this.make_canvas():b==="webgl"?this.make_webgl():b==="div"?(this.g=d3.select(this.el),tributary.g=this.g,tributary.clear=function(){a.$el.empty()}):tributary.clear=function(){a.$el.empty()}},make_svg:function(){this.svg=d3.select(this.el).append("svg").attr({xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink","class":"tributary_svg"}),tributary.g=this.svg,tributary.clear=function(){$(tributary.g.node()).empty()}},make_canvas:function(){tributary.clear=function(){tributary.canvas.width=tributary.sw,tributary.canvas.height=tributary.sh,tributary.ctx.clearRect(0,0,tributary.sw,tributary.sh)},tributary.canvas=d3.select(this.el).append("canvas").classed("tributary_canvas",!0).node(),tributary.ctx=tributary.canvas.getContext("2d"),tributary.g=tributary.ctx},make_clones:function(){this.clones=this.svg.selectAll("g.clones").data([0]),this.clones.enter().append("g").attr("class","clones"),tributary.g=this.svg.selectAll("g.delta").data([0]),tributary.g.enter().append("g").attr("class","delta");var a=d3.range(tributary.nclones),b=this.clones.selectAll("g.bvclone").data(a).enter().append("g").attr("class","bvclone").style("opacity",tributary.clone_opacity);b.each(function(a,b){var c=b+1,d=d3.select(this);tributary.init(d,c);var e=tributary.ease(c/(tributary.nclones+1));tributary.run(d,e,c)})},make_webgl:function(){function b(){windowHalfX=tributary.sw/2,windowHalfY=tributary.sh/2,tributary.camera.aspect=tributary.sw/tributary.sh,tributary.camera.updateProjectionMatrix(),tributary.renderer.setSize(tributary.sw,tributary.sh)}container=this.el,tributary.camera=new THREE.PerspectiveCamera(70,tributary.sw/tributary.sh,1,1e3),tributary.camera.position.y=150,tributary.camera.position.z=500,tributary.scene=new THREE.Scene,THREE.Object3D.prototype.clear=function(){var a=this.children,b;for(b=a.length-1;b>=0;b--){var c=a[b];c.clear(),this.remove(c)}},tributary.renderer=new THREE.WebGLRenderer,tributary.renderer.setSize(tributary.sw,tributary.sh),container.appendChild(tributary.renderer.domElement);var a=new THREE.TrackballControls(tributary.camera);a.target.set(0,0,0),a.rotateSpeed=1,a.zoomSpeed=1.2,a.panSpeed=.8,a.noZoom=!1,a.noPan=!1,a.staticMoving=!1,a.dynamicDampingFactor=.15,tributary.controls=a,tributary.render=function(){tributary.useThreejsControls&&tributary.controls.update(),tributary.renderer.render(tributary.scene,tributary.camera)},tributary.render(),tributary.events.on("resize",b,!1),tributary.clear=function(){tributary.scene.clear()}}}),tributary.JSONContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=JSON.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.JSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.get("code");if(js.length>0){var hints=JSHINT(js,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});hints?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CoffeeContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.handle_coffee();console.log("JS",js);try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.csv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.TSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.tsv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")}),this.model.on("delete",function(){d3.select(this.el).remove()},this)},execute:function(){try{this.el.textContent=this.model.get("code")}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){this.el=d3.select("head").selectAll("style.csscontext").data([this.model],function(a){return a.cid}).enter().append("style").classed("csscontext",!0).attr({type:"text/css"}).node()}}),tributary.HTMLContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{$(this.el).append(this.model.get("code"))}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.SVGContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{var a=d3.select(this.el).select("svg").node();tributary.appendSVGFragment(a,this.model.get("code"))}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.make_editor=function(a){var b=a.parent||tributary.edit,c=a.model;a.container?container=a.container:container=b.append("div").attr("id",c.cid);var d;return d=new tributary.Editor({el:container.node(),model:c}),d.render(),d},tributary.Editor=Backbone.View.extend({initialize:function(){this.model.on("show",function(){d3.select(this.el).style("display","")},this),this.model.on("hide",function(){d3.select(this.el).style("display","none")},this),this.model.on("delete",function(){this.$el.remove()},this)},getConfig:function(){var a=tributary.__config__.get("fileconfigs"),b=a[this.model.get("filename")];return b?b:this.defaultConfig()},setConfig:function(a,b){var c=tributary.__config__.get("fileconfigs"),d=c[this.model.get("filename")];d[a]=b;var c=tributary.__config__.set("fileconfigs",c)},defaultConfig:function(){var a=tributary.__config__.get("fileconfigs"),b={"default":!0,vim:!1,emacs:!1,fontSize:12};a[this.model.get("filename")]=b;var a=tributary.__config__.set("fileconfigs",a);return b},render:function(){var a=this,b=d3.select(this.el).classed("editor",!0),c=Handlebars.templates.editor,d=c(this.getConfig());this.$el.html(d),filetype=a.model.get("filename").split(".")[1];if(filetype=="js")var e="lesser-dark";else if(filetype=="svg")var e="vibrant-ink";else if(filetype=="html")var e="ambiance";else if(filetype=="coffee")var e="elegant";else if(filetype=="css")var e="elegant";else var e="lesser-dark";var f={mode:a.model.get("mode"),theme:e,lineNumbers:!0};a.model.get("mode")==="json"&&(f.mode="javascript",f.json=!0),this.cm=CodeMirror(this.el,f),this.cm.on("change",function(){var b=a.cm.getValue();a.model.set("code",b)}),this.cm.setValue(this.model.get("code")),this.inlet=Inlet(this.cm),this.model.on("error",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!0)}),this.model.on("noerror",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!1)});var g=b.select(".toolbar"),h=b.select(".settings").on("click",function(){g.classed("hidden",!g.classed("hidden")),h.classed("active-settings",!g.classed("hidden"))});g.selectAll(".radio").on("change",function(){a.setConfig("default",!1),a.setConfig("vim",!1),a.setConfig("emacs",!1),a.setConfig(this.value,!0),a.cm.setOption("keyMap",this.value)}),g.select(".plusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize+1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()}),g.select(".minusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize-1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()});var i=a.getConfig(),j=i.fontSize,k=a.cm.getWrapperElement();d3.select(k).select(".CodeMirror-scroll").style({"font-size":j+"px","line-height":j+"px"}),a.cm.refresh()}}),tributary.loadGist=function(a,b){var c={};if(!a)return c.config=new tributary.Config,c.models=new tributary.CodeModels(new tributary.CodeModel),b(null,c);var d;try{d=a.files["config.json"]}catch(e){d=!1}if(d)try{c.config=new tributary.Config(JSON.parse(d.content))}catch(f){c.config=new tributary.Config}else c.config=new tributary.Config;var g=_.keys(a.files);fileconfigs=c.config.get("fileconfigs")||{},c.models=new tributary.CodeModels;var h,i,j,k=0,l;g.forEach(function(b){h=b.split("."),l=h[h.length-1],b!=="config.json"&&(i=new tributary.CodeModel({filename:b,name:h[0],code:a.files[b].content,type:l}),c.models.add(i)),fileconfigs[b]||(fileconfigs[b]={"default":!0,vim:!1,emacs:!1,fontSize:12})}),c.config.set("fileconfigs",fileconfigs),c.config.require(function(a,d){b(null,c)})},tributary.FilesView=Backbone.View.extend({initialize:function(){},render:function(){var a=this,b=Handlebars.templates.files,c=_.map(tributary.__config__.contexts,function(a){return a.model.toJSON()});c=c.sort(function(a,b){return a.filename<b.filename?-1:1});var d=_.find(c,function(a){return a.filename==="inlet.js"||a.filename==="inlet.coffee"});d&&(c.splice(c.indexOf(d),1),c.unshift(d)),$(this.el).html(b({contexts:c}));var e=d3.select("#file-list").selectAll("li.file");e.on("click",function(b){var c=this.dataset.filename,d=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});a.model.trigger("hide"),d.model.trigger("show")}),e.select(".delete-file").style("z-index",1e3).on("click",function(){var b=this.parentNode.dataset,c=b.filename,d=b.filename.split(".")[0];tributary.__config__.unset(c);var e=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});e.model.trigger("delete");var f=tributary.__config__.contexts.indexOf(e);tributary.__config__.contexts.splice(f,1),delete e,tributary.__config__.todelete||(tributary.__config__.todelete=[]),tributary.__config__.todelete.push(c),d3.select(a.el).selectAll("li.file").each(function(){this.dataset.filename===c&&$(this).remove()});var g=tributary.__config__.contexts[0].model;g.trigger("show"),d3.event.stopPropagation()});var f=d3.select(this.el).select(".add-file").on("click",function(){var b=d3.select(this).select("input").style("display","inline-block");b.node().focus(),b.on("keypress",function(){if(d3.event.charCode===13){var c=tributary.make_context({filename:b.node().value,config:tributary.__config__});if(c){tributary.__config__.contexts.push(c),c.render(),c.execute();var d=tributary.make_editor({model:c.model});c.editor=d,a.$el.empty(),a.render(),tributary.__config__.contexts.forEach(function(a){a.model.trigger("hide")}),c.model.trigger("show"),d.cm.focus()}else b.classed("error",!0)}})})}}),tributary.FileView=Backbone.View.extend({render:function(){}}),tributary.ControlsView=Backbone.View.extend({initialize:function(){this.model.on("change:play",this.play_button,this),this.model.on("change:loop",this.time_slider,this),this.model.on("change:restart",this.restart_button,this)},render:function(){var a=d3.select(this.el);a.append("div").attr("id","time_controls"),a.append("div").attr("id","user_controls"),a.append("div").attr("id","time_options"),this.play_button(),this.time_slider(),this.restart_button()},play_button:function(){var a=d3.select(this.el).select("#time_controls");if(this.model.get("play")){var b=a.append("button").classed("play",!0).classed("button_on",!0).text("Play");b.on("click",function(a){tributary.pause?tributary.pause&&(b.classed("playing",!0),b.text("Pause")):(b.classed("playing",!1),b.text("Play"));if(tributary.t<1||!tributary.loop)tributary.pause=!tributary.pause,tributary.pause||(tributary.timer.then=new Date,tributary.timer.duration=(1-tributary.t)*tributary.duration,tributary.timer.ctime=tributary.t)})}else a.select("button.play").remove()},time_slider:function(){tributary.loop=this.model.get("loop");var a=d3.select(this.el).select("#time_controls");if(tributary.loop){var b=a.append("input").attr({type:"range",min:0,max:1,step:.01,value:0,name:"time"}).classed("time_slider",!0);$(b.node()).on("change",function(){tributary.t=parseFloat(this.value),tributary.pause&&tributary.execute()}),this.model.on("tick",function(a){$(b.node()).attr("value",tributary.t)});if(this.model.get("display")==="svg"){var c=a.append("button").classed("bv",!0).classed("button_on",!0).text("BV");c.on("click",function(){tributary.bv=!tributary.bv,tributary.events.trigger("execute")})}}else tributary.bv=!1,a.select("input.time_slider").remove(),a.select("button.bv").remove()},restart_button:function(){var a=this,b=d3.select(this.el).select("#time_controls");if(this.model.get("restart")){tributary.autoinit=!1;var c=b.append("button").classed("restart",!0).classed("button_on",!0).text("Restart");c.on("click",function(a){tributary.clear(),tributary.initialize(tributary.g,tributary),tributary.init(tributary.g),tributary.execute()})}else tributary.autoinit=!0,b.select("button.restart").remove()}}),tributary.batch={},tributary.batch._execute=function(){var a=_.functions(this);_.each(a,function(a){a!=="_execute"&&tributary.batch[a]()})},tributary.ui={},tributary.trace=!1,tributary.hint=!1;var parentWindow;return window.addEventListener("message",recieveMessage,!1),tributary.events.on("warnchanged",function(){parentWindow.postMessage({request:"warnchanged"},tributary._origin)}),tributary.events.on("imgur",function(a){parentWindow.postMessage({request:"imgur",img:a},tributary._origin)}),tributary.ui.setup=function(){tributary.events.on("resize",function(){$("#display").width()>767?tributary.sw=$("#display").width()-$("#panel").width():tributary.sw=$("#display").width(),$("#container").hasClass("fullscreen")&&(tributary.sw=$("#display").width()),tributary.sh=$("#display").height(),tributary.events.trigger("execute")}),tributary.events.trigger("resize")},tributary};
+var Tributary=function(){function recieveMessage(a){if(a.origin!==tributary._origin||!a.data)return;var b=a.data;if(b.request==="load")parentWindow=a.source,tributary.loadGist(b.gist,_assemble);else if(b.request==="save"){var c=serializeGist();a.source.postMessage({request:"save",config:c,salt:b.salt},a.origin)}else if(b.request==="description")tributary.__config__.set("description",b.description);else if(b.request==="exitfullscreen")$("#container").removeClass("fullscreen"),tributary.events.trigger("resize");else if(b.request==="thumbnail"){var d=b.image;d3.select("#trib-thumbnail").attr("src",d.data.link),d3.select("#trib-thumbnail").style("display",""),tributary.__config__.set("thumbnail",d.data.link)}}function goFullscreen(){parentWindow.postMessage({request:"fullscreen"},tributary._origin)}function _assemble(a,b){if(a){console.log("error!",a);return}var c=b.config;tributary.__config__=c,c.contexts=[];var d,e,f,g,h=c.get("endpoint");tributary.endpoint&&(h=tributary.endpoint),h==="delta"?(c.set("display","svg"),c.set("play",!0),c.set("loop",!0),c.set("autoinit",!0)):h==="cypress"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!0)):h==="hourglass"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!0)):h==="curiosity"?(c.set("display","webgl"),c.set("play",!0),c.set("autoinit",!0)):h==="bigfish"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="fly"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="ocean"&&c.set("display","div"),c.get("display")||c.set("display","svg"),c.set("endpoint","");var i=d3.select("#code");tributary.edit=i,b.models.each(function(a){g=a.get("type"),d=tributary.make_context({config:c,model:a,display:d3.select("#display")}),d&&(c.contexts.push(d),d.render(),mainfiles.indexOf(a.get("filename"))<0&&d.execute(),d.editor=tributary.make_editor({model:a,parent:i}),a.trigger("hide"))}),c.contexts.forEach(function(a){mainfiles.indexOf(a.model.get("filename"))>=0&&(a.model.trigger("show"),tributary.autoinit=!0,a.execute(),tributary.autoinit=c.get("autoinit"))});var j=new tributary.FilesView({el:"#file-list",model:c});j.render();var k=new tributary.ConfigView({el:"#config",model:c});k.render();var l=new tributary.ControlsView({el:"#controls",model:c});l.render(),$("#config-toggle").on("click",function(){$("#config-content").toggle(),$("#config-toggle").text()=="Config"?$("#config-toggle").text("Close Config"):$("#config-toggle").text("Config")}),$("#library-toggle").on("click",function(){$("#library-content").toggle(),$("#library-toggle").text()=="Add libraries"?$("#library-toggle").text("Close libraries"):$("#library-toggle").text("Add libraries")}),$("#fullscreen").on("click",function(){$("#container").addClass("fullscreen"),goFullscreen(),tributary.events.trigger("resize")})}function serializeGist(){var a=tributary.__config__,b={description:a.get("description"),"public":a.get("public"),files:{}},c="";return a.contexts.forEach(function(a){c=a.model.get("code"),c===""&&(c="{}"),b.files[a.model.get("filename")]={content:c}}),a.todelete&&a.todelete.forEach(function(a){b.files[a]=null}),b.files["config.json"]={content:JSON.stringify(a.toJSON())},b}var tributary={};tributary.events=_.clone(Backbone.Events),tributary.data={},window.trib={},window.trib_options={},window.addEventListener("resize",function(a){tributary.events.trigger("resize",a)});var mainfiles=["inlet.js","inlet.coffee","sinwaves.js","squarecircle.js"];tributary.displays=[{name:"svg",description:"creates an <svg> element for you to use"},{name:"canvas",description:"creates a <canvas> element and gives you a Context for the canvas"},{name:"webgl",description:"gives you a Three.js WebGLRenderer scene"},{name:"html",description:"gives you <div id=display>"}],tributary.time_controls=[{name:"play",description:"gives you a play button, and tributary.t. if you provide tributary.run(g,t) it will be executed in a run loop"},{name:"loop",description:"gives you a loop where tributary.t goes from 0 to 1."},{name:"restart",description:"assumes you only want tributary.init(g) to be run when the restart button is clicked"}],tributary.make_context=function(a){var b,c,d,e,f=a.config;if(a.model)c=a.model,g=c.get("filename"),e=c.get("type");else{var g,h;a.filename?g=a.filename:g="inlet.js",a.content?h=a.content:h="";var i=g.split(".");e=i[i.length-1],c=new tributary.CodeModel({name:i[0],filename:g,code:h})}return a.display?d=a.display:d=d3.select("#display"),c.set("type",e),mainfiles.indexOf(g)>=0?(e==="coffee"&&c.set("mode","coffeescript"),b=new tributary.TributaryContext({config:f,model:c,el:d.node()})):e==="json"?(c.set("mode","json"),b=new tributary.JSONContext({config:f,model:c})):e==="csv"?(c.set("mode","text"),b=new tributary.CSVContext({config:f,model:c})):e==="tsv"?(c.set("mode","text"),b=new tributary.TSVContext({config:f,model:c})):e==="js"?b=new tributary.JSContext({config:f,model:c}):e==="coffee"?(c.set("mode","coffeescript"),b=new tributary.CoffeeContext({config:f,model:c})):e==="css"?(c.set("mode","css"),b=new tributary.CSSContext({config:f,model:c})):e==="html"?(c.set("mode","text/html"),b=new tributary.HTMLContext({config:f,model:c,el:d.node()})):e==="svg"&&g!=="inlet.svg"&&(c.set("mode","text/html"),b=new tributary.SVGContext({config:f,model:c,el:d.node()})),b},d3.selection.prototype.moveToFront=function(){return this.each(function(){this.parentNode.appendChild(this)})},tributary.appendSVGFragment=function(a,b){var c="<svg xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink>",d="</svg>",e=document.createRange();e.selectNode(a);var f=e.createContextualFragment(c+b+d),g=f.childNodes[0].childNodes;for(var h=0,i=g.length;h<i;h++)a.appendChild(g[0])},tributary.getContext=function(a){var b=_.find(tributary.__config__.contexts,function(b){return b.model.get("filename")===a});return b},tributary.getCodeEditor=function(a){var b=tributary.getContext(a);if(!b||!b.editor)return;return b.editor.cm},tributary.getModel=function(a){var b=tributary.getContext(a);if(!b||!b.model)return;return b.model},Handlebars.getTemplate=function(a,b){(Handlebars.templates===undefined||Handlebars.templates[a]===undefined)&&$.ajax({url:"/static/templates/"+a+".handlebars",success:function(c){Handlebars.templates===undefined&&(Handlebars.templates={}),Handlebars.templates[a]=Handlebars.compile(c),b&&b(template)}})},tributary.CodeModel=Backbone.Model.extend({defaults:{code:"",filename:"inlet.js",name:"inlet",type:"js",mode:"javascript"},initialize:function(){this.binder()},binder:function(){this.on("error",this.handle_error)},handle_error:function(a){tributary.trace&&(console.trace(),console.log(a))},handle_coffee:function(){var a=this.get("code");return this.get("mode")==="coffeescript"&&(a=CoffeeScript.compile(a,{bare:!0})),a},local_storage:function(a){a||(a="");var b=this.get("filename")+"/code/"+a;return localStorage[b]},set_local_storage:function(a,b){var c=this.get("filename")+"/code/"+b;localStorage[c]=a}}),tributary.CodeModels=Backbone.Collection.extend({model:tributary.CodeModel}),tributary.Config=Backbone.Model.extend({defaults:{description:"Tributary inlet",endpoint:"tributary",display:"svg","public":!0,require:[],fileconfigs:{},play:!1,loop:!1,restart:!1,autoinit:!0,pause:!0,loop_type:"period",bv:!1,nclones:15,clone_opacity:.4,duration:3e3,ease:"linear",dt:.01},require:function(a){var b=this.get("require"),c=_.pluck(b,"url"),d=function(){return a(null,arguments)};require(c,d)},initialize:function(){this.on("hide",function(){this.contexts.forEach(function(a){a.model.trigger("hide")})},this)}}),tributary.ConfigView=Backbone.View.extend({initialize:function(){},render:function(){function c(){var a=d3.event.target.files;for(var c=0,d;d=a[c];c++){if(!d.type.match("image.*")){console.log("not an image");continue}b.onload=function(a){return function(a){var b="data:image/png;base64,".length,c=a.target.result.substring(b);tributary.events.trigger("imgur",c)}}(d),b.readAsDataURL(d)}}function m(){var b={name:k.node().value,url:l.node().value},c=a.model.get("require");c.push(b),a.model.require(function(a,b){}),a.model.set("require",c),o(i.selectAll("li.lib").data(c).enter())}function o(b){var c=b.append("li").classed("lib",!0);c.append("input").attr("type","checkbox").attr("checked",!0).on("change",function(b){var c=a.model.get("require"),d=c.indexOf(b);d>=0?(c.splice(d,1),a.model.set("require",c)):(c.push(b),a.model.set("require",c))}),c.append("span").text(function(a){return a.name})}var a=this,b=new FileReader;d3.select("#thumbnail-content").select("input").on("change",c);var d=this.model.get("thumbnail");d&&d3.select("#thumbnail-content").select("img").attr("src",d).style("display","");var e=d3.select(this.el).select("#config-content select").on("change",function(){var b=this.selectedOptions[0].value;a.model.set("display",b),tributary.events.trigger("execute")}),f=this.model.get("display");e.selectAll("option").each(function(a,b){this.value===f&&(e.node().value=this.value)});var g=d3.select("#timecontrols").selectAll("button");g.datum(function(){return this.dataset}),g.filter(function(b){return a.model.get(b.name)}).classed("active",!0),g.on("click",function(b){var c=!a.model.get(b.name);d3.select(this).classed("active",c),a.model.set(b.name,c)});var h=d3.select(this.el).select("#logerrors").on("click",function(a){var b=d3.select(this);$(this).attr("data-name")==="log-errors"&&(b.classed("active")?(console.log("Error logging disabled"),tributary.hint=!1,tributary.trace=!1,tributary.events.trigger("execute"),b.classed("active",!1)):(console.log("Error logging initiated"),tributary.hint=!0,tributary.trace=!0,tributary.events.trigger("execute"),b.classed("active",!0)))}),i=d3.select(this.el).select("#library-checklist"),j=d3.select(this.el).select("#library-links"),k=j.select("input.library-title"),l=j.select("input.library-url"),n=j.select(".add-library").on("click",m);k.on("keypress",function(){d3.event.charCode===13&&m()}),l.on("keypress",function(){d3.event.charCode===13&&m()});var p=i.selectAll("li.lib").data(this.model.get("require")).enter();o(p)}}),tributary.Context=Backbone.View.extend({initialize:function(){},execute:function(){},render:function(){}}),tributary.TributaryContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("execute",this.execute,this),tributary.__config__||(tributary.__config__=this.options.config),this.model.on("change:code",function(){tributary.events.trigger("warnchanged")},this),this.config=this.options.config,this.config.on("change:display",this.set_display,this);var a=this.config;tributary.init=undefined,tributary.run=undefined,tributary.loop=a.get("loop"),tributary.autoinit=a.get("autoinit"),tributary.pause=a.get("pause"),tributary.loop_type=a.get("loop_type"),tributary.bv=a.get("bv"),tributary.nclones=a.get("nclones"),tributary.clone_opacity=a.get("clone_opacity"),tributary.duration=a.get("duration"),tributary.ease=d3.ease(a.get("ease")),tributary.t=0,tributary.dt=a.get("dt"),tributary.reverse=!1,tributary.useThreejsControls=!0,tributary.render=function(){},tributary.execute=function(){if(tributary.run!==undefined){var a=tributary.t;tributary.loop&&(a=tributary.ease(tributary.t)),tributary.run(tributary.g,a,0)}},tributary.timer={then:new Date,duration:tributary.duration,ctime:tributary.t},d3.timer(function(){tributary.render();if(tributary.pause)return!1;var b=new Date,c=b-tributary.timer.then,d;if(tributary.loop){tributary.reverse?d=tributary.timer.ctime*c/tributary.timer.duration*-1:d=(1-tributary.timer.ctime)*c/tributary.timer.duration,tributary.t=tributary.timer.ctime+d;if(tributary.t>=1||tributary.t<=0||tributary.t==="NaN")tributary.loop_type==="period"?(tributary.t=0,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!1):tributary.loop_type==="pingpong"?(tributary.t=!tributary.reverse,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!tributary.reverse):tributary.t!==0&&(tributary.t=1,tributary.pause=!0);tributary.t===!0&&(tributary.t=1),tributary.t===!1&&(tributary.t=0)}else tributary.t+=tributary.dt;tributary.execute(),a.trigger("tick",tributary.t)})},execute:function(){var a=this.model.handle_coffee();if(a.length>0&&this.model.get("type")!=="coffee"){var b=JSHINT(a,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});b?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{tributary.initialize=new Function("g","tributary",a)}catch(c){return this.model.trigger("error",c),!1}try{window.trib={},window.trib_options={},trib=window.trib,trib_options=window.trib_options,tributary.autoinit&&(tributary.clear(),tributary.events.trigger("prerender")),this.clones&&$(this.clones.node()).empty(),tributary.bv&&this.make_clones(),tributary.initialize(tributary.g,tributary),tributary.autoinit&&tributary.init!==undefined&&tributary.init(tributary.g,0),tributary.execute()}catch(d){return this.model.trigger("error",d),!1}return this.model.trigger("noerror"),!0},render:function(){this.set_display()},set_display:function(){var a=this;this.$el.empty();var b=this.config.get("display");b==="svg"?this.make_svg():b==="canvas"?this.make_canvas():b==="webgl"?this.make_webgl():b==="div"?(this.g=d3.select(this.el),tributary.g=this.g,tributary.clear=function(){a.$el.empty()}):tributary.clear=function(){a.$el.empty()}},make_svg:function(){this.svg=d3.select(this.el).append("svg").attr({xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink","class":"tributary_svg"}),tributary.g=this.svg,tributary.clear=function(){$(tributary.g.node()).empty()}},make_canvas:function(){tributary.clear=function(){tributary.canvas.width=tributary.sw,tributary.canvas.height=tributary.sh,tributary.ctx.clearRect(0,0,tributary.sw,tributary.sh)},tributary.canvas=d3.select(this.el).append("canvas").classed("tributary_canvas",!0).node(),tributary.ctx=tributary.canvas.getContext("2d"),tributary.g=tributary.ctx},make_clones:function(){this.clones=this.svg.selectAll("g.clones").data([0]),this.clones.enter().append("g").attr("class","clones"),tributary.g=this.svg.selectAll("g.delta").data([0]),tributary.g.enter().append("g").attr("class","delta");var a=d3.range(tributary.nclones),b=this.clones.selectAll("g.bvclone").data(a).enter().append("g").attr("class","bvclone").style("opacity",tributary.clone_opacity);b.each(function(a,b){var c=b+1,d=d3.select(this);tributary.init(d,c);var e=tributary.ease(c/(tributary.nclones+1));tributary.run(d,e,c)})},make_webgl:function(){function b(){windowHalfX=tributary.sw/2,windowHalfY=tributary.sh/2,tributary.camera.aspect=tributary.sw/tributary.sh,tributary.camera.updateProjectionMatrix(),tributary.renderer.setSize(tributary.sw,tributary.sh)}container=this.el,tributary.camera=new THREE.PerspectiveCamera(70,tributary.sw/tributary.sh,1,1e3),tributary.camera.position.y=150,tributary.camera.position.z=500,tributary.scene=new THREE.Scene,THREE.Object3D.prototype.clear=function(){var a=this.children,b;for(b=a.length-1;b>=0;b--){var c=a[b];c.clear(),this.remove(c)}},tributary.renderer=new THREE.WebGLRenderer,tributary.renderer.setSize(tributary.sw,tributary.sh),container.appendChild(tributary.renderer.domElement);var a=new THREE.TrackballControls(tributary.camera);a.target.set(0,0,0),a.rotateSpeed=1,a.zoomSpeed=1.2,a.panSpeed=.8,a.noZoom=!1,a.noPan=!1,a.staticMoving=!1,a.dynamicDampingFactor=.15,tributary.controls=a,tributary.render=function(){tributary.useThreejsControls&&tributary.controls.update(),tributary.renderer.render(tributary.scene,tributary.camera)},tributary.render(),tributary.events.on("resize",b,!1),tributary.clear=function(){tributary.scene.clear()}}}),tributary.JSONContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=JSON.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.JSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.get("code");if(js.length>0){var hints=JSHINT(js,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});hints?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CoffeeContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.handle_coffee();console.log("JS",js);try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.csv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.TSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.tsv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")}),this.model.on("delete",function(){d3.select(this.el).remove()},this)},execute:function(){try{this.el.textContent=this.model.get("code")}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){this.el=d3.select("head").selectAll("style.csscontext").data([this.model],function(a){return a.cid}).enter().append("style").classed("csscontext",!0).attr({type:"text/css"}).node()}}),tributary.HTMLContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{$(this.el).append(this.model.get("code"))}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.SVGContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{var a=d3.select(this.el).select("svg").node();tributary.appendSVGFragment(a,this.model.get("code"))}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.make_editor=function(a){var b=a.parent||tributary.edit,c=a.model;a.container?container=a.container:container=b.append("div").attr("id",c.cid);var d;return d=new tributary.Editor({el:container.node(),model:c}),d.render(),d},tributary.Editor=Backbone.View.extend({initialize:function(){this.model.on("show",function(){d3.select(this.el).style("display","")},this),this.model.on("hide",function(){d3.select(this.el).style("display","none")},this),this.model.on("delete",function(){this.$el.remove()},this)},getConfig:function(){var a=tributary.__config__.get("fileconfigs"),b=a[this.model.get("filename")];return b?b:this.defaultConfig()},setConfig:function(a,b){var c=tributary.__config__.get("fileconfigs"),d=c[this.model.get("filename")];d[a]=b;var c=tributary.__config__.set("fileconfigs",c)},defaultConfig:function(){var a=tributary.__config__.get("fileconfigs"),b={"default":!0,vim:!1,emacs:!1,fontSize:12};a[this.model.get("filename")]=b;var a=tributary.__config__.set("fileconfigs",a);return b},render:function(){var a=this,b=d3.select(this.el).classed("editor",!0),c=Handlebars.templates.editor,d=c(this.getConfig());this.$el.html(d),filetype=a.model.get("filename").split(".")[1];if(filetype=="js")var e="lesser-dark";else if(filetype=="svg")var e="vibrant-ink";else if(filetype=="html")var e="ambiance";else if(filetype=="coffee")var e="elegant";else if(filetype=="css")var e="elegant";else var e="lesser-dark";var f={mode:a.model.get("mode"),theme:e,lineNumbers:!0};a.model.get("mode")==="json"&&(f.mode="javascript",f.json=!0),this.cm=CodeMirror(this.el,f),this.cm.on("change",function(){var b=a.cm.getValue();a.model.set("code",b)}),this.cm.setValue(this.model.get("code")),this.inlet=Inlet(this.cm),this.model.on("error",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!0)}),this.model.on("noerror",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!1)});var g=b.select(".toolbar"),h=b.select(".settings").on("click",function(){g.classed("hidden",!g.classed("hidden")),h.classed("active-settings",!g.classed("hidden"))});g.selectAll(".radio").on("change",function(){a.setConfig("default",!1),a.setConfig("vim",!1),a.setConfig("emacs",!1),a.setConfig(this.value,!0),a.cm.setOption("keyMap",this.value)}),g.select(".plusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize+1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()}),g.select(".minusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize-1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()});var i=a.getConfig(),j=i.fontSize,k=a.cm.getWrapperElement();d3.select(k).select(".CodeMirror-scroll").style({"font-size":j+"px","line-height":j+"px"}),a.cm.refresh()}}),tributary.loadGist=function(a,b){var c={};if(!a)return c.config=new tributary.Config,c.models=new tributary.CodeModels(new tributary.CodeModel),b(null,c);var d;try{d=a.files["config.json"]}catch(e){d=!1}if(d)try{c.config=new tributary.Config(JSON.parse(d.content))}catch(f){c.config=new tributary.Config}else c.config=new tributary.Config;var g=_.keys(a.files);fileconfigs=c.config.get("fileconfigs")||{},c.models=new tributary.CodeModels;var h,i,j,k=0,l;g.forEach(function(b){h=b.split("."),l=h[h.length-1],b!=="config.json"&&(i=new tributary.CodeModel({filename:b,name:h[0],code:a.files[b].content,type:l}),c.models.add(i)),fileconfigs[b]||(fileconfigs[b]={"default":!0,vim:!1,emacs:!1,fontSize:12})}),c.config.set("fileconfigs",fileconfigs),c.config.require(function(a,d){b(null,c)})},tributary.FilesView=Backbone.View.extend({initialize:function(){},render:function(){var a=this,b=Handlebars.templates.files,c=_.map(tributary.__config__.contexts,function(a){return a.model.toJSON()});c=c.sort(function(a,b){return a.filename<b.filename?-1:1});var d=_.find(c,function(a){return a.filename==="inlet.js"||a.filename==="inlet.coffee"});d&&(c.splice(c.indexOf(d),1),c.unshift(d)),$(this.el).html(b({contexts:c}));var e=d3.select("#file-list").selectAll("li.file");e.on("click",function(b){var c=this.dataset.filename,d=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});a.model.trigger("hide"),d.model.trigger("show")}),e.select(".delete-file").style("z-index",1e3).on("click",function(){var b=this.parentNode.dataset,c=b.filename,d=b.filename.split(".")[0];tributary.__config__.unset(c);var e=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});e.model.trigger("delete");var f=tributary.__config__.contexts.indexOf(e);tributary.__config__.contexts.splice(f,1),delete e,tributary.__config__.todelete||(tributary.__config__.todelete=[]),tributary.__config__.todelete.push(c),d3.select(a.el).selectAll("li.file").each(function(){this.dataset.filename===c&&$(this).remove()});var g=tributary.__config__.contexts[0].model;g.trigger("show"),d3.event.stopPropagation()});var f=d3.select(this.el).select(".add-file").on("click",function(){var b=d3.select(this).select("input").style("display","inline-block");b.node().focus(),b.on("keypress",function(){if(d3.event.charCode===13){var c=tributary.make_context({filename:b.node().value,config:tributary.__config__});if(c){tributary.__config__.contexts.push(c),c.render(),c.execute();var d=tributary.make_editor({model:c.model});c.editor=d,a.$el.empty(),a.render(),tributary.__config__.contexts.forEach(function(a){a.model.trigger("hide")}),c.model.trigger("show"),d.cm.focus()}else b.classed("error",!0)}})})}}),tributary.FileView=Backbone.View.extend({render:function(){}}),tributary.ControlsView=Backbone.View.extend({initialize:function(){this.model.on("change:play",this.play_button,this),this.model.on("change:loop",this.time_slider,this),this.model.on("change:restart",this.restart_button,this)},render:function(){var a=d3.select(this.el);a.append("div").attr("id","time_controls"),a.append("div").attr("id","user_controls"),a.append("div").attr("id","time_options"),this.play_button(),this.time_slider(),this.restart_button()},play_button:function(){var a=d3.select(this.el).select("#time_controls");if(this.model.get("play")){var b=a.append("button").classed("play",!0).classed("button_on",!0).text("Play");b.on("click",function(a){tributary.pause?tributary.pause&&(b.classed("playing",!0),b.text("Pause")):(b.classed("playing",!1),b.text("Play"));if(tributary.t<1||!tributary.loop)tributary.pause=!tributary.pause,tributary.pause||(tributary.timer.then=new Date,tributary.timer.duration=(1-tributary.t)*tributary.duration,tributary.timer.ctime=tributary.t)})}else a.select("button.play").remove()},time_slider:function(){tributary.loop=this.model.get("loop");var a=d3.select(this.el).select("#time_controls");if(tributary.loop){var b=a.append("input").attr({type:"range",min:0,max:1,step:.01,value:0,name:"time"}).classed("time_slider",!0);$(b.node()).on("change",function(){tributary.t=parseFloat(this.value),tributary.pause&&tributary.execute()}),this.model.on("tick",function(a){$(b.node()).attr("value",tributary.t)});if(this.model.get("display")==="svg"){var c=a.append("button").classed("bv",!0).classed("button_on",!0).text("BV");c.on("click",function(){tributary.bv=!tributary.bv,tributary.events.trigger("execute")})}}else tributary.bv=!1,a.select("input.time_slider").remove(),a.select("button.bv").remove()},restart_button:function(){var a=this,b=d3.select(this.el).select("#time_controls");if(this.model.get("restart")){tributary.autoinit=!1;var c=b.append("button").classed("restart",!0).classed("button_on",!0).text("Restart");c.on("click",function(a){tributary.clear(),tributary.initialize(tributary.g,tributary),tributary.init(tributary.g),tributary.execute()})}else tributary.autoinit=!0,b.select("button.restart").remove()}}),tributary.batch={},tributary.batch._execute=function(){var a=_.functions(this);_.each(a,function(a){a!=="_execute"&&tributary.batch[a]()})},tributary.ui={},tributary.trace=!1,tributary.hint=!1;var parentWindow;return window.addEventListener("message",recieveMessage,!1),tributary.events.on("warnchanged",function(){parentWindow.postMessage({request:"warnchanged"},tributary._origin)}),tributary.events.on("imgur",function(a){parentWindow.postMessage({request:"imgur",img:a},tributary._origin)}),tributary.ui.setup=function(){tributary.events.on("resize",function(){$("#display").width()>767?tributary.sw=$("#display").width()-$("#panel").width():tributary.sw=$("#display").width(),$("#container").hasClass("fullscreen")&&(tributary.sw=$("#display").width()),tributary.sh=$("#display").height(),tributary.events.trigger("execute")}),tributary.events.trigger("resize")},tributary};
Please sign in to comment.
Something went wrong with that request. Please try again.