scripts.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. ;(function($) {
  2. $.fn.serializeObject = function() {
  3. var o = {};
  4. var a = this.serializeArray();
  5. $.each(a, function() {
  6. if (o[this.name]) {
  7. if (!o[this.name].push) {
  8. o[this.name] = [o[this.name]];
  9. }
  10. o[this.name].push(this.value || '');
  11. } else {
  12. o[this.name] = this.value || '';
  13. }
  14. });
  15. return o;
  16. }
  17. })(jQuery);
  18. $(function() {
  19. popBrowserTips();
  20. $("img").lazyload({
  21. effect: "fadeIn", //渐现,show(直接显示),fadeIn(淡入),slideDown(下拉)
  22. threshold: 2700, //预加载,在图片距离屏幕180px时提前载入
  23. //event: 'click', // 事件触发时才加载,click(点击),mouseover(鼠标划过),sporty(运动的),默认为scroll(滑动)
  24. //container: $("#container"), // 指定对某容器中的图片实现效果
  25. failure_limit: 2 //加载2张可见区域外的图片,lazyload默认在找到第一张不在可见区域里的图片时则不再继续加载,但当HTML容器混乱的时候可能出现可见区域内图片并没加载出来的情况
  26. });
  27. $(".demo1").bootstrapNews({
  28. newsPerPage: 5,
  29. autoplay: true,
  30. pauseOnHover: true,
  31. direction: 'up',
  32. newsTickerInterval: 2000,
  33. onToDo: function() {
  34. //console.log(this);
  35. }
  36. });
  37. $(".notices").bootstrapNews({
  38. newsPerPage: 4,
  39. autoplay: true,
  40. pauseOnHover: true,
  41. navigation: false,
  42. direction: 'down',
  43. newsTickerInterval: 2500,
  44. onToDo: function() {
  45. //console.log(this);
  46. }
  47. });
  48. //全局加载动画
  49. $("a[href]").click(function(e) {
  50. if ($(this).attr("target") == "_blank") {
  51. return;
  52. }
  53. if ($(this).attr("href").indexOf("#") >= 0 || $(this).attr("href").indexOf("javascript") >= 0) {
  54. return;
  55. }
  56. loading();
  57. setTimeout(function() {
  58. loadingDone();
  59. window.notie.alert({
  60. type: 4,
  61. text: "页面加载失败!",
  62. time: 4
  63. });
  64. }, 60000);
  65. });
  66. //new WOW().init();//滚动加载
  67. var nav = $(".cd-main-header");
  68. if (document.documentElement.scrollTop || document.body.scrollTop > 0) {
  69. nav.css("background-color", "white");
  70. } else {
  71. nav.css("background-color", "transparent");
  72. }
  73. document.onscroll = function() {
  74. if (document.documentElement.scrollTop || document.body.scrollTop > 10) {
  75. nav.css({
  76. "background-color": "white",
  77. transition: "all 1s ease-in-out"
  78. });
  79. } else {
  80. nav.css({
  81. "background-color": "transparent",
  82. transition: "all 1s ease-in-out"
  83. });
  84. }
  85. }
  86. //搜索建议
  87. $("#search").bsSuggest({
  88. allowNoKeyword: false, //是否允许无关键字时请求数据。为 false 则无输入时不执行过滤请求
  89. multiWord: true, //以分隔符号分割的多关键字支持
  90. separator: ",", //多关键字支持时的分隔符,默认为空格
  91. getDataMethod: "url", //获取数据的方式,总是从 URL 获取
  92. url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?p=3&t=' + (new Date()).getTime() + '&wd=', /*优先从url ajax 请求 json 帮助数据,注意最后一个参数为关键字请求参数*/
  93. jsonp: 'cb', //如果从 url 获取数据,并且需要跨域,则该参数必须设置
  94. processData: function(json) { // url 获取数据时,对数据的处理,作为 getData 的回调函数
  95. var i, data = {
  96. value: []
  97. };
  98. if (!json || !json.s || json.s.length === 0) {
  99. return false;
  100. }
  101. var len = json.s.length;
  102. for (i = 0; i < len; i++) {
  103. data.value.push({
  104. word: json.s[i]
  105. });
  106. }
  107. data.defaults = 'baidu';
  108. //字符串转化为 js 对象
  109. return data;
  110. }
  111. });
  112. $(".btn").on("mousedown", function(e) {
  113. window.ripplet(e, {
  114. color: null,
  115. className: 'rainbow',
  116. clearingDuration: '3s',
  117. spreadingDuration: '1s'
  118. });
  119. });
  120. if (!Object.prototype.hasOwnProperty.call(window, 'event')) {
  121. ['mousedown', 'mouseenter', 'onmouseleave'].forEach(function(eventType) {
  122. window.addEventListener(eventType, function(event) {
  123. window.event = event;
  124. }, true);
  125. });
  126. }
  127. window.fetch("/notice/last").then(function(response) {
  128. return response.json();
  129. }).then(function(data) {
  130. if (!data.Success) {
  131. return ;
  132. }
  133. data = data.Data;
  134. var nid = [].concat(JSON.parse(window.localStorage.getItem("notice") || '[]'));
  135. if (nid.indexOf(data.Id)==-1) {
  136. //公告层
  137. layer.open({
  138. title: '网站公告:' + data.Title,
  139. offset: (window.screen.width > 400 ? "100px" : "40px"),
  140. area: (window.screen.width > 400 ? 400 : window.screen.width - 10) + 'px',
  141. shade: 0.6,
  142. closeBtn: true,
  143. content: data.Content,
  144. btn: ["查看详情", '知道了'],
  145. btn1: function(layero) {
  146. nid.push(data.Id);
  147. window.localStorage.setItem("notice", JSON.stringify(nid));
  148. window.location.href = "/notice/" + data.Id;
  149. loading();
  150. },
  151. btn2: function(index) {
  152. nid.push(data.Id);
  153. window.localStorage.setItem("notice", JSON.stringify(nid));
  154. layer.closeAll();
  155. }
  156. });
  157. }
  158. }).catch(function(e) {
  159. console.log("Oops, error");
  160. });
  161. setInterval(function() {
  162. let timestamp = new Date().getTime();
  163. DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'Latency').then(data => {
  164. $("#ping").text(new Date().getTime()-timestamp);
  165. });
  166. }, 2000);
  167. // 自动重试加载图片
  168. $('img').on("error",function() {
  169. var that=$(this);
  170. var retry=that.attr("retry")||0;
  171. if(retry>10){
  172. return ;
  173. }else{
  174. retry++;
  175. that.attr("retry", retry);//重试次数+1
  176. that.attr('src', that.attr("src"));//继续刷新图片
  177. }
  178. });
  179. });
  180. //全局加载动画
  181. function loading() {
  182. $(".loading1").show();
  183. }
  184. function loadingDone() {
  185. $(".loading1").hide();
  186. }
  187. var clearSelect= "getSelection" in window ? function(){
  188. window.getSelection().removeAllRanges();
  189. } : function(){
  190. document.selection.empty();
  191. };
  192. /**禁止复制 */
  193. function CopyrightProtect() {
  194. setInterval(function() {
  195. try {
  196. (function() {}["constructor"]("debugger")());
  197. $(".article-content").on("keydown",function (e) {
  198. var currKey = 0, evt = e || window.event;
  199. currKey = evt.keyCode || evt.which || evt.charCode;
  200. if (currKey == 123 || (evt.ctrlKey && currKey == 67) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85)) { //禁止F12,Ctrl+C,Ctrl+U
  201. clearSelect();
  202. evt.cancelBubble = true;
  203. evt.returnValue = false;
  204. return false;
  205. }
  206. });
  207. document.onkeydown = function (e) {
  208. var currKey = 0, evt = e || window.event;
  209. currKey = evt.keyCode || evt.which || evt.charCode;
  210. if (currKey == 123 || (evt.ctrlKey && currKey == 65) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85) || (evt.ctrlKey && evt.shiftKey) || evt.altKey) {
  211. clearSelect();
  212. evt.cancelBubble = true;
  213. evt.returnValue = false;
  214. return false;
  215. }
  216. }
  217. document.ondragstart=function () {
  218. return false;
  219. }
  220. $(".article-content").on("copy",function (e) {
  221. e.returnValue = false;
  222. return false;
  223. });
  224. document.oncontextmenu = function (e) {
  225. e.returnValue = false;
  226. return false;
  227. }
  228. } catch (ex) {
  229. console.error(ex);
  230. }
  231. },500);
  232. }
  233. /**禁止编辑器内复制 */
  234. function CopyrightProtect4Editor() {
  235. setInterval(function() {
  236. try {
  237. (function() {}["constructor"]("debugger")());
  238. document.getElementById("ueditor_0").contentWindow.document.body.onkeydown = function (e) {
  239. var currKey = 0, evt = e || window.event;
  240. currKey = evt.keyCode || evt.which || evt.charCode;
  241. if (currKey == 123 || (evt.ctrlKey && currKey == 67) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85) || (evt.ctrlKey && currKey == 88) || (evt.ctrlKey && evt.shiftKey) || evt.altKey) {
  242. clearSelect();
  243. evt.cancelBubble = true;
  244. evt.returnValue = false;
  245. return false;
  246. }
  247. }
  248. document.getElementById("ueditor_0").contentWindow.document.body.ondragstart = function (e) {
  249. e.returnValue = false;
  250. return false;
  251. }
  252. document.getElementById("ueditor_0").contentWindow.document.body.oncopy = function (e) {
  253. e.returnValue = false;
  254. return false;
  255. }
  256. } catch (ex) {
  257. console.error(ex);
  258. }
  259. },500);
  260. }
  261. /**禁止全局复制 */
  262. function GlobalCopyrightProtect() {
  263. setInterval(function() {
  264. try {
  265. (function() {}["constructor"]("debugger")());
  266. $(".article-content").on("keydown",function (e) {
  267. var currKey = 0, evt = e || window.event;
  268. currKey = evt.keyCode || evt.which || evt.charCode;
  269. if (currKey == 123 || (evt.ctrlKey && currKey == 67) || (evt.ctrlKey && currKey == 83)|| (evt.ctrlKey && currKey == 85)) { //禁止F12,Ctrl+C,Ctrl+U
  270. clearSelect();
  271. evt.cancelBubble = true;
  272. evt.returnValue = false;
  273. return false;
  274. }
  275. });
  276. document.onkeydown = function (e) {
  277. var currKey = 0, evt = e || window.event;
  278. currKey = evt.keyCode || evt.which || evt.charCode;
  279. if (currKey == 123 || (evt.ctrlKey && currKey == 65) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85) || (evt.ctrlKey && evt.shiftKey) || evt.altKey) {
  280. clearSelect();
  281. evt.cancelBubble = true;
  282. evt.returnValue = false;
  283. return false;
  284. }
  285. }
  286. document.ondragstart=function () {
  287. return false;
  288. }
  289. $(".article-content").on("copy",function (e) {
  290. e.returnValue = false;
  291. return false;
  292. });
  293. document.oncontextmenu = function () {
  294. event.returnValue = false;
  295. return false;
  296. }
  297. } catch (ex) {
  298. console.error(ex);
  299. }
  300. },500);
  301. }
  302. function GetOperatingSystem(os) {
  303. if (os) {
  304. if (os.indexOf("Windows") >= 0) {
  305. return '<i class="icon-windows8"></i>'+os;
  306. } else if (os.indexOf("Mac") >= 0) {
  307. return '<i class="icon-apple"></i>'+os;
  308. } else if (os.indexOf("Chrome") >= 0) {
  309. return '<i class="icon-chrome"></i>'+os;
  310. } else if (os.indexOf("Android") >= 0) {
  311. return '<i class="icon-android"></i>'+os;
  312. } else {
  313. return '<i class="icon-stats"></i>'+os;
  314. }
  315. } else {
  316. return '<i class="icon-stats"></i>未知操作系统';
  317. }
  318. }
  319. function GetBrowser(browser) {
  320. if (browser) {
  321. if (browser.indexOf("Chrome") >= 0) {
  322. return '<i class="icon-chrome"></i>'+browser;
  323. } else if (browser.indexOf("Firefox") >= 0) {
  324. return '<i class="icon-firefox"></i>'+browser;
  325. } else if (browser.indexOf("IE") >= 0) {
  326. return '<i class="icon-IE"></i>'+browser;
  327. } else if (browser.indexOf("Edge") >= 0) {
  328. return '<i class="icon-edge"></i>'+browser;
  329. } else if (browser.indexOf("Opera") >= 0) {
  330. return '<i class="icon-opera"></i>'+browser;
  331. } else if (browser.indexOf("Safari") >= 0) {
  332. return '<i class="icon-safari"></i>'+browser;
  333. } else {
  334. return '<i class="icon-browser2"></i>'+browser;
  335. }
  336. } else {
  337. return '<i class="icon-browser2"></i>未知浏览器';
  338. }
  339. }
  340. function getFile(obj, inputName) {
  341. $("input[name='" + inputName + "']").val($(obj).val());
  342. }
  343. function popBrowserTips() {
  344. if (window.sessionStorage) {
  345. var deny = window.sessionStorage.getItem("deny") || false;
  346. if (window.screen.width <= 320 && !deny) {
  347. swal({
  348. title: '访问受限制?',
  349. html: "由于检测到您的设备<span style='color:red'>屏幕宽度过小</span>,网站的部分功能可能不会兼容你的设备,但是您<span style='color:red'>可以继续浏览</span>,为确保最佳用户体验,建议使用<span style='color:red'>5寸以上移动设备</span>,或分辨率大于<span style='color:red'>1360 x 768</span>的<span style='color:red'>电脑浏览器</span>访问本站,感谢您的来访和支持!",
  350. type: 'error',
  351. showCloseButton: true,
  352. showCancelButton: true,
  353. confirmButtonColor: '#3085d6',
  354. cancelButtonColor: '#d33',
  355. confirmButtonText: '我知道了',
  356. cancelButtonText: '哦哦'
  357. }).then(function(isConfirm) {
  358. if (isConfirm) {
  359. window.sessionStorage.setItem("deny", true);
  360. }
  361. });
  362. }
  363. }
  364. }
  365. function post(url, params, callback, error) {
  366. var formData = new FormData();
  367. Object.keys(params).forEach(function(key) {
  368. formData.append(key, params[key]);
  369. });
  370. window.fetch(url, {
  371. credentials: 'include',
  372. method: 'POST',
  373. mode: 'cors',
  374. body: formData
  375. }).then(function(response) {
  376. return response.json();
  377. }).then(function(data) {
  378. callback(data);
  379. }).catch(function(e) {
  380. loadingDone();
  381. if (error) {
  382. error(e);
  383. }
  384. });
  385. }
  386. function get(url, callback, error) {
  387. window.fetch(url, {
  388. credentials: 'include',
  389. method: 'GET',
  390. mode: 'cors'
  391. }).then(function(response) {
  392. return response.json();
  393. }).then(function(data) {
  394. callback(data);
  395. }).catch(function(e) {
  396. loadingDone();
  397. if (error) {
  398. error(e);
  399. }
  400. });
  401. }
  402. /**
  403. * 鼠标桃心
  404. */
  405. (function(window, document) {
  406. var hearts = [];
  407. window.requestAnimationFrame = (function() {
  408. return window.requestAnimationFrame ||
  409. window.webkitRequestAnimationFrame ||
  410. window.mozRequestAnimationFrame ||
  411. window.oRequestAnimationFrame ||
  412. window.msRequestAnimationFrame ||
  413. function(callback) {
  414. setTimeout(callback, 1000 / 60);
  415. }
  416. })();
  417. init();
  418. function init() {
  419. css(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
  420. attachEvent();
  421. gameloop();
  422. }
  423. function gameloop() {
  424. for (var i = 0; i < hearts.length; i++) {
  425. if (hearts[i].alpha <= 0) {
  426. document.body.removeChild(hearts[i].el);
  427. hearts.splice(i, 1);
  428. continue;
  429. }
  430. hearts[i].y--;
  431. hearts[i].scale += 0.004;
  432. hearts[i].alpha -= 0.013;
  433. hearts[i].el.style.cssText =
  434. "left:" +
  435. hearts[i].x +
  436. "px;top:" +
  437. hearts[i].y +
  438. "px;opacity:" +
  439. hearts[i].alpha +
  440. ";transform:scale(" +
  441. hearts[i].scale +
  442. "," +
  443. hearts[i].scale +
  444. ") rotate(45deg);background:" +
  445. hearts[i].color;
  446. }
  447. requestAnimationFrame(gameloop);
  448. }
  449. function attachEvent() {
  450. var old = typeof window.onclick === "function" && window.onclick;
  451. window.onclick = function(event) {
  452. old && old();
  453. createHeart(event);
  454. }
  455. }
  456. function createHeart(event) {
  457. var d = document.createElement("div");
  458. d.className = "heart";
  459. hearts.push({
  460. el: d,
  461. x: event.clientX - 5,
  462. y: event.clientY - 5,
  463. scale: 1,
  464. alpha: 1,
  465. color: randomColor()
  466. });
  467. document.body.appendChild(d);
  468. }
  469. function css(css) {
  470. var style = document.createElement("style");
  471. style.type = "text/css";
  472. try {
  473. style.appendChild(document.createTextNode(css));
  474. } catch (ex) {
  475. style.styleSheet.cssText = css;
  476. }
  477. document.getElementsByTagName('head')[0].appendChild(style);
  478. }
  479. function randomColor() {
  480. return "rgb(" +
  481. (~~(Math.random() * 255)) +
  482. "," +
  483. (~~(Math.random() * 255)) +
  484. "," +
  485. (~~(Math.random() * 255)) +
  486. ")";
  487. }
  488. })(window, document);