diff --git a/cinera/cinera.c b/cinera/cinera.c index e9aa9bc..805e7db 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -23,7 +23,7 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 8, - .Patch = 9 + .Patch = 10 }; #include // NOTE(matt): varargs diff --git a/cinera/cinera_pre.js b/cinera/cinera_pre.js index da33c95..915f9c7 100644 --- a/cinera/cinera_pre.js +++ b/cinera/cinera_pre.js @@ -63,6 +63,16 @@ GetWindowDim(IsMobile) return Result; } +function IsVisible(Element, WindowDim) { + var BoundingRect = Element.getBoundingClientRect(); + return ((BoundingRect.top >= 0 && BoundingRect.top <= WindowDim.Y) || + (BoundingRect.bottom >= 0 && BoundingRect.bottom <= WindowDim.Y) || + (BoundingRect.top < 0 && BoundingRect.bottom > WindowDim.Y)) + && ((BoundingRect.left >= 0 && BoundingRect.left <= WindowDim.X) || + (BoundingRect.right >= 0 && BoundingRect.right <= WindowDim.X) || + (BoundingRect.left < 0 && BoundingRect.right > WindowDim.X)); +} + function GetRealOrientation(PreferredLandscape, IsMobile) { @@ -306,55 +316,58 @@ var ScrollerFunction; var ScrollCondition; function ScrollTo(Element, ScrollPos, IsMobile, StickyObscuringElement) { - var ScrolledToTop = ScrollPos == 0; - var ScrolledToBottom = (window.innerHeight + Math.ceil(window.pageYOffset)) >= document.body.scrollHeight; - if(!ScrolledToTop || !ScrolledToBottom) + if(Element.offsetWidth && Element.offsetHeight) { - var Ceiling = StickyObscuringElement ? StickyObscuringElement.offsetHeight : 0; - var VisibleArea = GetWindowDim(IsMobile); - VisibleArea.Y -= Ceiling; - - var PercentageOfVisibleHeightToGather = 5; - var GatherableHeight = VisibleArea.Y * PercentageOfVisibleHeightToGather / 100; - - var BoundingRect = Element.getBoundingClientRect(); - - var ElementTop = BoundingRect.top - Ceiling; - var ElementBottom = ElementTop + BoundingRect.height; - - var UpperProtrusion = -ElementTop; - var LowerProtrusion = ElementBottom - VisibleArea.Y; - - var DesiredScroll = null; - var YOffsetFromPage = getElementYOffsetFromPage(Element); - if(IsInRangeEx(0, UpperProtrusion, GatherableHeight)) + var ScrolledToTop = ScrollPos == 0; + var ScrolledToBottom = (window.innerHeight + Math.ceil(window.pageYOffset)) >= document.body.scrollHeight; + if(!ScrolledToTop || !ScrolledToBottom) { - if(!ScrolledToBottom) + var Ceiling = StickyObscuringElement ? StickyObscuringElement.offsetHeight : 0; + var VisibleArea = GetWindowDim(IsMobile); + VisibleArea.Y -= Ceiling; + + var PercentageOfVisibleHeightToGather = 5; + var GatherableHeight = VisibleArea.Y * PercentageOfVisibleHeightToGather / 100; + + var BoundingRect = Element.getBoundingClientRect(); + + var ElementTop = BoundingRect.top - Ceiling; + var ElementBottom = ElementTop + BoundingRect.height; + + var UpperProtrusion = -ElementTop; + var LowerProtrusion = ElementBottom - VisibleArea.Y; + + var DesiredScroll = null; + var YOffsetFromPage = getElementYOffsetFromPage(Element); + if(IsInRangeEx(0, UpperProtrusion, GatherableHeight)) { - DesiredScroll = YOffsetFromPage - Ceiling; - } - } - else if(IsInRangeEx(0, LowerProtrusion, GatherableHeight)) - { - if(!ScrolledToTop) - { - if(IsInRangeEx(0, UpperProtrusion + LowerProtrusion, GatherableHeight)) + if(!ScrolledToBottom) { DesiredScroll = YOffsetFromPage - Ceiling; } - else + } + else if(IsInRangeEx(0, LowerProtrusion, GatherableHeight)) + { + if(!ScrolledToTop) { - DesiredScroll = ScrollPos + LowerProtrusion; + if(IsInRangeEx(0, UpperProtrusion + LowerProtrusion, GatherableHeight)) + { + DesiredScroll = YOffsetFromPage - Ceiling; + } + else + { + DesiredScroll = ScrollPos + LowerProtrusion; + } } } - } - if(DesiredScroll !== null && DesiredScroll != ScrollPos) - { - window.scrollTo({ - top: DesiredScroll, - behavior: "smooth" - }); + if(DesiredScroll !== null && DesiredScroll != ScrollPos) + { + window.scrollTo({ + top: DesiredScroll, + behavior: "smooth" + }); + } } } } diff --git a/cinera/cinera_search_pre.js b/cinera/cinera_search_pre.js index 1f57a1e..5cb3162 100644 --- a/cinera/cinera_search_pre.js +++ b/cinera/cinera_search_pre.js @@ -553,28 +553,6 @@ function renderResults() { } } -function IsVisible(el) { - var xPos = 0; - var yPos = 0; - var Height = parseInt(getComputedStyle(el).height); - - while (el) { - if (el.tagName == "BODY") { - var xScroll = el.scrollLeft || document.documentElement.scrollLeft; - var yScroll = el.scrollTop || document.documentElement.scrollTop; - - xPos += (el.offsetLeft - xScroll + el.clientLeft) - yPos += (el.offsetTop - yScroll + el.clientTop) - } else { - xPos += (el.offsetLeft - el.scrollLeft + el.clientLeft); - yPos += (el.offsetTop - el.scrollTop + el.clientTop); - } - - el = el.offsetParent; - } - return ((xPos > 0 && xPos < window.innerWidth) && (yPos > 0 && yPos + Height < window.innerHeight)); -} - function InitQuery(QueryElement) { @@ -588,7 +566,7 @@ InitQuery(QueryElement) QueryElement.value = decodeURIComponent(initialQuery); } - if(document.hasFocus() && IsVisible(QueryElement)) { QueryElement.focus(); } + if(document.hasFocus() && IsVisible(QueryElement, GetWindowDim(CineraProps.IsMobile))) { QueryElement.focus(); } } function