-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy patheditor.js
104 lines (86 loc) · 2.37 KB
/
editor.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var SessionStore = require('./sessionstore');
/**
* A code editor wrapper around the client-side text editor
*
* @param {String} selector - Dom element the editor should bind to
*/
function Editor(selector) {
this.$element = $('#' + selector);
this._editor = window.ace.edit(selector);
this._editor.getSession().setMode({path: 'ace/mode/php', inline: true});
this._editor.getSession().setUseSoftTabs(true);
this._editor.getSession().setTabSize(2);
this._editor.$blockScrolling = Infinity;
this._editor.setShowPrintMargin(false);
this._editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});
this._sessionStore = new SessionStore();
this._defaultValue = 'echo "We\'re running php version: " . phpversion();';
}
/**
* @return {String}
*/
Editor.prototype.getValue = function() {
return this._editor.getValue();
};
/**
* @param {String} val
*/
Editor.prototype.setValue = function(val) {
this._editor.setValue(val);
};
/**
* Highlights the line in the gutter with the error
*
* @param {Number} line
*/
Editor.prototype.showLineError = function(line) {
this.$element
.find('.ace_gutter-cell:nth-child(' + line + ')')
.addClass('error-gutter');
};
Editor.prototype.clearLineErrors = function() {
this.$element.find('.ace_gutter-cell').removeClass('error-gutter');
};
Editor.prototype.saveSession = function() {
this._sessionStore.save(this.getValue());
};
Editor.prototype.loadPreviousSession = function() {
this.setValue(this._sessionStore.getPrevious());
};
Editor.prototype.loadNextSession = function() {
this.setValue(this._sessionStore.getNext());
};
Editor.prototype.loadLastSession = function() {
this.setValue(this.getLastSession() || this._defaultValue);
};
/**
* Preload where you last left off
* @return {String}
*/
Editor.prototype.getLastSession = function() {
return this._sessionStore.getLast() || '';
};
/**
* Process/Eval the code
*
* @param {Object} options
* @param {Object} options.evalURL - Url to use for evaluation
* @return {Deferred}
*/
Editor.prototype.evaluateCode = function(options) {
var promise = $.ajax({
type: 'POST',
url: options.evalURL,
data: {code: this.getValue()},
dataType: 'json'
});
promise.then(function() {
this.saveSession();
}.bind(this));
return promise;
};
module.exports = Editor;