mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 01:10:04 +02:00
markdown grabber
This commit is contained in:
parent
36bfd99d9e
commit
3ade2bdd71
8 changed files with 329 additions and 12 deletions
|
@ -22,7 +22,8 @@ var toGlobalize = {
|
|||
Sandbox: require('../level/sandbox'),
|
||||
GitDemonstrationView: require('../views/gitDemonstrationView'),
|
||||
Markdown: require('markdown'),
|
||||
LevelDropdownView: require('../views/levelDropdownView')
|
||||
LevelDropdownView: require('../views/levelDropdownView'),
|
||||
BuilderViews: require('../views/builderViews')
|
||||
};
|
||||
|
||||
_.each(toGlobalize, function(module) {
|
||||
|
|
88
src/js/views/builderViews.js
Normal file
88
src/js/views/builderViews.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
var _ = require('underscore');
|
||||
var Q = require('q');
|
||||
// horrible hack to get localStorage Backbone plugin
|
||||
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
|
||||
|
||||
var util = require('../util');
|
||||
var KeyboardListener = require('../util/keyboard').KeyboardListener;
|
||||
|
||||
var Views = require('../views');
|
||||
var ModalTerminal = Views.ModalTerminal;
|
||||
var ContainedBase = Views.ContainedBase;
|
||||
|
||||
var MarkdownGrabber = ContainedBase.extend({
|
||||
tagName: 'div',
|
||||
className: 'MarkdownGrabber box horizontal',
|
||||
template: _.template($('#markdown-grabber-view').html()),
|
||||
events: {
|
||||
'keyup textarea': 'keyup'
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
options = options || {};
|
||||
this.deferred = options.deferred || Q.defer();
|
||||
this.options = options;
|
||||
this.JSON = {};
|
||||
|
||||
this.container = new ModalTerminal({
|
||||
title: options.title || 'Enter some markdown'
|
||||
});
|
||||
this.render();
|
||||
|
||||
if (!options.withoutButton) {
|
||||
// do button stuff
|
||||
var buttonDefer = Q.defer();
|
||||
buttonDefer.promise
|
||||
.then(_.bind(function() {
|
||||
this.confirmed();
|
||||
}, this))
|
||||
.fail(_.bind(function() {
|
||||
this.cancelled();
|
||||
}, this))
|
||||
.done();
|
||||
var confirmCancel = new Views.ConfirmCancelView({
|
||||
deferred: buttonDefer,
|
||||
destination: this.getDestination()
|
||||
});
|
||||
}
|
||||
|
||||
this.updatePreview();
|
||||
|
||||
if (!options.wait) {
|
||||
this.show();
|
||||
}
|
||||
},
|
||||
|
||||
confirmed: function() {
|
||||
this.die();
|
||||
this.deferred.resolve(this.getRawText());
|
||||
},
|
||||
|
||||
cancelled: function() {
|
||||
this.die();
|
||||
this.deferred.resolve();
|
||||
},
|
||||
|
||||
keyup: function() {
|
||||
if (!this.throttledPreview) {
|
||||
this.throttledPreview = _.throttle(
|
||||
_.bind(this.updatePreview, this),
|
||||
500
|
||||
);
|
||||
}
|
||||
this.throttledPreview();
|
||||
},
|
||||
|
||||
getRawText: function() {
|
||||
return this.$('textarea').val();
|
||||
},
|
||||
|
||||
updatePreview: function() {
|
||||
var raw = this.getRawText();
|
||||
var HTML = require('markdown').markdown.toHTML(raw);
|
||||
this.$('div.insidePreview').html(HTML);
|
||||
}
|
||||
});
|
||||
|
||||
exports.MarkdownGrabber = MarkdownGrabber;
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
var GitError = require('../util/errors').GitError;
|
||||
var _ = require('underscore');
|
||||
var Q = require('q');
|
||||
// horrible hack to get localStorage Backbone plugin
|
||||
|
@ -7,6 +6,7 @@ var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.
|
|||
var Main = require('../app');
|
||||
var Constants = require('../util/constants');
|
||||
var KeyboardListener = require('../util/keyboard').KeyboardListener;
|
||||
var GitError = require('../util/errors').GitError;
|
||||
|
||||
var BaseView = Backbone.View.extend({
|
||||
getDestination: function() {
|
||||
|
|
|
@ -271,7 +271,6 @@ var SeriesView = BaseView.extend({
|
|||
// property changing but it's the 11th hour...
|
||||
var toLoop = this.$('div.levelIcon').each(function(index, el) {
|
||||
var id = $(el).attr('data-id');
|
||||
console.log('updating id', id);
|
||||
$(el).toggleClass('solved', Main.getLevelArbiter().isLevelSolved(id));
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue