373 lines
15 KiB
JavaScript
373 lines
15 KiB
JavaScript
(function (a) {
|
||
(jQuery.browser = jQuery.browser || {}).mobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4));
|
||
})(navigator.userAgent || navigator.vendor || window.opera);
|
||
$.ajaxSetup({
|
||
contentType: 'application/x-www-form-urlencoded;charset=utf-8',
|
||
complete: function (XMLHttpRequest, textStatus) {
|
||
var sessionstatus = XMLHttpRequest.getResponseHeader('loginStatus'); //通过XMLHttpRequest取得响应头,sessionstatus,
|
||
if (sessionstatus == 'accessDenied') {
|
||
ELEMENT.Notification({title: '提示', message: '\u6ca1\u6709\u6743\u9650', type: 'warning'})
|
||
}
|
||
if (sessionstatus == 'unauthorized') {
|
||
ELEMENT.Notification({title: '提示', message: '\u6ca1\u6709\u6743\u9650', type: 'warning'})
|
||
}
|
||
}
|
||
});
|
||
|
||
function removeHTMLTag(str) {
|
||
str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
|
||
str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
|
||
str = str.replace(/\n[\s| | ]*\r/g, '\n'); //去除多余空行
|
||
str = str.replace(/ /ig, '');//去掉
|
||
return str;
|
||
}
|
||
|
||
function GetQueryString(name) {
|
||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||
var r = window.location.search.substr(1).match(reg);
|
||
if (r != null) return unescape(r[2]);
|
||
return "";
|
||
}
|
||
|
||
function getQueryVariable(variable) {
|
||
return GetQueryString(variable)
|
||
}
|
||
|
||
//函数在一定时间内只会触发一次 FN.ABC
|
||
function throttle(func, wait) {
|
||
let previous = 0;
|
||
return function () {
|
||
let now = Date.now();
|
||
let context = this;
|
||
let args = arguments;
|
||
if (now - previous > wait) {
|
||
func.apply(context, args);
|
||
previous = now;
|
||
}
|
||
}
|
||
}
|
||
|
||
function containsXSS(str) {
|
||
// 检查是否包含一些常见的XSS攻击模式
|
||
// 例如:<script>, javascript:, on..., eval(), ...
|
||
const xssPatterns = [
|
||
/<script>/i,
|
||
/javascript:/i,
|
||
/on\w+/i,
|
||
/eval\(/i,
|
||
/expression\(/i,
|
||
/<body/i,
|
||
/<html/i,
|
||
/<head/i,
|
||
/<iframe/i,
|
||
/<frame/i,
|
||
/<object/i,
|
||
/<embed/i,
|
||
/<link/i,
|
||
/<meta/i,
|
||
/<style/i,
|
||
/<title/i,
|
||
/<svg/i,
|
||
/<math/i,
|
||
/<img/i,
|
||
/<audio/i,
|
||
/<video/i,
|
||
/<source/i,
|
||
/<track/i,
|
||
/<script/i,
|
||
/<applet/i,
|
||
/<body/i,
|
||
/<frameset/i,
|
||
/<frame/i,
|
||
/<noframes/i,
|
||
/<ilayer/i,
|
||
/<layer/i,
|
||
/<xml/i,
|
||
/<xss/i
|
||
];
|
||
|
||
// 检查字符串是否匹配任何XSS模式
|
||
for (let i = 0; i < xssPatterns.length; i++) {
|
||
if (xssPatterns[i].test(str)) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
var sublime = function () {
|
||
var linkLocation, searchOpen = false, app = $("#mainApp"), maxHeight = 0;
|
||
var sidebar = false, boxed = false, scroll = false;
|
||
|
||
function redirectPage() {
|
||
window.location = linkLocation;
|
||
}
|
||
|
||
function events() {
|
||
$(".offscreen-left, .main-navigation").ontouchstart = function () {
|
||
};
|
||
$(".accordion > dd").hide();
|
||
$(window).on("load", function () {
|
||
$(".pageload").fadeOut("slow");
|
||
});
|
||
$(window).resize(function () {
|
||
if (!$.browser.mobile && !checkBreakout()) {
|
||
$(".no-touch .main-navigation").slimScroll({height: 'auto'});
|
||
$(".no-touch .slimscroll").slimScroll({height: 'auto'});
|
||
}
|
||
});
|
||
}
|
||
|
||
function simulateLoad(el) {
|
||
$(el).block({
|
||
message: '<div class="loader"></div>',
|
||
css: {border: "none", backgroundColor: "none"},
|
||
overlayCSS: {backgroundColor: "#fff", opacity: 0.5}
|
||
});
|
||
}
|
||
|
||
function checkBreakout() {
|
||
var state = false;
|
||
var app = $("#mainApp");
|
||
if (app.hasClass("small-menu") || app.hasClass("fixed-scroll")) {
|
||
state = true;
|
||
}
|
||
return state;
|
||
}
|
||
|
||
function initLinkTransition() {
|
||
$(document).on("click", "a.transition", function (e) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
linkLocation = this.href;
|
||
$("body").fadeOut(1000, "easeInOutExpo", redirectPage);
|
||
return;
|
||
});
|
||
}
|
||
|
||
function initAnimationAPI() {
|
||
if (!$.browser.mobile && $.fn.appear) {
|
||
$("[data-animation]").appear();
|
||
$("[data-animation]").on("appear", function () {
|
||
var elm = $(this), animation = elm.data("animation") || "fadeIn", delay = elm.data("delay") || 0;
|
||
if (!elm.hasClass("done")) {
|
||
setTimeout(function () {
|
||
elm.addClass("animated " + animation + " done");
|
||
}, delay);
|
||
}
|
||
});
|
||
} else {
|
||
$("[data-animation]").each(function () {
|
||
var elm = $(this), animation = elm.data("animation") || "fadeIn";
|
||
if (!elm.hasClass("done")) {
|
||
elm.addClass("animated " + animation + " done");
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
function initAnimateNumbers() {
|
||
if (!$.browser.mobile && $.fn.appear) {
|
||
$(".count").appear();
|
||
$(".count").on("appear", function () {
|
||
if (!$(this).hasClass("done")) {
|
||
var speed = $(this).data("speed") || 2000, interval = $(this).data("interval") || 100;
|
||
$(this).addClass("done").countTo({speed: speed, refreshInterval: interval});
|
||
}
|
||
});
|
||
} else {
|
||
$(".count").each(function () {
|
||
if (!$(this).hasClass("done")) {
|
||
$(this).addClass("done").countTo({speed: 1000});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
function initAnimateProgressBars() {
|
||
if (!$.browser.mobile && $.fn.appear) {
|
||
$(".progress-bar").appear();
|
||
$(".progress-bar").on("appear", function () {
|
||
var elm = $(this), percent = elm.data("percent");
|
||
if (!elm.hasClass("done")) {
|
||
elm.addClass("done").css("width", Math.ceil(percent) + "%");
|
||
}
|
||
});
|
||
} else {
|
||
$(".progress-bar").each(function () {
|
||
var elm = $(this), percent = elm.data("percent");
|
||
if (!elm.hasClass("done")) {
|
||
elm.addClass("done").css("width", Math.ceil(percent) + "%");
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
function initBrowserFix() {
|
||
if (navigator.userAgent.search("Firefox") >= 0) {
|
||
$(".layout > aside, .layout > section").wrapInner("<div class=\"fffix\"/>");
|
||
}
|
||
}
|
||
|
||
|
||
function initMenuCollapse() {
|
||
//顶部导航浮动显示,觉得体验不好注释掉
|
||
$(document).on("click", ".main-navigation a", function (e) {
|
||
var app = $("#mainApp");
|
||
var links = $(this).parents('li'), parentLink = $(this).closest("li"),
|
||
otherLinks = $('.main-navigation li').not(links), subMenu = $(this).next();
|
||
if (!subMenu.hasClass("sub-menu")) {
|
||
offscreen.hide();
|
||
$(".fa-dot-circle-o").parent().parent().attr('style', 'color: black')
|
||
$(".fa-dot-circle-o").removeClass("fa-dot-circle-o");
|
||
if ($(this).find("i").hasClass("fa fa-circle-o")) {
|
||
$(".fa-dot-circle-o").addClass("fa-circle-o");
|
||
$(".fa-dot-circle-o").parent().parent().attr('style', 'color: black')
|
||
$(".fa-dot-circle-o").removeClass("fa-dot-circle-o");
|
||
$(this).find("i").addClass("fa fa-dot-circle-o");
|
||
$(this).attr('style', 'color: #1867b0')
|
||
}
|
||
return;
|
||
}
|
||
|
||
otherLinks.find("a").removeClass('active');
|
||
otherLinks.removeClass('open');
|
||
otherLinks.find('.sub-menu').slideUp();
|
||
if (subMenu.is("ul") && (!subMenu.is(":visible")) && (!app.hasClass("small-sidebar"))) {
|
||
subMenu.slideDown();
|
||
parentLink.addClass("open");
|
||
} else if (subMenu.is("ul") && (subMenu.is(":visible")) && (!app.hasClass("small-sidebar"))) {
|
||
parentLink.removeClass("open");
|
||
subMenu.slideUp();
|
||
}
|
||
if ($(this).hasClass('active') === false) {
|
||
$(this).parents("ul.dropdown-menu").find('a').removeClass('active');
|
||
$(this).addClass('active');
|
||
}
|
||
if ($(this).attr('href') === '#') {
|
||
e.preventDefault();
|
||
}
|
||
if (subMenu.is("ul")) {
|
||
return false;
|
||
}
|
||
e.stopPropagation();
|
||
return true;
|
||
});
|
||
$(".main-navigation > .nav > li.open").each(function () {
|
||
$(".sub-menu").hide();
|
||
$(this).children(".sub-menu").show();
|
||
});
|
||
|
||
}
|
||
|
||
function bindLeft() {
|
||
$('.main-navigation a[data-pjax]').on('click', function () {
|
||
$('.main-navigation a[data-pjax]').each(function () {
|
||
$(this).parent().removeClass('active');
|
||
});
|
||
$(this).parent().addClass('active');
|
||
});
|
||
}
|
||
|
||
function initHome() {
|
||
$(".gallery-loader").fadeOut();
|
||
$.get(base + "/platform/home/path?url=" + window.location.href + "&rnd=" + new Date().getTime(), function (data) {
|
||
// $("#leftnav").html(data);
|
||
bindLeft();
|
||
}, "html");
|
||
//PJAX实现
|
||
if ($.support.pjax) {
|
||
|
||
$(document).pjax('a[data-pjax]', '#container', {
|
||
maxCacheLength: 0,
|
||
push: false,
|
||
replace: true,
|
||
fragment: '#container',
|
||
timeout: 8000
|
||
});
|
||
|
||
$(document).on('pjax:send', function (options) { //pjax链接点击后显示加载动画;
|
||
$(".gallery-loader").fadeIn();
|
||
});
|
||
$(document).on('pjax:complete', function (options) { //pjax链接加载完成后隐藏加载动画;
|
||
window.sessionStorage.setItem('pjax_url', options.currentTarget.URL)
|
||
setTimeout(function () {
|
||
$(".gallery-loader").fadeOut()
|
||
}, 250);
|
||
});
|
||
}
|
||
}
|
||
|
||
return {
|
||
checkBreakout: checkBreakout, init: function () {
|
||
events();
|
||
initAnimationAPI();
|
||
initAnimateNumbers();
|
||
initAnimateProgressBars();
|
||
initLinkTransition();
|
||
initBrowserFix();
|
||
initMenuCollapse();
|
||
initHome();
|
||
},
|
||
showLoadingbar: function (obj) {//显示顶部进度条
|
||
var clz = "waiting";
|
||
if (!obj) {
|
||
clz += " full";
|
||
}
|
||
obj = obj || $("body");
|
||
if ($("#loadingbar").length < 1) {
|
||
obj.prepend("<div id=\"loadingbar\"></div>");
|
||
$("#loadingbar").addClass(clz).append($("<dt/><dd/>"));
|
||
$("#loadingbar").width((50 + Math.random() * 30) + "%");
|
||
var width = (50 + Math.random() * 30);
|
||
var interval = setInterval(function () {
|
||
width = width + 10;
|
||
if (width < 100) {
|
||
$("#loadingbar").width(width + "%");
|
||
} else {
|
||
$("#loadingbar").width("101%");
|
||
clearInterval(interval);
|
||
}
|
||
}, 600);
|
||
$("#loadingbar").attr("interval", interval);
|
||
}
|
||
},
|
||
closeLoadingbar: function (obj) {//关闭顶部进度条
|
||
obj = obj || $("body");
|
||
obj.find("#loadingbar").width("101%").delay(200).fadeOut(400, function () {
|
||
var interval = $(this).attr("interval");
|
||
clearInterval(interval);
|
||
$("#loadingbar").remove();
|
||
});
|
||
},
|
||
//2022/02/14 zxy pjax跳转自定义页面
|
||
jumpPagePjax(pageUrl) {
|
||
const index = pageUrl.indexOf("?")
|
||
const doMainUrl = index > -1 ? pageUrl.substring(0, index) : pageUrl
|
||
const {protocol, host} = window.location
|
||
const nodes = document.querySelectorAll('a[data-pjax]')
|
||
for (let node of nodes) {
|
||
if (node.hasAttribute('data-pjax') && node.href.trim() === protocol + "//" + host + doMainUrl) {
|
||
const metaHref = node.href
|
||
node.href = pageUrl
|
||
node.click()
|
||
|
||
//父级节点展开
|
||
const links = $(node).parents('li'),
|
||
parentLink = $(node).closest("li");
|
||
links.addClass("open")
|
||
links.children(".sub-menu").slideDown()
|
||
parentLink.removeClass("open")
|
||
|
||
node.href = metaHref
|
||
}
|
||
}
|
||
}
|
||
};
|
||
}();
|
||
$(function () {
|
||
"use strict";
|
||
sublime.init();
|
||
});
|