even more objectification of JS

master
Andrew Dolgov 6 years ago
parent 1d82bd4f19
commit 97df81d8d9

@ -29,7 +29,7 @@ class Feeds extends Handler_Protected {
$tog_marked_link = "selectionToggleMarked()";
$tog_published_link = "selectionTogglePublished()";
$set_score_link = "setSelectionScore()";
$set_score_link = "Article.setSelectionScore()";
if ($is_cat) $cat_q = "&is_cat=$is_cat";
@ -345,7 +345,7 @@ class Feeds extends Handler_Protected {
$score_pic = "images/" . get_score_pic($score);
$score_pic = "<img class='score-pic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
$score_pic = "<img class='score-pic' score='$score' onclick='Article.changeScore($id, this)' src=\"$score_pic\"
title=\"$score\">";
if ($score > 500) {
@ -413,7 +413,7 @@ class Feeds extends Handler_Protected {
$reply['content'] .= "</div>";
$reply['content'] .= "<div onclick='return hlClicked(event, $id)'
$reply['content'] .= "<div onclick='return Headlines.click(event, $id)'
class=\"title\"><span class='hl-content $hlc_suffix'>";
$reply['content'] .= "<a class=\"title $hlc_suffix\"
href=\"" . htmlspecialchars($line["link"]) . "\"
@ -523,7 +523,7 @@ class Feeds extends Handler_Protected {
// data-article-id included for context menu
$tmp_content .= "<span
onclick=\"return cdmClicked(event, $id);\"
onclick=\"return Headlines.click(event, $id);\"
data-article-id=\"$id\"
class=\"titleWrap hlMenuAttach $hlc_suffix\">
<a class=\"title $hlc_suffix\"
@ -536,7 +536,7 @@ class Feeds extends Handler_Protected {
$tmp_content .= $labels_str;
$tmp_content .= "<span class='collapse'>
<img src=\"images/collapse.png\" onclick=\"return cdmCollapseActive(event)\"
<img src=\"images/collapse.png\" onclick=\"return Article.cdmCollapseActive(event)\"
title=\"".__("Collapse article")."\"/></span>";
$tmp_content .= "</span>";
@ -567,7 +567,7 @@ class Feeds extends Handler_Protected {
$tmp_content .= "</div>"; //header
$tmp_content .= "<div class=\"content\" onclick=\"return cdmClicked(event, $id, true);\">";
$tmp_content .= "<div class=\"content\" onclick=\"return Headlines.click(event, $id, true);\">";
$tmp_content .= "<div id=\"POSTNOTE-$id\">";
if ($line['note']) {

@ -43,7 +43,7 @@ const Feeds = {
parseCounters: function (elems) {
for (let l = 0; l < elems.length; l++) {
if (this._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) {
if (Feeds._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) {
continue;
}
@ -169,7 +169,7 @@ const Feeds = {
const id = String(item.id);
const is_cat = id.match("^CAT:");
const feed = id.substr(id.indexOf(":") + 1);
this.viewfeed({feed: feed, is_cat: is_cat});
Feeds.viewfeed({feed: feed, is_cat: is_cat});
return false;
},
openOnClick: false,

@ -326,7 +326,7 @@ function init_hotkey_actions() {
};
hotkey_actions["close_article"] = function () {
if (App.isCombinedMode()) {
cdmCollapseActive();
Article.cdmCollapseActive();
} else {
Article.closeArticlePanel();
}

@ -38,6 +38,60 @@ const ArticleCache = {
};
const Article = {
setSelectionScore: function() {
const ids = getSelectedArticleIds2();
if (ids.length > 0) {
console.log(ids);
const score = prompt(__("Please enter new score for selected articles:"));
if (score != undefined) {
const query = {
op: "article", method: "setScore", id: ids.toString(),
score: score
};
xhrJson("backend.php", query, (reply) => {
if (reply) {
reply.id.each((id) => {
const row = $("RROW-" + id);
if (row) {
const pic = row.getElementsByClassName("score-pic")[0];
if (pic) {
pic.src = pic.src.replace(/score_.*?\.png/,
reply["score_pic"]);
pic.setAttribute("score", reply["score"]);
}
}
});
}
});
}
} else {
alert(__("No articles are selected."));
}
},
changeScore: function(id, pic) {
const score = pic.getAttribute("score");
const new_score = prompt(__("Please enter new score for this article:"), score);
if (new_score != undefined) {
const query = {op: "article", method: "setScore", id: id, score: new_score};
xhrJson("backend.php", query, (reply) => {
if (reply) {
pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
pic.setAttribute("score", new_score);
pic.setAttribute("title", new_score);
}
});
}
},
closeArticlePanel: function () {
if (dijit.byId("content-insert"))
dijit.byId("headlines-wrap-inner").removeChild(
@ -136,10 +190,55 @@ const Article = {
return false;
},
}
cdmCollapseActive: function(event) {
const row = $("RROW-" + getActiveArticleId());
if (row) {
row.removeClassName("active");
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb && !row.hasClassName("Selected"))
cb.attr("checked", false);
setActiveArticleId(0);
if (event)
event.stopPropagation();
return false;
}
}
};
const Headlines = {
_headlines_scroll_timeout: 0,
click: function(event, id, in_body) {
in_body = in_body || false;
if (App.isCombinedMode()) {
if (!in_body && (event.ctrlKey || id == getActiveArticleId() || getInitParam("cdm_expanded"))) {
Article.openArticleInNewWindow(id);
}
setActiveArticleId(id);
if (!getInitParam("cdm_expanded"))
cdmScrollToArticleId(id);
return in_body;
} else {
if (event.ctrlKey) {
Article.openArticleInNewWindow(id);
setActiveArticleId(id);
} else {
Article.view(id);
}
return false;
}
},
initScrollHandler: function() {
$("headlines-frame").onscroll = (event) => {
clearTimeout(this._headlines_scroll_timeout);
@ -1238,33 +1337,6 @@ function updateHeadlineLabels(transport) {
}
}
function cdmClicked(event, id, in_body) {
in_body = in_body || false;
if (!in_body && (event.ctrlKey || id == getActiveArticleId() || getInitParam("cdm_expanded"))) {
Article.openArticleInNewWindow(id);
}
setActiveArticleId(id);
if (!getInitParam("cdm_expanded"))
cdmScrollToArticleId(id);
return in_body;
}
function hlClicked(event, id) {
if (event.ctrlKey) {
Article.openArticleInNewWindow(id);
setActiveArticleId(id);
} else {
Article.view(id);
}
return false;
}
function getRelativePostIds(id, limit) {
const tmp = [];
@ -1313,25 +1385,6 @@ function headlineActionsChange(elem) {
elem.attr('value', 'false');
}
function cdmCollapseActive(event) {
const row = $("RROW-" + getActiveArticleId());
if (row) {
row.removeClassName("active");
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb && !row.hasClassName("Selected"))
cb.attr("checked", false);
setActiveArticleId(0);
if (event)
event.stopPropagation();
return false;
}
}
function initFloatingMenu() {
if (!dijit.byId("floatingMenu")) {
@ -1539,59 +1592,5 @@ function initHeadlinesMenu() {
}
}
// noinspection JSUnusedGlobalSymbols
function setSelectionScore() {
const ids = getSelectedArticleIds2();
if (ids.length > 0) {
console.log(ids);
const score = prompt(__("Please enter new score for selected articles:"));
if (score != undefined) {
const query = { op: "article", method: "setScore", id: ids.toString(),
score: score };
xhrJson("backend.php", query, (reply) => {
if (reply) {
reply.id.each((id) => {
const row = $("RROW-" + id);
if (row) {
const pic = row.getElementsByClassName("score-pic")[0];
if (pic) {
pic.src = pic.src.replace(/score_.*?\.png/,
reply["score_pic"]);
pic.setAttribute("score", reply["score"]);
}
}
});
}
});
}
} else {
alert(__("No articles are selected."));
}
}
// noinspection JSUnusedGlobalSymbols
function changeScore(id, pic) {
const score = pic.getAttribute("score");
const new_score = prompt(__("Please enter new score for this article:"), score);
if (new_score != undefined) {
const query = { op: "article", method: "setScore", id: id, score: new_score };
xhrJson("backend.php", query, (reply) => {
if (reply) {
pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
pic.setAttribute("score", new_score);
pic.setAttribute("title", new_score);
}
});
}
}

Loading…
Cancel
Save