Skip to content

Commit d5b23d2

Browse files
author
binnng
committed
该一些细节。完善了demo
1 parent b7790a6 commit d5b23d2

File tree

4 files changed

+70
-28
lines changed

4 files changed

+70
-28
lines changed

debug.coffee

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
class Debug
4949

5050
# 种类和颜色
51-
colorMap =
51+
debugMap =
5252
log: "0074cc"
5353
danger: "da4f49"
5454
warn: "faa732"
@@ -57,7 +57,7 @@
5757

5858
# 将不同类型的msg转换为可读的String
5959
render = (msg) ->
60-
text = []
60+
text = ""
6161
arr = []
6262

6363
if isArray msg
@@ -83,13 +83,18 @@
8383
# debug 容器底部预留的高度
8484
parentBottom = 6
8585

86+
publicCss = [
87+
"-webkit-transition: all .3s ease"
88+
"transition: all .3s ease"
89+
]
90+
8691
# 每个debug信息样式
8792
childCss = [
8893
"margin-top:-1px"
8994
"padding:.5em"
9095
"border-top:1px solid rgba(255,255,255,.1)"
9196
"margin:0"
92-
]
97+
].concat publicCss
9398

9499
# debug容器的样式
95100
parentCss = [
@@ -105,12 +110,10 @@
105110
"color:#fff"
106111
"width:100%"
107112
"padding-bottom:#{parentBottom}px"
108-
"-webkit-transition: all .3s ease"
109-
"transition: all .3s ease"
110-
]
113+
].concat publicCss
111114

112115
constructor: ->
113-
# 是否初始化; 是否收起
116+
# 是否初始化是否收起
114117
@isInit = @isHide = no
115118

116119
# 当前消息,当前执行函数,当前颜色
@@ -136,6 +139,7 @@
136139

137140
@
138141

142+
# `debug.print()`
139143
# 核心的输出debug信息方法
140144
print: ->
141145

@@ -149,6 +153,7 @@
149153

150154
@
151155

156+
# `debug.toggle()`
152157
# 隐藏和收起
153158
toggle: (event) ->
154159
(if @isHide then @show else @hide).call @, event
@@ -166,12 +171,19 @@
166171
@
167172

168173
# 添加所有debug方法
169-
for fn of colorMap
174+
# ```
175+
# debug.log()
176+
# debug.danger()
177+
# debug.warn()
178+
# debug.error()
179+
# debug.success()
180+
# ```
181+
for fn of debugMap
170182
@::[fn] = ((fn) ->
171183
(msg) ->
172184
@fn = fn
173185
@msg = render msg
174-
@color = colorMap[fn]
186+
@color = debugMap[fn]
175187
@print()
176188
) fn
177189

@@ -180,7 +192,7 @@
180192

181193
# 绑定window,捕捉js报错信息
182194
bind WIN, ERROR, (error) ->
183-
195+
# 只输出有用的错误信息
184196
msg = [
185197
"Error:"
186198
"filename: #{error.filename}"

debug.js

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
88
</head>
99
<body style="background: #eee">
10+
<p onclick="debug.error('error')" style="margin-top: 200px">增加一个错误信息</p>
1011
<script type="text/javascript">
1112
debug.success("This is success message:)");
12-
debug.error("This is error message:)");
13-
debug.log("This is primary message:)");
1413
debug.log({a: 1, b: 2});
15-
debug.log([1,2,3]);
16-
1714
</script>
1815
</body>
1916
</html>

demo/index.html

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,53 @@
2323
float: none;
2424
margin: 0 auto;
2525
}
26+
27+
#buttons{
28+
margin-top: 10px;
29+
}
30+
#buttons p{
31+
text-align: center;
32+
background-color: #0074cc;
33+
margin: .4em 10px;
34+
padding: .4em;
35+
color: #fff;
36+
border-radius: 2px;
37+
}
38+
39+
40+
#buttons .success{
41+
background-color: #5bb75b;
42+
}
43+
#buttons .error{
44+
background-color: #bd362f;
45+
}
46+
#buttons .warn{
47+
background-color: #faa732;
48+
}
49+
#buttons .danger{
50+
background-color: #da4f49;
51+
}
2652
</style>
2753
</head>
2854
<body style="background: #eee">
2955
<header>
30-
<h1>Debug.js</h1>
56+
<h1>debug.js</h1>
3157
<h2>在手机上打印调试信息。</h2>
3258
</header>
59+
<section id="buttons">
60+
<p onclick="debug.success('success!')" class="success">输出一个成功信息</p>
61+
<p onclick="debug.error('error!')" class="error">输出一个错误信息</p>
62+
<p onclick="debug.warn('warning!')" class="warn">输出一个警告信息</p>
63+
<p onclick="debug.warn('danger!')" class="danger">输出一个危险信息</p>
64+
<p onclick="debug.log('primary!')" class="primary">输出一个普通信息</p>
65+
<p onclick="debug.log({a:1,b:2})">输出一个Obejct</p>
66+
<p onclick="debug.log([1,2,3])">输出一个Array</p>
67+
</section>
3368
<section id="downloads">
34-
<a href="https://github.com/binnng/debug.js" id="view-on-github" class="button"><span>View on GitHub</span></a>
69+
<a href="../debug.js" id="view-on-github" class="button"><span>View on GitHub</span></a>
3570
</section>
3671
<script type="text/javascript">
37-
debug.success("This is success message:)");
38-
debug.error("This is error message:)");
39-
debug.log("This is primary message:)");
40-
debug.log({a: 1, b: 2});
41-
debug.log([1,2,3]);
72+
debug.success("Welcome to debug.js:)");
4273
</script>
4374
</body>
4475
</html>

0 commit comments

Comments
 (0)