b7b15a261ae3e28941a2891ee568c9b472fcda7e angie Wed Jul 30 14:44:14 2014 -0700 Added jsMakeSetClearContainer / jsEndContainer to jsHelper.c, and apppliedthem to a couple long lists of checkboxes in hgVai. While at it, I moved jsHelper.c's javascript-inlined-in-HTML out to a new .js file, jsHelper.js. diff --git src/hg/lib/jsHelper.c src/hg/lib/jsHelper.c index 0e9701a..9914549 100644 --- src/hg/lib/jsHelper.c +++ src/hg/lib/jsHelper.c @@ -27,140 +27,43 @@ * We accomplish this by maintaining two forms - a mainForm and a * hiddenForm. The hiddenForm maintains echo's of all the variables * in the main form, which get updated onChange of controls that need * to 'ripple' to other controls. The onChange also submits the * control. */ void jsInit() /* If this is the first call, set window.onload to the operations * performed upon loading a page and print supporting javascript. * Currently this just sets the page vertical position if specified on * CGI, and also calls jsWriteFunctions. * Subsequent calls do nothing, so this can be called many times. */ { if (! jsInited) { - puts( - -"\n" -"\n"); + // jsh_pageVertPos trick taken from + // http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html + puts(""); int pos = cgiOptionalInt("jsh_pageVertPos", 0); if (pos > 0) - printf("\n\n", pos); - jsWriteFunctions(); jsInited = TRUE; + jsIncludeFile("jsHelper.js", NULL); } } -void jsWriteFunctions() -/* Write out Javascript functions. */ -{ -hPrintf("\n\n"); -} - struct dyString *jsOnChangeStart() /* Start up an onChange string */ { struct dyString *dy = dyStringNew(1024); dyStringAppend(dy, "onChange=\""); return dy; } char *jsOnChangeEnd(struct dyString **pDy) /* Finish up javascript onChange command. */ { dyStringAppend(*pDy, "document.hiddenForm.submit();\""); return dyStringCannibalize(pDy); } @@ -264,30 +167,47 @@ "document.%s.jsh_pageVertPos.value = f_scrollTop(); ", form); return vertPosSet; } void jsMakeCheckboxGroupSetClearButton(char *buttonVar, boolean isSet) /* Make a button for setting or clearing a set of checkboxes with the same name. * Uses only javascript to change the checkboxes, no resubmit. */ { char javascript[256]; safef(javascript, sizeof(javascript), "var list = document.getElementsByName('%s'); " "for (var ix = 0; ix < list.length; ix++) {list[ix].checked = %s}", buttonVar, isSet ? "true" : "false"); cgiMakeOnClickButton(javascript, isSet ? JS_SET_ALL_BUTTON_LABEL : JS_CLEAR_ALL_BUTTON_LABEL); } +void jsMakeSetClearContainer() +/* Begin a wrapper div with class setClearContainer, plus 'Set all' and 'Clear all' buttons. + * This should be followed by a bunch of checkboxes, and then a call to jsEndContainer. */ +{ +puts("
\n" + "\n" + "\n" + "
" + ); +} + +void jsEndContainer() +/* End a wrapper div. */ +{ +puts("
"); +} + char *jsPressOnEnter(char *button) /* Returns a javascript statement that clicks button when the Enter key * has been pressed; typically this would go in a text input. * jsInit must be called first. * Do not free return value! */ { if (! jsInited) errAbort("jsPressOnEnter: jsInit must be called first."); static char poe[2048]; safef(poe, sizeof(poe), "return pressOnEnter(event, %s);", button); return poe; } void jsIncludeFile(char *fileName, char *noScriptMsg) {