html.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. var _gaq = [];
  2. var userAgent = navigator.userAgent.toLowerCase();
  3. if(userAgent == null || userAgent == ''){
  4. //
  5. }else{
  6. if(userAgent.indexOf("android") != -1 || userAgent.indexOf("ios") != -1 || userAgent.indexOf("iphone") != -1 || userAgent.indexOf("ipad") != -1 || userAgent.indexOf("windows phone") != -1 ){
  7. //
  8. }else{
  9. //google 统计start
  10. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  11. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  12. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  13. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  14. ga('create', 'UA-64962204-1', 'auto');
  15. ga('send', 'pageview');
  16. //google 统计end
  17. }
  18. }
  19. //tag推荐弹窗
  20. (function(){
  21. var protocol = location.protocol.substr(0, 4) === 'http' ? '' : 'http:';
  22. $.getScript(protocol + '//c.csdnimg.cn/public/common/tag-suggest-pop/js/main.js?'+(new Date()/120000|0));
  23. })();
  24. !(function(){
  25. var currUser={
  26. userName:"",
  27. userNick:'<a class="set-nick" href="https://passport.csdn.net/account/profile">设置昵称<span class="write-icon"></span></a>',
  28. userInfo:"",
  29. desc : '<a class="fill-dec" href="//my.csdn.net" target="_blank">编辑自我介绍,让更多人了解你<span class="write-icon"></span></a>',
  30. avatar:"//static.csdn.net/public/common/toolbar/images/100x100.jpg"
  31. };
  32. var prodLogo = "none";
  33. var $oScriptTag =$("#toolbar-tpl-scriptId");
  34. var skin =$oScriptTag.attr("skin")=="black"?" csdn-toolbar-skin-black ":"";
  35. var fixed = $oScriptTag.attr("fixed")=="top"?" navbar-fixed-top ":"";
  36. var prodIndex= $oScriptTag.attr("domain")?$oScriptTag.attr("domain"):window.location.protocol+"//"+window.location.host;
  37. prodIndex+='?ref=toolbar_logo';
  38. var getCookie =function (objName){//获取指定名称的cookie的值
  39. var arrStr = document.cookie.split("; ");
  40. for(var i = 0;i < arrStr.length;i ++){
  41. var temp = arrStr[i].split("=");
  42. if(temp[0] == objName) return decodeURI(temp[1]);
  43. }
  44. }
  45. var setCookie = function (name,value) {
  46. var Days = 30;
  47. var exp = new Date();
  48. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  49. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();// + ";domain=.csdn.net;path=/";
  50. }
  51. var HTMLEncode =function(str) {
  52. var s = "";
  53. if(str.length == 0) return "";
  54. s = str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\'/g, "&#39;").replace(/\"/g, "&quot;");
  55. return s;
  56. }
  57. var AUtoAvatar = function(AU){
  58. if(!AU||!currUser.userName){
  59. return false;
  60. }
  61. var _AUPath = AU.split("").join("/");
  62. var userName = currUser.userName&&currUser.userName.toLowerCase();
  63. return "http://avatar.csdn.net/"+_AUPath+"/2_"+userName+".jpg";
  64. }
  65. var hasLogin = false;
  66. var loginMark ="unlogin";
  67. function checkLogin(callback) {
  68. currUser.userNick = getCookie("UserNick") ||currUser.userNick;
  69. currUser.userName = getCookie("UserName") || currUser.userName;
  70. currUser.userInfo = getCookie("UserInfo") || currUser.userInfo;
  71. currUser.avatar = AUtoAvatar(getCookie("AU")) || currUser.avatar;
  72. currUser.desc = getCookie("UD") || currUser.desc;
  73. if(getCookie("UD")){
  74. currUser.desc = HTMLEncode(decodeURIComponent(currUser.desc).replace(/\+/g," "));
  75. }
  76. callback(currUser);
  77. }
  78. checkLogin(function(currUser){
  79. if(currUser.userName&&currUser.userInfo){
  80. hasLogin = true;
  81. }
  82. loginMark = hasLogin?"":"unlogin";
  83. })
  84. /*
  85. * init pord logo
  86. */
  87. var prodJSON = {
  88. "blog" : "blog-icon",
  89. "download" : "down-icon",
  90. "bbs" : "bbs-icon",
  91. "my" :"space-icon",
  92. "code" : "code-icon",
  93. "share" : "share-icon",
  94. "tag" : "tag-icon",
  95. "dashboard":"dashboard-icon",
  96. "news" : "news-icon",
  97. "tag" : "tag-icon",
  98. "ask" : "ask-icon",
  99. "notify" : "notify-icon"
  100. }
  101. if(prodJSON[$oScriptTag.attr("prod")]){
  102. prodLogo=prodJSON[$oScriptTag.attr("prod")]||$oScriptTag.attr("prod");
  103. }
  104. // $( 'head' ).append( '<link rel="stylesheet" href="//csdnimg.cn/public/common/toolbar/css/font-awesome.min.css">' );
  105. // 注册url,https://passport.csdn.net/account/register?ref=toolbar
  106. var tpl ='\<div class="csdn-toolbar'+skin+fixed+'">\
  107. <div class="container row center-block ">\
  108. <div class="col-md-3 pull-left logo clearfix"><a href="http://www.csdn.net?ref=toolbar" title="CSDN首页" target="_blank" class="icon"></a><a title="频道首页" href="'+prodIndex+'" class="img '+prodLogo+'"></a></div>\
  109. <div class="pull-right login-wrap '+loginMark+'">\
  110. <ul class="btns">\
  111. <li class="loginlink"><a href="https://passport.csdn.net/account/login?ref=toolbar" target="_top">登录&nbsp;</a>|<a target="_top" href="http://passport.csdn.net/account/mobileregister?ref=toolbar&action=mobileRegister">&nbsp;注册</a></li>\
  112. <li class="search">\
  113. <div class="icon on-search-icon">\
  114. <div class="wrap">\
  115. <div class="curr-icon-wrap">\
  116. <div class="curr-icon"></div>\
  117. </div>\
  118. <form action="http://so.csdn.net/search" method="get" target="_blank">\
  119. <input type="hidden" value="toolbar" name="ref" accesskey="2">\
  120. <div class="border">\
  121. <input placeholder="搜索" type="text" value="" name="q" accesskey="2"><span class="icon-enter-sm"></span>\
  122. </div>\
  123. </form>\
  124. </div>\
  125. </div>\
  126. </li>\
  127. <li class="favor">\
  128. <div class="icon on-favor-icon">\
  129. <div class="wrap">\
  130. <div class="curr-icon-wrap">\
  131. <div class="curr-icon"></div>\
  132. </div>\
  133. <div style="display:none;" class="favor-success"><span class="msg">收藏成功</span>\
  134. <div class="btns"><span class="btn btn-primary ok">确定</span></div>\
  135. </div>\
  136. <div style="display:none;" class="favor-failed"><span class="icon-danger-lg"></span><span class="msg">收藏失败,请重新收藏</span>\
  137. <div class="btns"><span class="btn btn-primary ok">确定</span></div>\
  138. </div>\
  139. <form role="form" class="form-horizontal favor-form">\
  140. <div class="form-group">\
  141. <div class="clearfix">\
  142. <label for="input-title" class="col-sm-2 control-label">标题</label>\
  143. <div class="col-sm-10">\
  144. <input id="inputTitle" type="text" placeholder="" class="title form-control">\
  145. </div>\
  146. </div>\
  147. <div class="alert alert-danger"><strong></strong>标题不能为空</div>\
  148. </div>\
  149. <div class="form-group">\
  150. <label for="input-url" class="col-sm-2 control-label">网址</label>\
  151. <div class="col-sm-10">\
  152. <input id="input-url" type="text" placeholder="" class="url form-control">\
  153. </div>\
  154. </div>\
  155. <div class="form-group">\
  156. <label for="input-tag" class="col-sm-2 tag control-label">标签</label>\
  157. <div class="col-sm-10">\
  158. <input id="input-tag" type="text" class="form-control tag">\
  159. </div>\
  160. </div>\
  161. <div class="form-group">\
  162. <label for="input-description" class="description col-sm-2 control-label">摘要</label>\
  163. <div class="col-sm-10">\
  164. <textarea id="input-description" class="form-control description"></textarea>\
  165. </div>\
  166. </div>\
  167. <div class="form-group">\
  168. <div class="col-sm-offset-2 col-sm-10 ft">\
  169. <div class="col-sm-4 pull-left">\
  170. <div class="checkbox">\
  171. <label>\
  172. <input type="checkbox" name="share" checked="checked" class="share">公开\
  173. </label>\
  174. </div>\
  175. </div>\
  176. <div class="col-sm-8 pull-right favor-btns">\
  177. <button type="button" class="cancel btn btn-default">取消</button>\
  178. <button type="submit" class="submit btn btn-primary">收藏</button>\
  179. </div>\
  180. </div>\
  181. </div>\
  182. </form>\
  183. </div>\
  184. </div>\
  185. </li>\
  186. <li class="notify">\
  187. <div style="display:none" class="number"></div>\
  188. <div style="display:none" class="icon-hasnotes-sm"></div>\
  189. <div id="header_notice_num"></div>\
  190. <div class="icon on-notify-icon">\
  191. <div class="wrap">\
  192. <div class="curr-icon-wrap">\
  193. <div class="curr-icon"></div>\
  194. </div>\
  195. <div id="note1" class="csdn_note">\
  196. <div class="box"></div>\
  197. </div>\
  198. </div>\
  199. </div>\
  200. </li>\
  201. <li class="ugc">\
  202. <div class="icon on-ugc-icon">\
  203. <div class="wrap clearfix">\
  204. <div class="curr-icon-wrap">\
  205. <div class="curr-icon"></div>\
  206. </div>\
  207. <dl>\
  208. <dt><a href="http://geek.csdn.net/news/expert?ref=toolbar" target="_blank" class="p-news clearfix" style="display:none;"><em class="icon"></em><span>分享资讯</span></a></dt>\
  209. <dt><a href="http://u.download.csdn.net/upload?ref=toolbar" target="_blank" class="p-doc clearfix"><em class="icon"></em><span>传PPT/文档</span></a></dt>\
  210. <dt><a href="http://bbs.csdn.net/topics/new?ref=toolbar" target="_blank" class="p-ask clearfix"><em class="icon"></em><span>提问题</span></a></dt>\
  211. <dt><a href="http://write.blog.csdn.net/postedit?ref=toolbar" target="_blank" class="p-blog clearfix"><em class="icon"></em><span>写博客</span></a></dt>\
  212. <dt><a href="http://u.download.csdn.net/upload?ref=toolbar" target="_blank" class="p-src clearfix"><em class="icon"></em><span>传资源</span></a></dt>\
  213. <dt><a href="https://code.csdn.net/projects/new?ref=toolbar" target="_blank" class="c-obj clearfix"><em class="icon"></em><span>创建项目</span></a></dt>\
  214. <dt><a href="https://code.csdn.net/snippets/new?ref=toolbar" target="_blank" class="c-code clearfix"><em class="icon"></em><span>创建代码片</span></a></dt>\
  215. </dl>\
  216. </div>\
  217. </div>\
  218. </li>\
  219. <li class="profile">\
  220. <div class="icon on-profile-icon"><img src="'+currUser.avatar+'" class="curr-icon-img">\
  221. <div class="wrap clearfix">\
  222. <div class="curr-icon-wrap">\
  223. <div class="curr-icon"></div>\
  224. </div>\
  225. <div class="bd">\
  226. <dl class="clearfix">\
  227. <dt class="pull-left img"><a target="_blank" href="http://my.csdn.net?ref=toolbar" class="avatar"><img src="'+currUser.avatar+'"></a></dt>\
  228. <dd class="info" style="border: none;"><a target="_blank" href="http://my.csdn.net?ref=toolbar" class="nickname">'+currUser.userNick+'</a><span class="dec">'+currUser.desc+'</span></dd>\
  229. </dl>\
  230. </div>\
  231. <div class="ft clearfix"><a target="_blank" href="http://my.csdn.net/my/account/changepwd?ref=toolbar" class="pull-left"><span class="icon-cog"></span>帐号设置</a><a href="https://passport.csdn.net/account/logout?ref=toolbar" target="_top" class="pull-left" style="margin-left:132px; width:18px; height:27px; white-space:nowrap; overflow:hidden;"><span class="icon-signout"></span><span class="out">退出</span></a></div>\
  232. </div>\
  233. </div>\
  234. </li>\
  235. <li class="apps">\
  236. <div id="chasnew123" class="hasnew"></div>\
  237. <div id="cappsarea123" class="icon on-apps-icon">\
  238. <div class="wrap clearfix">\
  239. <div class="curr-icon-wrap">\
  240. <div class="curr-icon"></div>\
  241. </div>\
  242. <div class="detail">\
  243. <dl>\
  244. <dt>\
  245. <h5>社区</h5>\
  246. </dt>\
  247. <dd> <a href="http://blog.csdn.net?ref=toolbar" target="_blank">博客</a></dd>\
  248. <dd> <a href="http://bbs.csdn.net?ref=toolbar" target="_blank">论坛</a></dd>\
  249. <dd> <a href="http://download.csdn.net?ref=toolbar" target="_blank">下载</a></dd>\
  250. <dd><a href="http://ask.csdn.net?ref=toolbar" target="_blank">技术问答</a></dd>\
  251. <dd><a href="http://geek.csdn.net?ref=toolbar" target="_blank">极客头条</a></dd>\
  252. <dd> <a href="http://hero.csdn.net?ref=toolbar" target="_blank">英雄会</a></dd>\
  253. </dl>\
  254. </div>\
  255. <div class="detail">\
  256. <dl>\
  257. <dt>\
  258. <h5>服务</h5>\
  259. </dt>\
  260. <dd> <a href="http://job.csdn.net?ref=toolbar" target="_blank">JOB<img src="http://c.csdnimg.cn/public/common/toolbar/images/new.gif" style="display: none; margin-top: -26px; width: 23px;"></a></dd>\
  261. <dd> <a href="http://edu.csdn.net?ref=toolbar" target="_blank">学院<img src="http://c.csdnimg.cn/public/common/toolbar/images/new.gif" style="display: none; margin-top: -26px; width: 23px;"></a></dd>\
  262. <dd> <a href="https://code.csdn.net?ref=toolbar" target="_blank">CODE</a></dd>\
  263. <dd> <a href="http://huiyi.csdn.net/?ref=toolbar" target="_blank">活动</a></dd>\
  264. <dd> <a href="http://www.csto.com?ref=toolbar" target="_blank">CSTO</a></dd>\
  265. <dd> <a href="http://mall.csdn.net?ref=toolbar" target="_blank">C币兑换<img src="http://c.csdnimg.cn/public/common/toolbar/images/new.gif" style="display: none; margin-top: -26px; width: 23px;"></a></dd>\
  266. </dl>\
  267. </div>\
  268. <div class="detail last">\
  269. <dl>\
  270. <dt>\
  271. <h5>俱乐部</h5>\
  272. </dt>\
  273. <dd> <a href="http://cto.csdn.net?ref=toolbar" target="_blank">CTO俱乐部</a></dd>\
  274. <dd> <a href="http://student.csdn.net?ref=toolbar" target="_blank">高校俱乐部</a></dd>\
  275. </dl>\
  276. </div>\
  277. </div>\
  278. </div>\
  279. </li>\
  280. </ul>\
  281. </div>\
  282. </div>\
  283. </div>';
  284. $(document.body).append($(tpl));
  285. $("#chasnew123").hide();
  286. //var newTag = true;
  287. //if (newTag) {
  288. // var hasNew = getCookie("csdn_has_new_product");
  289. // if (hasNew == "2")
  290. // $("#chasnew123").hide();
  291. // else {
  292. // $("#cappsarea123").one("mouseover", function () {
  293. // setCookie("csdn_has_new_product", "2");
  294. // $("#chasnew123").hide();
  295. // });
  296. // }
  297. //}
  298. })();