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

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

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

  1. var ZANTEMP;
  2.  
  3. //cookies
  4. jQuery.cookie = function(name, value, options) {
  5. if (typeof value != 'undefined') { // name and value given, set cookie
  6. options = options || {};
  7. if (value === null) {
  8. value = '';
  9. options.expires = -1;
  10. }
  11. var expires = '';
  12. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  13. var date;
  14. if (typeof options.expires == 'number') {
  15. date = new Date();
  16. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  17. } else {
  18. date = options.expires;
  19. }
  20. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  21. }
  22. var path = options.path ? '; path=' + options.path : '';
  23. var domain = options.domain ? '; domain=' + options.domain : '';
  24. var secure = options.secure ? '; secure' : '';
  25. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  26. } else { // only name given, get cookie
  27. var cookieValue = null;
  28. if (document.cookie && document.cookie != '') {
  29. var cookies = document.cookie.split(';');
  30. for (var i = 0; i < cookies.length; i++) {
  31. var cookie = jQuery.trim(cookies[i]);
  32. // Does this cookie string begin with the name we want?
  33. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  34. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  35. break;
  36. }
  37. }
  38. }
  39. return cookieValue;
  40. }
  41. };
  42.  
  43. //chrome上传预览
  44. function handleFiles(files) {
  45. if (!$.browser.msie||($.browser.msie&& $.browser.version=="10.0")){
  46. //遍历files并处理
  47. files=files.files;
  48. for (var i = 0; i < files.length; i++) {
  49. var file = files[i];
  50. var imageType = /image.*/;
  51. //通过type属性进行图片格式过滤
  52. if (!file.type.match(imageType)) {
  53. continue;
  54. }
  55. //读入文件
  56. var reader = new FileReader();
  57. reader.onload = function (e) {
  58. //e.target.result返回的即是图片的dataURI格式的内容
  59. var imgData = e.target.result,
  60. img = document.createElement('img');
  61. //img.src = imgData;
  62. //展示img
  63. $(".pre-img").attr("src", imgData).css("visibility", "visible");
  64. }
  65. reader.readAsDataURL(file);
  66. }
  67.  
  68. }else{//IE
  69. var html="<div class='pre-img'></div>";
  70. $('.pre-div').html('').html(html);
  71. //采用滤镜效果生成图片预览
  72. // files.select();
  73. path =$('#upload-btn').val();
  74. $('.pre-img').css({"filter":"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\""+ path + "\")"});
  75. }
  76. }
  77.  
  78. //temp
  79. var clickedMask;
  80. //check cookie
  81. function cookie_check_logined() {
  82. var s_info = $.cookie("S_INFO");
  83. var p_info = $.cookie("P_INFO");
  84. var now = new Date();
  85. if (s_info != null && s_info != "" && p_info != null && p_info != "" && (now.getTime() / 1000 - s_info.split('|')[0]) / 600 < 1) {
  86. return p_info.split('|')[0];
  87. }
  88. return false;
  89. }
  90.  
  91. //扩展中文字符截断
  92. String.prototype.sub = function(n)
  93. {
  94. var r = /[^\x00-\xff]/g;
  95. if(this.replace(r, "mm").length <= n) return this;
  96. var m = Math.floor(n/2);
  97. for(var i=m; i<this.length; i++) {
  98. if(this.substr(0, i).replace(r, "mm").length>=n) {
  99. return this.substr(0, i) ; }
  100. } return this;
  101. };
  102.  
  103. //post回调
  104. function postArtCallback(result){
  105. $('#captcha_img').trigger('click');
  106. if(!result){
  107. $('.post-tips').text('请填写完整').show();
  108. return ;
  109. }
  110. if(result.success){
  111. var maskHeight=315;
  112. var maskWidth=645;
  113. var maskPosition=$('.post-form').position();
  114. $('.post-form').css({width:0,height:0}).hide();
  115. $('.success-box').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  116. $('#captcha_answer').val('');
  117. $('#content,#nickname,#title').val('');
  118.  
  119. }else{
  120. if(result.unlogin){
  121. $('.post-tips').text('帐号验证失败,请重新登录').show();
  122. return;
  123. }
  124. $('.post-tips').text(result.msg).show();
  125. }
  126. }
  127. //验证码
  128. rnd.today=new Date();
  129. rnd.seed=rnd.today.getTime();
  130. function rnd() {
  131. rnd.seed = (rnd.seed*9301+2973467) % 2332425280;
  132. return rnd.seed;
  133. };
  134.  
  135. $(function () {
  136. var userName=cookie_check_logined()?cookie_check_logined():'';
  137. var zanIsclick=false;
  138. $('.username-span').text(userName);
  139.  
  140. //绑定验证码
  141. $('#captcha_img').click(function(){
  142. var temp_id = parseInt(rnd());
  143. $('#captcha_img').attr('src', "http://captcha-for-what.webapp.163.com/get_captcha?captcha_id=zdcq" + temp_id);
  144. $('#captcha_id').val('zdcq' + temp_id);
  145. });
  146. $('#captcha_img').click();
  147.  
  148. var myWaterfall = gWaterFall.initWaterfall();
  149. $('.top').click(function () {
  150. $(window).scrollTop(0);
  151. })
  152.  
  153. //导航绑定
  154. $('.nav4').toggle(function(){
  155. $(this).addClass('current')
  156. },function(){
  157. $(this).removeClass('current')
  158. })
  159.  
  160. $('.a2').click(function(){
  161. var display=$('.tc-jp').css('display');
  162. $('.nav a').removeClass('current');
  163.  
  164. $('.tc').slideUp();
  165. if(display=='none'){
  166. $(this).addClass('current');
  167. $('.tc-jp').slideDown();
  168. }else{
  169. $(this).removeClass('current');
  170. $('.tc-jp').slideUp();
  171. }
  172. })
  173.  
  174. $('.a3').click(function(){
  175. var display=$('.tc-gz').css('display');
  176. $('.nav a').removeClass('current');
  177.  
  178. $('.tc').slideUp();
  179.  
  180. if(display=='none'){
  181. $('.tc-gz').slideDown();
  182. $(this).addClass('current');
  183. }else{
  184. $('.tc-gz').slideUp();
  185. $(this).removeClass('current');
  186. }
  187. })
  188.  
  189. $('.a5').click(function(){
  190. var display=$('.tc-mt').css('display');
  191. $('.nav a').removeClass('current');
  192.  
  193. $('.tc').slideUp();
  194. if(display=='none'){
  195. $(this).addClass('current');
  196. $('.tc-mt').slideDown();
  197. }else{
  198. $(this).removeClass('current');
  199. $('.tc-mt').slideUp();
  200. }
  201. })
  202.  
  203. //上传绑定
  204. $("#upload-a").click(function(){
  205. $("#upload-btn").trigger('click');
  206. })
  207. $(".a1").click(function(){
  208. $('.j-1').trigger('click');
  209. })
  210.  
  211. $('.gz-btn').click(function(){
  212. $('.j-1').trigger('click');
  213. })
  214.  
  215. $("#post-btn").click(function(e){
  216.  
  217. })
  218. //点赞
  219. $('.mask .y-up,.mask .y-up-only').live('click',function(){
  220. ZANTEMP=$(this);
  221. var id=$(this).attr('data-artid');
  222. var p=$(this);
  223. var _this=$(this);
  224. if(!cookie_check_logined()){
  225. if(!zanIsclick){
  226. var maskHeight=315;
  227. var maskWidth=645;
  228. var maskPosition=$('.mask').position();
  229. $('.encourage-box').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  230. return;
  231. }
  232. }
  233. $.getJSON('http://zdcq.webapp.163.com/script/user/vote_article?article_id='+id+'&callback=?',function(data){
  234. if(data.article_resp){
  235.  
  236. _this.trigger('click');
  237. // return;
  238. }
  239. if(data.success){
  240. // alert('点"赞"成功');
  241. var newNum=parseInt( p.html().toLowerCase().split('</i>')[1],10)+1;
  242. // console.log(p.html()) ;
  243. console.log(parseInt( p.html().split('</i>')[1],10));
  244. p.html('<i></i>'+newNum) ;
  245. clickedMask.find('.y-up,.y-up-only').html('<i></i>'+newNum);
  246.  
  247. }else{
  248. alert(data.msg);
  249. }
  250. });
  251. })
  252.  
  253. //选择登录与否
  254. $('.yes-login').click(function(){
  255. var maskHeight=315;
  256. var maskWidth=645;
  257. var maskPosition=$(this).parent().position();
  258. $(this).parent().animate({width:0,height:0}).hide();
  259. $('.login-form').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  260. if(!cookie_check_logined()){
  261. $('.logout-tips').hide();
  262. }else{
  263. $('.logout-tips').show();
  264. }
  265. })
  266.  
  267. $('.no-zan').click(function(){
  268. $('.encourage-box').animate({width:0,height:0},function(){
  269. $('.encourage-box').hide();
  270. })
  271. zanIsclick=true;
  272. ZANTEMP.trigger('click');
  273.  
  274. })
  275.  
  276. $('.no-post').click(function(){
  277. var maskHeight=315;
  278. var maskWidth=645;
  279. var maskPosition=$(this).parent().position();
  280. $(this).parent().animate({width:0,height:0}).hide();
  281. $('.post-form').css({width:0,height:0}).css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  282. if(!cookie_check_logined()){
  283. $('.logout-tips').hide();
  284. }else{
  285. $('.logout-tips').show();
  286. }
  287. })
  288. //填写用户信息
  289. $('#info-btn').click(function(){
  290. var name=$("#name").val();
  291. var phone=$('#phone').val();
  292. $.getJSON('http://zdcq.webapp.163.com/script/user/fill_userinfo?name='+name+'&phone='+phone+'&callback=?',function(data){
  293. if(data.success){
  294. if(!ZANTEMP){
  295. var maskHeight=$('.info-form').height();
  296. var maskWidth=$('.info-form').width();
  297. var maskPosition=$('.info-form').position();
  298. $('.info-form').hide();
  299. $('.post-form').css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  300. $('.logout-tips').show();
  301. }else{
  302. ZANTEMP.trigger('click');
  303. $('.info-form').hide();
  304. }
  305. }
  306. if(data.error){
  307. alert(data.msg);
  308. }
  309. })
  310. })
  311.  
  312. $('.mask').live('click',function(e){
  313. if($(e.target).hasClass('y-up')||$(e.target).hasClass('NIE-share')||$(e.target).hasClass('y-up-only')){
  314. return;
  315. }
  316. var _self=$(this);
  317. $(this).animate({
  318. width:0,
  319. height:0
  320. },function(){
  321. _self.hide();
  322. })
  323. })
  324.  
  325. //登录开始
  326. AutoUrs.bind("username", {
  327. mailList: [
  328. "163.com",
  329. "126.com",
  330. "yeah.net",
  331. "qq.com",
  332. "vip.163.com",
  333. "vip.126.com",
  334. "188.com",
  335. "gmail.com",
  336. "sina.com",
  337. "hotmail.com"
  338. ],
  339. tabTo: "password",
  340. cookie: "global"
  341. });
  342.  
  343. $("#login-form-box").ntesLoginForm({
  344. beforeSubmit: function() {
  345. var is_ok = true;
  346. var username = $("#login-form-box input[name=username]");
  347. var password = $("#login-form-box input[name=password]");
  348. if (!username.val() || username.val() == "如name@example.com") {
  349. // $("#acErr").show()
  350. is_ok = false;
  351. }
  352.  
  353. if (!password.val()) {
  354. // $("#pwdErr").show()
  355. is_ok = false;
  356. }
  357. return is_ok;
  358. },
  359. success: function(params) {
  360. userName=cookie_check_logined();
  361. var maskHeight=$('.login-form').height();
  362. var maskWidth=$('.login-form').width();
  363. var maskPosition=$('.login-form').position();
  364. $('.username-span').html(userName);
  365. $('.login-tips').text('').hide();
  366. $.getJSON('http://zdcq.webapp.163.com/script/user/is_userinfo_fill?urs='+userName+'&callback=?',function(data){
  367.  
  368. if(!data.fill){
  369. $('.login-form').hide();
  370. $('.info-form').css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  371. }else{
  372. $('.login-form').hide();
  373. if(ZANTEMP){
  374. ZANTEMP.trigger('click');
  375. }else{
  376. $('.post-form').css(maskPosition).animate({height:maskHeight, width:maskWidth}).show();
  377. }
  378.  
  379. $('.logout-tips').show();
  380. }
  381. })
  382. },
  383. fail: function(params) {
  384. $('.login-tips').text(params.errorMsg).show();
  385. }
  386. });
  387.  
  388. //out login
  389. $("#login-out").click(function () {
  390. var oldUrl=window.location.href;
  391. window.location='http://reg.163.com/Logout.jsp?username='+userName+'&url='+oldUrl;
  392. })
  393.  
  394. //成功分享
  395. nie.use(['util.share'],function(){
  396. var successShare = nie.util.share({
  397. fat: ".s-share",
  398. type: 6,
  399. defShow: [5, 1, 3, 2],
  400. title: '我刚刚参与了《藏地传奇》真言活动,提交你的真言,说出你对西藏游戏化的建议,一起探索西藏题材的无限可能!还有机会获得iPad mini等精美奖品哦!活动地址:',
  401. img: ''
  402. });
  403. })
  404.  
  405. //post input focus
  406. $('#title').focus(function(){
  407. if($(this).val()=='20字以内'){
  408. $(this).val("")
  409. }
  410. })
  411. /*
  412. $('#title').blur(function(){
  413. if($(this).val()==''){
  414. $(this).val("20字以内")
  415. }
  416. })
  417. */
  418. $('#nickname').focus(function(){
  419. if($(this).val()=='6字以内'){
  420. $(this).val('')
  421. }
  422. })
  423. /*
  424. $('#nickname').blur(function(){
  425. if($(this).val()==''){
  426. $(this).val("6字以内")
  427. }
  428. })
  429. */
  430. $('#content').focus(function(){
  431. if($(this).val()=='140字以内'){
  432. $(this).val('')
  433. }
  434. })
  435. /*
  436. $('#content').blur(function(){
  437. if($(this).val()==''){
  438. $(this).val("140字以内")
  439. }
  440. })
  441. */
  442. $('.top').css('right',($(window).width()-$('.out').width())/2-50);
  443. $(window).resize(function(){
  444. $('.top').css('right',($(window).width()-$('.out').width())/2-50);
  445. })
  446.  
  447. $('.form-close').live('click',function(){
  448. var parent=$(this).parent();
  449. $(this).parent().animate({
  450. width:0,
  451. height:0
  452. },function(){
  453. parent.hide();
  454. })
  455. })
  456.  
  457. $('.tc-close').click(function(){
  458. $(this).parent().slideUp();
  459. var pid=$(this).attr('data-parent');
  460. $(pid).removeClass('current');
  461. })
  462. })

藏地传奇js的更多相关文章

  1. 【小练习02】CSS--网易产品

    要求用css和HTML实现下图效果: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...

  2. 第1天:CSS基本样式

    今天学习了CSS基本样式和属性.在做练习的时候遇到一个小问题,最后解决了. 记住:浏览器有默认margin和padding.样式最开始记得一定写:*{margin:0;padding:0}. 学习经验 ...

  3. 前台的url通过 ActionName?var1=xx&var2=yy 的形式传给特定action

    本文对自己开发的基于lucene和J2EE技术的搜索引擎开发经验进行简单总结.今后可能会从性能的角度总结lucene开发经验.当数据上TB级别后,分布式lucene以及结合分布式文件系统(如HDFS) ...

  4. 意外作出了一个javascript的服务器,可以通过js调用并执行任何java(包括 所有java 内核基本库)及C#类库,并最终由 C# 执行你提交的javascript代码! 不敢藏私,特与大家分

    最近研发BDC 云开发部署平台的数据路由及服务管理器意外作出了一个javascript的服务器,可以通过js调用并执行任何java(包括 所有java 内核基本库)及C#类库,并最终由 C# 执行你提 ...

  5. js控制TR的显示影藏

    在很多现实的场景中,有的文本框我们希望在选择“是”的按钮之后才出现,这就需要js控制TR的隐藏和显示,(div的影藏显示类似) 以下是一段选择是的按钮就显示身高和体重的文本框的代码.注意:ready方 ...

  6. JS+CSS简单实现DIV遮罩层显示隐藏【转藏】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. js和jquery通过this获取html标签中的属性值[转藏]

    <html> <head> <script type="text/javascript" src="jquery-1.10.2.min.js ...

  8. JS or C#?不存在的脚本之争

    前言: 又来到了周末,小匹夫也终于有了喘口气写写博客的时间和精力.话说周五的下午,小匹夫偶然间晃了一眼蛮牛的QQ群,又看到了一个Unity3D开发中老生长谈的问题,“我的开发语言究竟是选择JavaSc ...

  9. JS实现文字截取(雾)

    今天在跳板群那里看到一个神奇的样式,效果: 感觉十分神奇,因为一开始以为他是只有一个P元素包着文字然后最后一个自动截取文字,而且最后一行还可以提前截取???这怎么做到的,然后想了一下css怎么做,好像 ...

随机推荐

  1. Notepad++ 删除空行

    先选中要删部分文本内容,假设是整个文件那就全选Ctrl+A,然后使用Notepad++自带的Textfx插件,在长长的列表中找到Delete Blank Lines,点击就可以. 例如以下图:

  2. SQLServer表变量对IO及内存影响测试

    原文:SQLServer表变量对IO及内存影响测试 1. 测试创建表变量对IO的影响 测试创建表变量前后,tempdb的空间大小,目前使用sp_spaceused得到大小,也可以使用视图sys.dm_ ...

  3. JSF+EJB+JPA总体思路

    前言: JSF+EJB+JPA 其实我并没有想象中的难,只是想做好,建立在正确的地方应用,真正的困难. 良好的技术,在错误的地方做应用,这是唯一能够被垃圾. 用. 重量级企业应用能够使用这个主要的3层 ...

  4. 【核心研究】消息队列_MessageQueue

    消息队列排队过程中的消息.这第一条消息将首先被处理.但假设消息本身指定要处理的时间.我们必须等待,直到时间的消息处理能力.新闻MessageQueue正在使用Message类的表示,队列中的邮件保存结 ...

  5. 【iOS发展-81】setNeedsDisplay刷新显卡,并CADisplayLink它用来模拟计时器效果

    (1)效果 (2)源码下载(假设提示没有小图片的话,自己找一个替换一下即可,看到效果即可) http://download.csdn.net/detail/wsb200514/8176339 (3)总 ...

  6. java数据结构系列之——数组(1)

    import javax.management.RuntimeErrorException; public class MyArray { private long array[]; private ...

  7. STUN协议简介

    STUN简要 STUN(Simple Traversal of UDP over NATs,NAT 的UDP简单穿越)是一种网络协议.它同意位于NAT(或多重NAT)后的client找出自己的公网地址 ...

  8. bnu 34986 Football on Table(数学+暴力)

    pid=34986" target="_blank" style="">题目连接:bnu 34986 Football on Table 题目大 ...

  9. C#并行和多线程编程

    5天玩转C#并行和多线程编程 —— 第二天 并行集合和PLinq   5天玩转C#并行和多线程编程系列文章目录 5天玩转C#并行和多线程编程 —— 第一天 认识Parallel 5天玩转C#并行和多线 ...

  10. Studio-Class Diagram

    UML Design Via Visual Studio-Class Diagram 用过几个建模设计工具,小的有staruml,大的有rational rose,EA.最后发现还是Visual St ...