als-document 1.0.0-beta → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/document.js +2 -2
- package/index.js +2 -2
- package/index.mjs +2 -2
- package/package.json +1 -1
- package/src/node/node.js +7 -4
- package/src/query/query.js +12 -6
- package/tests/index.html +1 -1
package/package.json
CHANGED
package/src/node/node.js
CHANGED
|
@@ -117,10 +117,13 @@ class Node {
|
|
|
117
117
|
insertAdjacentElement(position, newElement) {
|
|
118
118
|
if(newElement.tagName === 'ROOT' && newElement.childNodes.length > 0) newElement = newElement.childNodes[0]
|
|
119
119
|
const pos = position.toLowerCase();
|
|
120
|
-
if
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
if(pos === 'afterbegin' || pos === 'beforeend') {
|
|
121
|
+
if (pos === "afterbegin") this.childNodes.unshift(newElement);
|
|
122
|
+
else if (pos === "beforeend") this.childNodes.push(newElement);
|
|
123
|
+
newElement.parent = this
|
|
124
|
+
return newElement
|
|
125
|
+
}
|
|
126
|
+
if (!this.parent) throw new Error("Can't insert element to element without parent")
|
|
124
127
|
if (pos === "beforebegin") insertBefore(this.parent.childNodes, this.childNodeIndex, newElement)
|
|
125
128
|
else if (pos === "afterend") this.parent.childNodes.splice(this.childNodeIndex + 1, 0, newElement);
|
|
126
129
|
newElement.parent = this.parent
|
package/src/query/query.js
CHANGED
|
@@ -31,7 +31,7 @@ class Query {
|
|
|
31
31
|
|
|
32
32
|
splitAndCutLast(string, splitBy) {
|
|
33
33
|
const array = string.split(splitBy);
|
|
34
|
-
const last = array.pop();
|
|
34
|
+
const last = array.pop();
|
|
35
35
|
return [last, array];
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -104,11 +104,17 @@ class Query {
|
|
|
104
104
|
attribs = attribs.map(attrib => {
|
|
105
105
|
let query = attrib
|
|
106
106
|
attrib = attrib.replace('[', '').replace(']', '')
|
|
107
|
-
let [name
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if
|
|
111
|
-
|
|
107
|
+
let [name,...values] = attrib.split('=')
|
|
108
|
+
const value = values.join('=').trim().replace(/^\"/,'').replace(/\"$/,'')
|
|
109
|
+
let sign
|
|
110
|
+
if(value) {
|
|
111
|
+
sign = '='
|
|
112
|
+
name = name.replace(/[\~\|\^\$\*]$/,(match => {
|
|
113
|
+
sign = match+sign
|
|
114
|
+
return ''
|
|
115
|
+
}))
|
|
116
|
+
}
|
|
117
|
+
attrib = {query,name,value}
|
|
112
118
|
if (sign) {
|
|
113
119
|
attrib.sign = sign
|
|
114
120
|
attrib.check = this.getAttribFn(sign).bind(attrib)
|
package/tests/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<!-- <script src="./data/html2.js"></script> -->
|
|
11
11
|
<script src="./data/svg.js"></script>
|
|
12
12
|
<script>
|
|
13
|
-
const { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc } = alsDocument
|
|
13
|
+
const { parseHTML, Node, Query, TextNode, SingleNode, buildFromCache, cacheDoc,Root } = alsDocument
|
|
14
14
|
let {describe,it,beforeEach,runTests,expect,delay,assert,beforeAll} = SimpleTest
|
|
15
15
|
SimpleTest.showFullError = true
|
|
16
16
|
</script>
|