public.js 10.7 KB
$(function() {
    var host = 'http://' + window.location.host + '/themes/simpleboot3_mobile/public/assets';
    // 点击左上角
    $('.nav_downN9,.nav_drop-down ul a').click(function() {
        $('.nav_down').hide();
        $('.navImg1 img').attr('src', host + "/images/cicon_02@2x.png")
    });

    //导航
    $('.navImg1 img').click(function(e) {
        if ($(this).attr('src') == host + "/images/cicon_02@2x.png") {
            e.stopPropagation();
            $(this).attr('src', host + '/images/xx.png');
            $('.nav_down').slideDown();
        } else {
            $(this).attr('src', host + '/images/cicon_02@2x.png');
            $('.nav_down').slideUp();
        }
    });

    // 关闭导航
    $(document).click(function(e) {
        if (!$(e.target).closest(".nav_down").length) {
            $(".nav_down").slideUp(200);
            $('.navImg1 img').attr('src', host + "/images/cicon_02@2x.png")
                // $(this).children('.bottom_liCir p').css('color', '#999999');
        }
    });


    //二级导航
    $('.nav_downN').each(function() {
        $(this).click(function() {
            if ($(this).children('.nav_downImg2').attr('src') == host + '/images/down.png') {
                $(this).children('.nav_downImg2').attr('src', host + '/images/top.png');
                $(this).next('.nav_drop-down').slideDown();
            } else {
                $(this).children('.nav_downImg2').attr('src', host + '/images/down.png');
                $(this).next('.nav_drop-down').slideUp();
            }
        });
    });

    // 收藏
    $('.collections').click(function() {
        if ($(this).children('img').attr('src') == host + '/images/bicon_02.png') {
            var login = operation('/portal/star/collection');
            if (login == 0) {
                return false;
            }
            $(this).children('img').attr('src', host + '/images/bicon_15.png');
        } else {
            var login = operation('/portal/star/cancelCollection');
            if (login == 0) {
                return false;
            }
            $(this).children('img').attr('src', host + '/images/bicon_02.png');
        }
    });
    //点赞
    $('.likes').click(function() {
        if ($(this).children('img').attr('src') == host + '/images/bicon_03.png') {
            var login = operation('/portal/star/like');
            if (login == 0) {
                return false;
            }
            $(this).children('img').attr('src', host + '/images/bicon_16.png');
        } else {
            var login = operation('/portal/star/cancelLike');
            if (login == 0) {
                return false;
            }
            $(this).children('img').attr('src', host + '/images/bicon_03.png');
        }
    });

    // 收藏更多视频
    $('#collections').click(function() {
        if ($(this).attr('src') == host + '/images/bicon_02.png') {
            var login = operation('/portal/star/collection', 1);
            if (login == 0) {
                return false;
            }
            $(this).attr('src', host + '/images/bicon_15.png');
        } else {
            var login = operation('/portal/star/cancelCollection', 1);
            if (login == 0) {
                return false;
            }
            $(this).attr('src', host + '/images/bicon_02.png');
        }
    });

    //点赞
    $('#likes').click(function() {
        if ($(this).attr('src') == host + '/images/bicon_031.png') {
            var login = operation('/portal/star/like', 1);
            if (login == 0) {
                return false;
            }
            $(this).attr('src', host + '/images/bicon_161.png');
        } else {
            var login = operation('/portal/star/cancelLike', 1);
            if (login == 0) {
                return false;
            }
            $(this).attr('src', host + '/images/bicon_031.png');
        }
    });


    // 评论判断长度显示与隐藏
    if ($('.show_2_pinL').length < 3) {
        $('.show_main_more').hide();
        $('.show_main2_show ul').removeClass('show_main2_show_H');
        $('.show_main_more').removeClass('comments2_more');
    } else {
        $('.show_main_more').show();
    }

    var maxwidth = 4;//设置最多显示的字数
    var user_nickname = $('#user_nickname').text();
    if(user_nickname.length > maxwidth){
        var user = user_nickname.substring(0,maxwidth);
        $('#user_nickname').text(user+'...');
    }

    //改变分页图标
    $('.page-item').eq(0).children().text('<');
    $('.page-item:last').children().text('>');

    //点击评论收起与展开
    $('.comments2_more').click(function() {
        if ($.trim($(this).text()) == '查看更多评论') {
            $('.comments2').removeClass('comments2N');
            $(this).text('收起');
        } else {
            $('.comments2').addClass('comments2N');
            $(this).text('查看更多评论');
        }
    });
    // 点击出现搜索栏
    $('.navImg3').click(function() {
        $('.navImg2').hide();
        $(this).addClass('searchs');
        setInterval(function() {
            $('.nav_search').show();
        }, 200);
        //搜索
        $(".searchs").click(function() {
            $("#searchForm").submit(); //处理事件
        });
    });

    //登录
    $("#login").click(function() {
        window.location.href = "/portal/login/login";
    });
    //注册
    $("#register").click(function() {
        window.location.href = "/portal/login/register";
    });
    //个人中心
    $('.login_person').click(function() {
        window.location.href = '/portal/login/info';
    });

    //修改资料页面
    $('#editInfo').click(function() {
        window.location.href = '/portal/login/editInfo';
    });

    //我的收藏页面
    $('#myCollection').click(function() {
        window.location.href = '/portal/login/myCollection';
    });

    //跳转链接
    $('.nav_drop-down a').click(function() {
        $('.nav_down').css('display', 'none');
    });

    //评论
    $('#comment').click(function() {
        var content = $('#comment_content').val();
        var article_id = getUrlParam('id');
        var url = window.location.pathname + window.location.search;
        $.ajax({
            type: 'POST',
            url: "/portal/star/comment",
            data: {
                'content': content,
                'article_id': article_id,
                'url': url

            },
            dataType: 'json',
            success: function(data) {
                console.log(data);
                if (data.code == 1) {
                    mask(data.msg);
                    $('#comment_content').val('');
                } else {
                    mask(data.msg);
                }
            }
        });
    });
    //退出登录
    $('#logout').click(function() {
        $.ajax({
            type: 'POST',
            url: "/portal/login/logout",
            data: {
            },
            dataType: 'json',
            success: function(data) {
                console.log(data);
                if (data.code == 1) {
                    mask(data.msg);
                    window.location.href = '/';
                } else {
                    mask(data.msg);
                }
            }
        });
    });

    //关于我们
    $('#about_us,#about_us1').click(function() {
        window.location.href = '/portal/index/aboutUs';
    });
    //搜索
    $("#keywords").keypress(function(e) {
        if (e.which == 13) {
            $("#searchForm").submit(); //处理事件
        }
    });
    var share_url = encodeURIComponent(location.href);
    var share_title = encodeURIComponent(document.title);
    //分享到微博
    $('.weibo').click(function() {
        var param = {
            url: share_url,
            title: share_title,
            rnd: new Date().valueOf()
        };
        var temp = [];
        for (var p in param) {
            temp.push(p + '=' + encodeURIComponent(param[p] || ''))
        }
        window.open('http://v.t.sina.com.cn/share/share.php?' + temp.join('&'));
    });
    //微博分享
    $('.wb_share').click(function() {
        thirdShare('/portal/login/wb_share');
    });

    //星球影院微博分享
    $('.wb_share_video').click(function() {
        thirdShare('/portal/login/wb_share');
    });

    //微博登录
    $('#wb_login').click(function(){
        $('#wb_form').submit();
    });

    //微信登录(暂时无用)
    $('#wx_login').click(function(){
        window.location.href = '/portal/login/wx_login_mobile';
    });

    //微信分享
    $('#wx_share,#wx_share_video').click(function(){
        mask('打开微信,点击右上角即可分享网页');
    });
});
//第三方分享
function thirdShare(url){
    var title = $(document).attr("title");
    var share_url = window.location.href;
    var article_id = getUrlParam('id');
    $.ajax({
        type: 'POST',
        url: url,
        data: {
            'id': article_id,
            'title': title,
            'share_url': share_url
        },
        dataType: 'json',
        async: false,
        success: function(data) {
            if (data.code == 1) {
                mask(data.msg);
                window.location.reload();
            } else {
                mask(data.msg);
            }
        }
    });
}
//弹框
function mask(msg) {
    $('.mask').text(msg);
    $('.mask').show();
    setTimeout(function() {
        $('.mask').hide();
        $('.mask').text('');
    }, 6000);
}

//弹框
function video_mask(msg) {
    $('.mask').text(msg);
    $('.mask').show();
    setTimeout(function() {
        $('.mask').hide();
        $('.mask').text('');
    }, 6000);
}
//点赞收藏
function operation(url,id) {
    if (id == '' || id == undefined) {
        var article_id = getUrlParam('id');
    } else {
        var article_id = $('#li_id').val();
    }
    var is_login = 1;
    var post_url = window.location.pathname + window.location.search;
    $.ajax({
        type: 'POST',
        url: url,
        data: {
            'article_id': article_id,
            'post_url': post_url
        },
        dataType: 'json',
        async: false,
        success: function(data) {
            if (data.code == 1) {
                mask(data.msg);
            } else {
                mask(data.msg);
                is_login = data.code;
            }
        }
    });
    return is_login;
}

//获取url的参数
function getUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");

    if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;

        for (var i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");

            if (arr != null && arr[0] == paraName) {
                return arr[1];
            }
        }
        return "";
    } else {
        return "";
    }
}