Skip to content

Commit aa08330

Browse files
committed
feat: 0.1.3
1 parent 518931b commit aa08330

21 files changed

+1715
-1493
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"typescript.validate.enable": true,
1818
"editor.codeActionsOnSave": {
19-
"source.fixAll.eslint": true
19+
"source.fixAll.eslint": "explicit"
2020
}
2121
}
2222

README.cn.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ npm i easy-dom-util
3131
使用
3232

3333
```js
34-
import $ from 'easy-dom-util';
35-
36-
let el = $.create('div'); // 返回一个 Ele 类型的元素,封装了dom操作的方法
37-
...
34+
import {dom} from 'easy-dom-util';
35+
let el = dom.div; // 返回一个 Ele 类型的元素,封装了dom操作的方法
3836
```
3937

4038
#### 0.2 script 标签引入
@@ -44,7 +42,7 @@ let el = $.create('div'); // 返回一个 Ele 类型的元素,封装了dom操
4442
<!-- or -->
4543
<!-- <script src="https://cdn.jsdelivr.net/npm/easy-dom-util@x.x.x"></script> -->
4644
<script>
47-
var el = EasyDom.create('div');
45+
var el = EasyDom.dom.div;
4846
</script>
4947
```
5048

@@ -68,7 +66,7 @@ Ele 元素上面的方法大都支持链式调用,Ele元素有以下方法可
6866
| value | [string] | string/Ele | 设置或获取元素value |
6967
| html | [string] | string/Ele | 设置或获取元素innerHTML |
7068
| empty | -- | Ele | 清空元素内容 |
71-
| cls | [string] | string/Ele | 给元素设置类或者获取元素的类名 |
69+
| class | [string] | string/Ele | 给元素设置类或者获取元素的类名 |
7270
| id | [string] | string/Ele | 给元素设置id或者获取元素的id |
7371
| click | function | Ele | 设置元素 click 事件 |
7472
| on | json/name,func | Ele | 设置元素的事件 |
@@ -85,7 +83,8 @@ Ele 元素上面的方法大都支持链式调用,Ele元素有以下方法可
8583
| remove | int/Ele/-- | Ele/-- | 根据位置或者ele元素删除孩子节点,或删除自身 |
8684
| parent | [index] | Ele/null | 获取元素的父元素或第n级父元素 |
8785
| index | -- | number | 获取元素在父元素中的位置 |
88-
| child | [index] | Ele/Array[Ele]/null | 获取第几个或全部子元素 |
86+
| children | [index] | Ele/Array[Ele]/null | 获取第几个或全部子元素 |
87+
| children | ...Array[dom/Ele] / Array[dom/Ele] | Ele | 给元素插入孩子节点 |
8988
| next | [index] | Ele/null| 获取元素的前一个或前第n个元素 |
9089
| prev | [index] | Ele/null | 获取元素的后一个或后第n个元素 |
9190
| exe | function(dom){} | Ele | 以Ele为this执行一个方法,回调参数为对应的dom元素 |
@@ -97,8 +96,8 @@ Ele 元素上面的方法大都支持链式调用,Ele元素有以下方法可
9796
基本使用
9897

9998
```js
100-
let el = $.create('div')
101-
.cls('easy-dom')
99+
let el = dom.div
100+
.class('easy-dom')
102101
.text('easy-dom')
103102
.click(()=>{
104103
alert('click')
@@ -108,7 +107,7 @@ let el = $.create('div')
108107
emmet 风格
109108

110109
```js
111-
let el = $.create('div#app.cls1.cls2[attr1=1][attr2]')
110+
let el = dom('div#app.cls1.cls2[attr1=1][attr2]')
112111
```
113112

114113
render方法
@@ -171,18 +170,20 @@ api 列表
171170
详细使用
172171

173172
```js
173+
import $, {dom} from 'easy-dom-util';
174174
$.classPrefix('el-test-');
175-
$.create('div').cls('1') // class = el-test-1
175+
dom.div.class('1') // class = el-test-1
176176
$.clearClassPrefix();
177177
// 或者
178178
$.classPrefix('el-test-',()=>{
179-
$.create('div').cls('1') // class = el-test-1
179+
dom.div.class('1') // class = el-test-1
180180
});
181181
```
182182

183183
样式相关
184184

185185
```js
186+
import $ from 'easy-dom-util';
186187
$.addCommonStyle({
187188
fontSize: '12px',
188189
textCenter: 'text-align:center;'
@@ -219,6 +220,7 @@ function initStyle(common){ // common 为公用样式
219220
registTouchEvent
220221

221222
```js
223+
import $ from 'easy-dom-util';
222224
$.registTouchEvent({
223225
el: 'dom/Ele/selector',
224226
touchStart(touchList){

README.md

+88-92
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ npm i easy-dom-util
3232
use
3333

3434
```js
35-
import $ from'easy-dom-util';
36-
37-
let el = $.create('div'); // returns an element of type Ele, which encapsulates the method of dom operation
38-
...
35+
import {dom} from 'easy-dom-util';
36+
let el = dom.div; // Returns an element of type Ele, encapsulating the method of dom operation
3937
```
4038

4139
#### 0.2 script tag introduction
@@ -45,170 +43,168 @@ let el = $.create('div'); // returns an element of type Ele, which encapsulates
4543
<!-- or -->
4644
<!-- <script src="https://cdn.jsdelivr.net/npm/easy-dom-util@x.x.x"></script> -->
4745
<script>
48-
var el = EasyDom.create('div');
46+
var el = EasyDom.dom.div;
4947
</script>
5048
```
5149

5250
### 1. Ele object
5351

54-
easy-dom encapsulates the dom element, and each dom element will be encapsulated into an Ele element
52+
easy-dom encapsulates dom elements. Each dom element will be encapsulated into an Ele element.
5553

56-
Most of the methods on the Ele element support chained calls. The Ele element has the following methods for use:
54+
Most of the methods on the Ele element support chain calls. The following methods are available for the Ele element:
5755

58-
A list of methods, used in detail below:
56+
The method list, detailed usage is below:
5957

60-
| Method | Parameters | Return Value | Description |
58+
| Method | Parameters | Return value | Description |
6159
| :--: | :--: | :--: | :--: |
62-
| dom | - | HTMLElement | Return the corresponding native dom element |
60+
| dom | -- | HTMLElement | Returns the corresponding native dom element |
6361
| attr | json/name,value/-- | Ele/string/Ele | Set or get element attributes |
64-
| data | json/name/null/--,value/null/-- | any | Temporarily store and manipulate some data on dom elements |
65-
| hasAttr | string | boolean | Determine whether there is an attribute |
62+
| data | json/name/null/--,value/null/-- | any | Temporarily store and operate some data on dom elements |
63+
| hasAttr | string | boolean | Determine whether there is a certain attribute |
6664
| rmAttr | string | Ele/string/Ele | Delete attribute |
6765
| style | json/name,value | Ele/string/Ele | Set or get element style |
6866
| text | [string] | string/Ele | Set or get element innerText |
6967
| value | [string] | string/Ele | Set or get element value |
70-
| html | [string] | string/Ele | Set or get element innerHTML |
71-
| empty | - | Ele | Empty element content |
72-
| cls | [string],[withPrefix=boolean] | string/Ele | Set the class of the element or get the class name of the element |
73-
| id | [string] | string/Ele | Set the id of the element or get the id of the element |
68+
| html | [string] | string/Ele | Set or get the element innerHTML |
69+
| empty | -- | Ele | Clear element content |
70+
| class | [string] | string/Ele | Set the class for the element or get the class name of the element |
71+
| id | [string] | string/Ele | Set id to element or get element's id |
7472
| click | function | Ele | Set element click event |
7573
| on | json/name,func | Ele | Set the event of the element |
76-
| render | {html,method={},result=null} | Ele | Render element |
74+
| render | {html,method={},result=null} | Ele | render element |
7775
| addClass | string | Ele | Add class to element |
7876
| rmClass | string | Ele | Remove a class |
79-
| hasClass | string | boolean | Determine whether there is a class |
80-
| replaceClass | string,string | Ele | Replacement class |
81-
| append | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert child node to element |
82-
| appendSingle | dom/Ele | Ele | Insert child node to element |
77+
| hasClass | string | boolean | Determine whether there is a certain class |
78+
| replaceClass | string,string | Ele | Replace class |
79+
| append | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert child nodes into elements |
8380
| insert | index, ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert child at specified position |
84-
| prepend | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Head Insert Child |
85-
| before | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert sibling elements in front of elements |
86-
| after | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert an element of the same level after the element |
87-
| remove | int/Ele/-- | Ele/-- | Delete child nodes according to position or ele element, or delete itself |
88-
| parent | [index] | Ele/null | Get the parent element or the nth level parent element of an element |
89-
| index | - | number | Get the position of the element in the parent element |
90-
| child | [index] | Ele/Array[Ele]/null | Get how many or all child elements |
91-
| next | [index] | Ele/null| Get the previous or previous nth element of an element |
92-
| prev | [index] | Ele/null | Get the next or last nth element of an element |
93-
| exe | function(dom){} | Ele | Use Ele as this to execute a method, and the callback parameter is the corresponding dom element |
81+
| prepend | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Head-insert child |
82+
| before | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert sibling elements before the element |
83+
| after | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert sibling elements after the element |
84+
| remove | int/Ele/-- | Ele/-- | Remove child nodes based on position or ele element, or delete itself |
85+
| parent | [index] | Ele/null | Get the parent element or nth-level parent element of the element |
86+
| index | -- | number | Get the position of the element in the parent element |
87+
| children | [index] | Ele/Array[Ele]/null | Get the first or all child elements |
88+
| children | ...Array[dom/Ele] / Array[dom/Ele] | Ele | Insert child nodes into elements |
89+
| next | [index] | Ele/null| Get the previous or nth element of the element |
90+
| prev | [index] | Ele/null | Get the next or nth element after the element |
91+
| exe | function(dom){} | Ele | Execute a method with Ele as this, and the callback parameter is the corresponding dom element |
9492
| src | string | Ele | Set the src attribute of dom |
95-
| query | selector | Array[Ele] | Query all children of an element based on the css selector |
96-
| name | string | Ele | Add name to element or query element based on name |
97-
| hide | - | Ele | hide elements |
98-
| show | [display] | Ele | Display element |
99-
| setVisible | [visible],[display] | Ele | Display element |
93+
| query | selector | Array[Ele] | Query all children of an element based on css selector |
10094

101-
Some api usage examples:
95+
Some API usage examples:
10296

103-
Basic use
97+
Basic usage
10498

10599
```js
106-
let el = $.create('div')
107-
.cls('easy-dom')
108-
.text('easy-dom')
109-
.click(()=>{
110-
alert('click')
111-
})
100+
let el = dom.div
101+
.class('easy-dom')
102+
.text('easy-dom')
103+
.click(()=>{
104+
alert('click')
105+
})
112106
```
113107

114108
emmet style
115109

116110
```js
117-
let el = $.create('div#app.cls1.cls2[attr1=1][attr2]')
111+
let el = dom('div#app.cls1.cls2[attr1=1][attr2]')
118112
```
119113

120114
render method
121115

122116
```js
123117
el.render({
124-
method:{
125-
alert(text){
126-
// this: {el,bindEl,self,method}
127-
console.log(this);
128-
window.alert(text);
129-
}
130-
},
131-
result(el){
132-
console.log(el.div1,el.div2);
133-
},
134-
// Using the es6-string-html plugin in vscode will make the following html with syntax highlighting
135-
html:/*html*/`
136-
<div @el='div1' @event=alert('test')></div>
137-
<div @el='div2'></div>
138-
`
118+
method:{
119+
alert(text){
120+
// this : {el,bindEl,self,method}
121+
console.log(this);
122+
window.alert(text);
123+
}
124+
},
125+
result(el){
126+
console.log(el.div1,el.div2);
127+
},
128+
// Using the es6-string-html plug-in in vscode will make the following html have syntax highlighting
129+
html:/*html*/`
130+
<div @el='div1' @event=alert('test')></div>
131+
<div @el='div2'></div>
132+
`
139133
})
140134
```
141135

142-
.data() usage
136+
.data() Usage
143137

144138
```js
145139
el.data(); // Get data object
146140
el.data(null); // Clear the data object
147-
el.data('name','test'); // set a data
141+
el.data('name', 'test'); // Set a data
148142
el.data('name'); // Get a data
149-
el.data('name', null); // remove a data
150-
el.data({ // batch operation
151-
name: null, // remove a data
152-
age: 12 // set a data
143+
el.data('name', null); // Remove a data
144+
el.data({ // Batch operation
145+
name: null, // Remove a data
146+
age: 12 //Set a data
153147
});
154148
```
155149

156-
The only attribute of the Ele element is .el, get the corresponding dom element
150+
The Ele element has only one attribute, which is .el. Get the corresponding dom element.
157151

158152
### 2. api list
159153

160154
api list
161155

162-
| api | Parameters | Return value | Description |
156+
| api | parameters | return value | description |
163157
| :--: | :--: | :--: | :--: |
164158
| create | string | Ele | Generate an Ele element based on tag |
165-
| query | selector[,boolean] | Ele/NodeList/null | Query element, the bool parameter behind indicates whether to query all elements, otherwise only the first one is queried |
166-
| checkDom | string/selector/HTMLElement | HTMLElement/NodeList | Get dom element |
167-
| classPrefix | string[,function] | - | Add a default prefix to the class name. If a callback function is used as a parameter, the prefix will be cleared after the callback is completed, otherwise please manually call clearClassPrefix to clear |
168-
| clearClassPrefix | - | - | Clear class name prefix |
169-
| addCommonStyle | object/name,value | - | Add css variables and common styles |
170-
| reportStyle | {function, id ='el-style', usePool = false} | - | Report css style |
171-
| initStylePool | - | - | Initialize style pool |
172-
| registTouchEvent | {el[dom/Ele/selector],touchStart,touchMove,touchEnd} | - | Touch event package on mobile terminal, compatible with pc terminal |
173-
| windowSize | - | {width:height} | Get browser size |
174-
| version | Attributes | - | easy-dom version information |
159+
| query | selector[,boolean] | Ele/NodeList/null | Query elements, the following bool parameter indicates whether to query all elements, otherwise only the first one |
160+
| checkDom | string/selector/HTMLElement | HTMLElement/NodeList | Get dom elements |
161+
| classPrefix | string[,function] | -- | Add a default prefix to the class name. If a callback function is used as a parameter, the prefix will be cleared after the callback is completed. Otherwise, please manually call clearClassPrefix to clear |
162+
| clearClassPrefix | -- | -- | Clear class name prefix |
163+
| addCommonStyle | object/name,value | -- | Add css variables and common styles |
164+
| reportStyle | {function, id = 'el-style', usePool = false} | -- | Report css style |
165+
| initStylePool | -- | -- | Initialize style pool |
166+
| registTouchEvent | {el[dom/Ele/selector],touchStart,touchMove,touchEnd} | -- | Mobile touch event encapsulation, compatible with PC |
167+
| windowSize | -- | {width:height} | Get browser size |
168+
| version | properties | -- | easy-dom version information |
175169

176170

177171
Detailed use
178172

179173
```js
174+
import $, {dom} from 'easy-dom-util';
180175
$.classPrefix('el-test-');
181-
$.create('div').cls('1') // class = el-test-1
176+
dom.div.class('1') // class = el-test-1
182177
$.clearClassPrefix();
183178
// or
184179
$.classPrefix('el-test-',()=>{
185-
$.create('div').cls('1') // class = el-test-1
180+
dom.div.class('1') // class = el-test-1
186181
});
187182
```
188183

189-
Style related
184+
style related
190185

191186
```js
192187
$.addCommonStyle({
193-
fontSize: '12px',
194-
textCenter:'text-align:center;'
188+
fontSize: '12px',
189+
textCenter: 'text-align:center;'
195190
})
196191

197192
$.reportStyle({
198-
func:initStyle,
199-
id:'MyStyle' // id of style tag
200-
}); // Do not use the style pool, the style will be added to the head immediately
193+
func:initStyle,
194+
id: 'MyStyle' // The id of the style tag
195+
}); // Without using the style pool, the style will be added to the head immediately
201196

202197
// or
198+
203199
$.reportStyle({
204200
func:initStyle,
205-
id:'MyStyle', // id of style tag
201+
id: 'MyStyle', // id of style tag
206202
usePool: true
207-
}); // Use the style pool, the style will be added to the head after calling initStylePool. When there are many scattered styles, it is recommended to use the style pool
203+
}); // Use the style pool. The style will be added to the head after calling initStylePool. When there are many scattered styles, it is recommended to use the style pool.
208204
$.initStylePool();
209205

210-
function initStyle(common){ // common is a common style
211-
// Using the es6-string-css plugin in vscode will make the following css syntax highlighting
206+
function initStyle(common){ // common is the public style
207+
// Using the es6-string-css plug-in in vscode will make the following css with syntax highlighting
212208
return /*css*/`
213209
.el-test-1{
214210
color:#f44;
@@ -221,11 +217,11 @@ function initStyle(common){ // common is a common style
221217
`
222218
}
223219
```
224-
registTouchEvent
220+
registerTouchEvent
225221

226222
```js
227223
$.registTouchEvent({
228-
el:'dom/Ele/selector',
224+
el: 'dom/Ele/selector',
229225
touchStart(touchList){
230226
},
231227
touchMove(touchList){

0 commit comments

Comments
 (0)