cinera: Single browser tab and no autofocus mode

This allows search result links to open in the same tab, and prevents
automatic scrolling to the search input box on page load
This commit is contained in:
Matt Mascarenhas 2018-07-03 15:26:17 +01:00
parent 92909a9ee9
commit aa0a8ba327
2 changed files with 28 additions and 12 deletions

View File

@ -16,7 +16,7 @@ typedef struct
version CINERA_APP_VERSION = {
.Major = 0,
.Minor = 5,
.Patch = 63
.Patch = 64
};
// TODO(matt): Copy in the DB 3 stuff from cinera_working.c
@ -92,6 +92,7 @@ enum
MODE_EXAMINE = 1 << 2,
MODE_NOCACHE = 1 << 3,
MODE_NOPRIVACY = 1 << 4,
MODE_SINGLETAB = 1 << 5
} modes;
enum
@ -2290,9 +2291,6 @@ PrintUsage(char *BinaryLocation, config *DefaultConfig)
"\e[0m -s <style>\n"
" Set the style / theme, corresponding to a cinera__*.css file\n"
" This is equal to the \"project\" field in the HMML files by default\n"
" -q\n"
" Quit after syncing with annotation files in project input directory\n"
" \e[1;30mUNSUPPORTED: This is likely to be removed in the future\e[0m\n"
"\n"
" Project Input Paths\n"
" -d <annotations directory>\n"
@ -2325,14 +2323,19 @@ PrintUsage(char *BinaryLocation, config *DefaultConfig)
" -o <output location>\n"
" Override default output player location (\"%s\")\n"
"\n"
" -e\n"
" Display (examine) index file and exit\n"
" -1\n"
" Open search result links in the same browser tab and do not autofocus\n"
" search input box on page load\n"
" NOTE: Ideal for a guide embedded in an iframe\n"
" -f\n"
" Force integration with an incomplete template\n"
" -g\n"
" Ignore video privacy status\n"
" NOTE: For use with projects whose videos are known to all be public,\n"
" to save us having to check their privacy status\n"
" -q\n"
" Quit after syncing with annotation files in project input directory\n"
" \e[1;30mUNSUPPORTED: This is likely to be removed in the future\e[0m\n"
" -w\n"
" Force quote cache rebuild \e[1;30m(memory aid: \"wget\")\e[0m\n"
"\n"
@ -2341,6 +2344,9 @@ PrintUsage(char *BinaryLocation, config *DefaultConfig)
" -u <seconds>\n"
" Override default update interval (%d)\n"
//" -c config location\n"
"\n"
" -e\n"
" Display (examine) index file and exit\n"
" -v\n"
" Display version and exit\n"
" -h\n"
@ -5504,25 +5510,27 @@ IndexToBuffer(index *Index, buffers *CollationBuffers) // NOTE(matt): This guy m
}
char *Theme = StringsDiffer(Config.Theme, "") ? Config.Theme : Config.ProjectID;
int Allowance = StringLength(Theme) * 2 + StringLength(Config.ProjectID) + StringLength(Config.BaseURL) + StringLength(Config.PlayerLocation);
char queryContainer[656 + Allowance]; // NOTE(matt): Update the size if changing the string
int Allowance = StringLength(Theme) * 2 + StringLength(Config.ProjectID) + StringLength(Config.BaseURL) + StringLength(Config.PlayerLocation) + (Config.Mode & MODE_SINGLETAB ? 0 : 10);
char queryContainer[659 + Allowance]; // NOTE(matt): Update the size if changing the string
CopyString(queryContainer, sizeof(queryContainer),
"<div class=\"cineraQueryContainer %s\">\n"
" <label for=\"query\">Query:</label>\n"
" <div class=\"inputContainer\">\n"
" <input type=\"text\" id=\"query\" autofocus=\"\">\n"
" <input type=\"text\" id=\"query\"%s>\n"
" <div class=\"spinner\">\n"
" Downloading data...\n"
" </div>\n"
" </div>\n"
" </div>\n"
" <div id=\"cineraResultsSummary\">Found: 0 episodes, 0 markers, 0h 0m 0s total.</div>\n"
" <div id=\"cineraResults\"></div>\n"
" <div id=\"cineraResults\" data-single=\"%d\"></div>\n"
"\n"
" <div id=\"cineraIndex\" class=\"%s\" data-project=\"%s\" data-baseURL=\"%s\" data-playerLocation=\"%s\">\n"
" <div id=\"cineraIndexSort\">Sort: Old to New &#9206;</div>\n"
" <div id=\"cineraIndexEntries\">\n",
Theme,
Config.Mode & MODE_SINGLETAB ? "": " autofocus",
Config.Mode & MODE_SINGLETAB ? 1 : 0,
Theme,
Config.ProjectID,
Config.BaseURL,
@ -6342,10 +6350,13 @@ main(int ArgC, char **Args)
}
char CommandLineArg;
while((CommandLineArg = getopt(ArgC, Args, "a:b:B:c:d:efghi:j:l:m:n:o:p:qr:R:s:t:u:vwx:y:")) != -1)
while((CommandLineArg = getopt(ArgC, Args, "1a:b:B:c:d:efghi:j:l:m:n:o:p:qr:R:s:t:u:vwx:y:")) != -1)
{
switch(CommandLineArg)
{
case '1':
Config.Mode |= MODE_SINGLETAB;
break;
case 'a':
Config.PlayerLocation = StripSurroundingSlashes(optarg);
break;
@ -6647,6 +6658,7 @@ main(int ArgC, char **Args)
" Player Page Prefix: \e[1;30m(hardcoded)\e[0m\t%s\n"
"\n"
"Modes\n"
" Single browser tab: \e[1;30m(-1)\e[0m\t\t%s\n"
" Force template integration: \e[1;30m(-f)\e[0m\t%s\n"
" Ignore video privacy status: \e[1;30m(-g)\e[0m\t%s\n"
" Quit after sync: \e[1;30m(-q)\e[0m\t\t%s\n"
@ -6677,6 +6689,7 @@ main(int ArgC, char **Args)
StringsDiffer(Config.PlayerLocation, "") ? Config.PlayerLocation : "(directly descended from base)",
StringsDiffer(Config.PlayerURLPrefix, "") ? Config.PlayerURLPrefix : Config.ProjectID,
Config.Mode & MODE_SINGLETAB ? "on" : "off",
Config.Mode & MODE_FORCEINTEGRATION ? "on" : "off",
Config.Mode & MODE_NOPRIVACY ? "on" : "off",
Config.Mode & MODE_ONESHOT ? "on" : "off",

View File

@ -54,7 +54,10 @@ dayContainerPrototype.appendChild(markerListPrototype);
var markerPrototype = document.createElement("A");
markerPrototype.classList.add("marker");
markerPrototype.setAttribute("target", "_blank");
if(resultsContainer.getAttribute("data-single") == 0)
{
markerPrototype.setAttribute("target", "_blank");
}
var highlightPrototype = document.createElement("B");