-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
48 lines (40 loc) · 1.18 KB
/
parser.js
File metadata and controls
48 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function ParsomaticController(view, model){
this.view = new view(this);
this.model = new model(this);
this.view.listenToTextArea();
}
ParsomaticController.prototype = {
receiveTextForParsing: function(text){
this.model.parseMyShit(text);
},
receiveParsedText: function(parsedTxt){
this.view.renderParsedText(parsedTxt);
}
}
function ParsomaticView(delegate){
this.delegate = delegate;
}
ParsomaticView.prototype = {
listenToTextArea: function(){
var txtArea = document.getElementsByTagName('textarea')[0];
txtArea.addEventListener('keyup', function(){
this.delegate.receiveTextForParsing(txtArea.value)
}.bind(this))
},
renderParsedText: function(text){
var preview = document.getElementsByClassName('preview')[0];
preview.innerHTML = text;
}
}
function ParsomaticModel(delegate){
this.delegate = delegate;
}
ParsomaticModel.prototype = {
parseMyShit: function(text){
var parsedShit = marked(text);
this.delegate.receiveParsedText(parsedShit);
}
}
window.addEventListener('load', function(){
new ParsomaticController(ParsomaticView, ParsomaticModel);
})