Skip to content

Commit

Permalink
Script: Move scripts into a global hotcrp object.
Browse files Browse the repository at this point in the history
Preparing for modularization.
  • Loading branch information
kohler committed Oct 28, 2020
1 parent fea0fd1 commit 5c4c69d
Show file tree
Hide file tree
Showing 29 changed files with 213 additions and 171 deletions.
2 changes: 1 addition & 1 deletion assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function pcAssignments($qreq) {
'<div class="revcard-head"><h2>PC assignments</h2></div>',
'<div class="revcard-body">',
Ht::form($Conf->hoturl_post("assign", "p=$prow->paperId"), array("id" => "ass", "class" => "need-unload-protection"));
Ht::stash_script('hiliter_children("#ass")');
Ht::stash_script('hotcrp.highlight_form_children("#ass")');

if ($Conf->has_topics()) {
echo "<p>Review preferences display as “P#”, topic scores as “T#”.</p>";
Expand Down
97 changes: 5 additions & 92 deletions autoassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ function progress($status) {
}
if (!$this->live) {
$t = '<h3 class="form-h">Preparing assignment</h3><p><strong>Status:</strong> ' . htmlspecialchars($status);
echo Ht::script('$$("propass").innerHTML=' . json_encode_browser($t) . ';'), "\n";
echo Ht::script('document.getElementById("propass").innerHTML=' . json_encode_browser($t) . ';'), "\n";
flush();
while (@ob_end_flush()) {
/* skip */
Expand Down Expand Up @@ -505,7 +505,7 @@ function run() {
if ($this->live) {
echo $w;
} else {
echo Ht::unstash_script('$$("propass").innerHTML=' . json_encode($w)), "\n";
echo Ht::unstash_script('document.getElementById("propass").innerHTML=' . json_encode($w)), "\n";
}
return null;
} else {
Expand Down Expand Up @@ -602,7 +602,7 @@ function divClass($name, $classes = null) {
<dt>', review_type_icon(REVIEW_PC), ' Optional</dt><dd>May be declined</dd>
<dt>', review_type_icon(REVIEW_META), ' Metareview</dt><dd>Can view all other reviews before completing their own</dd></dl>
</div></div>', "\n";
echo Ht::unstash_script("hiliter_children(\"#autoassignform\")");
echo Ht::unstash_script("hotcrp.highlight_form_children(\"#autoassignform\")");

// paper selection
echo divClass("pap"), "<h3 class=\"form-h\">Paper selection</h3>";
Expand Down Expand Up @@ -730,75 +730,7 @@ function divClass($name, $classes = null) {
$sep = ", ";
}
echo ")";
Ht::stash_script('function make_pcsel_members(tag) {
if (tag === "__flip__")
return function () { return !this.checked; };
else if (tag === "all")
return function () { return true; };
else if (tag === "none")
return function () { return false; };
else {
tag = " " + tag.toLowerCase() + "#";
return function () {
var tlist = hotcrp_pc_tags[this.name.substr(3)] || "";
return tlist.indexOf(tag) >= 0;
};
}
}
function pcsel_tag(event) {
var $g = $(this).closest(".js-radio-focus"), e;
if (this.tagName === "A") {
$g.find("input[type=radio]").first().click();
var tag = this.hash.substring(4),
f = make_pcsel_members(tag),
full = true;
if (tag !== "all" && tag !== "none" && tag !== "__flip__"
&& !hasClass(this, "font-weight-bold")) {
$g.find("input").each(function () {
if (this.name.startsWith("pcc") && !this.checked)
return (full = false);
});
}
$g.find("input").each(function () {
if (this.name.startsWith("pcc")) {
var on = f.call(this);
if (full || on)
this.checked = on;
}
});
event.preventDefault();
}
var tags = [], functions = {}, isall = true;
$g.find("a.js-pcsel-tag").each(function () {
var tag = this.hash.substring(4);
if (tag !== "none") {
tags.push(tag);
functions[tag] = make_pcsel_members(tag);
}
});
$g.find("input").each(function () {
if (this.name.startsWith("pcc") && !this.checked) {
isall = false;
for (var i = 0; i < tags.length; ) {
if (functions[tags[i]].call(this))
tags.splice(i, 1);
else
++i;
}
return isall || tags.length !== 0;
}
});
$g.find("a.js-pcsel-tag").each(function () {
var tag = this.hash.substring(4);
if ($.inArray(tag, tags) >= 0 && (tag === "all" || !isall))
addClass(this, "font-weight-bold");
else
removeClass(this, "font-weight-bold");
});
}
$(document).on("click", "a.js-pcsel-tag", pcsel_tag);
$(document).on("change", "input.js-pcsel-tag", pcsel_tag);
$(function(){$("input.js-pcsel-tag").first().trigger("change")})');
Ht::stash_script('$(function(){$("input.js-pcsel-tag").first().trigger("change")});');

$summary = [];
$nrev = AssignmentCountSet::load($Me, AssignmentCountSet::HAS_REVIEW);
Expand All @@ -820,7 +752,7 @@ functions[tag] = make_pcsel_members(tag);
function bpSelector($i, $which) {
global $Qreq;
return Ht::select("bp$which$i", [], 0,
["class" => "need-pcselector badpairs", "data-pcselector-selected" => $Qreq["bp$which$i"], "data-pcselector-options" => "[\"(PC member)\",\"*\"]", "data-default-value" => $Qreq["bp$which$i"]]);
["class" => "need-pcselector uich badpairs", "data-pcselector-selected" => $Qreq["bp$which$i"], "data-pcselector-options" => "[\"(PC member)\",\"*\"]", "data-default-value" => $Qreq["bp$which$i"]]);
}

echo '<div class="g"></div><div class="relative"><table id="bptable"><tbody>', "\n";
Expand All @@ -842,25 +774,6 @@ function bpSelector($i, $which) {
}
echo "</tbody></table></div>\n";
$Conf->stash_hotcrp_pc($Me);
echo Ht::unstash_script('$("#bptable").on("change", "select.badpairs", function () {
if (this.value !== "none") {
var x = $$("badpairs");
x.checked || x.click();
}
});
$("#bptable a.js-badpairs-row").on("click", function () {
var tbody = $("#bptable > tbody"), n = tbody.children().length;
if (hasClass(this, "more")) {
++n;
tbody.append(\'<tr><td class="rentry nw">or &nbsp;</td><td class="lentry"><span class="select"><select name="bpa\' + n + \'" class="badpairs"></select></span> &nbsp;and&nbsp; <span class="select"><select name="bpb\' + n + \'" class="badpairs"></select></span></td></tr>\');
var options = tbody.find("select").first().html();
tbody.find("select[name=bpa" + n + "], select[name=bpb" + n + "]").html(options).val("none");
} else if (n > 1) {
--n;
tbody.children().last().remove();
}
return false;
});');


// Load balancing
Expand Down
11 changes: 6 additions & 5 deletions bulkassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function keep_browser_alive($assignset, $lineno, $line) {
} else {
$text .= " <code>" . htmlspecialchars(join(",", $line->as_array())) . "</code>";
}
echo Ht::unstash_script("\$\$('mailcount').innerHTML=" . json_encode_browser($text) . ";");
echo Ht::unstash_script("document.getElementById('mailcount').innerHTML=" . json_encode_browser($text) . ";");
flush();
while (@ob_end_flush()) {
}
Expand All @@ -66,8 +66,9 @@ function keep_browser_alive($assignset, $lineno, $line) {

function finish_browser_alive() {
global $csv_preparing;
if ($csv_preparing)
echo Ht::unstash_script("fold('mail',null)");
if ($csv_preparing) {
echo Ht::unstash_script("hotcrp.fold('mail',null)");
}
}

function complete_assignment($qreq, $callback) {
Expand Down Expand Up @@ -229,8 +230,8 @@ function complete_assignment($qreq, $callback) {
'</label>';
Ht::stash_script('$(function(){
$("#tsel").on("change",function(){
foldup.call(this,null,{f:this.value!=="review"});
foldup.call(this,null,{f:!/^(?:primary|secondary|(?:pc|meta)?review)$/.test(this.value),n:2});
hotcrp.foldup.call(this,null,{f:this.value!=="review"});
hotcrp.foldup.call(this,null,{f:!/^(?:primary|secondary|(?:pc|meta)?review)$/.test(this.value),n:2});
}).trigger("change")})');
$rev_rounds = $Conf->round_selector_options(null);
$expected_round = $Qreq->rev_round ? : $Conf->assignment_round_option(false);
Expand Down
2 changes: 1 addition & 1 deletion buzzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function kiosk_lookup($key) {
$buzzer_status["no_discussion"] = $no_discussion . '</div>';
echo Ht::unstash();
echo $Conf->make_script_file("scripts/buzzer.js");
echo Ht::unstash_script('start_buzzer_page(' . json_encode_browser($buzzer_status) . ')');
echo Ht::unstash_script('hotcrp.start_buzzer_page(' . json_encode_browser($buzzer_status) . ')');

echo "</tr></table></form>\n";
$Conf->footer();
4 changes: 2 additions & 2 deletions graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function echo_graph($searchable, $fg, $h2) {
if ($Graph == "procrastination") {
echo_graph(false, null, "Procrastination");
$rt = new ReviewTimes($Me);
echo Ht::unstash_script('$(function () { hotcrp_graph("#hotgraph",' . json_encode_browser($rt->json()) . ') })');
echo Ht::unstash_script('$(function () { hotcrp.graph("#hotgraph",' . json_encode_browser($rt->json()) . ') })');
}


Expand Down Expand Up @@ -146,7 +146,7 @@ function formulas_qrow($i, $q, $s, $status) {
} else if ($fg->type === FormulaGraph::BOXPLOT) {
$gtype = "boxplot";
}
echo Ht::unstash_script("\$(function () { hotcrp_graph(\"#hotgraph\", " . json_encode_browser($fg->graph_json()) . ") });"), "\n";
echo Ht::unstash_script("\$(function () { hotcrp.graph(\"#hotgraph\", " . json_encode_browser($fg->graph_json()) . ") });"), "\n";
} else {
echo "<h2>Formulas</h2>\n";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ function styles($tags, $match = 0, $no_pattern_fill = false) {
static function mark_pattern_fill($classes) {
$key = is_array($classes) ? join(" ", $classes) : $classes;
if (!isset(self::$multicolor_map[$key]) && strpos($key, " ") !== false) {
Ht::stash_script("make_pattern_fill(" . json_encode_browser($key) . ")");
Ht::stash_script("hotcrp.make_pattern_fill(" . json_encode_browser($key) . ")");
self::$multicolor_map[$key] = true;
}
}
Expand Down
20 changes: 10 additions & 10 deletions mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,15 @@ private function echo_prologue() {
echo '<div class="fn2 warning">Scroll down to send the prepared mail once the page finishes loading.</div>',
"</div>\n";
}
echo Ht::unstash_script("fold('mail',0,2)");
echo Ht::unstash_script("hotcrp.fold('mail',0,2)");
$this->started = true;
}

private function echo_mailinfo($nrows_done, $nrows_total) {
if (!$this->started) {
$this->echo_prologue();
}
$s = "\$\$('mailcount').innerHTML=\"";
$s = "document.getElementById('mailcount').innerHTML=\"";
if ($nrows_done >= $nrows_total) {
$s .= "100";
} else {
Expand All @@ -330,7 +330,7 @@ private function echo_mailinfo($nrows_done, $nrows_total) {
$s .= "% done.\";";
$m = plural($this->mcount, "mail") . ", "
. plural($this->mrecipients, "recipient");
$s .= "\$\$('mailinfo').innerHTML=\"<span class='barsep'>·</span>" . $m . "\";";
$s .= "document.getElementById('mailinfo').innerHTML=\"<span class='barsep'>·</span>" . $m . "\";";
if (!$this->sending && $this->groupable) {
$s .= "\$('.mail_groupable').show();";
}
Expand Down Expand Up @@ -533,7 +533,7 @@ private function run() {
$this->echo_prologue();
$nwarnings = $mailer->warning_count();
echo "<div id=\"foldmailwarn$nwarnings\" class=\"hidden\"><div class=\"warning\">", join("<br>", $mailer->warning_htmls()), "</div></div>";
echo Ht::unstash_script("\$\$('mailwarnings').innerHTML = \$\$('foldmailwarn$nwarnings').innerHTML;");
echo Ht::unstash_script("document.getElementById('mailwarnings').innerHTML = document.getElementById('foldmailwarn$nwarnings').innerHTML;");
}

if ($this->sending && $revinform !== null && $prow) {
Expand All @@ -548,7 +548,7 @@ private function run() {
if (empty($preperrors)) {
Conf::msg_error("No users match “" . $this->recip->unparse() . "” for that search.");
}
echo Ht::unstash_script("addClass(document.getElementById('foldmail'),'hidden');document.getElementById('mailform').action=" . json_encode_browser($this->conf->hoturl("mail", "check=1", Conf::HOTURL_RAW | Conf::HOTURL_POST)));
echo Ht::unstash_script("\$(\"#foldmail\").addClass('hidden');document.getElementById('mailform').action=" . json_encode_browser($this->conf->hoturl("mail", "check=1", Conf::HOTURL_RAW | Conf::HOTURL_POST)));
return false;
}

Expand All @@ -561,7 +561,7 @@ private function run() {
}
}
echo "</form>";
echo Ht::unstash_script("fold('mail', null);");
echo Ht::unstash_script("hotcrp.fold('mail', null);");
$this->conf->footer();
exit;
}
Expand Down Expand Up @@ -693,11 +693,11 @@ private function run() {
echo '<div class="fx9 g"></div>';

Ht::stash_script('function mail_recipients_fold(event) {
var plimit = $$("plimit");
foldup.call(this, null, {f: !!plimit && !plimit.checked, n: 8});
var plimit = document.getElementById("plimit");
hotcrp.foldup.call(this, null, {f: !!plimit && !plimit.checked, n: 8});
var sopt = $(this).find("option[value=\'" + this.value + "\']");
foldup.call(this, null, {f: sopt.hasClass("mail-want-no-papers"), n: 9});
foldup.call(this, null, {f: !sopt.hasClass("mail-want-since"), n: 10});
hotcrp.foldup.call(this, null, {f: sopt.hasClass("mail-want-no-papers"), n: 9});
hotcrp.foldup.call(this, null, {f: !sopt.hasClass("mail-want-since"), n: 10});
}
$("#to, #plimit").on("change", mail_recipients_fold);
$(function () { $("#to").trigger("change"); })');
Expand Down
6 changes: 3 additions & 3 deletions manualassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function saveAssignments($qreq, $reviewer) {
// Change PC member
echo "<table><tr><td><div class=\"assignpc_pcsel\">",
Ht::form(hoturl("manualassign"), array("method" => "get", "id" => "selectreviewerform"));
Ht::stash_script('hiliter_children("#selectreviewerform")');
Ht::stash_script('hotcrp.highlight_form_children("#selectreviewerform")');

$result = $Conf->qe_raw("select ContactInfo.contactId, count(reviewId)
from ContactInfo
Expand Down Expand Up @@ -310,8 +310,8 @@ function show_ass_elements($pl) {
echo '<div class="aab aabr aabig"><div class="aabut">',
Ht::submit("update", "Save assignments", ["class" => "btn-primary"]),
"</div></div></form>\n";
Ht::stash_script('hiliter_children("form.assignpc");$("#assrevimmediate").trigger("change");'
. "$(\"#showau\").on(\"change\", function () { foldup.call(this, null, {n:10}) })");
Ht::stash_script('hotcrp.highlight_form_children("form.assignpc");$("#assrevimmediate").trigger("change");'
. "$(\"#showau\").on(\"change\", function () { hotcrp.foldup.call(this, null, {n:10}) })");
}

echo '<hr class="c" />';
Expand Down
4 changes: 2 additions & 2 deletions paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function errorMsgExit($msg) {
json_exit(["ok" => false]);
} else {
confHeader();
Ht::stash_script("shortcut().add()");
Ht::stash_script("hotcrp.shortcut().add()");
$msg && Conf::msg_error($msg);
Conf::$main->footer();
exit;
Expand Down Expand Up @@ -541,7 +541,7 @@ function update_paper(Qrequest $qreq, $action) {
$j->blind = !!$Qreq->blind;
$j->draft = !!$Qreq->draft;
}
Ht::stash_script("papercomment.edit(" . json_encode_browser($j) . ")");
Ht::stash_script("hotcrp.edit_comment(" . json_encode_browser($j) . ")");
}
}

Expand Down
4 changes: 2 additions & 2 deletions profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function change_email_by_capability($Qreq) {
Ht::submit("go", "Change email", ["class" => "btn-primary", "value" => 1]),
Ht::submit("cancel", "Cancel", ["formnovalidate" => true]),
'</div></form>';
Ht::stash_script("focus_within(\$(\"#changeemailform\"));window.scroll(0,0)");
Ht::stash_script("hotcrp.focus_within(\$(\"#changeemailform\"));window.scroll(0,0)");
$Conf->footer();
exit;
}
Expand Down Expand Up @@ -728,6 +728,6 @@ function parseBulkFile($text, $filename) {
echo "</main></form>";

if (!$newProfile) {
Ht::stash_script('hiliter_children("#form-profile")');
Ht::stash_script('hotcrp.highlight_form_children("#form-profile")');
}
$Conf->footer();
2 changes: 1 addition & 1 deletion review.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function review_header() {
function review_error($msg) {
global $Conf;
review_header();
Ht::stash_script("shortcut().add()");
Ht::stash_script("hotcrp.shortcut().add()");
$msg && Conf::msg_error($msg);
Conf::$main->footer();
exit;
Expand Down
4 changes: 2 additions & 2 deletions reviewprefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function parseUploadedPreferences($text, $filename, $apply) {
}

echo Ht::select("reviewer", $sel, $reviewer->email, ["id" => "htctl-prefs-user"]), '</div>';
Ht::stash_script('$("#searchform select[name=reviewer]").on("change", function () { $$("searchform").submit() })');
Ht::stash_script('$("#searchform select[name=reviewer]").on("change", function () { $("#searchform")[0].submit() })');
}

echo '<div class="entryi"><label for="htctl-prefs-q">Search</label><div class="entry">',
Expand Down Expand Up @@ -305,7 +305,7 @@ function show_pref_element($pl, $name, $text, $extra = []) {
'<ul class="entry inline">', join('', $show_data), '</ul></div>';
}
echo "</form>";
Ht::stash_script("$(\"#showau\").on(\"change\", function () { foldup.call(this, null, {n:10}) })");
Ht::stash_script("$(\"#showau\").on(\"change\", function () { hotcrp.foldup.call(this, null, {n:10}) })");


// main form
Expand Down
2 changes: 1 addition & 1 deletion scripts/buzzer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var start_buzzer_page = (function ($) {
hotcrp.start_buzzer_page = (function ($) {
var info, has_format, muted, show_papers, initial = true, last_html = {};

function render_pc(pc) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/graph.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// graph.js -- HotCRP JavaScript library for graph drawing
// Copyright (c) 2006-2020 Eddie Kohler; see LICENSE.

var hotcrp_graph = (function ($, d3) {
hotcrp.graph = (function ($, d3) {
var BOTTOM_MARGIN = 30;
var PATHSEG_ARGMAP = {
m: 2, M: 2, z: 0, Z: 0, l: 2, L: 2, h: 1, H: 1, v: 1, V: 1, c: 6, C: 6,
Expand Down
Loading

0 comments on commit 5c4c69d

Please sign in to comment.