0db9775f8ef4f63fadacadbc5fd46573cb6481f0
max
  Sat May 5 17:38:00 2012 -0700
inversed order of stylesheet/background for themes, added more docs
diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index bebf67d..4371e6c 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -1503,61 +1503,68 @@
 #endif /* GBROWSE */
 htmlEnd();		/* because it is in a higher library */
 }
 
 void cartHtmlEnd()
 /* Write out HTML footer and get rid or error handler. */
 {
 if (inWeb)
     webEnd();	/*	this does googleAnalytics for a lot of CGIs	*/
 else
     cartFooter();
 popWarnHandler();
 }
 
 void setThemeFromCart(struct cart *cart) 
-/* If 'theme' variable is set in cart: overwrite background with the one from
- * defined for this theme Also set the "styleTheme", with additional styles
- * that can overwrite the main style settings */
-{
-// get theme from cart and use it to get background file from config
+/* If 'theme' variable is set in cart: overwrite background with the one 
+ * defined for this theme in hg.conf. Also set the "styleTheme", with additional
+ * styles that can overwrite the main style settings 
+ * config syntax in hg.conf is:
+ *   browser.theme.<name>=<cssFile>
+ * or:
+ *   browser.theme.<name>=<cssFile>,<backgroundFile>
+ * */
+{
+// get theme from cart and use it to get style/background file from config
 char *cartTheme = cartOptionalString(cart, "theme");
 if (cartTheme==NULL)
     return;
 
 char *themeKey = catTwoStrings("browser.theme.", cartTheme);
 char *themeDefLine = cfgOption(themeKey);
 freeMem(themeKey);
 if (themeDefLine == NULL)
     return;
 
-char * background = cloneString(themeDefLine);
-chopSuffixAt(background, ',');
-htmlSetBackground(background);
-
-// set css style (optional, after ',' in hg.conf line)
-if (! stringIn(",", themeDefLine))
-    return;
+// set style file 
 char * styleFile = cloneString(themeDefLine);
-styleFile = chopPrefixAt(styleFile, ',');
-
+chopSuffixAt(styleFile, ',');
+if (strlen(styleFile)==0)
+    return;
 char * link = webTimeStampedLinkToResourceOnFirstCall(styleFile,TRUE); // resource file link wrapped in html
-if (link)
+if (link!=NULL)
     {
     htmlSetStyleTheme(link); // for htmshell.c, used by hgTracks
     webSetStyle(link);       // for web.c, used by hgc
     }
+
+// set background file (optional, after ',' in hg.conf line)
+if (! stringIn(",", themeDefLine))
+    return;
+char * backgroundFile = cloneString(themeDefLine);
+backgroundFile = chopPrefixAt(backgroundFile, ',');
+htmlSetBackground(backgroundFile);
 }
 
 void cartHtmlShellWithHead(char *head, char *title, void (*doMiddle)(struct cart *cart),
 	char *cookieName, char **exclude, struct hash *oldVars)
 /* Load cart from cookie and session cgi variable.  Write web-page
  * preamble including head and title, call doMiddle with cart, and write end of web-page.
  * Exclude may be NULL.  If it exists it's a comma-separated list of
  * variables that you don't want to save in the cart between
  * invocations of the cgi-script. */
 {
 struct cart *cart;
 char *db, *org, *pos, *clade=NULL;
 char titlePlus[128];
 char extra[128];
 pushWarnHandler(cartEarlyWarningHandler);