<commit_before>/*
 * Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @fileoverview util and every page should be used.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version 1.0.1.5, Jan 23, 2014
 */

/**
 * @description Util
 * @static
 */
var Util = {
    /**
     * @description 关注
     * @param {BOM} it 触发事件的元素
     * @param {String} id 关注 id
     */
    follow: function(it, id) {
        if ($(it).hasClass("disabled")) {
            return false;
        }

        var requestJSONObject = {
            followingId: id
        };

        $(it).addClass("disabled");

        $.ajax({
            url: "/follow/user",
            type: "POST",
            cache: false,
            data: JSON.stringify(requestJSONObject),
            success: function(result, textStatus) {
                if (result.sc) {
                    $(it).removeClass("disabled").removeClass("green").addClass("red")
                            .attr("onclick", "Util.unfollow(this, '" + id + "')")
                            .text(Label.unfollowLabel);
                }
            }
        });
    },
    /**
     * @description 取消关注     
     * @param {String} type 取消关注的类型
     */
    unfollow: function(it, id) {
        if ($(it).hasClass("disabled")) {
            return false;
        }

        var requestJSONObject = {
            followingId: id
        };

        $(it).addClass("disabled");

        $.ajax({
            url: "/follow/user",
            type: "DELETE",
            cache: false,
            data: JSON.stringify(requestJSONObject),
            success: function(result, textStatus) {
                if (result.sc) {
                    $(it).removeClass("disabled").removeClass("red").addClass("green")
                            .attr("onclick", "Util.follow(this, '" + id + "')")
                            .text(Label.followLabel);
                }
            }
        });
    },
    /**
     * @description 回到顶部
     */
    goTop: function() {
        var acceleration = acceleration || 0.1;
        var y = $(window).scrollTop();
        var speed = 1 + acceleration;
        window.scrollTo(0, Math.floor(y / speed));
        if (y > 0) {
            var invokeFunction = "Util.goTop(" + acceleration + ")";
            window.setTimeout(invokeFunction, 16);
        }
    },
    /**
     * @description 页面初始化执行的函数 
     */
    showLogin: function() {
        $(".nav .form").slideToggle();
    },
    /**
     * @description 跳转到注册页面
     */
    goRegister: function() {
        window.location = "/register?goto=" + encodeURIComponent(location.href);
    },
    /**
     * @description 禁止 IE7 以下浏览器访问
     */
    _kill: function() {
        //if ($.browser.msie && parseInt($.browser.version) < 8) {
        $.ajax({
            url: "/kill-browser",
            type: "GET",
            cache: false,
            success: function(result, textStatus) {
                $("body").append(result);
                $("#killBrowser").dialog({
                    "modal": true,
                    "hideFooter": true,
                    "height": 258,
                    "width": 530
                });

                $("#killBrowser").dialog("open");
            }
        });
        // }
    },
    /**
     * @description 初识化前台页面
     */
    init: function() {
        //禁止 IE7 以下浏览器访问<commit_msg>忘记删测试代码了<commit_after>/*
 * Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @fileoverview util and every page should be used.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version 1.0.1.6, Feb 8, 2014
 */

/**
 * @description Util
 * @static
 */
var Util = {
    /**
     * @description 关注
     * @param {BOM} it 触发事件的元素
     * @param {String} id 关注 id
     */
    follow: function(it, id) {
        if ($(it).hasClass("disabled")) {
            return false;
        }

        var requestJSONObject = {
            followingId: id
        };

        $(it).addClass("disabled");

        $.ajax({
            url: "/follow/user",
            type: "POST",
            cache: false,
            data: JSON.stringify(requestJSONObject),
            success: function(result, textStatus) {
                if (result.sc) {
                    $(it).removeClass("disabled").removeClass("green").addClass("red")
                            .attr("onclick", "Util.unfollow(this, '" + id + "')")
                            .text(Label.unfollowLabel);
                }
            }
        });
    },
    /**
     * @description 取消关注     
     * @param {String} type 取消关注的类型
     */
    unfollow: function(it, id) {
        if ($(it).hasClass("disabled")) {
            return false;
        }

        var requestJSONObject = {
            followingId: id
        };

        $(it).addClass("disabled");

        $.ajax({
            url: "/follow/user",
            type: "DELETE",
            cache: false,
            data: JSON.stringify(requestJSONObject),
            success: function(result, textStatus) {
                if (result.sc) {
                    $(it).removeClass("disabled").removeClass("red").addClass("green")
                            .attr("onclick", "Util.follow(this, '" + id + "')")
                            .text(Label.followLabel);
                }
            }
        });
    },
    /**
     * @description 回到顶部
     */
    goTop: function() {
        var acceleration = acceleration || 0.1;
        var y = $(window).scrollTop();
        var speed = 1 + acceleration;
        window.scrollTo(0, Math.floor(y / speed));
        if (y > 0) {
            var invokeFunction = "Util.goTop(" + acceleration + ")";
            window.setTimeout(invokeFunction, 16);
        }
    },
    /**
     * @description 页面初始化执行的函数 
     */
    showLogin: function() {
        $(".nav .form").slideToggle();
    },
    /**
     * @description 跳转到注册页面
     */
    goRegister: function() {
        window.location = "/register?goto=" + encodeURIComponent(location.href);
    },
    /**
     * @description 禁止 IE7 以下浏览器访问
     */
    _kill: function() {
        if ($.browser.msie && parseInt($.browser.version) < 8) {
            $.ajax({
                url: "/kill-browser",
                type: "GET",
                cache: false,
                success: function(result, textStatus) {
                    $("body").append(result);
                    $("#killBrowser").dialog({
                        "modal": true,
                        "hideFooter": true,
                        "height": 258,
                        "width": 530
                    });

                    $("#killBrowser").dialog("open");
                }
            });
        }
    },
    /**
     * @description 初识化前台页面
     */
    init: function() {
        //禁止 IE7 以下浏览器访问
{'fraction_non_alphanumeric': 0.1426942085920669, 'fraction_numerical': 0.01279939171207705, 'mean_word_length': 1.531109685695959, 'pattern_counts': {'":': 8, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '7459810', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2266, 'n_words': 531}