diff options
author | Andrew Dolgov <[email protected]> | 2021-11-20 17:36:17 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-11-20 17:36:17 +0300 |
commit | f4176110f78d725d6e83cebdd1e4c0b78b4a3007 (patch) | |
tree | 53c314645d49449962a092e692273aded92d8f99 |
initial
-rw-r--r-- | init.css | 21 | ||||
-rw-r--r-- | init.js | 29 | ||||
-rw-r--r-- | init.php | 38 |
3 files changed, 88 insertions, 0 deletions
diff --git a/init.css b/init.css new file mode 100644 index 0000000..d05c2aa --- /dev/null +++ b/init.css @@ -0,0 +1,21 @@ +#headlines-frame:not([data-headlines-count="0"])[data-is-cdm="true"][data-is-cdm-expanded="true"][data-enable-grid="true"] { + display : grid; + grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)) ! important; +} + +.cdm .titleWrap { + display : none; +} + +.cdm .content-inner a.card-title { + font-size: 16px; + color: #999; + font-weight: 600; + transition: color 0.2s, background 0.2s; + text-rendering: optimizelegibility; + font-family: system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif; +} + +.cdm.Unread .content-inner a.card-title { + color : black; +} @@ -0,0 +1,29 @@ +/* global require, PluginHost, Headlines, App */ + +require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { + + ready(function () { + PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function (article) { + + const article_id = article.getAttribute('data-article-id'); + + // we need access to unrendered data + const hl = Headlines.headlines[article_id]; + + if (hl) { + const flavor = hl.flavor; + + article.querySelector('.content .content-inner').innerHTML = ` + <span onclick="return Headlines.click(event, ${hl.id});" data-article-id="${hl.id}" class="hlMenuAttach"> + <a class="card-title" title="${App.escapeHtml(hl.title)}" target="_blank" rel="noopener noreferrer" href="${App.escapeHtml(hl.link)}"> + ${hl.title}</a> + </span> + <img src="${App.escapeHtml(flavor.image)}"> + <p class="text-muted text-small">${hl.content_preview.replace(" ", "")}</p> + `; + } + + return true; + }); + }); +}); diff --git a/init.php b/init.php new file mode 100644 index 0000000..58abb82 --- /dev/null +++ b/init.php @@ -0,0 +1,38 @@ +<?php +class Card_View extends Plugin { + + function about() { + return array(1.0, + "Experimental card view for combined mode", + "fox"); + } + + function init($host) { + $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); + } + + function hook_render_article_cdm($article) { + list ($flavor_image, $flavor_stream, $flavor_kind) = Article::_get_image( + Article::_get_enclosures($article['id']), + $article["content"], // unsanitized + $article["site_url"] ?? "", // could be null if archived article + $article); + + $article["flavor"] = ["image" => $flavor_image, "stream" => $flavor_stream, "kind" => $flavor_kind]; + + return $article; + } + + function get_css() { + return file_get_contents(__DIR__ . "/init.css"); + } + + function get_js() { + return file_get_contents(__DIR__ . "/init.js"); + } + + function api_version() { + return 2; + } + +} |