Skip to content
Permalink
Browse files

Use localStorage/sessionStorage to remember what user wants folded.

Paper pages and home.
  • Loading branch information...
kohler committed Nov 7, 2019
1 parent 6a1808b commit 9dbb654a3454153b891da0f0d88f7c72a5c0d025
Showing with 59 additions and 32 deletions.
  1. +45 −12 scripts/script.js
  2. +2 −2 src/contactlist.php
  3. +10 −15 src/papertable.php
  4. +2 −3 src/partials/p_home.php
@@ -2686,8 +2686,43 @@ var hotcrp_load = (function ($) {
})(jQuery);


function fold_storage() {
if (!this || this === window) {
$(".need-fold-storage").each(fold_storage);
} else {
removeClass(this, "need-fold-storage");
var sn = this.getAttribute("data-fold-storage"), smap, k, v,
spfx = this.getAttribute("data-fold-storage-prefix") || "";
if (sn.charAt(0) === "{" || sn.charAt(0) === "[") {
smap = JSON.parse(sn) || {};
} else {
var m = this.className.match(/\bfold(\d*)[oc]\b/),
n = m[1] === "" ? 0 : +m[1];
smap = {};
smap[n] = sn;
}
sn = wstorage.json(true, "fold") || wstorage.json(false, "fold") || {};
for (k in smap) {
if (sn[spfx + smap[k]]) {
foldup.call(this, null, {f: false, n: +k});
}
}
}
}

function fold_session_for(foldnum, type) {
var s = this.getAttribute("data-fold-" + type);
if (s && (s.charAt(0) === "{" || s.charAt(0) === "[")) {
s = (JSON.parse(s) || {})[foldnum];
}
if (s && this.hasAttribute("data-fold-" + type + "-prefix")) {
s = this.getAttribute("data-fold-" + type + "-prefix") + s;
}
return s;
}

function fold(elt, dofold, foldnum) {
var i, foldname, opentxt, closetxt, isopen, foldnumid;
var i, foldname, opentxt, closetxt, isopen, foldnumid, s;

// find element
if (elt && ($.isArray(elt) || elt.jquery)) {
@@ -2723,17 +2758,15 @@ function fold(elt, dofold, foldnum) {
}

// check for session
var ses = elt.getAttribute("data-fold-session");
if (ses) {
if (ses.charAt(0) === "{" || ses.charAt(0) === "[") {
ses = (JSON.parse(ses) || {})[foldnum];
}
if (elt.hasAttribute("data-fold-session-prefix")) {
ses = elt.getAttribute("data-fold-session-prefix") + ses;
}
if (ses) {
$.post(hoturl_post("api/session", {v: ses + (isopen ? "=1" : "=0")}));
}
if ((s = fold_session_for.call(elt, foldnum, "storage"))) {
var sj = wstorage.json(true, "fold") || {};
isopen ? delete sj[s] : sj[s] = 1;
wstorage(true, "fold", $.isEmptyObject(sj) ? null : sj);
var sj = wstorage.json(false, "fold") || {};
isopen ? delete sj[s] : sj[s] = 1;
wstorage(false, "fold", $.isEmptyObject(sj) ? null : sj);
} else if ((s = fold_session_for.call(elt, foldnum, "session"))) {
$.post(hoturl_post("api/session", {v: s + (isopen ? "=1" : "=0")}));
}
}

@@ -770,9 +770,9 @@ function table_html($listname, $url, $listtitle = "", $foldsession = null) {
if ($foldclasses && $foldsession) {
$fs = [];
foreach (self::$folds as $k => $fold) {
$fs[$k + 1] = $foldsession . $fold;
$fs[$k + 1] = $fold;
}
$x .= "\" data-fold-session=\"" . htmlspecialchars(json_encode_browser($fs));
$x .= "\" data-fold-session=\"" . htmlspecialchars(json_encode_browser($fs)) . "\" data-fold-session-prefix=\"" . htmlspecialchars($foldsession);
}
$x .= "\">\n";
@@ -251,14 +251,9 @@ private function abstract_foldable($abstract) {
}
private function echoDivEnter() {
// translate session
$unfolds = $this->user->session("foldpaper", []);
if (is_string($unfolds))
$unfolds = explode(" ", $unfolds);
// 5: topics, 6: abstract, 7: [JavaScript abstract expansion],
// 8: blind authors, 9: full authors
$foldsession = [5 => "t", 6 => "b", 8 => "a", 9 => "p"];
$foldstorage = [5 => "t", 6 => "b", 8 => "a", 9 => "p"];
$this->foldnumber = ["topics" => 5];
// other expansions
@@ -272,12 +267,12 @@ private function echoDivEnter() {
if (strlen($o->display_group) > 1
&& !isset($this->foldnumber[$o->display_group])) {
$this->foldnumber[$o->display_group] = $next_foldnum;
$foldsession[$next_foldnum] = str_replace(" ", "_", $o->display_group);
$foldstorage[$next_foldnum] = str_replace(" ", "_", $o->display_group);
++$next_foldnum;
}
if ($o->display_expand) {
$this->foldnumber[$o->formid] = $next_foldnum;
$foldsession[$next_foldnum] = $o->formid;
$foldstorage[$next_foldnum] = $o->formid;
++$next_foldnum;
}
}
@@ -286,9 +281,8 @@ private function echoDivEnter() {
// what is folded?
// if highlighting, automatically unfold abstract/authors
$this->foldmap = [];
foreach ($foldsession as $num => $k) {
$this->foldmap[$num] = !in_array($k, $unfolds)
&& ($this->allFolded || $k === "a");
foreach ($foldstorage as $num => $k) {
$this->foldmap[$num] = $this->allFolded || $k === "a";
}
if ($this->foldmap[6]) {
$abstract = $this->entryData("abstract");
@@ -302,16 +296,17 @@ private function echoDivEnter() {
}
// collect folders
$folders = array("clearfix");
$folders = ["clearfix", "need-fold-storage"];
foreach ($this->foldmap as $num => $f) {
if ($num !== 8 || $this->user->view_authors_state($this->prow) === 1)
$folders[] = "fold" . $num . ($f ? "c" : "o");
}
// echo div
echo '<div id="foldpaper" class="', join(" ", $folders),
'" data-fold-session-prefix="foldpaper." data-fold-session="',
htmlspecialchars(json_encode_browser($foldsession)), '">';
'" data-fold-storage-prefix="p." data-fold-storage="',
htmlspecialchars(json_encode_browser($foldstorage)), '">';
Ht::stash_script("fold_storage()");
}
private function echoDivExit() {
@@ -1358,7 +1353,7 @@ private function papstripCollaborators() {
$fold = 0;
$option = $this->conf->paper_opts->get(PaperOption::COLLABORATORSID);
$this->_papstripBegin("pscollab", $fold, ["data-fold-session" => "foldpscollab"]);
$this->_papstripBegin("pscollab", $fold, ["data-fold-storage" => "p.collab", "class" => "need-fold-storage"]);
echo $this->papt("collaborators", $option->title_html(),
["type" => "ps", "fold" => "pscollab", "folded" => $fold]),
'<div class="psv"><div class="fx">', $data,
@@ -470,12 +470,11 @@ function render_reviews(Contact $user, Qrequest $qreq, $gx) {
echo "</div>";
if ($user->is_reviewer()) {
echo "<div class=\"homesubgrp has-fold fold20c ui-unfold js-open-activity\" id=\"homeactivity\" data-fold-session=\"foldhomeactivity\">",
echo "<div class=\"homesubgrp has-fold fold20c ui-unfold js-open-activity need-fold-storage\" id=\"homeactivity\" data-fold-storage=\"homeactivity\">",
foldupbutton(20),
"<a href=\"\" class=\"q homeactivity ui js-foldup\" data-fold-target=\"20\">Recent activity<span class=\"fx20\">:</span></a>",
"</div>";
if (!$user->session("foldhomeactivity", 1))
Ht::stash_script("foldup.call(\$(\"#homeactivity\")[0],null,20)");
Ht::stash_script("fold_storage()");
}
echo "</div>\n";

0 comments on commit 9dbb654

Please sign in to comment.
You can’t perform that action at this time.