Skip to content

Commit e7e467f

Browse files
authored
Merge pull request Tencent#44 from Maizify/dev
v2.1.0
2 parents 69dba6d + 0208721 commit e7e467f

13 files changed

+890
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
English | [简体中文](./CHANGELOG_CN.md)
22

3+
#### V2.1.0 (2016-06-29)
4+
5+
- [FEATURE] Add `vConsole.tool` & `vConsole.$` helper functions, see [Helper Functions](./doc/helper_functions.md).
6+
- [FEATURE] Public properties & methods of vConsole are available, see [Public Properties & Methods](./doc/public_properties_methods.md).
7+
- [FIX] Fix issue that `error` in `window.onerror()` may be undefined.
8+
- [FIX] Fix error that `xhr.status` may be unavailable when `xhr.readyState < 4`.
9+
310

411
#### v2.0.1 (2016-06-16)
512

CHANGELOG_CN.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
[English](./CHANGELOG.md) | 简体中文
22

3+
#### v2.1.0 (2016-06-29)
4+
5+
- 【特性】新增 `vConsole.tool``vConsole.$` 辅助函数,请查阅[辅助函数](./doc/helper_functions_CN.md)
6+
- 【特性】公开部分 vConsole 的属性及方法,请查阅[公共属性及方法](./doc/public_properties_methods_CN.md)
7+
- 【修复】修复 `window.onerror()``error` 可能为空而导致堆栈读取错误的问题。
8+
- 【修复】修复当 `xhr.readyState < 4` 时读取 `xhr.status` 可能导致错误的问题。
9+
310

411
#### v2.0.1 (2016-06-16)
512

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ See [Tutorial](./doc/tutorial.md) for more details.
4949

5050
## Documentation
5151

52+
vConsole:
53+
5254
- [Tutorial](./doc/tutorial.md)
55+
- [Public Properties & Methods](./doc/public_properties_methods.md)
56+
- [Helper Functions](./doc/helper_functions.md)
57+
58+
Plugin:
59+
5360
- [Plugin: Getting Started](./doc/plugin_getting_started.md)
5461
- [Plugin: Building a Plugin](./doc/plugin_building_a_plugin.md)
5562
- [Plugin: Event List](./doc/plugin_event_list.md)

README_CN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ console.log('Hello world');
5050

5151
## 文档
5252

53+
54+
vConsole 本体:
55+
5356
- [使用教程](./doc/tutorial_CN.md)
57+
- [公共属性及方法](./doc/public_properties_methods_CN.md)
58+
- [辅助函数](./doc/helper_functions_CN.md)
59+
60+
插件:
61+
5462
- [插件:入门](./doc/plugin_getting_started_CN.md)
5563
- [插件:编写插件](./doc/plugin_building_a_plugin_CN.md)
5664
- [插件:Event 事件列表](./doc/plugin_event_list_CN.md)

dist/vconsole.min.js

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

doc/a_doc_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Documentation Index
77
## vConsole
88

99
- [Tutorial](./tutorial.md)
10+
- [Public Properties & Methods](./public_properties_methods.md)
11+
- [Helper Functions](./helper_functions.md)
1012

1113

1214
## Plugin

doc/a_doc_index_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
## vConsole 本体
88

99
- [使用教程](./tutorial_CN.md)
10+
- [公共属性及方法](./public_properties_methods_CN.md)
11+
- [辅助函数](./helper_functions_CN.md)
1012

1113

1214
## Plugin 插件

doc/helper_functions.md

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
Helper Functions
2+
==============================
3+
4+
vConsole provides some useful helper functions for efficient plugin development.
5+
6+
Helper functions are mounted in different vConsole properties according to their usage:
7+
8+
- `vConsole.tool`: Helper functions.
9+
- `vConsole.$`: DOM-related functions.
10+
11+
12+
## vConsole.tool
13+
14+
### vConsole.tool.isString(value)
15+
### vConsole.tool.isArray(value)
16+
### vConsole.tool.isBoolean(value)
17+
### vConsole.tool.isElement(value)
18+
### vConsole.tool.isFunction(value)
19+
### vConsole.tool.isNull(value)
20+
### vConsole.tool.isNumber(value)
21+
### vConsole.tool.isObject(value)
22+
### vConsole.tool.isSymbol(value)
23+
### vConsole.tool.isUndefined(value)
24+
25+
Check whether a value is a certain type.
26+
27+
##### Return:
28+
- Boolean
29+
30+
31+
32+
### vConsole.tool.htmlEncode(text)
33+
34+
Encode a text into a HTML non-sensitive string.
35+
36+
##### Parameters:
37+
- (required) text: A string to be encoded.
38+
39+
##### Return:
40+
- String
41+
42+
43+
44+
### vConsole.tool.setStorage(key, value)
45+
46+
Set data to `localStorage`. A prefix `vConsole_` will be added to `key` automatically.
47+
48+
Note that some devices may not have `localStorage` and then `value` would not be saved under this situation, so DO NOT use this method to save permanent data.
49+
50+
##### Parameters:
51+
- (required) key: A string, the name of data.
52+
- (required) value: A string, the value of data.
53+
54+
##### Return:
55+
- None
56+
57+
##### Example:
58+
59+
```javascript
60+
vConsole.tool.setStorage('count', 1);
61+
```
62+
63+
64+
65+
### vConsole.tool.getStorage(key)
66+
67+
Get data from `localStorage`. A prefix `vConsole_` will be added to `key` automatically.
68+
69+
##### Parameters:
70+
- (required) key: A string, the name of data.
71+
72+
##### Return:
73+
- String, the value of data.
74+
75+
##### Example:
76+
77+
```javascript
78+
var num = vConsole.tool.setStorage('count'); // => 1
79+
```
80+
81+
82+
83+
## vConsole.$
84+
85+
### vConsole.$.one(selectors, baseElement)
86+
87+
Returns the first element within the document or baseElement that matches the specified group of selectors.
88+
89+
##### Parameters:
90+
- (required) selectors: A string containing one or more CSS selectors separated by commas.
91+
- (optional) baseElement: An element object, default to be `document`.
92+
93+
##### Return:
94+
- Element object
95+
96+
##### Example:
97+
98+
```javascript
99+
var $page = vConsole.$.one('#my_page');
100+
var $item = vConsole.$.one('.item', $page);
101+
```
102+
103+
104+
### vConsole.$.all(selectors, baseElement)
105+
106+
Returns a list of elements within the document or baseElement that matches the specified group of selectors.
107+
108+
##### Parameters:
109+
- (required) selectors: A string containing one or more CSS selectors separated by commas.
110+
- (optional) baseElement: An element object, default to be `document`.
111+
112+
##### Return:
113+
- Element object
114+
115+
##### Example:
116+
117+
```javascript
118+
var $page = vConsole.$.one('#my_page');
119+
var $items = vConsole.$.all('.item', $page);
120+
```
121+
122+
123+
### vConsole.$.addClass(elements, className)
124+
125+
Add the specified class(es) to element(s).
126+
127+
##### Parameters:
128+
- (required) elements: A single or a list of element object(s).
129+
- (required) className: A string of one or more space-separated classes.
130+
131+
##### Return:
132+
- None
133+
134+
##### Example:
135+
136+
```javascript
137+
var $items = vConsole.$.all('.item');
138+
vConsole.$.addClass($items, 'selected');
139+
```
140+
141+
142+
### vConsole.$.removeClass(elements, className)
143+
144+
Remove the specified class(es) of element(s).
145+
146+
##### Parameters:
147+
- (required) elements: A single or a list of element object(s).
148+
- (required) className: A string of one or more space-separated classes.
149+
150+
##### Return:
151+
- None
152+
153+
##### Example:
154+
155+
```javascript
156+
var $items = vConsole.$.all('.item');
157+
vConsole.$.removeClass($items, 'selected');
158+
```
159+
160+
161+
### vConsole.$.hasClass(element, className)
162+
163+
Check whether an element is assigned the given class.
164+
165+
##### Parameters:
166+
- (required) element: An element object.
167+
- (required) className: A string.
168+
169+
##### Return:
170+
- Boolean
171+
172+
##### Example:
173+
174+
```javascript
175+
var $page = vConsole.$.one('#my_page');
176+
if (vConsole.$.hasClass($page, 'actived')) {
177+
// do something
178+
}
179+
```
180+
181+
182+
### vConsole.$.bind(elements, eventType, fn, useCapture)
183+
184+
Bind an event to element(s).
185+
186+
##### Parameters:
187+
- (required) elements: A single or a list of element object(s).
188+
- (required) eventType: A string of event's type.
189+
- (required) fn: A function to execute when the event is triggered.
190+
- (optional) useCapture: A boolean that indicates the event uses capturing or bubbling, default to be `false`.
191+
192+
##### Return:
193+
- None
194+
195+
##### Example:
196+
197+
```javascript
198+
var $btn = vConsole.$.one('#submit');
199+
vConsole.$.bind($btn, 'click', function(event) {
200+
event.preventDefault();
201+
alert('submit!');
202+
});
203+
```
204+
205+
206+
### vConsole.$.delegate(element, eventType, selectors, fn)
207+
208+
Bind an event to an element, and only this element's descendants which match the selectors can trigger the event.
209+
210+
##### Parameters:
211+
- (required) element: An element object.
212+
- (required) eventType: A string of event's type.
213+
- (required) selectors: A string containing one or more CSS selectors separated by commas.
214+
- (required) fn: A function to execute when the event is triggered.
215+
216+
##### Return:
217+
- None
218+
219+
##### Example:
220+
221+
```javascript
222+
var $page = vConsole.$.one('#my_page');
223+
vConsole.$.delegate($page, 'click', '.item', function(event) {
224+
vConsole.$.addClass(this, 'selected'); // this => '.item'
225+
});
226+
```
227+
228+
229+
### vConsole.$.render(tpl, data, toString)
230+
231+
Compile a template into an element object or a HTML string with given data.
232+
233+
##### Parameters:
234+
- (required) tpl: A template string.
235+
- (required) data: A key-value data which is used to render the template.
236+
- (optional) toString: A boolean that indicates whether returns an element object or a HTML string, default to be `false`.
237+
238+
##### Return:
239+
- Element object or HTML string
240+
241+
##### Syntax:
242+
243+
If:
244+
```html
245+
{{if}}
246+
...
247+
{{else}}
248+
...
249+
{{/if}}
250+
```
251+
252+
For:
253+
```html
254+
{{for (var i=0; i<10; i++)}}
255+
...
256+
{{continue}}
257+
{{break}}
258+
{{/for}}
259+
```
260+
261+
Switch:
262+
```html
263+
{{switch (flag)}}
264+
{{case 1}}
265+
...
266+
{{break}}
267+
{{default}}
268+
...
269+
{{/switch}}
270+
```
271+
272+
Print:
273+
```html
274+
{{flag}}
275+
```
276+
277+
###### Example:
278+
279+
```javascript
280+
var tpl = '<ul>' +
281+
'{{for (var i = 0; i < list.length; i++)}}' +
282+
'<li>' + '{{list[i]}}' + '</li>' +
283+
'{{/for}}' +
284+
'</ul>';
285+
var data = {
286+
list: ['Red', 'Blue', 'Yellow']
287+
};
288+
289+
var html = vConsole.&.render(tpl, data, true);
290+
document.body.innerHTML += html;
291+
```
292+
293+
Output:
294+
295+
```html
296+
<ul>
297+
<li>Red</li>
298+
<li>Blue</li>
299+
<li>Yellow</li>
300+
</ul>
301+
```
302+
303+
304+
[Back to Index](./a_doc_index.md)

0 commit comments

Comments
 (0)