e47907296621d97a9d893556b3fb78ad4cbcc14b angie Fri Jun 14 11:19:21 2013 -0700 Libifying a javascript trick to detect that the back button has been pressed, and reload the page to redraw with the latest cart vars. refs #6152 diff --git src/hg/lib/jsHelper.c src/hg/lib/jsHelper.c index 9bbe544..07f834f 100644 --- src/hg/lib/jsHelper.c +++ src/hg/lib/jsHelper.c @@ -466,30 +466,53 @@ void jsBeginCollapsibleSection(struct cart *cart, char *track, char *section, char *sectionTitle, boolean isOpenDefault) /* Make the hidden input, collapse/expand button and <TR id=...> needed for utils.js's * setTableRowVisibility(). Caller needs to have already created a <TABLE> and <FORM>. */ { jsBeginCollapsibleSectionFontSize(cart, track, section, sectionTitle, isOpenDefault, "larger"); } void jsEndCollapsibleSection() /* End the collapsible <TR id=...>. */ { puts("</TD></TR>"); } +void jsReloadOnBackButton(struct cart *cart) +/* Add some javascript to detect that the back button (or reload) has been pressed, + * and to resubmit in that case to redraw the page with the latest cart contents. */ +// __detectback trick from +// http://siphon9.net/loune/2009/07/detecting-the-back-or-refresh-button-click/ +// Yes, I know this along with every other inline <script> here belongs in a .js module +{ +printf("<script>\n" + "document.write(\"<form style='display: none'><input name='__detectback' id='__detectback' " + "value=''></form>\");\n" + "function checkPageBackOrRefresh() {\n" + " if (document.getElementById('__detectback').value) {\n" + " return true;\n" + " } else {\n" + " document.getElementById('__detectback').value = 'been here';\n" + " return false;\n" + " }\n" + "}\n" + "window.onload = function() { " + " if (checkPageBackOrRefresh()) { window.location.replace('%s?%s'); } };\n" + "</script>\n", cgiScriptName(), cartSidUrlString(cart)); +} + static struct jsonElement *newJsonElement(jsonElementType type) // generic constructor for a jsonElement; callers fill in the appropriate value { struct jsonElement *ele; AllocVar(ele); ele->type = type; return ele; } struct jsonElement *newJsonString(char *str) { struct jsonElement *ele = newJsonElement(jsonString); ele->val.jeString = cloneString(str); return ele; }