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

fix gadget.getElementByPath()

parent 8aa5557a
...@@ -1191,6 +1191,7 @@ ...@@ -1191,6 +1191,7 @@
path, path,
scope, scope,
key, key,
next_data_path,
slash_count = 0, slash_count = 0,
slash_count_next, slash_count_next,
bingo, bingo,
...@@ -1199,21 +1200,26 @@ ...@@ -1199,21 +1200,26 @@
if (data_path !== "/") { if (data_path !== "/") {
for (path in options.arrays) { for (path in options.arrays) {
if (options.arrays.hasOwnProperty(path) && data_path.startsWith(path)) { if (options.arrays.hasOwnProperty(path) && data_path.startsWith(path)) {
array = options.arrays[path] slash_count_next = path.split("/").length - 1;
.querySelectorAll("div[data-gadget-parent-scope='" + g.element.getAttribute("data-gadget-scope") + "']"); if (slash_count_next > slash_count) {
data_path = data_path.slice(path.length).split("/"); bingo = path;
idx = data_path[0]; slash_count = slash_count_next;
data_path = "/" + data_path.slice(1).join("/"); }
bingo = array[idx].getAttribute('data-gadget-scope');
} }
} }
if (bingo) { 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) { .push(function (gadget) {
return gadget.getElementByPath(data_path); return gadget.getElementByPath(next_data_path);
}); });
} }
slash_count = 0;
for (path in options.objects) { for (path in options.objects) {
if (options.objects.hasOwnProperty(path) && data_path.startsWith(path)) { if (options.objects.hasOwnProperty(path) && data_path.startsWith(path)) {
slash_count_next = path.split("/").length - 1; slash_count_next = path.split("/").length - 1;
...@@ -1225,17 +1231,13 @@ ...@@ -1225,17 +1231,13 @@
} }
if (bingo) { if (bingo) {
path = options.objects[bingo]; path = options.objects[bingo];
for (key in path) { key = decodeJsonPointer(data_path.slice(bingo.length).split('/')[0]);
if (path.hasOwnProperty(key)) { if (path.hasOwnProperty(key)) {
if (data_path.startsWith(bingo + encodeJsonPointer(key))) { next_data_path = data_path.slice(bingo.length + encodeJsonPointer(key).length);
data_path = data_path.slice(bingo.length + encodeJsonPointer(key).length); if (!next_data_path) {
if (!data_path) { next_data_path = "/";
data_path = "/";
} }
scope = path[key]; scope = path[key];
break;
}
}
} }
} }
if (scope === false) { if (scope === false) {
...@@ -1246,7 +1248,7 @@ ...@@ -1246,7 +1248,7 @@
if (scope) { if (scope) {
return g.getDeclaredGadget(scope) return g.getDeclaredGadget(scope)
.push(function (gadget) { .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