diff options
author | Andrew Dolgov <[email protected]> | 2021-05-07 16:01:41 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-05-07 16:01:41 +0300 |
commit | 04e54b161d97447f7c13b4ede80b65c93b05cc8a (patch) | |
tree | 8837b4da974faba5b37e019aa27f089b665f0393 |
initial
-rw-r--r-- | init.js | 40 | ||||
-rw-r--r-- | init.php | 23 | ||||
-rw-r--r-- | loading.png | bin | 0 -> 4603 bytes |
3 files changed, 63 insertions, 0 deletions
@@ -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 @@ +<?php +class Af_Img_PlaceHolders extends Plugin { + private $host; + + function about() { + return array(null, + "Add loading placeholders for images (for slow connections)", + "fox"); + } + + function init($host) { + $this->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 Binary files differnew file mode 100644 index 0000000..cf55432 --- /dev/null +++ b/loading.png |