mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2025-10-18 14:31:00 +02:00
shorten_expanded: add simple event debounce
This commit is contained in:
parent
a071edaa9d
commit
f0687060d7
@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
Plugins.Shorten_Expanded = {
|
Plugins.Shorten_Expanded = {
|
||||||
threshold: 1.5, // of window height
|
threshold: 1.5, // of window height
|
||||||
observer: new ResizeObserver((entries) => {
|
debounce: (callback, wait) => {
|
||||||
entries.forEach((entry) => {
|
let timeoutId = null;
|
||||||
const row = entry.target;
|
return (...args) => {
|
||||||
|
window.clearTimeout(timeoutId);
|
||||||
Plugins.Shorten_Expanded.shorten_if_needed(row);
|
timeoutId = window.setTimeout(() => {
|
||||||
});
|
callback(...args);
|
||||||
}),
|
}, wait);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
observer: false,
|
||||||
shorten_if_needed: function(row) {
|
shorten_if_needed: function(row) {
|
||||||
|
|
||||||
const content = row.querySelector(".content");
|
const content = row.querySelector(".content");
|
||||||
@ -63,10 +66,20 @@ Plugins.Shorten_Expanded = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
|
require(['dojo/_base/kernel', 'dojo/ready'], (dojo, ready) => {
|
||||||
ready(function() {
|
ready(() => {
|
||||||
|
const self = Plugins.Shorten_Expanded;
|
||||||
|
|
||||||
|
self.observer = new ResizeObserver(self.debounce((entries) => {
|
||||||
|
entries.forEach((entry) => {
|
||||||
|
const row = entry.target;
|
||||||
|
|
||||||
|
self.shorten_if_needed(row);
|
||||||
|
});
|
||||||
|
})),
|
||||||
|
|
||||||
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
|
PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
|
||||||
Plugins.Shorten_Expanded.process_row(row);
|
self.process_row(row);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user