2018-12-02 15:38:27 +00:00
|
|
|
'use strict'
|
|
|
|
/* global __, ngettext */
|
2018-12-02 14:18:59 +00:00
|
|
|
define(["dojo/_base/declare"], function (declare) {
|
2018-12-03 06:33:44 +00:00
|
|
|
Article = {
|
2019-12-09 19:42:43 +00:00
|
|
|
_scroll_reset_timeout: false,
|
2018-12-11 07:00:54 +00:00
|
|
|
getScoreClass: function (score) {
|
|
|
|
if (score > 500) {
|
|
|
|
return "score-high";
|
|
|
|
} else if (score > 0) {
|
|
|
|
return "score-half-high";
|
|
|
|
} else if (score < -100) {
|
|
|
|
return "score-low";
|
|
|
|
} else if (score < 0) {
|
|
|
|
return "score-half-low";
|
|
|
|
} else {
|
|
|
|
return "score-neutral";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getScorePic: function (score) {
|
|
|
|
if (score > 500) {
|
|
|
|
return "trending_up";
|
|
|
|
} else if (score > 0) {
|
|
|
|
return "trending_up";
|
|
|
|
} else if (score < 0) {
|
|
|
|
return "trending_down";
|
|
|
|
} else {
|
|
|
|
return "trending_neutral";
|
|
|
|
}
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
selectionSetScore: function () {
|
2018-12-02 14:18:59 +00:00
|
|
|
const ids = Headlines.getSelected();
|
|
|
|
|
|
|
|
if (ids.length > 0) {
|
|
|
|
const score = prompt(__("Please enter new score for selected articles:"));
|
|
|
|
|
2019-08-29 09:52:22 +00:00
|
|
|
if (!isNaN(parseInt(score))) {
|
2018-12-11 07:30:32 +00:00
|
|
|
ids.each((id) => {
|
|
|
|
const row = $("RROW-" + id);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
if (row) {
|
|
|
|
row.setAttribute("data-score", score);
|
2018-12-06 11:23:45 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
const pic = row.select(".icon-score")[0];
|
2018-12-06 11:23:45 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
pic.innerHTML = Article.getScorePic(score);
|
|
|
|
pic.setAttribute("title", score);
|
2018-12-11 07:00:54 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
|
|
|
|
.each(function(scl) {
|
|
|
|
if (row.hasClassName(scl))
|
|
|
|
row.removeClassName(scl);
|
|
|
|
});
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
row.addClassName(Article.getScoreClass(score));
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
alert(__("No articles selected."));
|
|
|
|
}
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
setScore: function (id, pic) {
|
2018-12-06 11:23:45 +00:00
|
|
|
const row = pic.up("div[id*=RROW]");
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
if (row) {
|
|
|
|
const score_old = row.getAttribute("data-score");
|
|
|
|
const score = prompt(__("Please enter new score for this article:"), score_old);
|
|
|
|
|
2019-08-29 09:52:22 +00:00
|
|
|
if (!isNaN(parseInt(score))) {
|
2018-12-11 07:30:32 +00:00
|
|
|
row.setAttribute("data-score", score);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
const pic = row.select(".icon-score")[0];
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
pic.innerHTML = Article.getScorePic(score);
|
|
|
|
pic.setAttribute("title", score);
|
2018-12-06 11:23:45 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
|
|
|
|
.each(function(scl) {
|
|
|
|
if (row.hasClassName(scl))
|
2018-12-11 07:00:54 +00:00
|
|
|
row.removeClassName(scl);
|
|
|
|
});
|
2018-12-06 11:23:45 +00:00
|
|
|
|
2018-12-11 07:30:32 +00:00
|
|
|
row.addClassName(Article.getScoreClass(score));
|
|
|
|
}
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
cdmUnsetActive: function (event) {
|
2018-12-02 14:18:59 +00:00
|
|
|
const row = $("RROW-" + Article.getActive());
|
|
|
|
|
|
|
|
if (row) {
|
|
|
|
row.removeClassName("active");
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
if (dijit.byId("content-insert"))
|
|
|
|
dijit.byId("headlines-wrap-inner").removeChild(
|
|
|
|
dijit.byId("content-insert"));
|
2018-12-10 16:51:20 +00:00
|
|
|
|
|
|
|
Article.setActive(0);
|
2018-12-02 14:18:59 +00:00
|
|
|
},
|
|
|
|
displayUrl: function (id) {
|
|
|
|
const query = {op: "rpc", method: "getlinktitlebyid", id: id};
|
|
|
|
|
|
|
|
xhrJson("backend.php", query, (reply) => {
|
|
|
|
if (reply && reply.link) {
|
|
|
|
prompt(__("Article URL:"), reply.link);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
openInNewWindow: function (id) {
|
|
|
|
const w = window.open("");
|
|
|
|
|
2018-12-09 01:32:41 +00:00
|
|
|
if (w) {
|
|
|
|
w.opener = null;
|
|
|
|
w.location = "backend.php?op=article&method=redirect&id=" + id;
|
|
|
|
|
|
|
|
Headlines.toggleUnread(id, 0);
|
|
|
|
}
|
2018-12-02 14:18:59 +00:00
|
|
|
},
|
|
|
|
render: function (article) {
|
2018-12-02 19:08:18 +00:00
|
|
|
App.cleanupMemory("content-insert");
|
2018-12-02 14:18:59 +00:00
|
|
|
|
|
|
|
dijit.byId("headlines-wrap-inner").addChild(
|
|
|
|
dijit.byId("content-insert"));
|
|
|
|
|
|
|
|
const c = dijit.byId("content-insert");
|
|
|
|
|
|
|
|
try {
|
|
|
|
c.domNode.scrollTop = 0;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
c.attr('content', article);
|
|
|
|
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
|
|
|
|
|
|
|
|
Headlines.correctHeadlinesOffset(Article.getActive());
|
|
|
|
|
|
|
|
try {
|
|
|
|
c.focus();
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
},
|
2018-12-08 06:32:14 +00:00
|
|
|
formatComments: function(hl) {
|
|
|
|
let comments = "";
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-08 06:32:14 +00:00
|
|
|
if (hl.comments) {
|
|
|
|
let comments_msg = __("comments");
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-08 06:32:14 +00:00
|
|
|
if (hl.num_comments > 0) {
|
|
|
|
comments_msg = hl.num_comments + " " + ngettext("comment", "comments", hl.num_comments)
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 06:32:14 +00:00
|
|
|
comments = `<a href="${hl.comments}">(${comments_msg})</a>`;
|
|
|
|
}
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-08 06:32:14 +00:00
|
|
|
return comments;
|
|
|
|
},
|
|
|
|
formatOriginallyFrom: function(hl) {
|
|
|
|
return hl.orig_feed ? `<span>
|
|
|
|
${__('Originally from:')} <a target="_blank" rel="noopener noreferrer" href="${hl.orig_feed[1]}">${hl.orig_feed[0]}</a>
|
|
|
|
</span>` : "";
|
|
|
|
},
|
2018-12-10 12:06:47 +00:00
|
|
|
unpack: function(row) {
|
|
|
|
if (row.hasAttribute("data-content")) {
|
|
|
|
console.log("unpacking: " + row.id);
|
|
|
|
|
2018-12-12 05:56:02 +00:00
|
|
|
const container = row.querySelector(".content-inner");
|
|
|
|
|
|
|
|
container.innerHTML = row.getAttribute("data-content").trim();
|
|
|
|
|
|
|
|
// blank content element might screw up onclick selection and keyboard moving
|
|
|
|
if (container.textContent.length == 0)
|
|
|
|
container.innerHTML += " ";
|
|
|
|
|
2018-12-10 12:06:47 +00:00
|
|
|
row.removeAttribute("data-content");
|
|
|
|
|
|
|
|
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row);
|
|
|
|
}
|
|
|
|
},
|
2018-12-08 06:32:14 +00:00
|
|
|
view: function (id, noexpand) {
|
|
|
|
this.setActive(id);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-08 06:32:14 +00:00
|
|
|
if (!noexpand) {
|
|
|
|
const hl = Headlines.objectById(id);
|
|
|
|
|
|
|
|
if (hl) {
|
|
|
|
|
|
|
|
const comments = this.formatComments(hl);
|
|
|
|
const originally_from = this.formatOriginallyFrom(hl);
|
|
|
|
|
|
|
|
const article = `<div class="post post-${hl.id}">
|
|
|
|
<div class="header">
|
|
|
|
<div class="row">
|
|
|
|
<div class="title"><a target="_blank" rel="noopener noreferrer" title="${hl.title}" href="${hl.link}">${hl.title}</a></div>
|
|
|
|
<div class="date">${hl.updated_long}</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="buttons left">${hl.buttons_left}</div>
|
|
|
|
<div class="comments">${comments}</div>
|
|
|
|
<div class="author">${hl.author}</div>
|
|
|
|
<i class="material-icons">label_outline</i>
|
|
|
|
<span id="ATSTR-${hl.id}">${hl.tags_str}</span>
|
|
|
|
<a title="${__("Edit tags for this article")}" href="#"
|
|
|
|
onclick="Article.editTags(${hl.id})">(+)</a>
|
|
|
|
<div class="buttons right">${hl.buttons}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="POSTNOTE-${hl.id}">${hl.note}</div>
|
|
|
|
<div class="content" lang="${hl.lang ? hl.lang : 'en'}">
|
|
|
|
${originally_from}
|
|
|
|
${hl.content}
|
|
|
|
${hl.enclosures}
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
Headlines.toggleUnread(id, 0);
|
|
|
|
this.render(article);
|
|
|
|
}
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
editTags: function (id) {
|
2018-12-02 17:07:57 +00:00
|
|
|
const query = "backend.php?op=article&method=editArticleTags¶m=" + encodeURIComponent(id);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
|
|
|
if (dijit.byId("editTagsDlg"))
|
|
|
|
dijit.byId("editTagsDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "editTagsDlg",
|
|
|
|
title: __("Edit article Tags"),
|
|
|
|
style: "width: 600px",
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Saving article tags...", true);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", this.attr('value'), (transport) => {
|
|
|
|
try {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 14:18:59 +00:00
|
|
|
dialog.hide();
|
|
|
|
|
|
|
|
const data = JSON.parse(transport.responseText);
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
const id = data.id;
|
|
|
|
|
|
|
|
const tags = $("ATSTR-" + id);
|
|
|
|
const tooltip = dijit.byId("ATSTRTIP-" + id);
|
|
|
|
|
|
|
|
if (tags) tags.innerHTML = data.content;
|
|
|
|
if (tooltip) tooltip.attr('label', data.content_full);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2018-12-03 10:38:13 +00:00
|
|
|
App.Error.report(e);
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: query
|
|
|
|
});
|
|
|
|
|
|
|
|
const tmph = dojo.connect(dialog, 'onLoad', function () {
|
|
|
|
dojo.disconnect(tmph);
|
|
|
|
|
|
|
|
new Ajax.Autocompleter('tags_str', 'tags_choices',
|
|
|
|
"backend.php?op=article&method=completeTags",
|
|
|
|
{tokens: ',', paramName: "search"});
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
},
|
2019-12-10 05:51:45 +00:00
|
|
|
cdmScrollToId: function (id, force, event) {
|
2018-12-02 14:18:59 +00:00
|
|
|
const ctr = $("headlines-frame");
|
|
|
|
const e = $("RROW-" + id);
|
2019-12-10 05:58:32 +00:00
|
|
|
const is_expanded = App.getInitParam("cdm_expanded");
|
2018-12-02 14:18:59 +00:00
|
|
|
|
|
|
|
if (!e || !ctr) return;
|
|
|
|
|
2019-12-10 05:58:32 +00:00
|
|
|
if (force || is_expanded || e.offsetTop + e.offsetHeight > (ctr.scrollTop + ctr.offsetHeight) ||
|
2018-12-02 14:18:59 +00:00
|
|
|
e.offsetTop < ctr.scrollTop) {
|
|
|
|
|
2019-12-10 05:58:32 +00:00
|
|
|
if (event && event.repeat || !is_expanded) {
|
2019-12-10 05:51:45 +00:00
|
|
|
ctr.addClassName("forbid-smooth-scroll");
|
|
|
|
window.clearTimeout(this._scroll_reset_timeout);
|
|
|
|
|
|
|
|
this._scroll_reset_timeout = window.setTimeout(() => {
|
|
|
|
if (ctr) ctr.removeClassName("forbid-smooth-scroll");
|
|
|
|
}, 250)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ctr.removeClassName("forbid-smooth-scroll");
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:40:47 +00:00
|
|
|
ctr.scrollTop = e.offsetTop;
|
2018-12-02 14:18:59 +00:00
|
|
|
|
|
|
|
Element.hide("floatingTitle");
|
|
|
|
}
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
setActive: function (id) {
|
2018-12-02 14:18:59 +00:00
|
|
|
console.log("setActive", id);
|
|
|
|
|
|
|
|
$$("div[id*=RROW][class*=active]").each((e) => {
|
|
|
|
e.removeClassName("active");
|
|
|
|
});
|
|
|
|
|
|
|
|
const row = $("RROW-" + id);
|
|
|
|
|
|
|
|
if (row) {
|
2018-12-10 12:06:47 +00:00
|
|
|
Article.unpack(row);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2018-12-10 18:19:33 +00:00
|
|
|
row.removeClassName("Unread");
|
2018-12-02 14:18:59 +00:00
|
|
|
row.addClassName("active");
|
|
|
|
|
2018-12-10 17:56:09 +00:00
|
|
|
PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id"));
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
getActive: function () {
|
2018-12-10 17:56:09 +00:00
|
|
|
const row = document.querySelector("#headlines-frame > div[id*=RROW][class*=active]");
|
|
|
|
|
|
|
|
if (row)
|
|
|
|
return row.getAttribute("data-article-id");
|
|
|
|
else
|
|
|
|
return 0;
|
2018-12-02 14:18:59 +00:00
|
|
|
},
|
2019-12-09 19:42:43 +00:00
|
|
|
scrollByPages: function (page_offset, event) {
|
2019-12-11 03:53:32 +00:00
|
|
|
const elem = App.isCombinedMode() ? $("headlines-frame") : $("content-insert");
|
2019-12-09 19:42:43 +00:00
|
|
|
|
|
|
|
const offset = elem.offsetHeight * page_offset * 0.99;
|
|
|
|
|
|
|
|
this.scroll(offset, event);
|
2019-12-04 12:50:49 +00:00
|
|
|
},
|
2019-12-09 19:42:43 +00:00
|
|
|
scroll: function (offset, event) {
|
|
|
|
|
2019-12-11 03:53:32 +00:00
|
|
|
const elem = App.isCombinedMode() ? $("headlines-frame") : $("content-insert");
|
2019-12-09 19:42:43 +00:00
|
|
|
|
2019-12-09 20:23:54 +00:00
|
|
|
if (event && event.repeat) {
|
2019-12-09 19:42:43 +00:00
|
|
|
elem.addClassName("forbid-smooth-scroll");
|
|
|
|
window.clearTimeout(this._scroll_reset_timeout);
|
2018-12-02 14:18:59 +00:00
|
|
|
|
2019-12-09 19:42:43 +00:00
|
|
|
this._scroll_reset_timeout = window.setTimeout(() => {
|
|
|
|
if (elem) elem.removeClassName("forbid-smooth-scroll");
|
|
|
|
}, 250)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
elem.removeClassName("forbid-smooth-scroll");
|
2018-12-02 14:18:59 +00:00
|
|
|
}
|
2019-12-09 19:42:43 +00:00
|
|
|
|
|
|
|
elem.scrollTop += offset;
|
2018-12-02 14:18:59 +00:00
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
mouseIn: function (id) {
|
2018-12-02 14:18:59 +00:00
|
|
|
this.post_under_pointer = id;
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
mouseOut: function (id) {
|
2018-12-02 14:18:59 +00:00
|
|
|
this.post_under_pointer = false;
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
getUnderPointer: function () {
|
2018-12-02 14:18:59 +00:00
|
|
|
return this.post_under_pointer;
|
|
|
|
}
|
2018-12-03 06:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Article;
|
2019-08-29 09:52:22 +00:00
|
|
|
});
|