藏地传奇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({width:0,height:0}).hide();
- $('.success-box').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width: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({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width: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({width:0,height:0}).hide();
- $('.login-form').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
- if(!cookie_check_logined()){
- $('.logout-tips').hide();
- }else{
- $('.logout-tips').show();
- }
- })
- $('.no-zan').click(function(){
- $('.encourage-box').animate({width: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({width:0,height:0}).hide();
- $('.post-form').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width: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, width: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({
- width: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, width:maskWidth}).show();
- }else{
- $('.login-form').hide();
- if(ZANTEMP){
- ZANTEMP.trigger('click');
- }else{
- $('.post-form').css(maskPosition).animate({height:maskHeight, width: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({
- width:0,
- height:0
- },function(){
- parent.hide();
- })
- })
- $('.tc-close').click(function(){
- $(this).parent().slideUp();
- var pid=$(this).attr('data-parent');
- $(pid).removeClass('current');
- })
- })
藏地传奇js的更多相关文章
- 【小练习02】CSS--网易产品
要求用css和HTML实现下图效果: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...
- 第1天:CSS基本样式
今天学习了CSS基本样式和属性.在做练习的时候遇到一个小问题,最后解决了. 记住:浏览器有默认margin和padding.样式最开始记得一定写:*{margin:0;padding:0}. 学习经验 ...
- 前台的url通过 ActionName?var1=xx&var2=yy 的形式传给特定action
本文对自己开发的基于lucene和J2EE技术的搜索引擎开发经验进行简单总结.今后可能会从性能的角度总结lucene开发经验.当数据上TB级别后,分布式lucene以及结合分布式文件系统(如HDFS) ...
- 意外作出了一个javascript的服务器,可以通过js调用并执行任何java(包括 所有java 内核基本库)及C#类库,并最终由 C# 执行你提交的javascript代码! 不敢藏私,特与大家分
最近研发BDC 云开发部署平台的数据路由及服务管理器意外作出了一个javascript的服务器,可以通过js调用并执行任何java(包括 所有java 内核基本库)及C#类库,并最终由 C# 执行你提 ...
- js控制TR的显示影藏
在很多现实的场景中,有的文本框我们希望在选择“是”的按钮之后才出现,这就需要js控制TR的隐藏和显示,(div的影藏显示类似) 以下是一段选择是的按钮就显示身高和体重的文本框的代码.注意:ready方 ...
- JS+CSS简单实现DIV遮罩层显示隐藏【转藏】
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js和jquery通过this获取html标签中的属性值[转藏]
<html> <head> <script type="text/javascript" src="jquery-1.10.2.min.js ...
- JS or C#?不存在的脚本之争
前言: 又来到了周末,小匹夫也终于有了喘口气写写博客的时间和精力.话说周五的下午,小匹夫偶然间晃了一眼蛮牛的QQ群,又看到了一个Unity3D开发中老生长谈的问题,“我的开发语言究竟是选择JavaSc ...
- JS实现文字截取(雾)
今天在跳板群那里看到一个神奇的样式,效果: 感觉十分神奇,因为一开始以为他是只有一个P元素包着文字然后最后一个自动截取文字,而且最后一行还可以提前截取???这怎么做到的,然后想了一下css怎么做,好像 ...
随机推荐
- Notepad++ 删除空行
先选中要删部分文本内容,假设是整个文件那就全选Ctrl+A,然后使用Notepad++自带的Textfx插件,在长长的列表中找到Delete Blank Lines,点击就可以. 例如以下图:
- SQLServer表变量对IO及内存影响测试
原文:SQLServer表变量对IO及内存影响测试 1. 测试创建表变量对IO的影响 测试创建表变量前后,tempdb的空间大小,目前使用sp_spaceused得到大小,也可以使用视图sys.dm_ ...
- JSF+EJB+JPA总体思路
前言: JSF+EJB+JPA 其实我并没有想象中的难,只是想做好,建立在正确的地方应用,真正的困难. 良好的技术,在错误的地方做应用,这是唯一能够被垃圾. 用. 重量级企业应用能够使用这个主要的3层 ...
- 【核心研究】消息队列_MessageQueue
消息队列排队过程中的消息.这第一条消息将首先被处理.但假设消息本身指定要处理的时间.我们必须等待,直到时间的消息处理能力.新闻MessageQueue正在使用Message类的表示,队列中的邮件保存结 ...
- 【iOS发展-81】setNeedsDisplay刷新显卡,并CADisplayLink它用来模拟计时器效果
(1)效果 (2)源码下载(假设提示没有小图片的话,自己找一个替换一下即可,看到效果即可) http://download.csdn.net/detail/wsb200514/8176339 (3)总 ...
- java数据结构系列之——数组(1)
import javax.management.RuntimeErrorException; public class MyArray { private long array[]; private ...
- STUN协议简介
STUN简要 STUN(Simple Traversal of UDP over NATs,NAT 的UDP简单穿越)是一种网络协议.它同意位于NAT(或多重NAT)后的client找出自己的公网地址 ...
- bnu 34986 Football on Table(数学+暴力)
pid=34986" target="_blank" style="">题目连接:bnu 34986 Football on Table 题目大 ...
- C#并行和多线程编程
5天玩转C#并行和多线程编程 —— 第二天 并行集合和PLinq 5天玩转C#并行和多线程编程系列文章目录 5天玩转C#并行和多线程编程 —— 第一天 认识Parallel 5天玩转C#并行和多线 ...
- Studio-Class Diagram
UML Design Via Visual Studio-Class Diagram 用过几个建模设计工具,小的有staruml,大的有rational rose,EA.最后发现还是Visual St ...