From 04e54b161d97447f7c13b4ede80b65c93b05cc8a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 7 May 2021 16:01:41 +0300 Subject: initial --- init.js | 40 ++++++++++++++++++++++++++++++++++++++++ init.php | 23 +++++++++++++++++++++++ loading.png | Bin 0 -> 4603 bytes 3 files changed, 63 insertions(+) create mode 100644 init.js create mode 100644 init.php create mode 100644 loading.png diff --git a/init.js b/init.js new file mode 100644 index 0000000..87a2299 --- /dev/null +++ b/init.js @@ -0,0 +1,40 @@ +/* global require, PluginHost */ + +require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { + function set_placeholder(img) { + + img.style.backgroundColor = '#bbb'; + img.style.backgroundImage = 'url(plugins.local/af_img_placeholders/loading.png)'; + img.style.backgroundPosition = 'center center'; + img.style.backgroundRepeat = 'no-repeat'; + img.style.minWidth = '300px'; + img.style.minHeight = '300px'; + + img.onload = function() { + img.style.minWidth = ''; + img.style.minHeight = ''; + } + + img.onerror = function() { + this.style.backgroundColor = ''; + this.style.backgroundImage = ''; + } + + } + + function set_placeholders(row) { + [...row.querySelectorAll("img")].forEach((img) => set_placeholder(img)); + } + + ready(function () { + PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function (row) { + set_placeholders(row.querySelector(".content")); + return true; + }); + + PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED, function (row) { + set_placeholders(row); + return true; + }); + }); +}); diff --git a/init.php b/init.php new file mode 100644 index 0000000..092334e --- /dev/null +++ b/init.php @@ -0,0 +1,23 @@ +host = $host; + } + + function get_js() { + return file_get_contents(__DIR__ . "/init.js"); + } + + function api_version() { + return 2; + } + +} diff --git a/loading.png b/loading.png new file mode 100644 index 0000000..cf55432 Binary files /dev/null and b/loading.png differ -- cgit v1.2.3