Skip to content

Commit 6eb79cc

Browse files
committed
fix: Scroll to selected side nav item when the Kendo TreeView is bound
1 parent dc2b99c commit 6eb79cc

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

_assets/js/side-nav.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,38 @@ function scrollNodeIntoView(li) {
1313

1414
function expandNavigation(url) {
1515
return function expand(e) {
16-
if (e.node) {
17-
return;
18-
}
16+
var that = this;
17+
$(document).ready(function () {
18+
if (e.node) {
19+
return;
20+
}
1921

20-
var segments = url.split("/");
22+
var segments = url.split("/");
2123

22-
var dataSource = this.dataSource;
23-
var node;
24+
var dataSource = that.dataSource;
25+
var node;
2426

25-
var isInNavigation = true;
26-
for (var i = 0; i < segments.length; i++) {
27-
node = dataSource.get(segments[i]);
28-
if (!node) {
29-
isInNavigation = false;
30-
break;
27+
var isInNavigation = true;
28+
for (var i = 0; i < segments.length; i++) {
29+
node = dataSource.get(segments[i]);
30+
if (!node) {
31+
isInNavigation = false;
32+
break;
33+
}
34+
node.set("expanded", true);
35+
dataSource = node.children;
3136
}
32-
node.set("expanded", true);
33-
dataSource = node.children;
34-
}
3537

36-
if (isInNavigation) {
37-
var li = this.element.find("li[data-uid='" + node.uid + "']");
38-
scrollNodeIntoView(li);
39-
this.select(li);
38+
if (isInNavigation) {
39+
var li = that.element.find("li[data-uid='" + node.uid + "']");
40+
scrollNodeIntoView(li);
41+
that.select(li);
4042

41-
$('.side-nav > #page-tree > .k-group > .k-item > div > span.k-i-collapse').closest('li').addClass('expanded');
43+
$('.side-nav > #page-tree > .k-group > .k-item > div > span.k-i-collapse').closest('li').addClass('expanded');
4244

43-
this.unbind("dataBound", expand);
44-
}
45+
that.unbind("dataBound", expand);
46+
}
47+
});
4548
};
4649
}
4750

0 commit comments

Comments
 (0)