From 026585e50beadd791af937dcea8f9937ff79e736 Mon Sep 17 00:00:00 2001 From: Matt Mascarenhas Date: Tue, 21 Mar 2023 19:34:24 +0000 Subject: [PATCH] cinera: Fix mobile scrolling and centring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes spurious scrolling in DeriveReliableWindowDimensions() on mobile. It also fixes centring of Vimeo videos on mobile. In addition, it replaces some deprecated JavaScript: • window.orientation → screen.orientation.type • window.onorientationchange → screen.orientation.onchange --- cinera/cinera.c | 2 +- cinera/cinera_player_post.js | 2 +- cinera/cinera_player_pre.js | 8 +++++--- cinera/cinera_pre.js | 15 +++++++++++++-- cinera/cinera_search_pre.js | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cinera/cinera.c b/cinera/cinera.c index daa962f..27a49e6 100644 --- a/cinera/cinera.c +++ b/cinera/cinera.c @@ -23,7 +23,7 @@ typedef struct version CINERA_APP_VERSION = { .Major = 0, .Minor = 10, - .Patch = 25 + .Patch = 26 }; #define __USE_XOPEN2K8 // NOTE(matt): O_NOFOLLOW diff --git a/cinera/cinera_player_post.js b/cinera/cinera_player_post.js index de2e18f..9cbc389 100644 --- a/cinera/cinera_player_post.js +++ b/cinera/cinera_player_post.js @@ -42,7 +42,7 @@ window.addEventListener("resize", function() { } }); -window.onorientationchange = function() { +screen.orientation.onchange = function() { if(CineraProps.IsMobile) { setTimeout(DelayedUpdateSize, 512, player); diff --git a/cinera/cinera_player_pre.js b/cinera/cinera_player_pre.js index 1ef1124..f781269 100644 --- a/cinera/cinera_player_pre.js +++ b/cinera/cinera_player_pre.js @@ -955,8 +955,7 @@ Player.prototype.InitMobileStyle = function() this.IconifyMenuTogglers(); this.InitMobileControls(); this.ConnectMobileControls(); - var VideoContainer = this.root.querySelector(".video_container"); - this.ApplyMobileStyle(VideoContainer); + this.ApplyMobileStyle(this.videoContainer); } // Call this after changing the size of the video container in order to update the platform player. @@ -1461,7 +1460,10 @@ Player.prototype.onPlatformReady = function() { case vod_platform.VIMEO: { this.videoContainer.style.position = "relative"; - this.videoContainer.style.alignSelf = "unset"; + if(!CineraProps.IsMobile) + { + this.videoContainer.style.alignSelf = "unset"; + } var CallData = { id: this.videoContainer.getAttribute("data-videoId"), diff --git a/cinera/cinera_pre.js b/cinera/cinera_pre.js index cab734c..5b23b3f 100644 --- a/cinera/cinera_pre.js +++ b/cinera/cinera_pre.js @@ -13,6 +13,9 @@ DeriveReliableWindowDimensions() Y: null, }; + var ScrollPosX = window.scrollX; + var ScrollPosY = window.scrollY; + var DisplaySettings = []; for(var i = 0; i < document.body.children.length; ++i) { @@ -40,6 +43,9 @@ DeriveReliableWindowDimensions() Child.style.display = DisplaySettings.shift(); } + ScrollTriggeredInternally = true; + window.scroll(ScrollPosX, ScrollPosY); + return Result; } @@ -76,7 +82,7 @@ function IsVisible(Element, WindowDim) { function GetRealOrientation(PreferredLandscape, IsMobile) { - var Result = window.orientation; + var Result = screen.orientation.angle; var WindowDim = GetWindowDim(IsMobile); if(WindowDim.Y > WindowDim.X) { @@ -317,6 +323,7 @@ function IsInRangeEx(Min, N, Max) } /* Auto-scrolling */ +var ScrollTriggeredInternally = false; var LastScrollYPos = 0; var ScrollTicking = false; var ScrollerFunction; @@ -383,7 +390,11 @@ function InitScrollEventListener(Element, IsMobile, StickyObscuringElement) { window.addEventListener('scroll', function() { - if(ScrollCondition == undefined || ScrollCondition == true) + if(ScrollTriggeredInternally) + { + ScrollTriggeredInternally = false; + } + else if(ScrollCondition == undefined || ScrollCondition == true) { LastScrollYPos = window.scrollY; diff --git a/cinera/cinera_search_pre.js b/cinera/cinera_search_pre.js index 0c7ee2b..0d0073b 100644 --- a/cinera/cinera_search_pre.js +++ b/cinera/cinera_search_pre.js @@ -3866,7 +3866,7 @@ InitResizeEventListener() function InitOrientationChangeListener() { - window.onorientationchange = function() + screen.orientation.onchange = function() { if(CineraProps.IsMobile) {