<commit_before>/* Copyright (C) 2011 Governo do Estado do Rio Grande do Sul
 *
 *   Author: <NAME> <<EMAIL>>
 *   Author: <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

$(function() {
    var moderatedBuzz = $("#buzz-moderated")
    var publicBuzz = $("#buzz-public");

    $("a.filter").click(
        function() {
            $(this).toggleClass('off');
            moderatedBuzz.toggle();
            publicBuzz.toggle();

        });

    /** Shows a tooltip of an element with manual control of show/hide
     *  operations */
    function showTooltip(elementOrSelector) {
        if (typeof elementOrSelector === 'string') {
            $element = $(elementOrSelector);
        } else {
            $element = elementOrSelector;
        }

        var $tooltip = $element.tooltip({
            effect: "fade",
            delay: 4200,
            opacity: 0.7,
            events: {
                input: 'customOpenEvent,customOpenEvent'
            }
        });
        $element.trigger('customOpenEvent');
        return $tooltip;
    }


    /** Posts a new notice on the message buzz */
    function postNotice(message) {
        var params = { aid: $('#aid').val(), message: message };
        $.post(url_for('buzz.post'), params, function (data) {
            var parsedData = $.parseJSON(data);
            if (parsedData.status !== 'ok') {
                // For any reason, the user got loged out, so, as it's
                // an async call, we have to request login credentials
                // again. It's not actually usual to happen but better
                // being safe than sorry.
                if (parsedData.code === 'NobodyHome') {
                    auth.showLoginForm({
                        success: function (userData) {
                            postNotice(message);
                        }
                    });
                    return;
                } else {
                    // Feedback the user. something wrong happened.
                    showTooltip(
                        $("#internal_chat textarea")
                            .attr('title', parsedData.msg));
                }
            } else {
                // Everything' fine, let's just clear the message box
                // and thank the user
                var $textbox = $("#internal_chat textarea")
                    .val('')
                    .attr('title', parsedData.msg);
                showTooltip($textbox);

                window.setTimeout(function () {
                    $textbox.attr('title', '');
                }, 10000);
            }
        });
    }


    $('#internal_chat').submit(function () {
        var $form = $(this);
        var $field = $('textarea', $form);
        var aid = $('#aid').val();
        var data = $.trim($field.val());

        // None received in the form. We cannot process this
        // request. Just feedback the user.
        if (data === '') {
            $field.addClass('error');
            return false;
        }

        // Just making sure that the user will not be confused by any
        // old error report.
        $field.removeClass('error');

        // Not authenticated users must access the login form
        if (!auth.isAuthenticated()) {
            auth.showLoginForm({
                success: function (userData) {
                    postNotice(data);
                }
            });
        } else {
            // Time to send the request to the server
            postNotice(data);
        }
        return false;
    });

    $('a.filter').tooltip({ opacity: 0.7 });

    // Starts a new instance of the buzz stream

    new Buzz(SIO_BASE, {
        new_buzz: function (msg) {
            var $el = $(tmpl("buzzTemplate", msg));
            $('#buzz-public').prepend($el);
        },

        buzz_accepted: function (msg) {
            var $el = $(tmpl("buzzTemplate", msg));
            $('#buzz-moderated').prepend($el);
        },

        buzz_published: function (msg) {
            var $el = $(tmpl("selectedNotice", msg));
            $('#beingAnswered').fadeOut(function () {
                $(this).html('');
                $(this).append($el);
                $(this).fadeIn();
            });
        }
    });

    // Initializing "how it works" stuff
    audience_how_it_works_spinning_gears_setup();

    $('img[rel]').overlay({
        oneInstance: false,
        speed: 'fast',
        top: '30%',
        mask: {
            color: '#111',
            opacity: 0.7
        },

        onLoad: function () {
            if ($(this.getOverlay()).data('firstRun') === undefined) {
                audience_show_how_it_works();
                $(this.getOverlay()).data('firstRun', 1);
            }
        }
    });


  var msg_area = $("textarea[name=message]");
  msg_area[0].onkeydown = msg_area[0].onkeyup = (function() {
    $(".current-msg-length").text(300-msg_area.val().length);
    if (msg_area.val().length > 300) {
      $("#send_comment").enable(false)
      msg_area.addClass("error");
    } else {
      $("#send_comment").enable(true)
      msg_area.removeClass("error");
    }
  })
});


function audience_how_it_works_spinning_gears_setup() {
  var big_gear = $("#how-it-works-big-gear");
  var small_gear = $("#how-it-works-small-gear");
  var how_it_works = $("#how-it-works");

  big_gear.data("angle",0);
  small_gear.data("angle",0);

  var timer = new Timer();
  timer.then(function(timer,accel) {
    var big_current_angle = big_gear.data("angle");
    var small_current_angle = small_gear.data("angle");

    var big_angle = (big_current_angle + (Math.log(accel+2))) % 360;
    var small_angle = (small_current_angle - (Math.log(accel+2))) % 360;

    big_gear.data("angle",big_angle);
    small_gear.data("angle",small_angle);

    big_gear.rotate(big_angle);
    small_gear.rotate(small_angle);

    if (accel == 0) timer.stop();
  });

  var accel = 0;
  var max_accel = 100;
  how_it_works.hover(
    function() {
      timer.stepper(function() {
        if (accel < max_accel) accel++;
        return accel;
      });
      if (!timer.isRunning()) timer.run();
    },
    function() {
      timer.stepper(function() {
        if (accel > 0) accel--;
        return accel;
      });
    });
}


function audience_show_how_it_works() {

  // lots of inicialization vars...

  var couple = $(".step-1-couple");
  var mail = $(".step-1-mail");
  var trail = $(".step-1-mail-trail");

  var big_gear = $(".step-2-big-gear");
  var small_gear = $(".step-2-small-gear");

  big_gear.data("angle",0);
  small_gear.data("angle",0);

  var step_2 = $(".step-2");

  var gentleman = $(".mustache-gentleman");
  var step_3_text = $(".step-3 p");
  var dialog = $(".mustache-gentleman-dialog");


  //the function to spin the step-2 gears
  //TODO: when the how-it-works dialog closes
  //      stop this interval
  var spinning_gears = null;
  function spin_gears() {
      spinning_gears = setInterval(function() {
      var big_angle = (big_gear.data("angle")+1) % 360;
      var small_angle = (small_gear.data("angle")-1) % 360;

      big_gear.data("angle",big_angle);
      small_gear.data("angle",small_angle);

      big_gear.rotate(big_angle);
      small_gear.rotate(small_angle);
      }, 13);
    }

  //the function to show the dialog in step-3

  // the animation...

  var timer = new Timer();

  timer.then(function(timer, step) {   /* step 1 */
    var opacity = step * 4 / 100.0;
    if (opacity > 1) opacity = 1;
    couple.css("opacity", opacity);
    if (opacity == 1) timer.next();

  }).then(function(timer,step) {
    var left = parseInt(mail.css("left"))+1;
    mail.css("left", left+"px");

    var opacity = parseFloat(mail.css("opacity")) + 0.05;
    if (opacity > 1) opacity = 1;<commit_msg>Limpando codigo<commit_after>/* Copyright (C) 2011 Governo do Estado do Rio Grande do Sul
 *
 *   Author: <NAME> <<EMAIL>>
 *   Author: <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

$(function() {
    var moderatedBuzz = $("#buzz-moderated")
    var publicBuzz = $("#buzz-public");

    $("a.filter").click(
        function() {
            $(this).toggleClass('off');
            moderatedBuzz.toggle();
            publicBuzz.toggle();

        });

    /** Shows a tooltip of an element with manual control of show/hide
     *  operations */
    function showTooltip(elementOrSelector) {
        if (typeof elementOrSelector === 'string') {
            $element = $(elementOrSelector);
        } else {
            $element = elementOrSelector;
        }

        var $tooltip = $element.tooltip({
            effect: "fade",
            delay: 4200,
            opacity: 0.7,
            events: {
                input: 'customOpenEvent,customOpenEvent'
            }
        });
        $element.trigger('customOpenEvent');
        return $tooltip;
    }


    /** Posts a new notice on the message buzz */
    function postNotice(message) {
        var params = { aid: $('#aid').val(), message: message };
        $.post(url_for('buzz.post'), params, function (data) {
            var parsedData = $.parseJSON(data);
            if (parsedData.status !== 'ok') {
                // For any reason, the user got loged out, so, as it's
                // an async call, we have to request login credentials
                // again. It's not actually usual to happen but better
                // being safe than sorry.
                if (parsedData.code === 'NobodyHome') {
                    auth.showLoginForm({
                        success: function (userData) {
                            postNotice(message);
                        }
                    });
                    return;
                } else {
                    // Feedback the user. something wrong happened.
                    showTooltip(
                        $("#internal_chat textarea")
                            .attr('title', parsedData.msg));
                }
            } else {
                // Everything' fine, let's just clear the message box
                // and thank the user
                var $textbox = $("#internal_chat textarea")
                    .val('')
                    .attr('title', parsedData.msg);
                showTooltip($textbox);

                window.setTimeout(function () {
                    $textbox.attr('title', '');
                }, 10000);
            }
        });
    }


    $('#internal_chat').submit(function () {
        var $form = $(this);
        var $field = $('textarea', $form);
        var aid = $('#aid').val();
        var data = $.trim($field.val());

        // None received in the form. We cannot process this
        // request. Just feedback the user.
        if (data === '') {
            $field.addClass('error');
            return false;
        }

        // Just making sure that the user will not be confused by any
        // old error report.
        $field.removeClass('error');

        // Not authenticated users must access the login form
        if (!auth.isAuthenticated()) {
            auth.showLoginForm({
                success: function (userData) {
                    postNotice(data);
                }
            });
        } else {
            // Time to send the request to the server
            postNotice(data);
        }
        return false;
    });

    $('a.filter').tooltip({ opacity: 0.7 });

    // Starts a new instance of the buzz stream

    new Buzz(SIO_BASE, {
        new_buzz: function (msg) {
            var $el = $(tmpl("buzzTemplate", msg));
            $('#buzz-public').prepend($el);
        },

        buzz_accepted: function (msg) {
            var $el = $(tmpl("buzzTemplate", msg));
            $('#buzz-moderated').prepend($el);
        },

        buzz_published: function (msg) {
            var $el = $(tmpl("selectedNotice", msg));
            $('#beingAnswered').fadeOut(function () {
                $(this).html('');
                $(this).append($el);
                $(this).fadeIn();
            });
        }
    });

    // Initializing "how it works" stuff
    audience_how_it_works_spinning_gears_setup();

    $('img[rel]').overlay({
        oneInstance: false,
        speed: 'fast',
        top: '30%',
        mask: {
            color: '#111',
            opacity: 0.7
        },

        onLoad: function () {
            if ($(this.getOverlay()).data('firstRun') === undefined) {
                audience_show_how_it_works();
                $(this.getOverlay()).data('firstRun', 1);
            }
        }
    });


  var msg_area = $("textarea[name=message]");
  msg_area[0].onkeydown = msg_area[0].onkeyup = (function() {
    $(".current-msg-length").text(300-msg_area.val().length);
    if (msg_area.val().length > 300) {
      $("#send_comment").enable(false)
      msg_area.addClass("error");
    } else {
      $("#send_comment").enable(true)
      msg_area.removeClass("error");
    }
  })
});


function audience_how_it_works_spinning_gears_setup() {
  var big_gear = $("#how-it-works-big-gear");
  var small_gear = $("#how-it-works-small-gear");
  var how_it_works = $("#how-it-works");

  big_gear.data("angle",0);
  small_gear.data("angle",0);

  var timer = new Timer();
  timer.then(function(timer,accel) {
    var big_current_angle = big_gear.data("angle");
    var small_current_angle = small_gear.data("angle");

    var big_angle = (big_current_angle + (Math.log(accel+2))) % 360;
    var small_angle = (small_current_angle - (Math.log(accel+2))) % 360;

    big_gear.data("angle",big_angle);
    small_gear.data("angle",small_angle);

    big_gear.rotate(big_angle);
    small_gear.rotate(small_angle);

    if (accel == 0) timer.stop();
  });

  var accel = 0;
  var max_accel = 100;
  how_it_works.hover(
    function() {
      timer.stepper(function() {
        if (accel < max_accel) accel++;
        return accel;
      });
      if (!timer.isRunning()) timer.run();
    },
    function() {
      timer.stepper(function() {
        if (accel > 0) accel--;
        return accel;
      });
    });
}


function audience_show_how_it_works() {
  var couple = $(".step-1-couple");
  var mail = $(".step-1-mail");
  var trail = $(".step-1-mail-trail");

  var big_gear = $(".step-2-big-gear");
  var small_gear = $(".step-2-small-gear");

  big_gear.data("angle",0);
  small_gear.data("angle",0);

  var step_2 = $(".step-2");

  var gentleman = $(".mustache-gentleman");
  var step_3_text = $(".step-3 p");
  var dialog = $(".mustache-gentleman-dialog");


  var spinning_gears = null;
  function spin_gears() {
      spinning_gears = setInterval(function() {
      var big_angle = (big_gear.data("angle")+1) % 360;
      var small_angle = (small_gear.data("angle")-1) % 360;

      big_gear.data("angle",big_angle);
      small_gear.data("angle",small_angle);

      big_gear.rotate(big_angle);
      small_gear.rotate(small_angle);
      }, 13);
    }

  // the animation...
  var timer = new Timer();

  timer.then(function(timer, step) {   /* step 1 */
    var opacity = step * 4 / 100.0;
    if (opacity > 1) opacity = 1;
    couple.css("opacity", opacity);
    if (opacity == 1) timer.next();

  }).then(function(timer,step) {
    var left = parseInt(mail.css("left"))+1;
    mail.css("left", left+"px");

    var opacity = parseFloat(mail.css("opacity")) + 0.05;
    if (opacity > 1) opacity = 1;
{'fraction_non_alphanumeric': 0.1471206389239176, 'fraction_numerical': 0.010448567825617006, 'mean_word_length': 1.9465675866949752, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4111262', 'n_tokens_mistral': 5114, 'n_tokens_neox': 4820, 'n_words': 1214}