• 藏地传奇js


    http://zd.163.com/m/zhenyan/

    js很厉害,有很多值得学习的地方,记录下来。

    http://res.nie.netease.com/zdcq/qt/13/0625_zhenyan/js/index.js

    var ZANTEMP;
    
    //cookies
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            var path = options.path ? '; path=' + options.path : '';
            var domain = options.domain ? '; domain=' + options.domain : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };
    
    
    
    //chrome上传预览
    function handleFiles(files) {
        if (!$.browser.msie||($.browser.msie&& $.browser.version=="10.0")){
            //遍历files并处理
            files=files.files;
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                var imageType = /image.*/;
                //通过type属性进行图片格式过滤
                if (!file.type.match(imageType)) {
                    continue;
                }
                //读入文件
                var reader = new FileReader();
                reader.onload = function (e) {
                    //e.target.result返回的即是图片的dataURI格式的内容
                    var imgData = e.target.result,
                        img = document.createElement('img');
                    //img.src = imgData;
                    //展示img
                    $(".pre-img").attr("src", imgData).css("visibility", "visible");
                }
                reader.readAsDataURL(file);
            }
    
        }else{//IE
            var html="<div class='pre-img'></div>";
            $('.pre-div').html('').html(html);
    //采用滤镜效果生成图片预览
           // files.select();
            path =$('#upload-btn').val();
            $('.pre-img').css({"filter":"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=""+ path + "")"});
        }
    }
    
    
    //temp
    var clickedMask;
    //check cookie
    function cookie_check_logined() {
        var s_info = $.cookie("S_INFO");
        var p_info = $.cookie("P_INFO");
        var now = new Date();
        if (s_info != null && s_info != "" && p_info != null && p_info != "" && (now.getTime() / 1000 - s_info.split('|')[0]) / 600 < 1) {
            return p_info.split('|')[0];
        }
        return false;
    }
    
    //扩展中文字符截断
    String.prototype.sub = function(n)
    {
        var r = /[^x00-xff]/g;
        if(this.replace(r, "mm").length <= n) return this;
        var m = Math.floor(n/2);
        for(var i=m; i<this.length; i++) {
            if(this.substr(0, i).replace(r, "mm").length>=n) {
                return this.substr(0, i) ; }
        } return this;
    };
    
    //post回调
    function postArtCallback(result){
        $('#captcha_img').trigger('click');
        if(!result){
            $('.post-tips').text('请填写完整').show();
            return ;
        }
        if(result.success){
            var maskHeight=315;
            var maskWidth=645;
            var maskPosition=$('.post-form').position();
            $('.post-form').css({0,height:0}).hide();
            $('.success-box').css({0,height:0}).css(maskPosition).animate({height:maskHeight, maskWidth}).show();
            $('#captcha_answer').val('');
            $('#content,#nickname,#title').val('');
    
        }else{
            if(result.unlogin){
                $('.post-tips').text('帐号验证失败,请重新登录').show();
                return;
            }
            $('.post-tips').text(result.msg).show();
        }
    }
    //验证码
    rnd.today=new Date();
    rnd.seed=rnd.today.getTime();
    function rnd() {
        rnd.seed = (rnd.seed*9301+2973467) % 2332425280;
        return rnd.seed;
    };
    
    $(function () {
        var userName=cookie_check_logined()?cookie_check_logined():'';
        var zanIsclick=false;
        $('.username-span').text(userName);
    
        //绑定验证码
        $('#captcha_img').click(function(){
            var temp_id = parseInt(rnd());
            $('#captcha_img').attr('src', "http://captcha-for-what.webapp.163.com/get_captcha?captcha_id=zdcq" + temp_id);
            $('#captcha_id').val('zdcq' + temp_id);
        });
        $('#captcha_img').click();
    
    
        var myWaterfall = gWaterFall.initWaterfall();
        $('.top').click(function () {
            $(window).scrollTop(0);
        })
    
        //导航绑定
        $('.nav4').toggle(function(){
            $(this).addClass('current')
        },function(){
            $(this).removeClass('current')
        })
    
        $('.a2').click(function(){
            var display=$('.tc-jp').css('display');
            $('.nav a').removeClass('current');
    
            $('.tc').slideUp();
            if(display=='none'){
                $(this).addClass('current');
                $('.tc-jp').slideDown();
            }else{
                $(this).removeClass('current');
                $('.tc-jp').slideUp();
            }
        })
    
        $('.a3').click(function(){
            var display=$('.tc-gz').css('display');
            $('.nav a').removeClass('current');
    
            $('.tc').slideUp();
    
            if(display=='none'){
                $('.tc-gz').slideDown();
                $(this).addClass('current');
            }else{
                $('.tc-gz').slideUp();
                $(this).removeClass('current');
            }
        })
    
        $('.a5').click(function(){
            var display=$('.tc-mt').css('display');
            $('.nav a').removeClass('current');
    
            $('.tc').slideUp();
            if(display=='none'){
                $(this).addClass('current');
                $('.tc-mt').slideDown();
            }else{
                $(this).removeClass('current');
                $('.tc-mt').slideUp();
            }
        })
    
    
        //上传绑定
        $("#upload-a").click(function(){
            $("#upload-btn").trigger('click');
        })
        $(".a1").click(function(){
            $('.j-1').trigger('click');
        })
    
        $('.gz-btn').click(function(){
            $('.j-1').trigger('click');
        })
    
        $("#post-btn").click(function(e){
    
        })
        //点赞
        $('.mask .y-up,.mask .y-up-only').live('click',function(){
            ZANTEMP=$(this);
            var id=$(this).attr('data-artid');
            var p=$(this);
            var _this=$(this);
            if(!cookie_check_logined()){
                if(!zanIsclick){
                    var maskHeight=315;
                    var maskWidth=645;
                    var maskPosition=$('.mask').position();
                    $('.encourage-box').css({0,height:0}).css(maskPosition).animate({height:maskHeight, maskWidth}).show();
                    return;
                }
            }
            $.getJSON('http://zdcq.webapp.163.com/script/user/vote_article?article_id='+id+'&callback=?',function(data){
                if(data.article_resp){
    
                   _this.trigger('click');
                  //  return;
                }
                if(data.success){
                   // alert('点"赞"成功');
                    var newNum=parseInt( p.html().toLowerCase().split('</i>')[1],10)+1;
                   // console.log(p.html()) ;
                    console.log(parseInt( p.html().split('</i>')[1],10));
                    p.html('<i></i>'+newNum) ;
                    clickedMask.find('.y-up,.y-up-only').html('<i></i>'+newNum);
    
    
                }else{
                    alert(data.msg);
                }
            });
        })
    
        //选择登录与否
        $('.yes-login').click(function(){
            var maskHeight=315;
            var maskWidth=645;
            var maskPosition=$(this).parent().position();
            $(this).parent().animate({0,height:0}).hide();
            $('.login-form').css({0,height:0}).css(maskPosition).animate({height:maskHeight, maskWidth}).show();
            if(!cookie_check_logined()){
                $('.logout-tips').hide();
            }else{
                $('.logout-tips').show();
            }
        })
    
        $('.no-zan').click(function(){
            $('.encourage-box').animate({0,height:0},function(){
                $('.encourage-box').hide();
            })
            zanIsclick=true;
            ZANTEMP.trigger('click');
    
        })
    
        $('.no-post').click(function(){
            var maskHeight=315;
            var maskWidth=645;
            var maskPosition=$(this).parent().position();
            $(this).parent().animate({0,height:0}).hide();
            $('.post-form').css({0,height:0}).css(maskPosition).animate({height:maskHeight, maskWidth}).show();
            if(!cookie_check_logined()){
                $('.logout-tips').hide();
            }else{
                $('.logout-tips').show();
            }
        })
        //填写用户信息
        $('#info-btn').click(function(){
            var name=$("#name").val();
            var phone=$('#phone').val();
            $.getJSON('http://zdcq.webapp.163.com/script/user/fill_userinfo?name='+name+'&phone='+phone+'&callback=?',function(data){
                if(data.success){
                    if(!ZANTEMP){
                        var maskHeight=$('.info-form').height();
                        var maskWidth=$('.info-form').width();
                        var maskPosition=$('.info-form').position();
                        $('.info-form').hide();
                        $('.post-form').css(maskPosition).animate({height:maskHeight, maskWidth}).show();
                        $('.logout-tips').show();
                    }else{
                        ZANTEMP.trigger('click');
                        $('.info-form').hide();
                    }
                }
                if(data.error){
                    alert(data.msg);
                }
            })
        })
    
        $('.mask').live('click',function(e){
            if($(e.target).hasClass('y-up')||$(e.target).hasClass('NIE-share')||$(e.target).hasClass('y-up-only')){
                return;
            }
            var _self=$(this);
            $(this).animate({
                0,
                height:0
            },function(){
                 _self.hide();
            })
        })
    
        //登录开始
        AutoUrs.bind("username", {
            mailList: [
                "163.com",
                "126.com",
                "yeah.net",
                "qq.com",
                "vip.163.com",
                "vip.126.com",
                "188.com",
                "gmail.com",
                "sina.com",
                "hotmail.com"
            ],
            tabTo: "password",
            cookie: "global"
        });
    
        $("#login-form-box").ntesLoginForm({
            beforeSubmit: function() {
                var is_ok = true;
                var username = $("#login-form-box input[name=username]");
                var password = $("#login-form-box input[name=password]");
                if (!username.val() || username.val() == "如name@example.com") {
                    //    $("#acErr").show()
                    is_ok = false;
                }
    
                if (!password.val()) {
                    //    $("#pwdErr").show()
                    is_ok = false;
                }
                return is_ok;
            },
            success: function(params) {
                userName=cookie_check_logined();
                var maskHeight=$('.login-form').height();
                var maskWidth=$('.login-form').width();
                var maskPosition=$('.login-form').position();
                $('.username-span').html(userName);
                $('.login-tips').text('').hide();
                $.getJSON('http://zdcq.webapp.163.com/script/user/is_userinfo_fill?urs='+userName+'&callback=?',function(data){
    
                    if(!data.fill){
                        $('.login-form').hide();
                        $('.info-form').css(maskPosition).animate({height:maskHeight, maskWidth}).show();
                    }else{
                        $('.login-form').hide();
                        if(ZANTEMP){
                            ZANTEMP.trigger('click');
                        }else{
                            $('.post-form').css(maskPosition).animate({height:maskHeight, maskWidth}).show();
                        }
    
                        $('.logout-tips').show();
                    }
                })
            },
            fail: function(params) {
                $('.login-tips').text(params.errorMsg).show();
            }
        });
    
    
        //out login
        $("#login-out").click(function  () {
            var oldUrl=window.location.href;
            window.location='http://reg.163.com/Logout.jsp?username='+userName+'&url='+oldUrl;
        })
    
        //成功分享
        nie.use(['util.share'],function(){
            var successShare = nie.util.share({
                fat: ".s-share",
                type: 6,
                defShow: [5, 1, 3, 2],
                title: '我刚刚参与了《藏地传奇》真言活动,提交你的真言,说出你对西藏游戏化的建议,一起探索西藏题材的无限可能!还有机会获得iPad mini等精美奖品哦!活动地址:',
                img: ''
            });
        })
    
        //post input focus
        $('#title').focus(function(){
            if($(this).val()=='20字以内'){
                $(this).val("")
            }
        })
        /*
        $('#title').blur(function(){
            if($(this).val()==''){
                $(this).val("20字以内")
            }
        })
        */
        $('#nickname').focus(function(){
            if($(this).val()=='6字以内'){
                $(this).val('')
            }
        })
        /*
        $('#nickname').blur(function(){
            if($(this).val()==''){
                $(this).val("6字以内")
            }
        })
        */
        $('#content').focus(function(){
            if($(this).val()=='140字以内'){
                $(this).val('')
            }
        })
        /*
        $('#content').blur(function(){
            if($(this).val()==''){
                $(this).val("140字以内")
            }
        })
        */
        $('.top').css('right',($(window).width()-$('.out').width())/2-50);
        $(window).resize(function(){
            $('.top').css('right',($(window).width()-$('.out').width())/2-50);
        })
    
        $('.form-close').live('click',function(){
            var parent=$(this).parent();
            $(this).parent().animate({
                0,
                height:0
            },function(){
                parent.hide();
            })
        })
    
        $('.tc-close').click(function(){
            $(this).parent().slideUp();
            var pid=$(this).attr('data-parent');
            $(pid).removeClass('current');
        })
    })
  • 相关阅读:
    ●sql语句-添加表和字段的说明
    ●sql-行列转换
    ●获取汉字全拼
    ●获取汉字首拼
    ●导出excel(NPOI)
    ●导出excel(office组件)
    JQuery
    CSS网页美化设计属性
    表单 框架集及CCS 20140916
    常见标签的属性及使用 20140915
  • 原文地址:https://www.cnblogs.com/wpbars/p/3951919.html
Copyright © 2020-2023  润新知