Skip to content

Commit 27ba987

Browse files
committed
respect parent element in getElementsFromSelector()
1 parent 5ff178c commit 27ba987

File tree

9 files changed

+63
-18
lines changed

9 files changed

+63
-18
lines changed

es6/getElementFromSelector.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let getElementFromSelector = function(selector, options = {jquery: false}) {
1616

1717
section_element = section_element[0];
1818
if (options.parent_element) {
19-
section_element = parent_element;
19+
section_element = options.parent_element;
2020
}
2121

2222
var elements = section_element.querySelectorAll(selector);
@@ -31,7 +31,12 @@ let getElementFromSelector = function(selector, options = {jquery: false}) {
3131
if (options.jquery) {
3232
return $(selector);
3333
} else {
34-
var elements = document.querySelectorAll(selector);
34+
let parent_element = document;
35+
if (options.parent_element) {
36+
parent_element = options.parent_element;
37+
}
38+
39+
var elements = parent_element.querySelectorAll(selector);
3540
if (elements.length) {
3641
if (options.return_all) {
3742
return elements;

js/assertions/elementHasChildren.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function assertion(selector) {
9191

9292
section_element = section_element[0];
9393
if (options.parent_element) {
94-
section_element = parent_element;
94+
section_element = options.parent_element;
9595
}
9696

9797
var elements = section_element.querySelectorAll(selector);
@@ -106,7 +106,12 @@ function assertion(selector) {
106106
if (options.jquery) {
107107
return $(selector);
108108
} else {
109-
var elements = document.querySelectorAll(selector);
109+
var parent_element = document;
110+
if (options.parent_element) {
111+
parent_element = options.parent_element;
112+
}
113+
114+
var elements = parent_element.querySelectorAll(selector);
110115
if (elements.length) {
111116
if (options.return_all) {
112117
return elements;

js/assertions/elementHasChildrenCount.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function assertion(selector, children_count) {
9595

9696
section_element = section_element[0];
9797
if (options.parent_element) {
98-
section_element = parent_element;
98+
section_element = options.parent_element;
9999
}
100100

101101
var elements = section_element.querySelectorAll(selector);
@@ -110,7 +110,12 @@ function assertion(selector, children_count) {
110110
if (options.jquery) {
111111
return $(selector);
112112
} else {
113-
var elements = document.querySelectorAll(selector);
113+
var parent_element = document;
114+
if (options.parent_element) {
115+
parent_element = options.parent_element;
116+
}
117+
118+
var elements = parent_element.querySelectorAll(selector);
114119
if (elements.length) {
115120
if (options.return_all) {
116121
return elements;

js/assertions/elementHasNoChildren.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function assertion(selector) {
8282

8383
section_element = section_element[0];
8484
if (options.parent_element) {
85-
section_element = parent_element;
85+
section_element = options.parent_element;
8686
}
8787

8888
var elements = section_element.querySelectorAll(selector);
@@ -97,7 +97,12 @@ function assertion(selector) {
9797
if (options.jquery) {
9898
return $(selector);
9999
} else {
100-
var elements = document.querySelectorAll(selector);
100+
var parent_element = document;
101+
if (options.parent_element) {
102+
parent_element = options.parent_element;
103+
}
104+
105+
var elements = parent_element.querySelectorAll(selector);
101106
if (elements.length) {
102107
if (options.return_all) {
103108
return elements;

js/commands/jqueryClick.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function command(selector, callback) {
6161

6262
section_element = section_element[0];
6363
if (options.parent_element) {
64-
section_element = parent_element;
64+
section_element = options.parent_element;
6565
}
6666

6767
var elements = section_element.querySelectorAll(selector);
@@ -76,7 +76,12 @@ function command(selector, callback) {
7676
if (options.jquery) {
7777
return $(selector);
7878
} else {
79-
var elements = document.querySelectorAll(selector);
79+
var parent_element = document;
80+
if (options.parent_element) {
81+
parent_element = options.parent_element;
82+
}
83+
84+
var elements = parent_element.querySelectorAll(selector);
8085
if (elements.length) {
8186
if (options.return_all) {
8287
return elements;

js/commands/jqueryElement.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function command(selector, callback) {
6565

6666
section_element = section_element[0];
6767
if (options.parent_element) {
68-
section_element = parent_element;
68+
section_element = options.parent_element;
6969
}
7070

7171
var elements = section_element.querySelectorAll(selector);
@@ -80,7 +80,12 @@ function command(selector, callback) {
8080
if (options.jquery) {
8181
return $(selector);
8282
} else {
83-
var elements = document.querySelectorAll(selector);
83+
var parent_element = document;
84+
if (options.parent_element) {
85+
parent_element = options.parent_element;
86+
}
87+
88+
var elements = parent_element.querySelectorAll(selector);
8489
if (elements.length) {
8590
if (options.return_all) {
8691
return elements;

js/commands/setSelect2Data.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function command(selector, data, callback) {
6161

6262
section_element = section_element[0];
6363
if (options.parent_element) {
64-
section_element = parent_element;
64+
section_element = options.parent_element;
6565
}
6666

6767
var elements = section_element.querySelectorAll(selector);
@@ -76,7 +76,12 @@ function command(selector, data, callback) {
7676
if (options.jquery) {
7777
return $(selector);
7878
} else {
79-
var elements = document.querySelectorAll(selector);
79+
var parent_element = document;
80+
if (options.parent_element) {
81+
parent_element = options.parent_element;
82+
}
83+
84+
var elements = parent_element.querySelectorAll(selector);
8085
if (elements.length) {
8186
if (options.return_all) {
8287
return elements;

js/commands/setSelect2Value.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function command(selector, value, callback) {
6161

6262
section_element = section_element[0];
6363
if (options.parent_element) {
64-
section_element = parent_element;
64+
section_element = options.parent_element;
6565
}
6666

6767
var elements = section_element.querySelectorAll(selector);
@@ -76,7 +76,12 @@ function command(selector, value, callback) {
7676
if (options.jquery) {
7777
return $(selector);
7878
} else {
79-
var elements = document.querySelectorAll(selector);
79+
var parent_element = document;
80+
if (options.parent_element) {
81+
parent_element = options.parent_element;
82+
}
83+
84+
var elements = parent_element.querySelectorAll(selector);
8085
if (elements.length) {
8186
if (options.return_all) {
8287
return elements;

js/commands/setValueAndTrigger.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function command(selector, value, callback) {
6262

6363
section_element = section_element[0];
6464
if (options.parent_element) {
65-
section_element = parent_element;
65+
section_element = options.parent_element;
6666
}
6767

6868
var elements = section_element.querySelectorAll(selector);
@@ -77,7 +77,12 @@ function command(selector, value, callback) {
7777
if (options.jquery) {
7878
return $(selector);
7979
} else {
80-
var elements = document.querySelectorAll(selector);
80+
var parent_element = document;
81+
if (options.parent_element) {
82+
parent_element = options.parent_element;
83+
}
84+
85+
var elements = parent_element.querySelectorAll(selector);
8186
if (elements.length) {
8287
if (options.return_all) {
8388
return elements;

0 commit comments

Comments
 (0)