diff --git a/src/main.js b/src/main.js index bc8e1d09..6edaf93a 100644 --- a/src/main.js +++ b/src/main.js @@ -21,7 +21,7 @@ $(document).ready(function(){ collection: commandCollection }); - // TODO make not global + // TODO make not global commandPromptView = new CommandPromptView({ el: $('#commandLineBar'), collection: commandCollection @@ -31,35 +31,11 @@ $(document).ready(function(){ collection: commandCollection }); + $('#commandTextField').focus(); + + var mainVis = new Visualization(); + // make the canvas for us - Raphael(10, 10, 200, 200, function() { - paper = this; - - // the two major collections that affect everything - var commitCollection = new CommitCollection(); - var branchCollection = new BranchCollection(); - - gitVisuals = new GitVisuals({ - commitCollection: commitCollection, - branchCollection: branchCollection - }); - - gitEngine = new GitEngine({ - collection: commitCollection, - branches: branchCollection - }); - - $('#commandTextField').focus(); - - // needs to be called before raphael ready - windowResize(); - events.trigger('raphaelReady'); - }); - - $(window).resize(windowResize); - windowResize(); - setTimeout(windowResize, 50); - if (/\?demo/.test(window.location.href)) { setTimeout(function() { events.trigger('submitCommandValueFromEvent', "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc; gc; git rebase master; git checkout master; gc; gc; git merge bugFix"); diff --git a/src/visuals.js b/src/visuals.js index 20d3c91f..bb843c18 100644 --- a/src/visuals.js +++ b/src/visuals.js @@ -1,3 +1,35 @@ +function Visualization(options) { + + var _this = this; + Raphael(10, 10, 200, 200, function() { + // for some reason raphael calls this function with a predefined + // context... + // so switch it + paper = this; + _this.initialize(this); + }); +} + +Visualization.prototype.initialize = function(paper, options) { + this.commitCollection = new CommitCollection(); + this.branchCollection = new BranchCollection(); + + gitVisuals = new GitVisuals({ + commitCollection: this.commitCollection, + branchCollection: this.branchCollection + }); + + gitEngine = new GitEngine({ + collection: this.commitCollection, + branches: this.branchCollection + }); + + // needs to be called before raphael ready + windowResize(); + events.trigger('raphaelReady'); +} + + function GitVisuals(options) { this.commitCollection = options.commitCollection; this.branchCollection = options.branchCollection;