-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss_utils.html
More file actions
93 lines (91 loc) · 2.79 KB
/
css_utils.html
File metadata and controls
93 lines (91 loc) · 2.79 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
87
88
89
90
91
92
93
<!DOCTYPE html >
<html>
<head>
<meta charset="UTF-8">
<title>CSS格式化工具</title>
<style type="text/css">
*{ margin:0; padding:0;}
html,body,form,fieldset,textarea { height:100%; border:0; font-size:10pt; background:linear-gradient(rgb(90,90,90),#222);background:-webkit-linear-gradient(rgb(90,90,90),#222);background:-o-linear-gradient(rgb(90,90,90),#222);background:-moz-linear-gradient(rgb(90,90,90),#222); }
form { margin:0 1%; overflow:hidden; }
legend { line-height:3em; font-weight:bolder;color:#fff;text-align:center;}
button { float:left; margin:1% 1% 0 0; cursor:pointer; }
textarea { width:100%; height:20em; border:1px solid #ccc; display:block; background:#ddd; }
footer {font-family:arial;text-align:center;color:#fff;line-height:1em;background:rgb(38,37,36);margin:-50px;}
</style>
</head>
<body>
<form action="" onsubmit="return false">
<fieldset>
<legend>css格式化工具</legend>
<textarea name="" rows="" cols="" id="codeText">
body * { font-size:10pt; }/* ss sda */
p
{ clear:left; padding:5px 10px;
}
td
,
fieldset
{ padding : 10px ; }
textarea {
width:90%;
height:10em;
}
</textarea>
<button type="button" onclick="$('codeText').value=code.A();">压缩代码</button>
<button type="button" onclick="$('codeText').value=code.B();">格式(多行)</button>
<button type="button" onclick="$('codeText').value=code.C();">格式(单行)</button>
<button type="button" onclick="$('codeText').value=code.Z();">还原代码</button>
</fieldset>
</form>
<footer>
<span>Copyright © www.collmall.com</span>
</footer>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function codeZip(obj){
this.S = function(){
var code=obj.value;
if(!this.codeZ || this.codeZ==""){
this.codeZ=code;
}
code = code.replace(/(\n|\t|\s)*/ig,'$1');
code = code.replace(/\n|\t|\s(\{|\}|\,|\:|\;)/ig,'$1');
code = code.replace(/(\{|\}|\,|\:|\;)\s/ig,'$1');
return code;
}
// 压缩代码
this.A = function(){
var code = this.S();
return code;
}
// 格式(多行)
this.B = function(){
var code = this.S();
code = code.replace(/(\{)/ig,' $1');
code = code.replace(/(\{|\;)/ig,'$1\n\t');
code = code.replace(/\t*(\})/ig,'$1\n');
code = code.replace(/(\*\/)/ig,'$1\n');
return code;
}
// 格式(单行)
this.C = function(){
var code = this.S();
code = code.replace(/(\})/ig,'$1\n');
code = code.replace(/(\*\/)/ig,'$1\n');
return code;
}
// 还原代码
this.Z = function(){
return (this.codeZ)?this.codeZ:obj.value;
}
var my = this;
obj.onkeydown = function(){
my.codeZ = "";
}
}
var code = new codeZip($('codeText'));
</script>
</body>
</html>