]> iEval git - plack-app-gruntmaster.git/commitdiff
Upgrade to ECMAScript 6
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 17 Apr 2015 20:34:27 +0000 (23:34 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 18 Apr 2015 08:52:00 +0000 (11:52 +0300)
12 files changed:
js/10-modal.js
js/80-sidebar.js
js/90-divine-format.js
js/90-form.js
js/90-mobilenav.js
js/90-nav.js
js/90-reqjs.js
js/90-themes.js
js/90-timers.js
js/90-tracker.js
js/95-login.js
make_static.PL

index 980bab79a987ae6001413765e665d6fb7390d69c..1c290ef1252ce3d236f7c4208efd3fd45c4f3704 100644 (file)
@@ -1,4 +1,4 @@
-var modal, hiding;
+let modal, hiding;
 
 function show_modal () {
        modal.classList.remove('hidden');
@@ -13,19 +13,17 @@ function hide_modal () {
 
 $(function() {
        modal = $('.modal')[0];
-       $(modal).on('transitionend', function (){
+       $(modal).on('transitionend', el => {
                if(!document.body.classList.contains('modal-open'))
                        modal.classList.add('hidden');
        });
-       $('.backdrop,.modal').each(function(el){
-               document.body.appendChild(el);
-       });
-       $('#solution').on('click', function (e){
+       $('.backdrop,.modal').each(el => document.body.appendChild(el) );
+       $('#solution').on('click', e => {
                show_modal();
                e.preventDefault();
        });
        $('.backdrop').on('click', hide_modal);
-       window.onkeyup = function (event) {
+       window.onkeyup = event => {
                if (event.keyCode === 27)
                        hide_modal();
        }
index ee777444e48bf8ba5b3c4596baebb4b823c497fb..505dc0f1992f781dbd260f3d24b7bc173091c886 100644 (file)
@@ -1,6 +1,6 @@
 $(function() {
        if(!document.getElementById('sidebar')) {
-        var content = $('main')[0];
+        let content = $('main')[0];
                content.innerHTML = '<div class="col-md-9">' + content.innerHTML + '</div><aside id="sidebar" class="col-md-3"></aside>';
                content.classList.add('row');
     }
index e44bf908b4a3395a36fd6e5e734803c54aca0da2..ab5a5f29fae79797592f7aae43fcef65d9e96e95 100644 (file)
@@ -37,6 +37,4 @@ function divine_format() {
                $('#prog_format')[0].value = ext_table[ext];
 }
 
-$(function() {
-       $('#prog').on('change', divine_format);
-});
+$(() => $('#prog').on('change', divine_format));
index 25a11f771640cdaeaa71bd1df4cc7e72b41731eb..0b7677642b5e484469da97efef0f4c29d57b9fa3 100644 (file)
@@ -1,17 +1,14 @@
 $(function(){
-       $('.jsform > input[type="submit"]').on('click', function(e){
-               var form_data = new FormData(this.parentElement);
-               var form = this.parentNode;
-               var xhr = new XMLHttpRequest();
+       let result = $('#result')[0];
+       $('.jsform > input[type="submit"]').on('click', e => {
+               let form_data = new FormData(this.parentElement);
+               let form = this.parentNode;
+               let xhr = new XMLHttpRequest();
                xhr.open(form.getAttribute('method'), form.getAttribute('action'));
-               xhr.onload = function() {
-                       $('#result')[0].innerHTML = this.responseText;
-               };
-               xhr.onerror = function() {
-                       $('#result')[0].innerHTML = 'Error!';
-               };
+               xhr.onload = () => result.innerHTML = this.responseText;
+               xhr.onerror = () => result.innerHTML = 'Error!';
                window.scrollTo(0, 0);
-               $('#result')[0].innerHTML = 'Loading...';
+               result.innerHTML = 'Loading...';
                xhr.send(form_data);
                e.preventDefault();
        });
index 8577ecc6a2e3f411328f2eb9c990e91382f09650..fb575d9288a34f375e1118418be5181a87fdfeed 100644 (file)
@@ -3,7 +3,5 @@ $(function(){
                return;
        $('#title')[0].insertAdjacentHTML('beforebegin', '<div class="text-center">Tap title to toggle menu</div>');
        $('nav')[0].classList.add('hidden');
-       $('#title').on('click', function () {
-               $('nav')[0].classList.toggle('hidden');
-       });
+       $('#title').on('click', () => $('nav')[0].classList.toggle('hidden'));
 });
index 4b59af41d86a7d7e1cbbd9cc798f226766235b30..03dcb8257931dff52d9775d8aea71e2bd23a8db5 100644 (file)
@@ -1,16 +1,16 @@
-var NAVS = {
-       'home': /^\/$/,
-       'pb': /^\/(?:pb|sol)\//,
-       'ct': /^\/(?:ct|st|ed)\//,
-       'log': /^\/log\//,
-       'us': /^\/us\//,
-       'account': /^\/account$/,
-       'contribute': /^\/contribute$/,
+const NAVS = {
+       home: /^\/$/,
+       pb: /^\/(?:pb|sol)\//,
+       ct: /^\/(?:ct|st|ed)\//,
+       log: /^\/log\//,
+       us: /^\/us\//,
+       account: /^\/account$/,
+       contribute: /^\/contribute$/,
 };
 
 $(function(){
-       var path = location.pathname;
-       for (var nav in NAVS)
+       let path = location.pathname;
+       for (let nav in NAVS)
                if(path.match(NAVS[nav]))
                        $('#nav-' + nav)[0].classList.add('active');
 });
index c4b492f287d6a2003a1022d84fadf61b220eaaca..e35dde5cc12f045e0f1af3d931aa88b891d18575 100644 (file)
@@ -1,5 +1 @@
-$(function() {
-               $('.reqjs').each(function(e){
-                       e.classList.remove('reqjs');
-               });
-});
+$(() => $('.reqjs').each(e => e.classList.remove('reqjs')));
index c280266f466e6ac7506ce355df3d4c8767bcdceb..c87291949e978a5af15fba9207b7ed72e104a09a 100644 (file)
@@ -1,7 +1,5 @@
 function set_style(name){
-       $('link[rel~="stylesheet"]').each(function (e){
-               e.disabled = true;
-       });
+       $('link[rel~="stylesheet"]').each(e => e.disabled = true);
        $('link[title="' + name + '"]')[0].disabled = false;
        localStorage.setItem("theme", name);
 }
@@ -13,12 +11,10 @@ $(function() {
                '<li><a role="button" data-theme="readable">White</a></ul>';
        var sidebar = $('#sidebar')[0];
        sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
-       $('#themes a').on('click', function(e){
-               set_style(this.dataset.theme);
-       });
+       $('#themes a').on('click', e => set_style(this.dataset.theme));
 });
 
-var theme = localStorage.getItem("theme");
+let theme = localStorage.getItem("theme");
 if(theme) {
        if(theme == "cerulean" || theme == "cosmo")
                theme = "readable";
index 7281f6f3fd689a9d37c364ff335886660802038f..af971be22f1a9ed320249d8c4ed999da291b99f3 100644 (file)
@@ -23,9 +23,7 @@ function update_timer(timer){
        }
 }
 
-$(function() {
-       $('.timer').each(function(item){
-               update_timer(item);
-               setInterval(function(){update_timer(item)}, 1000);
-       });
-});
+$(() => $('.timer').each(item => {
+       update_timer(item);
+       setInterval(() => update_timer(item), 1000);
+}));
index 42ee1f78c16bf602f2884d86737ce91fc032646e..5e1c9a20287359597de90525795203bcbd6f9f40 100644 (file)
@@ -1,30 +1,25 @@
-var TICK  = '<span class="tick tracker-mark">✔</span>';
-var XMARK = '<span class="x tracker-mark">✘</span>';
+const TICK  = '<span class="tick tracker-mark">✔</span>';
+const XMARK = '<span class="x tracker-mark">✘</span>';
 
 function clean_tracker(){
-       $('.tracker-mark').each(function(e){
-               e.parentNode.removeChild(e);
-       });
-       $('.tracker-info').each(function(e){
+       $('.tracker-mark').each(e => e.parentNode.removeChild(e));
+       $('.tracker-info').each(e => {
                e.classList.remove('tracker-info');
                e.classList.remove('info');
        });
 }
 
-var tracker;
+let tracker;
 
 function update_tracker(){
-       var data = localStorage.getItem('tracker_data');
-       var user = localStorage.getItem('tracker_username');
+       let data = localStorage.getItem('tracker_data');
+       let user = localStorage.getItem('tracker_username');
        if(!data)
                return;
        data = JSON.parse(data);
-       var solved = {};
-       var attempted = {};
-       var solvednr = 0;
-       var attemptednr = 0;
-       data.problems.forEach(function(e){
-               if(e.solved){
+       let contests = {}, solved = {}, attempted = {}, solvednr = 0, attemptednr = 0;
+       data.problems.forEach(e => {
+               if(e.solved) {
                        solved[e.problem] = 1;
                        solvednr++;
                } else {
@@ -33,10 +28,7 @@ function update_tracker(){
                }
        });
 
-       var contests = {};
-       data.contests.forEach(function(e){
-               contests[e.contest] = 1;
-       });
+       data.contests.forEach(e => contests[e.contest] = 1);
 
        clean_tracker();
        $('#tracker_userlink')[0].innerHTML = data.name;
@@ -46,8 +38,8 @@ function update_tracker(){
        $('#tracker_log')[0].setAttribute('href', '/log/?owner=' + user);
 
        if(location.pathname == '/pb/')
-               $('table .name a').each(function(el) {
-                       var id = el.getAttribute('href').split('?', 2)[0];
+               $('table .name a').each(el => {
+                       let id = el.getAttribute('href').split('?', 2)[0];
                        if(solved[id])
                                el.insertAdjacentHTML('beforebegin', TICK);
                        else if(attempted[id])
@@ -55,15 +47,15 @@ function update_tracker(){
                });
 
        if(location.pathname == '/ct/')
-               $('table .name a').each(function(el) {
-                       var id = el.getAttribute('href').substr(4);
+               $('table .name a').each(el => {
+                       let id = el.getAttribute('href').substr(4);
                        if(contests[id])
                                el.insertAdjacentHTML('beforebegin', TICK);
                });
 
        if(location.pathname == '/log/')
-               $('table tbody tr').each(function(el) {
-                       var owner = el.querySelector('.owner a');
+               $('table tbody tr').each(el => {
+                       let owner = el.querySelector('.owner a');
                        if(!owner || owner.getAttribute('href') != '/us/' + user)
                                return;
                        var state = el.getElementsByClassName('r0').length ? TICK : XMARK;
@@ -71,7 +63,7 @@ function update_tracker(){
                });
 
        if(location.pathname.match(/^\/st\//) || location.pathname == '/us/')
-               $('table tbody tr').each(function(el) {
+               $('table tbody tr').each(el => {
                        if(el.querySelector('.user a').getAttribute('href') == '/us/' + user){
                                el.classList.add('info');
                                el.classList.add('tracker-info');
@@ -94,7 +86,7 @@ function refresh_tracker(){
        var user = localStorage.getItem('tracker_username');
        var xhr = new XMLHttpRequest();
        xhr.open('GET', '/us/' + user + '?format=json');
-       xhr.onload = function () {
+       xhr.onload = () => {
                localStorage.setItem('tracker_data', this.responseText);
                localStorage.setItem('tracker_lastfetch', Date.now());
                update_tracker();
@@ -116,7 +108,7 @@ $(function(){
        sidebar.insertBefore(tracker, sidebar.firstChild);
        $('#tracker_stop').on('click', stop_tracking);
        $('#track_user').on('click', function() { stop_tracking(); start_tracking(this.dataset.user) });
-       $('#submitform').on('submit', function() { localStorage.removeItem('tracker_lastfetch') });
+       $('#submitform').on('submit', () => localStorage.removeItem('tracker_lastfetch'));
 
        if(localStorage.getItem('tracker_username'))
                start_tracking(localStorage.getItem('tracker_username'));
index 3173895e5d03ff386e1cfe1d5bad4393cdb86100..bf16d31f1f2e166a8b5e8c3e0ce501c81a39e7fd 100644 (file)
@@ -3,10 +3,10 @@ $(function(){
        var login = document.createElement('div');
        login.innerHTML = '<a role="button" id="login" class="show">Log in</a>';
        sidebar.insertBefore(login, sidebar.firstChild);
-       $('#login').on('click', function(e) {
+       $('#login').on('click', e => {
                var xhr = new XMLHttpRequest();
                xhr.open('GET', '/login');
-               xhr.onload = function () {
+               xhr.onload = () => {
                        if(this.status != 200)
                                return;
                        var username = this.responseText;
index 44ef19e253ea28cde50b7f92d0643477f8d62f2a..0d8d10b873a5dee5f6db1ae50cb885fe9829fb3b 100644 (file)
@@ -30,7 +30,7 @@ sub make_css {
 }
 
 sub make_js {
-       system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js/js.map --js_output_file static/js/all.js --language_in ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
+       system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js/js.map --js_output_file static/js/all.js --language_in ECMASCRIPT6_STRICT --language_out ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
        my $js = read_file 'static/js/all.js';
        write_file 'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
        system 'cp', '-rp', 'js', 'static/';
This page took 0.052249 seconds and 4 git commands to generate.