public async Task OnLinkClickAsync(MouseEventArgs args, AnchorLink anchorLink) { await JsInvokeAsync("window.eval", $"window.location.hash='{anchorLink._hash}'"); if (OnClick.HasDelegate) { await OnClick.InvokeAsync(new Tuple <MouseEventArgs, AnchorLink>(args, anchorLink)); } }
private async Task ActivateAsync(AnchorLink anchorLink, bool active) { anchorLink.Activate(active); if (active && _activeLink != _lastActiveLink) { _lastActiveLink = _activeLink; if (OnChange.HasDelegate) { await OnChange.InvokeAsync(anchorLink.Href); } } }
private async void OnScroll(JsonElement obj) { _activeLink = null; _flatLinks.ForEach(l => l.Activate(false)); int offset = OffsetBottom.HasValue ? OffsetBottom.Value : -OffsetTop.Value; foreach (var link in _flatLinks) { try { DomRect hrefDom = await link.GetHrefDom(); if (hrefDom != null) { _linkTops[link.Href] = hrefDom.top + offset; } } catch (Exception ex) { _linkTops[link.Href] = 1; } } string activeKey = _linkTops.Where(p => (int)p.Value <= 0).OrderBy(p => p.Value).LastOrDefault().Key; if (!string.IsNullOrEmpty(activeKey)) { _activeLink = _flatLinks.Single(l => l.Href == activeKey); await ActivateAsync(_activeLink, true); } if (Affix && _activeLink != null) { _ballClass = "ant-anchor-ink-ball visible"; decimal top = (_activeLink.LinkDom.top - _selfDom.top) + _activeLink.LinkDom.height / 2 - 2; _ballStyle = $"top: {top}px;"; } else { _ballClass = "ant-anchor-ink-ball"; _ballStyle = string.Empty; } StateHasChanged(); }
protected override async Task OnFirstAfterRenderAsync() { _selfDom = await JsInvokeAsync <DomRect>(JSInteropConstants.getBoundingClientRect, _ink); _linkTops = new Dictionary <string, decimal>(); _flatLinks = FlatChildren(); foreach (var link in _flatLinks) { _linkTops[link.Href] = 1; } if (GetCurrentAnchor != null) { AnchorLink link = _flatLinks.SingleOrDefault(l => l.Href == GetCurrentAnchor()); if (link != null) { try { DomRect hrefDom = await link.GetHrefDom(true); if (hrefDom != null) { await ActivateAsync(link, true); // the offset does not matter, since the dictionary's value will not change any more in case user set up GetCurrentAnchor _linkTops[link.Href] = hrefDom.top; StateHasChanged(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } await base.OnFirstAfterRenderAsync(); }
public void Add(AnchorLink anchorLink) { _links.Add(anchorLink); }