From db583287b29b23dd07125db3b40c3324ba26e000 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 24 Feb 2021 17:01:40 +0300 Subject: [PATCH] add hide/show events for feeds sidebar --- js/Feeds.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/js/Feeds.js b/js/Feeds.js index 3767f8b65..5a2dee5cf 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -1,6 +1,6 @@ 'use strict' -/* global __, App, Headlines, xhrPost, xhr, dojo, dijit, fox, PluginHost, Notify, fox */ +/* global __, App, Headlines, xhr, dojo, dijit, fox, PluginHost, Notify, fox */ const Feeds = { _default_feed_id: -3, @@ -13,6 +13,19 @@ const Feeds = { _search_query: false, last_search_query: [], _viewfeed_wait_timeout: false, + _feeds_holder_observer: new IntersectionObserver( + (entries/*, observer*/) => { + entries.forEach((entry) => { + //console.log('feeds',entry.target, entry.intersectionRatio); + + if (entry.intersectionRatio == 0) + Feeds.onHide(entry); + else + Feeds.onShow(entry); + }); + }, + {threshold: [0, 1], root: document.querySelector("body")} + ), _counters_prev: [], // NOTE: this implementation is incomplete // for general objects but good enough for counters @@ -120,14 +133,6 @@ const Feeds = { }, toggle: function() { Element.toggle("feeds-holder"); - - const splitter = App.byId("feeds-holder_splitter"); - - Element.visible("feeds-holder") ? splitter.show() : splitter.hide(); - - dijit.byId("main").resize(); - - Headlines.updateCurrentUnread(); }, cancelSearch: function() { this._search_query = ""; @@ -208,9 +213,23 @@ const Feeds = { App.Error.report(e); } }, + onHide: function() { + App.byId("feeds-holder_splitter").hide(); + + dijit.byId("main").resize(); + Headlines.updateCurrentUnread(); + }, + onShow: function() { + App.byId("feeds-holder_splitter").show(); + + dijit.byId("main").resize(); + Headlines.updateCurrentUnread(); + }, init: function() { console.log("in feedlist init"); + this._feeds_holder_observer.observe(App.byId("feeds-holder")); + App.setLoadingProgress(50); //document.onkeydown = (event) => { return App.hotkeyHandler(event) };