Commit 899c03a6 authored by Boris Kocherov's avatar Boris Kocherov

fix gadget.getElementByPath()

parent 8aa5557a
......@@ -1191,6 +1191,7 @@
path,
scope,
key,
next_data_path,
slash_count = 0,
slash_count_next,
bingo,
......@@ -1199,21 +1200,26 @@
if (data_path !== "/") {
for (path in options.arrays) {
if (options.arrays.hasOwnProperty(path) && data_path.startsWith(path)) {
array = options.arrays[path]
.querySelectorAll("div[data-gadget-parent-scope='" + g.element.getAttribute("data-gadget-scope") + "']");
data_path = data_path.slice(path.length).split("/");
idx = data_path[0];
data_path = "/" + data_path.slice(1).join("/");
bingo = array[idx].getAttribute('data-gadget-scope');
slash_count_next = path.split("/").length - 1;
if (slash_count_next > slash_count) {
bingo = path;
slash_count = slash_count_next;
}
}
}
if (bingo) {
return g.getDeclaredGadget(bingo)
array = options.arrays[bingo]
.querySelectorAll("div[data-gadget-parent-scope='" + g.element.getAttribute("data-gadget-scope") + "']");
next_data_path = data_path.slice(bingo.length).split("/");
idx = next_data_path[0];
next_data_path = "/" + next_data_path.slice(1).join("/");
return g.getDeclaredGadget(array[idx].getAttribute('data-gadget-scope'))
.push(function (gadget) {
return gadget.getElementByPath(data_path);
return gadget.getElementByPath(next_data_path);
});
}
slash_count = 0;
for (path in options.objects) {
if (options.objects.hasOwnProperty(path) && data_path.startsWith(path)) {
slash_count_next = path.split("/").length - 1;
......@@ -1225,17 +1231,13 @@
}
if (bingo) {
path = options.objects[bingo];
for (key in path) {
if (path.hasOwnProperty(key)) {
if (data_path.startsWith(bingo + encodeJsonPointer(key))) {
data_path = data_path.slice(bingo.length + encodeJsonPointer(key).length);
if (!data_path) {
data_path = "/";
}
scope = path[key];
break;
}
key = decodeJsonPointer(data_path.slice(bingo.length).split('/')[0]);
if (path.hasOwnProperty(key)) {
next_data_path = data_path.slice(bingo.length + encodeJsonPointer(key).length);
if (!next_data_path) {
next_data_path = "/";
}
scope = path[key];
}
}
if (scope === false) {
......@@ -1246,7 +1248,7 @@
if (scope) {
return g.getDeclaredGadget(scope)
.push(function (gadget) {
return gadget.getElementByPath(data_path);
return gadget.getElementByPath(next_data_path);
});
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment