<commit_before>// coffee.js - <NAME> (<EMAIL>) - Jul 2014
// This contains JS to drive some parts of the astroph-coffee interface


var coffee = {

    // this handles actual voting
    vote_on_paper: function(arxivid) {

        var arxividfilter = '[data-arxivid="' + arxivid + '"]';
        var votebutton = $('.vote-button').filter(arxividfilter);
        var votetotal = $('.vote-total').filter(arxividfilter);

        // use attr instead of data since jquery only knows about the first-ever
        // value on page-load and uses that for .data()
        var votetype = votebutton.attr('data-votetype');

        console.log(votetype + ' vote fired on ' + arxivid);

        var xsrftoken = $('#voting-form input').val();
        var messagebar = $('#message-bar');

        $.post('/astroph-coffee/vote',
               {arxivid: arxivid,
                votetype: votetype,
                _xsrf: xsrftoken},
               function(data) {

                   if (data.status == 'success') {

                       // update the vote total for this arxivid
                       votetotal.text(data.results['nvotes']);

                       // update the button to show that we've voted
                       if (votetype == 'up') {

                           votebutton
                               .addClass('alert')
                               .html('Remove your vote')
                               .attr('data-votetype','down');

                       }

                       else if (votetype == 'down') {

                           votebutton
                               .removeClass('alert')
                               .html('Vote for this paper')
                               .attr('data-votetype','up');

                       }

                   }

                   else {

                       var message = data.message;
                       var alertbox =
                           '<div data-alert class="alert-box warning radius">' +
                           message +
                           '<a href="#" class="close">&times;</a></div>'
                       messagebar.html(alertbox).fadeIn('fast').fadeOut(7500);
                       $(document).foundation();

                   }


               },
               'json').fail(function (data) {

                   var alertbox =
                       '<div data-alert class="alert-box alert radius">' +
                       'Something went wrong with the server, ' +
                       'please <a href="/astroph-coffee/about">' +
                       'let us know</a> about this problem!' +
                       '<a href="#" class="close">&times;</a></div>'
                   messagebar.html(alertbox);
                   $(document).foundation();

               });

    },


    // sets up all event bindings
    action_setup: function () {

        // handle sliding out the abstract when the paper title is clicked<commit_msg>working on cookie support for view options<commit_after>// coffee.js - <NAME> (<EMAIL>) - Jul 2014
// This contains JS to drive some parts of the astroph-coffee interface


var coffee = {

    // this handles actual voting
    vote_on_paper: function(arxivid) {

        var arxividfilter = '[data-arxivid="' + arxivid + '"]';
        var votebutton = $('.vote-button').filter(arxividfilter);
        var votetotal = $('.vote-total').filter(arxividfilter);

        // use attr instead of data since jquery only knows about the first-ever
        // value on page-load and uses that for .data()
        var votetype = votebutton.attr('data-votetype');

        console.log(votetype + ' vote fired on ' + arxivid);

        var xsrftoken = $('#voting-form input').val();
        var messagebar = $('#message-bar');

        $.post('/astroph-coffee/vote',
               {arxivid: arxivid,
                votetype: votetype,
                _xsrf: xsrftoken},
               function(data) {

                   if (data.status == 'success') {

                       // update the vote total for this arxivid
                       votetotal.text(data.results['nvotes']);

                       // update the button to show that we've voted
                       if (votetype == 'up') {

                           votebutton
                               .addClass('alert')
                               .html('Remove your vote')
                               .attr('data-votetype','down');

                       }

                       else if (votetype == 'down') {

                           votebutton
                               .removeClass('alert')
                               .html('Vote for this paper')
                               .attr('data-votetype','up');

                       }

                   }

                   else {

                       var message = data.message;
                       var alertbox =
                           '<div data-alert class="alert-box warning radius">' +
                           message +
                           '<a href="#" class="close">&times;</a></div>'
                       messagebar.html(alertbox).fadeIn('fast').fadeOut(7500);
                       $(document).foundation();

                   }


               },
               'json').fail(function (data) {

                   var alertbox =
                       '<div data-alert class="alert-box alert radius">' +
                       'Something went wrong with the server, ' +
                       'please <a href="/astroph-coffee/about">' +
                       'let us know</a> about this problem!' +
                       '<a href="#" class="close">&times;</a></div>'
                   messagebar.html(alertbox);
                   $(document).foundation();

               });

    },


    // this stores the current view settings to a cookie
    store_cookie_settings: function () {

        // get current settings
        var view = [];

        $('#show-local-check,#show-voted-check,#show-other-check')
            .each(function (ind, elem) {
                view.push(elem.checked);
            });

        var fontsize = $('[name="font-size-radio"]')
            .filter(':checked')
            .attr('id');

        // store in a cookie
        $.cookie('coffee_settings',{view:view, fontsize:fontsize}, {expires:30});

    },

    // this restores the cookied view settings
    restore_cookie_settings: function () {

        // get the settings from the cookie
        var viewsettings = $.cookie('coffee_settings');

        var viewcontrols = ['#show-local-check',
                            '#show-voted-check',
                            '#show-other-check'];

        if (typeof viewsettings != 'undefined') {

            // set the view options
            viewsettings.forEach(function (e,i,a) {

                if (viewsettings.view[i] == true) {



                }


            });

            // set the font options
            var control = '#' + viewsettings.fontsize;
            $(control).click();

        }

    },

    // sets up all event bindings
    action_setup: function () {

        // cookie settings
        $.cookie.json = true;
        coffee.restore_cookie_settings();

        // handle sliding out the abstract when the paper title is clicked
{'fraction_non_alphanumeric': 0.12007632547362683, 'fraction_numerical': 0.0024533187951478806, 'mean_word_length': 1.2303951367781154, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4192137', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1733, 'n_words': 448}