-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpicker.html
96 lines (89 loc) · 2.51 KB
/
cpicker.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no">
<title>CPicker</title>
<script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
<style type="text/css">
body {
margin: 0 10px;
padding: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, 'Microsoft YaHei', 'Microsoft JhengHei', STHeiti, MingLiu;
color: #000000;
}
h1 {
margin: 10px 0;
}
.options-panel {
margin: 10px 0;
}
.txt {
width: 49%;
height: 600px;
border: 1px solid #cccccc;
font-size: 16px;
}
.txt:last-child {
margin-left: 10px;
}
</style>
</head>
<body>
<h1>column picker</h1>
<div class="container">
<div class="options-panel">
<input type="checkbox" id="line-break">
<label for="line-break">换行</label>
</div>
<textarea class="txt input"></textarea>
<textarea class="txt output"></textarea>
</div>
<script>
var inputNode = $('.input');
var outputNode = $('.output');
var lineBreakNode = $('#line-break');
// Parse command `desc` results into columns array.
function parseCmdDesc(str) {
str = str.trim();
if (str.indexOf('|') !== 0) {
str = '|' + str;
}
var lines = str.split(/\|\r?\n/);
var res = [];
lines.forEach(function (line) {
line = line.trim();
var m = line.split(/\|/);
if (m.length < 4) {
return;
}
res.push(m[1].trim());
});
return res;
}
function renderResult() {
var cols = parseCmdDesc(inputNode.val());
if (lineBreakNode.prop('checked')) {
var connector = ',\n';
} else {
var connector = ',';
}
outputNode.val(cols.join(connector));
}
inputNode.on('input propertychange', renderResult);
var storage = window.localStorage;
if (storage) {
lineBreakNode.prop('checked', storage.getItem('lineBreak') === 'true');
}
lineBreakNode.on('change', function (evt) {
if (storage) {
storage.setItem('lineBreak', lineBreakNode.prop('checked'));
}
renderResult();
});
</script>
</body>