mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 17:27:22 +02:00
fixed long text in dmeonstarton view
This commit is contained in:
parent
f19f080d61
commit
0c4319911e
6 changed files with 291 additions and 18 deletions
|
@ -10,6 +10,41 @@ var Views = require('../views');
|
|||
var ModalTerminal = Views.ModalTerminal;
|
||||
var ContainedBase = Views.ContainedBase;
|
||||
|
||||
var MultiView = require('../views/multiView').MultiView;
|
||||
|
||||
var TextGrabber = ContainedBase.extend({
|
||||
tagName: 'div',
|
||||
className: 'textGrabber box vertical',
|
||||
template: _.template($('#text-grabber').html()),
|
||||
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.JSON = {
|
||||
helperText: options.helperText || 'Enter some text'
|
||||
};
|
||||
|
||||
this.container = options.container || new ModalTerminal({
|
||||
title: 'Enter some text'
|
||||
});
|
||||
this.render();
|
||||
if (options.initialText) {
|
||||
this.setText(options.initialText);
|
||||
}
|
||||
|
||||
if (!options.wait) {
|
||||
this.show();
|
||||
}
|
||||
},
|
||||
|
||||
getText: function() {
|
||||
return this.$('textarea').val();
|
||||
},
|
||||
|
||||
setText: function(str) {
|
||||
this.$('textarea').val(str);
|
||||
}
|
||||
});
|
||||
|
||||
var MarkdownGrabber = ContainedBase.extend({
|
||||
tagName: 'div',
|
||||
className: 'markdownGrabber box horizontal',
|
||||
|
@ -40,7 +75,7 @@ var MarkdownGrabber = ContainedBase.extend({
|
|||
|
||||
var confirmCancel = new Views.ConfirmCancelView({
|
||||
deferred: buttonDefer,
|
||||
destination: this.getDestination()
|
||||
destination: this
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -107,6 +142,18 @@ var DemonstrationBuilder = ContainedBase.extend({
|
|||
withoutButton: true,
|
||||
previewText: 'Before demonstration Markdown'
|
||||
});
|
||||
this.beforeCommandView = new TextGrabber({
|
||||
container: this,
|
||||
helperText: 'The git command(s) to set up the demonstration view (before it is displayed)',
|
||||
initialText: 'git checkout -b bugFix'
|
||||
});
|
||||
|
||||
this.commandView = new TextGrabber({
|
||||
container: this,
|
||||
helperText: 'The git command(s) to demonstrate to the reader',
|
||||
initialText: 'git commit'
|
||||
});
|
||||
|
||||
this.afterMarkdownView = new MarkdownGrabber({
|
||||
container: this,
|
||||
withoutButton: true,
|
||||
|
@ -134,15 +181,20 @@ var DemonstrationBuilder = ContainedBase.extend({
|
|||
},
|
||||
|
||||
testView: function() {
|
||||
var module = require('../views/gitDemonstrationView');
|
||||
new module.GitDemonstrationView(this.getExportObj());
|
||||
new MultiView({
|
||||
childViews: [{
|
||||
type: 'GitDemonstrationView',
|
||||
options: this.getExportObj()
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
getExportObj: function() {
|
||||
return {
|
||||
beforeMarkdowns: this.beforeMarkdownView.exportToArray(),
|
||||
afterMarkdowns: this.afterMarkdownView.exportToArray(),
|
||||
gitCommand: 'git commit'
|
||||
command: this.commandView.getText(),
|
||||
beforeCommand: this.beforeCommandView.getText()
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -163,4 +215,5 @@ var DemonstrationBuilder = ContainedBase.extend({
|
|||
|
||||
exports.MarkdownGrabber = MarkdownGrabber;
|
||||
exports.DemonstrationBuilder = DemonstrationBuilder;
|
||||
exports.TextGrabber = TextGrabber;
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ var GitDemonstrationView = ContainedBase.extend({
|
|||
title: options.title || 'Git Demonstration'
|
||||
});
|
||||
this.render();
|
||||
this.checkScroll();
|
||||
|
||||
this.navEvents = _.clone(Backbone.Events);
|
||||
this.navEvents.on('positive', this.positive, this);
|
||||
|
@ -74,6 +75,31 @@ var GitDemonstrationView = ContainedBase.extend({
|
|||
}
|
||||
},
|
||||
|
||||
checkScroll: function() {
|
||||
console.log('checking scroll');
|
||||
var children = this.$('div.demonstrationText').children();
|
||||
var heights = _.map(children, function(child) { return child.clientHeight; });
|
||||
var totalHeight = _.reduce(heights, function(a, b) { return a + b; });
|
||||
console.log(children, heights, totalHeight);
|
||||
if (totalHeight < this.$('div.demonstrationText').height()) {
|
||||
this.$('div.demonstrationText').addClass('noLongText');
|
||||
}
|
||||
},
|
||||
|
||||
dispatchBeforeCommand: function() {
|
||||
if (!this.options.beforeCommand) {
|
||||
return;
|
||||
}
|
||||
// here we just split the command and push them through to the git engine
|
||||
util.splitTextCommand(this.options.beforeCommand, function(commandStr) {
|
||||
this.mainVis.gitEngine.dispatch(new Command({
|
||||
rawStr: commandStr
|
||||
}), Q.defer());
|
||||
}, this);
|
||||
// then harsh refresh
|
||||
this.mainVis.gitVisuals.refreshTreeHarsh();
|
||||
},
|
||||
|
||||
takeControl: function() {
|
||||
this.hasControl = true;
|
||||
this.keyboardListener.listen();
|
||||
|
@ -193,6 +219,7 @@ var GitDemonstrationView = ContainedBase.extend({
|
|||
});
|
||||
this.mainVis.customEvents.on('paperReady', _.bind(function() {
|
||||
this.visFinished = true;
|
||||
this.dispatchBeforeCommand();
|
||||
if (this.shown) {
|
||||
// show the canvas once its done if we are shown
|
||||
this.show();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue