mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-08-02 09:05:06 +02:00
markdown grabber
This commit is contained in:
parent
36bfd99d9e
commit
3ade2bdd71
8 changed files with 329 additions and 12 deletions
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;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue