]> git.wh0rd.org Git - tt-rss.git/blob - plugins/shorten_expanded/init.js
ffec6271d70651b48a2a321faca8bb54561ee47d
[tt-rss.git] / plugins / shorten_expanded / init.js
1 var _shorten_expanded_threshold = 1.5; //window heights
2
3 function expandSizeWrapper(id) {
4         try {
5                 var row = $(id);
6
7                 console.log(row);
8
9                 if (row) {
10                         var content = row.select(".contentSizeWrapper")[0];
11                         var link = row.select(".expandPrompt")[0];
12
13                         if (content) content.removeClassName("contentSizeWrapper");
14                         if (link) Element.hide(link);
15
16                 }
17         } catch (e) {
18                 exception_error("expandSizeWrapper", e);
19         }
20
21         return false;
22
23 }
24
25 require(['dojo/_base/kernel', 'dojo/ready'], function  (dojo, ready) {
26
27         ready(function() {
28                 PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) {
29                         if (getInitParam('cdm_expanded')) {
30
31                                 window.setTimeout(function() {
32                                         if (row) {
33                                                 if (row.offsetHeight >= _shorten_expanded_threshold * window.innerHeight) {
34                                                         var content = row.select(".cdmContentInner")[0];
35
36                                                         if (content) {
37                                                                 content.innerHTML = "<div class='contentSizeWrapper'>" +
38                                                                         content.innerHTML + "</div><button class='expandPrompt' onclick='return expandSizeWrapper(\""+row.id+"\")' "+
39                                                                         "href='#'>" + __("Click to expand article") + "</button>";
40
41                                                         }
42                                                 }
43                                         }
44                                 }, 150);
45                         }
46
47                         return true;
48                 });
49         });
50
51 });