-
Notifications
You must be signed in to change notification settings - Fork 41
/
app.js
72 lines (62 loc) · 1.85 KB
/
app.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
var CodeMirror = require('codemirror/CodeMirror:lib/codemirror.js');
require('codemirror/CodeMirror:mode/php/php.js');
require('codemirror/CodeMirror:mode/javascript/javascript.js');
window.jQuery = require('jquery/jquery:dist/jquery.js');
window.$ = jQuery;
require('twbs/[email protected]:dist/js/bootstrap.js');
var js2php = require('./js2php.js');
$(function() {
var javascriptEditor = CodeMirror.fromTextArea(document.getElementById("javascript"), {
mode: 'javascript',
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true
});
var phpEditor = CodeMirror.fromTextArea(document.getElementById("php"), {
mode: 'php',
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true
});
var convert = function() { phpEditor.setValue( js2php(javascriptEditor.getValue()) ); }
javascriptEditor.on('change', convert);
javascriptEditor.on('keyup', convert);
convert();
// create examples
var examples = [
'class.txt',
'class_inheritance.txt',
'anonymous_function.txt',
'arrow_functions.txt',
'closures.txt',
'conditionals.txt',
'core_array.txt',
'core_function.txt',
'core_json.txt',
'core_math.txt',
'core_string.txt',
'date.txt',
'expression.txt',
'for_of.txt',
'function.txt',
'function_super.txt',
'loops.txt',
'namespaces.txt',
'namespaces_use.txt',
'regexp.txt',
'simple.txt',
'static_call.txt',
'string_template.txt',
];
for(var i=0;i<examples.length;i++) {
$('ul.dropdown-menu').append('<li><a href="#">'+examples[i].replace(".txt", "")+'</a></li>');
}
$('ul.dropdown-menu').on('click', 'a', function(e) {
e.preventDefault();
var example = $(this).text();
$.get('examples/' + example + '.txt', function(text) {
javascriptEditor.setValue(text);
});
});
$('ul.dropdown-menu a:first').click();
})