scripts.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. var tippy = new Tippy('.tippy-scale', {
  113. position: 'bottom',
  114. animation: 'scale',
  115. arrow: 'true',
  116. 'theme': 'light'
  117. }); //注册tooltips
  118. $(".btn").on("mousedown", function(e) {
  119. window.ripplet(e, {
  120. color: null,
  121. className: 'rainbow',
  122. clearingDuration: '3s',
  123. spreadingDuration: '1s'
  124. });
  125. });
  126. if (!Object.prototype.hasOwnProperty.call(window, 'event')) {
  127. ['mousedown', 'mouseenter', 'onmouseleave'].forEach(function(eventType) {
  128. window.addEventListener(eventType, function(event) {
  129. window.event = event;
  130. }, true);
  131. });
  132. }
  133. window.fetch("/notice/last").then(function(response) {
  134. return response.json();
  135. }).then(function(data) {
  136. if (!data.Success) {
  137. return ;
  138. }
  139. data = data.Data;
  140. var nid = [].concat(JSON.parse(window.localStorage.getItem("notice") || '[]'));
  141. if (nid.indexOf(data.Id)==-1) {
  142. //公告层
  143. layer.open({
  144. title: '网站公告:' + data.Title,
  145. offset: (window.screen.width > 400 ? "100px" : "40px"),
  146. area: (window.screen.width > 400 ? 400 : window.screen.width - 10) + 'px',
  147. shade: 0.6,
  148. closeBtn: true,
  149. content: data.Content,
  150. btn: ["查看详情", '知道了'],
  151. btn1: function(layero) {
  152. nid.push(data.Id);
  153. window.localStorage.setItem("notice", JSON.stringify(nid));
  154. window.location.href = "/notice/" + data.Id;
  155. loading();
  156. },
  157. btn2: function(index) {
  158. nid.push(data.Id);
  159. window.localStorage.setItem("notice", JSON.stringify(nid));
  160. layer.closeAll();
  161. }
  162. });
  163. }
  164. }).catch(function(e) {
  165. console.log("Oops, error");
  166. });
  167. setInterval(function() {
  168. let timestamp = new Date().getTime();
  169. DotNet.invokeMethodAsync('Masuit.MyBlogs.Core', 'Latency').then(data => {
  170. $("#ping").text(new Date().getTime()-timestamp);
  171. });
  172. }, 2000);
  173. // 自动重试加载图片
  174. $('img').on("error",function() {
  175. var that=$(this);
  176. var retry=that.attr("retry")||0;
  177. if(retry>10){
  178. return ;
  179. }else{
  180. retry++;
  181. that.attr("retry", retry);//重试次数+1
  182. that.attr('src', that.attr("src"));//继续刷新图片
  183. }
  184. });
  185. });
  186. //全局加载动画
  187. function loading() {
  188. $(".loading1").show();
  189. }
  190. function loadingDone() {
  191. $(".loading1").hide();
  192. }
  193. var clearSelect= "getSelection" in window ? function(){
  194. window.getSelection().removeAllRanges();
  195. } : function(){
  196. document.selection.empty();
  197. };
  198. /**禁止复制 */
  199. function CopyrightProtect() {
  200. setInterval(function() {
  201. try {
  202. (function() {}["constructor"]("debugger")());
  203. $(".article-content").on("keydown",function (e) {
  204. var currKey = 0, evt = e || window.event;
  205. currKey = evt.keyCode || evt.which || evt.charCode;
  206. if (currKey == 123 || (evt.ctrlKey && currKey == 67) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85)) { //禁止F12,Ctrl+C,Ctrl+U
  207. clearSelect();
  208. evt.cancelBubble = true;
  209. evt.returnValue = false;
  210. return false;
  211. }
  212. });
  213. document.onkeydown = function (e) {
  214. var currKey = 0, evt = e || window.event;
  215. currKey = evt.keyCode || evt.which || evt.charCode;
  216. if (currKey == 123 || (evt.ctrlKey && currKey == 65) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85) || (evt.ctrlKey && evt.shiftKey) || evt.altKey) {
  217. clearSelect();
  218. evt.cancelBubble = true;
  219. evt.returnValue = false;
  220. return false;
  221. }
  222. }
  223. document.ondragstart=function () {
  224. return false;
  225. }
  226. $(".article-content").on("copy",function (e) {
  227. e.returnValue = false;
  228. return false;
  229. });
  230. document.oncontextmenu = function (e) {
  231. e.returnValue = false;
  232. return false;
  233. }
  234. } catch (ex) {
  235. console.error(ex);
  236. }
  237. },500);
  238. }
  239. /**禁止编辑器内复制 */
  240. function CopyrightProtect4Editor() {
  241. setInterval(function() {
  242. try {
  243. (function() {}["constructor"]("debugger")());
  244. document.getElementById("ueditor_0").contentWindow.document.body.onkeydown = function (e) {
  245. var currKey = 0, evt = e || window.event;
  246. currKey = evt.keyCode || evt.which || evt.charCode;
  247. 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) {
  248. clearSelect();
  249. evt.cancelBubble = true;
  250. evt.returnValue = false;
  251. return false;
  252. }
  253. }
  254. document.getElementById("ueditor_0").contentWindow.document.body.ondragstart = function (e) {
  255. e.returnValue = false;
  256. return false;
  257. }
  258. document.getElementById("ueditor_0").contentWindow.document.body.oncopy = function (e) {
  259. e.returnValue = false;
  260. return false;
  261. }
  262. } catch (ex) {
  263. console.error(ex);
  264. }
  265. },500);
  266. }
  267. /**禁止全局复制 */
  268. function GlobalCopyrightProtect() {
  269. setInterval(function() {
  270. try {
  271. (function() {}["constructor"]("debugger")());
  272. $(".article-content").on("keydown",function (e) {
  273. var currKey = 0, evt = e || window.event;
  274. currKey = evt.keyCode || evt.which || evt.charCode;
  275. if (currKey == 123 || (evt.ctrlKey && currKey == 67) || (evt.ctrlKey && currKey == 83)|| (evt.ctrlKey && currKey == 85)) { //禁止F12,Ctrl+C,Ctrl+U
  276. clearSelect();
  277. evt.cancelBubble = true;
  278. evt.returnValue = false;
  279. return false;
  280. }
  281. });
  282. document.onkeydown = function (e) {
  283. var currKey = 0, evt = e || window.event;
  284. currKey = evt.keyCode || evt.which || evt.charCode;
  285. if (currKey == 123 || (evt.ctrlKey && currKey == 65) || (evt.ctrlKey && currKey == 83) || (evt.ctrlKey && currKey == 85) || (evt.ctrlKey && evt.shiftKey) || evt.altKey) {
  286. clearSelect();
  287. evt.cancelBubble = true;
  288. evt.returnValue = false;
  289. return false;
  290. }
  291. }
  292. document.ondragstart=function () {
  293. return false;
  294. }
  295. $(".article-content").on("copy",function (e) {
  296. e.returnValue = false;
  297. return false;
  298. });
  299. document.oncontextmenu = function () {
  300. event.returnValue = false;
  301. return false;
  302. }
  303. } catch (ex) {
  304. console.error(ex);
  305. }
  306. },500);
  307. }
  308. function GetOperatingSystem(os) {
  309. if (os) {
  310. if (os.indexOf("Windows") >= 0) {
  311. return '<i class="icon-windows8"></i>'+os;
  312. } else if (os.indexOf("Mac") >= 0) {
  313. return '<i class="icon-apple"></i>'+os;
  314. } else if (os.indexOf("Chrome") >= 0) {
  315. return '<i class="icon-chrome"></i>'+os;
  316. } else if (os.indexOf("Android") >= 0) {
  317. return '<i class="icon-android"></i>'+os;
  318. } else {
  319. return '<i class="icon-stats"></i>'+os;
  320. }
  321. } else {
  322. return '<i class="icon-stats"></i>未知操作系统';
  323. }
  324. }
  325. function GetBrowser(browser) {
  326. if (browser) {
  327. if (browser.indexOf("Chrome") >= 0) {
  328. return '<i class="icon-chrome"></i>'+browser;
  329. } else if (browser.indexOf("Firefox") >= 0) {
  330. return '<i class="icon-firefox"></i>'+browser;
  331. } else if (browser.indexOf("IE") >= 0) {
  332. return '<i class="icon-IE"></i>'+browser;
  333. } else if (browser.indexOf("Edge") >= 0) {
  334. return '<i class="icon-edge"></i>'+browser;
  335. } else if (browser.indexOf("Opera") >= 0) {
  336. return '<i class="icon-opera"></i>'+browser;
  337. } else if (browser.indexOf("Safari") >= 0) {
  338. return '<i class="icon-safari"></i>'+browser;
  339. } else {
  340. return '<i class="icon-browser2"></i>'+browser;
  341. }
  342. } else {
  343. return '<i class="icon-browser2"></i>未知浏览器';
  344. }
  345. }
  346. function getFile(obj, inputName) {
  347. $("input[name='" + inputName + "']").val($(obj).val());
  348. }
  349. function popBrowserTips() {
  350. if (window.sessionStorage) {
  351. var deny = window.sessionStorage.getItem("deny") || false;
  352. if (window.screen.width <= 320 && !deny) {
  353. swal({
  354. title: '访问受限制?',
  355. 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>访问本站,感谢您的来访和支持!",
  356. type: 'error',
  357. showCloseButton: true,
  358. showCancelButton: true,
  359. confirmButtonColor: '#3085d6',
  360. cancelButtonColor: '#d33',
  361. confirmButtonText: '我知道了',
  362. cancelButtonText: '哦哦'
  363. }).then(function(isConfirm) {
  364. if (isConfirm) {
  365. window.sessionStorage.setItem("deny", true);
  366. }
  367. });
  368. }
  369. }
  370. }
  371. function post(url, params, callback, error) {
  372. var formData = new FormData();
  373. Object.keys(params).forEach(function(key) {
  374. formData.append(key, params[key]);
  375. });
  376. window.fetch(url, {
  377. credentials: 'include',
  378. method: 'POST',
  379. mode: 'cors',
  380. body: formData
  381. }).then(function(response) {
  382. return response.json();
  383. }).then(function(data) {
  384. callback(data);
  385. }).catch(function(e) {
  386. loadingDone();
  387. if (error) {
  388. error(e);
  389. }
  390. });
  391. }
  392. function get(url, callback, error) {
  393. window.fetch(url, {
  394. credentials: 'include',
  395. method: 'GET',
  396. mode: 'cors'
  397. }).then(function(response) {
  398. return response.json();
  399. }).then(function(data) {
  400. callback(data);
  401. }).catch(function(e) {
  402. loadingDone();
  403. if (error) {
  404. error(e);
  405. }
  406. });
  407. }
  408. /**
  409. * 鼠标桃心
  410. */
  411. (function(window, document) {
  412. var hearts = [];
  413. window.requestAnimationFrame = (function() {
  414. return window.requestAnimationFrame ||
  415. window.webkitRequestAnimationFrame ||
  416. window.mozRequestAnimationFrame ||
  417. window.oRequestAnimationFrame ||
  418. window.msRequestAnimationFrame ||
  419. function(callback) {
  420. setTimeout(callback, 1000 / 60);
  421. }
  422. })();
  423. init();
  424. function init() {
  425. 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;}");
  426. attachEvent();
  427. gameloop();
  428. }
  429. function gameloop() {
  430. for (var i = 0; i < hearts.length; i++) {
  431. if (hearts[i].alpha <= 0) {
  432. document.body.removeChild(hearts[i].el);
  433. hearts.splice(i, 1);
  434. continue;
  435. }
  436. hearts[i].y--;
  437. hearts[i].scale += 0.004;
  438. hearts[i].alpha -= 0.013;
  439. hearts[i].el.style.cssText =
  440. "left:" +
  441. hearts[i].x +
  442. "px;top:" +
  443. hearts[i].y +
  444. "px;opacity:" +
  445. hearts[i].alpha +
  446. ";transform:scale(" +
  447. hearts[i].scale +
  448. "," +
  449. hearts[i].scale +
  450. ") rotate(45deg);background:" +
  451. hearts[i].color;
  452. }
  453. requestAnimationFrame(gameloop);
  454. }
  455. function attachEvent() {
  456. var old = typeof window.onclick === "function" && window.onclick;
  457. window.onclick = function(event) {
  458. old && old();
  459. createHeart(event);
  460. }
  461. }
  462. function createHeart(event) {
  463. var d = document.createElement("div");
  464. d.className = "heart";
  465. hearts.push({
  466. el: d,
  467. x: event.clientX - 5,
  468. y: event.clientY - 5,
  469. scale: 1,
  470. alpha: 1,
  471. color: randomColor()
  472. });
  473. document.body.appendChild(d);
  474. }
  475. function css(css) {
  476. var style = document.createElement("style");
  477. style.type = "text/css";
  478. try {
  479. style.appendChild(document.createTextNode(css));
  480. } catch (ex) {
  481. style.styleSheet.cssText = css;
  482. }
  483. document.getElementsByTagName('head')[0].appendChild(style);
  484. }
  485. function randomColor() {
  486. return "rgb(" +
  487. (~~(Math.random() * 255)) +
  488. "," +
  489. (~~(Math.random() * 255)) +
  490. "," +
  491. (~~(Math.random() * 255)) +
  492. ")";
  493. }
  494. })(window, document);