diff options
author | Yorhel <git@yorhel.nl> | 2010-11-21 12:21:32 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-11-21 12:21:32 +0100 |
commit | 66e8cbc808775356ea5beeea2f53ab6958ab6c2e (patch) | |
tree | 7c0c882fe225645d341e794226ca8006b7f8b2eb /util/jsgen.pl | |
parent | d93c2ae8db73c8936cc7261306886dcf3f64ccf9 (diff) |
Implemented the client side of the new release filter system
This isn't entirely functional yet, the server side will need to be
rewritten as well. And after that new filters should be added and this
system should also be used for VN/producer search.
script.js is getting quite large with all those new translation strings,
it may be an idea to generate a separate .js file for each language and
only load the one being used.
I won't have a valid reason to feel bored anytime soon, at least...
Diffstat (limited to 'util/jsgen.pl')
-rwxr-xr-x | util/jsgen.pl | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/util/jsgen.pl b/util/jsgen.pl index 27cbc6da..4d82bc95 100755 --- a/util/jsgen.pl +++ b/util/jsgen.pl @@ -56,8 +56,7 @@ sub l10n { for my $key (sort keys %lang) { $r .= ",\n" if !$first; $first = 0; - # let's assume all L10N keys are valid JS variable names - $r .= sprintf qq| "%s": {\n|, $key; + $r .= sprintf qq| %s: {\n|, $key !~ /^[a-z0-9_]+$/ ? "'$key'" : $key;; my $firstk = 1; for (sort keys %{$lang{$key}}) { $r .= ",\n" if !$firstk; @@ -77,6 +76,27 @@ sub l10n { } +# screen resolution information, suitable for usage in filFSelect() +sub resolutions { + my $res_cat = ''; + my $resolutions = ''; + my $comma = 0; + for my $i (0..$#{$S{resolutions}}) { + my $r = $S{resolutions}[$i]; + if($res_cat ne $r->[1]) { + $resolutions .= ']' if $res_cat; + $resolutions .= ",['$r->[1]',"; + $res_cat = $r->[1]; + $comma = 0; + } + $resolutions .= ($comma ? ',' : '')."[$i,'$r->[0]']"; + $comma = 1; + } + $resolutions .= ']' if $res_cat; + return "resolutions = [ $resolutions ];\n"; +} + + sub jsgen { # JavaScript::Minifier::XS doesn't correctly handle perl's unicode, # so just do everything in raw bytes instead. @@ -87,6 +107,12 @@ sub jsgen { $head .= sprintf "rlst_rstat = [ %s ];\n", join ', ', map qq{"$_"}, @{$S{rlst_rstat}}; $head .= sprintf "rlst_vstat = [ %s ];\n", join ', ', map qq{"$_"}, @{$S{rlst_vstat}}; $head .= sprintf "cookie_prefix = '%s';\n", $S{cookie_prefix}; + $head .= sprintf "age_ratings = [ %s ];\n", join ',', map !defined $_ ? -1 : $_, @{$S{age_ratings}}; + $head .= sprintf "languages = [ %s ];\n", join ', ', map qq{"$_"}, @{$S{languages}}; + $head .= sprintf "platforms = [ %s ];\n", join ', ', map qq{"$_"}, @{$S{platforms}}; + $head .= sprintf "media = [ %s ];\n", join ', ', map qq{"$_"}, sort keys %{$S{media}}; + $head .= sprintf "release_types = [ %s ];\n", join ', ', map qq{"$_"}, sort @{$S{release_types}}; + $head .= resolutions(); open my $NEWJS, '>', "$ROOT/static/f/script.js" or die $!; print $NEWJS $JavaScript::Minifier::XS::VERSION ? JavaScript::Minifier::XS::minify($head.$js) : $head.$js; close $NEWJS; |