Merge branch 'master' into newmc
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 4 Aug 2015 13:04:40 +0000 (16:04 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 4 Aug 2015 13:04:40 +0000 (16:04 +0300)
1  2 
js/90-mobilenav.js
js/90-nav.js
js/90-themes.js
make_static.PL
tmpl/skel.en

diff --combined js/90-mobilenav.js
index 9efe8fccb7b968b8759ab0d2cb78f50d51152771,bd47c8f90091af3f3fe1744931e6bae949f25748..981c843b7afc1f641cb6c9931956e654349d37b3
@@@ -1,6 -1,6 +1,6 @@@
  $(function(){
-       const nav = $('nav')[0];
+       const nav = q('nav');
        nav.classList.add('hidden-xs');
-       $('#title')[0].insertAdjacentHTML('beforebegin', '<div class="text-center visible-xs-block">Tap title to toggle menu</div>');
+       q('#title').insertAdjacentHTML('beforebegin', '<div class="text-center visible-xs-block">Tap title to toggle menu</div>');
 -      $('#title').on('click', () => nav.classList.toggle('hidden-xs'));
 +      $('#title,#logo').on('click', () => nav.classList.toggle('hidden-xs'));
  });
diff --combined js/90-nav.js
index 746ccd70eda3e1f66c811eed9704c3600d68ee16,36aec02c3b8c9b9229b6129778e78ba3fb9db93d..c6b776e0d721a3bf1d22389300a669c252c40fd2
@@@ -6,12 -6,11 +6,12 @@@ const NAVS = 
        us: /^\/us\//,
        account: /^\/account$/,
        contribute: /^\/contribute$/,
 +      about: /^\/about$/,
  };
  
  $(function(){
        const path = location.pathname;
        for (const nav in NAVS)
                if(path.match(NAVS[nav]))
-                       $('#nav-' + nav)[0].classList.add('active');
+                       q('#nav-' + nav).classList.add('active');
  });
diff --combined js/90-themes.js
index 6a4c6809dbbb3a7be503031d4823ebf0bcb1033d,a94d1300d9434140fc60004ea80eff1a09fb30fe..50834da65622a6ffd71536067798d34a8ad54d95
@@@ -3,15 -3,8 +3,14 @@@ function set_style(name, trans)
                document.body.classList.add('transition-color');
                setTimeout(() => document.body.classList.remove('transition-color'), 1000);
        }
-       $('link[title]').each(e => e.disabled = true);
-       $('link[title="' + name + '"]')[0].disabled = false;
+       q('html').className = name;
        localStorage.setItem("theme", name);
 +      $(function() {
 +              if(name == 'slate' || name == 'cyborg')
 +                      $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/light', 'logos/dark')));
 +              else
 +                      $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/dark', 'logos/light')));
 +      });
  }
  
  $(function() {
@@@ -19,7 -12,7 +18,7 @@@
                '<li><a role="button" data-theme="cyborg">Black</a>' +
                '<li><a role="button" data-theme="slate">Grey</a>' +
                '<li><a role="button" data-theme="readable">White</a></ul>';
-       const sidebar = $('#sidebar')[0];
+       const sidebar = q('#sidebar');
        sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
        $('#themes a').on('click', e => set_style(e.target.dataset.theme, true));
  });
diff --combined make_static.PL
index 06c9eeea791cd9e8da281f4d43fbb576d1398c4e,f599a56b5db514f6b15e87a1e9ae71b89d4afa2b..1e338addd1dc2d2657a6031d3cd71faa983325c2
@@@ -6,14 -6,12 +6,14 @@@ use CSS::Minifier::XS qw/minify/
  use Digest::SHA qw/sha256_base64/;
  use IO::Compress::Gzip qw/gzip/;
  use File::Slurp qw/read_file write_file edit_file_lines/;
 +use SVG::SpriteMaker;
  use File::Which;
  use List::Util qw/first/;
  
  mkdir 'static';
  mkdir 'static/css';
  mkdir 'static/js';
 +mkdir 'static/logos';
  
  sub gzip_file {
        my ($file) = @_;
@@@ -28,25 -26,6 +28,25 @@@ sub write_gzfile 
        gzip_file $file
  }
  
 +sub sprite_name {
 +      my ($name) = $_[0] =~ m,/(.*)\.svg,;
 +      "logo-$name"
 +}
 +
 +sub make_logos {
 +      my @logos = <logos/*>;
 +      my $logos = make_sprite \&sprite_name, @logos;
 +      my @logos_light;
 +      for (<logos/*>) {
 +              my $light = s/logos/logos-light/r;
 +              push @logos_light, -f $light ? $light : $_;
 +      }
 +      my $logos_light = make_sprite \&sprite_name, @logos_light;
 +
 +      write_gzfile 'static/logos/dark.svg', $logos->render;
 +      write_gzfile 'static/logos/light.svg', $logos_light->render;
 +}
 +
  sub read_css_into_blocks {
        my ($file) = @_;
        my (@blocks, $block);
        \@blocks
  }
  
 -my $default_theme = 'cyborg';
++my $default_theme = 'slate';
+ sub theme_prefix {
+       my ($theme, $decl, $default) = @_;
+       return $decl if $theme eq $default_theme || !$decl;
+       return '' if $decl eq $default;
+       $default =~ s/[^{]*{\n//;
+       $default =~ s/\n}[^}]*//;
+       $decl =~ s/^$_$//m for split "\n", $default;
+       $decl =~ s/\n+/\n/g;
+       my $prefix = "html.$theme";
+       my ($first_line) = $decl =~ /([^{]*){/;
+       $first_line =~ s/(,\s+)/$1 $prefix /g;
+       $first_line = "$prefix $first_line";
+       $decl =~ s/([^{]*){/$first_line\{/;
+       $decl
+ }
  sub make_css {
-       my %css;
-       $css{common} .= read_file $_ for <css/*.css>;
+       my $css = join '', map { read_file $_ } <css/*.css>;
  
-       my (%themes, $rndtheme);
+       my (%themes);
        for (<css/themes/*>) {
-               ($rndtheme) = m,themes/(.*)\.css,;
-               $themes{$rndtheme} = read_css_into_blocks $_;
+               my ($theme) = m,themes/(.*)\.css,;
+               $themes{$theme} = read_css_into_blocks $_;
        }
+       my @themes = sort grep { $_ ne $default_theme } keys %themes;
  
        while (grep { scalar @$_ } values %themes) {
                my %blocks = map { $_ => (shift @{$themes{$_}}) // '' } keys %themes;
-               if (grep { $_ ne $blocks{$rndtheme} } values %blocks) {
-                       $css{$_} .= $blocks{$_} for keys %themes;
-               } else {
-                       $css{common} .= $blocks{$rndtheme};
-               }
+               $css .= $blocks{$default_theme};
+               $css .= theme_prefix $_, $blocks{$_}, $blocks{$default_theme} for @themes
        }
  
-       write_gzfile "static/css/$_.css", minify $css{$_} for keys %css
+       write_gzfile "static/css/all.css", minify $css
  }
  
  sub make_js {
        system 'cp', '-rp', 'js', 'static/';
  }
  
- my $css_mtime = -M 'static/css/slate.css' // 0;
 +my $sprite_mtime = -M 'static/logos/dark.svg' // 0;
 +for (<logos/*>, <logos-light/*>) {
 +      if (!$sprite_mtime || $sprite_mtime > -M) {
 +              make_logos;
 +              last
 +      }
 +}
 +
+ my $css_mtime = -M 'static/css/all.css' // 0;
  for (<css/*>, <css/themes/*>) {
        if (!$css_mtime || $css_mtime > -M) {
                make_css;
@@@ -118,4 -106,4 +135,4 @@@ edit_file_lines 
        return unless $file;
        my $hash = sha256_base64 scalar read_file $file;
        s/integrity=".*"/integrity="sha256-$hash="/;
 -} 'tmpl/skel.en'
 +} 'tmpl/skel.en';
diff --combined tmpl/skel.en
index cb7156acf72680be062986850032996912de427b,32eb1f7ba264981e319f9ba9a28b856c94196e00..6406c51a233118553e2e11e798c40fc47b7d582a
@@@ -3,51 -3,33 +3,48 @@@
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
- <link href="/static/css/common.css" rel="stylesheet" integrity="x">
- <link href="/static/css/cyborg.css" title="cyborg" rel="alternate stylesheet" integrity="x">
- <link href="/static/css/slate.css" title="slate" rel="stylesheet" integrity="x">
- <link href="/static/css/readable.css" title="readable" rel="alternate stylesheet" integrity="x">
 +<link href="/static/favicon.png" rel="shortcut icon">
+ <link href="/static/css/all.css" rel="stylesheet" integrity="x">
  <script src="/static/js/all.js" type="text/javascript" async defer integrity="x"></script>
  
  <body>
  <div class="container-fluid">
  <nav role="navigation">
  <ul class="nav nav-pills nav-justified">
 -<li id="nav-home"><a href="/">Gruntmaster 6000</a>
 +<li id="nav-home"><a href="/">Home</a>
  <li id="nav-pb"><a href="/pb/">Problems</a>
  <li id="nav-ct"><a href="/ct/">Contests</a>
  <li id="nav-log"><a href="/log/">Job log</a>
  <li id="nav-us"><a href="/us/">Users</a>
  <li id="nav-account" static="no"><a href="/account">Account</a>
 +<li id="nav-about"><a href="/about">About / Help</a>
  <li id="nav-contribute"><a href="/contribute">Contribute!</a>
  
  </ul>
  </nav>
  
 +<img id="logo" class="center-block" src="/static/logos/dark.svg#logo-mindcoding" width="600px" height="152px">
 +
  <h1 id="title">TITLE</h1>
 -<div id="static" class="alert alert-info" static="yes">This is a static version of Gruntmaster 6000.</div>
 +<div id="static" class="alert alert-info" static="yes">This is a static version of MindCoding, useful when the <a class="alert-link" href="https://mindcoding.ro/">regular version</a> is overloaded.</div>
  
  <div id="result"></div>
  
  <main id="content">Content goes here</main>
  
 +<div id="webchat"><a href="http://webchat.oftc.net/?channels=%23mindcoding" target="_blank">Webchat</a></div>
 +
 +<div id="sponsors">
 +</div>
 +
  <footer>
 -Dilmom: Why don't you call your product the Gruntmaster 6000?<br>
 -Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000?<br>
 -Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable.
 +<div class="row">
 +<div class="col-md-6 text-center">
 +<a href="http://www.societatea-hermes.ro"><img src="/static/logos/dark.svg#logo-hermes" alt="Societatea Hermes" width="164px" height="100px"></a>
 +</div>
 +
 +<div class="col-md-6 text-center">
 +<a href="http://www.facebook.com/mindcodingcluj"><img src="/static/logos/dark.svg#logo-facebook" alt="MindCoding Facebook page" width="100px" height="100px"></a>
 +</div>
 +</div>
  </footer>
This page took 0.019033 seconds and 4 git commands to generate.