-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtext_transform.html
More file actions
executable file
·86 lines (72 loc) · 2.7 KB
/
text_transform.html
File metadata and controls
executable file
·86 lines (72 loc) · 2.7 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
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
<head>
<title>Text Transform Tools</title>
<meta charset="utf8"/>
<script src="./common/js/Tls.js"></script>
<script src="./common/js/VarExportParser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"
integrity="sha512-GZ1RIgZaSc8rnco/8CXfRdCpDxRCphenIiZ2ztLy3XQfCbQUSCuk8IudvNHxkRA3oUg6q0qejgN/qqyG1duv5Q=="
crossorigin="anonymous"></script>
</head>
<body>
Enter your text here:<br/>
<div id="describeInput"></div><br/>
<div id="buttonsCont"></div>
<label>var_export inline limit<input type="number" class="var-export-inline-limit" value="110"/></label>
<script type="module">
import {varExportExample} from "./common/js/PhpTools.js";
import ButtonsMapping from "./common/js/ButtonsMapping.js";
var $$ = s => [...document.querySelectorAll(s)];
let hashData = {};
let hashStr = window.location.hash.substr(1);
for (let pair of hashStr.split('&')) {
let [key, value] = pair.split('=');
hashData[key] = value;
}
window.onhashchange = () => window.location.reload();
const getInlineLimit = () => $$('.var-export-inline-limit')[0].value;
let buttons = ButtonsMapping;
let editor = ace.edit('describeInput');
editor.getSession().setMode("ace/mode/javascript");
let buttonsCont = document.getElementById('buttonsCont');
let makeCallback = (buttonInfo) => () => {
if (!editor.getValue() && buttonInfo.sample) {
editor.setValue(buttonInfo.sample);
} else {
editor.getSession().setMode({path: buttonInfo.language, inline: true});
editor.setValue(buttonInfo.implementation(editor.getValue()) + '\n');
}
};
for (let buttonInfo of buttons) {
let btnEl = document.createElement('button');
btnEl.innerHTML = buttonInfo.name;
btnEl.onclick = makeCallback(buttonInfo);
buttonsCont.appendChild(btnEl);
}
let xmlToArrBtnEl = document.createElement('button');
xmlToArrBtnEl.innerHTML = 'server-side: xmlToArr';
xmlToArrBtnEl.onclick = function(e) {
let xml = editor.getValue().trim();
editor.getSession().setMode({path: 'ace/mode/php', inline: true});
Tls.xmlToArr(xml).then = (parsed) => editor.setValue(
Tls.jsExport(parsed, null, getInlineLimit())
);
};
buttonsCont.appendChild(xmlToArrBtnEl);
if (hashData.dataset === 'varExportExample') {
editor.setValue(varExportExample);
}
</script>
</body>
<style>
#describeInput {
font-size: 10px;
float: left;
width: 900px;
resize: horizontal;
height: 600px;
border: solid grey 4px;
}
button {
display: block;
}
</style>