parent
1e0ae9e573
commit
1b6b8c2038
|
@ -16,6 +16,7 @@ git.osc地址:http://git.oschina.net/xuxueli0323/xxl-job
|
||||||
6、任务串行执行;
|
6、任务串行执行;
|
||||||
7、支持任务执行日志;
|
7、支持任务执行日志;
|
||||||
8、支持自定义参数;
|
8、支持自定义参数;
|
||||||
|
9、支持任务失败次数超阈值邮件报警;
|
||||||
|
|
||||||
# 新版本 V1.2.x,新特性
|
# 新版本 V1.2.x,新特性
|
||||||
1、支持任务分组;
|
1、支持任务分组;
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class JobMonitorHelper {
|
||||||
XxlJobInfo info = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
|
XxlJobInfo info = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
|
||||||
if (count >= info.getAlarmThreshold()) {
|
if (count >= info.getAlarmThreshold()) {
|
||||||
MailUtil.sendMail(info.getAlarmEmail(), "《调度平台中心-监控报警》",
|
MailUtil.sendMail(info.getAlarmEmail(), "《调度平台中心-监控报警》",
|
||||||
MessageFormat.format("调度任务[{0}]失败报警", monotorKey), false, null);
|
MessageFormat.format("调度任务[{0}]失败报警,连续失败次数:", monotorKey, count), false, null);
|
||||||
countMap.remove(monotorKey);
|
countMap.remove(monotorKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<!-- <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> -->
|
<!-- <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> -->
|
||||||
<link rel="stylesheet" href="${request.contextPath}/static/plugins/ionicons-2.0.1/css/ionicons.min.css">
|
<link rel="stylesheet" href="${request.contextPath}/static/plugins/ionicons-2.0.1/css/ionicons.min.css">
|
||||||
<!-- Theme style -->
|
<!-- Theme style -->
|
||||||
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/dist/css/AdminLTE.min.css">
|
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/dist/css/AdminLTE-local.min.css">
|
||||||
<!-- AdminLTE Skins. Choose a skin from the css/skins folder instead of downloading all of them to reduce the load. -->
|
<!-- AdminLTE Skins. Choose a skin from the css/skins folder instead of downloading all of them to reduce the load. -->
|
||||||
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/dist/css/skins/_all-skins.min.css">
|
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/dist/css/skins/_all-skins.min.css">
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
<!-- scrollup -->
|
<!-- scrollup -->
|
||||||
<script src="${request.contextPath}/static/plugins/scrollup/jquery.scrollUp.min.js"></script>
|
<script src="${request.contextPath}/static/plugins/scrollup/jquery.scrollUp.min.js"></script>
|
||||||
|
<script src="${request.contextPath}/static/plugins/jquery/jquery.cookie.js"></script>
|
||||||
<script src="${request.contextPath}/static/js/common.1.js"></script>
|
<script src="${request.contextPath}/static/js/common.1.js"></script>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
|
7
xxl-job-admin/src/main/webapp/static/adminlte/dist/css/AdminLTE-local.min.css
vendored
Normal file
7
xxl-job-admin/src/main/webapp/static/adminlte/dist/css/AdminLTE-local.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
168
xxl-job-admin/src/main/webapp/static/adminlte/dist/css/google-local/local.google.fonts.css
vendored
Normal file
168
xxl-job-admin/src/main/webapp/static/adminlte/dist/css/google-local/local.google.fonts.css
vendored
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 300;
|
||||||
|
src: local('Source Sans Pro Light'), local('SourceSansPro-Light'), url('fonts/toadOcfmlt9b38dHJxOBGD_j0nMiB9fPhg_k1wdK2h0.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 300;
|
||||||
|
src: local('Source Sans Pro Light'), local('SourceSansPro-Light'), url('fonts/toadOcfmlt9b38dHJxOBGDRVvBvQIc1z78c__uoBcyI.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 300;
|
||||||
|
src: local('Source Sans Pro Light'), local('SourceSansPro-Light'), url('fonts/toadOcfmlt9b38dHJxOBGOode0-EuMkY--TSyExeINg.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro'), local('SourceSansPro-Regular'), url('fonts/ODelI1aHBYDBqgeIAH2zlNOAHFN6BivSraYkjhveRHY.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro'), local('SourceSansPro-Regular'), url('fonts/ODelI1aHBYDBqgeIAH2zlC2Q8seG17bfDXYR_jUsrzg.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro'), local('SourceSansPro-Regular'), url('fonts/ODelI1aHBYDBqgeIAH2zlNV_2ngZ8dMf8fLgjYEouxg.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
src: local('Source Sans Pro Semibold'), local('SourceSansPro-Semibold'), url('fonts/toadOcfmlt9b38dHJxOBGClYwVOhDRq2vbpGRTZ7bbs.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
src: local('Source Sans Pro Semibold'), local('SourceSansPro-Semibold'), url('fonts/toadOcfmlt9b38dHJxOBGFKFh1TDTPrUZWzVp6FtpG8.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
src: local('Source Sans Pro Semibold'), local('SourceSansPro-Semibold'), url('fonts/toadOcfmlt9b38dHJxOBGCOFnW3Jk0f09zW_Yln67Ac.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url('fonts/toadOcfmlt9b38dHJxOBGDovqjS_dXPZszO_XltPdNg.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url('fonts/toadOcfmlt9b38dHJxOBGFxe-GPfKKFmiXaJ_Q0GFr8.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url('fonts/toadOcfmlt9b38dHJxOBGEo0As1BFRXtCDhS66znb_k.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 300;
|
||||||
|
src: local('Source Sans Pro Light Italic'), local('SourceSansPro-LightIt'), url('fonts/fpTVHK8qsXbIeTHTrnQH6E78GtRp3lhchupCJNw8t58.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 300;
|
||||||
|
src: local('Source Sans Pro Light Italic'), local('SourceSansPro-LightIt'), url('fonts/fpTVHK8qsXbIeTHTrnQH6Lpx497t94oDua8KfAL9f-E.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 300;
|
||||||
|
src: local('Source Sans Pro Light Italic'), local('SourceSansPro-LightIt'), url('fonts/fpTVHK8qsXbIeTHTrnQH6MAjkyiewWYrWZc50I8hK7I.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro Italic'), local('SourceSansPro-It'), url('fonts/M2Jd71oPJhLKp0zdtTvoM7YHq4FgHI02B8rPccK0FJQ.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro Italic'), local('SourceSansPro-It'), url('fonts/M2Jd71oPJhLKp0zdtTvoM40tgx99jmYGv_xzYuwd1rU.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro Italic'), local('SourceSansPro-It'), url('fonts/M2Jd71oPJhLKp0zdtTvoMxgy2Fsj5sj3EzlXpqVXRKo.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
||||||
|
/* vietnamese */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 600;
|
||||||
|
src: local('Source Sans Pro Semibold Italic'), local('SourceSansPro-SemiboldIt'), url('fonts/fpTVHK8qsXbIeTHTrnQH6CzM2XYAq8cDhaXsrN8WXcA.woff2') format('woff2');
|
||||||
|
unicode-range: U+0102-0103, U+1EA0-1EF1, U+20AB;
|
||||||
|
}
|
||||||
|
/* latin-ext */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 600;
|
||||||
|
src: local('Source Sans Pro Semibold Italic'), local('SourceSansPro-SemiboldIt'), url('fonts/fpTVHK8qsXbIeTHTrnQH6OXKTZYPNtG1yMB_YJSqlic.woff2') format('woff2');
|
||||||
|
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
/* latin */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: italic;
|
||||||
|
font-weight: 600;
|
||||||
|
src: local('Source Sans Pro Semibold Italic'), local('SourceSansPro-SemiboldIt'), url('fonts/fpTVHK8qsXbIeTHTrnQH6GQKuzMuncr0JB710wa2dPI.woff2') format('woff2');
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ $(function(){
|
||||||
scrollImg: true
|
scrollImg: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// logout
|
||||||
$("#logoutBtn").click(function(){
|
$("#logoutBtn").click(function(){
|
||||||
$.post(base_url + "/logout", function(data, status) {
|
$.post(base_url + "/logout", function(data, status) {
|
||||||
if (data.code == "S") {
|
if (data.code == "S") {
|
||||||
|
@ -28,4 +29,18 @@ $(function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// adminlte_settings
|
||||||
|
$('.sidebar-toggle').click(function(){
|
||||||
|
var adminlte_settings = $.cookie('adminlte_settings');
|
||||||
|
if ('off' == adminlte_settings) {
|
||||||
|
adminlte_settings = 'on';
|
||||||
|
} else {
|
||||||
|
adminlte_settings = 'off';
|
||||||
|
}
|
||||||
|
$.cookie('adminlte_settings', adminlte_settings, { expires: 7 }); //$.cookie('the_cookie', '', { expires: -1 });
|
||||||
|
});
|
||||||
|
var adminlte_settings = $.cookie('adminlte_settings');
|
||||||
|
if (adminlte_settings == 'off') {
|
||||||
|
$('body').addClass('sidebar-collapse');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,33 @@
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
// 过滤时间
|
||||||
|
$('#filterTime').daterangepicker({
|
||||||
|
timePicker: true, //是否显示小时和分钟
|
||||||
|
timePickerIncrement: 10, //时间的增量,单位为分钟
|
||||||
|
timePicker12Hour : false, //是否使用12小时制来显示时间
|
||||||
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
separator : ' - ',
|
||||||
|
ranges : {
|
||||||
|
'最近1小时': [moment().subtract('hours',1), moment()],
|
||||||
|
'今日': [moment().startOf('day'), moment()],
|
||||||
|
'昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
|
||||||
|
'最近7日': [moment().subtract('days', 6), moment()],
|
||||||
|
'最近30日': [moment().subtract('days', 29), moment()]
|
||||||
|
},
|
||||||
|
opens : 'left', //日期选择框的弹出位置
|
||||||
|
locale : {
|
||||||
|
customRangeLabel : '自定义',
|
||||||
|
applyLabel : '确定',
|
||||||
|
cancelLabel : '取消',
|
||||||
|
fromLabel : '起始时间',
|
||||||
|
toLabel : '结束时间',
|
||||||
|
daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
|
||||||
|
monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
|
||||||
|
firstDay : 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#filterTime').val( moment(new Date()).format("YYYY-MM-DD 00:00:00") + ' - ' + moment(new Date()).format("YYYY-MM-DD HH:mm:ss") );
|
||||||
|
|
||||||
// init date tables
|
// init date tables
|
||||||
var logTable = $("#joblog_list").dataTable({
|
var logTable = $("#joblog_list").dataTable({
|
||||||
"deferRender": true,
|
"deferRender": true,
|
||||||
|
@ -101,33 +129,7 @@ $(function() {
|
||||||
ComAlertTec.show(msg);
|
ComAlertTec.show(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 过滤时间
|
|
||||||
$('#filterTime').daterangepicker({
|
|
||||||
timePicker: true, //是否显示小时和分钟
|
|
||||||
timePickerIncrement: 10, //时间的增量,单位为分钟
|
|
||||||
timePicker12Hour : false, //是否使用12小时制来显示时间
|
|
||||||
format: 'YYYY-MM-DD HH:mm:ss',
|
|
||||||
separator : ' - ',
|
|
||||||
ranges : {
|
|
||||||
'最近1小时': [moment().subtract('hours',1), moment()],
|
|
||||||
'今日': [moment().startOf('day'), moment()],
|
|
||||||
'昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
|
|
||||||
'最近7日': [moment().subtract('days', 6), moment()],
|
|
||||||
'最近30日': [moment().subtract('days', 29), moment()]
|
|
||||||
},
|
|
||||||
opens : 'left', //日期选择框的弹出位置
|
|
||||||
locale : {
|
|
||||||
customRangeLabel : '自定义',
|
|
||||||
applyLabel : '确定',
|
|
||||||
cancelLabel : '取消',
|
|
||||||
fromLabel : '起始时间',
|
|
||||||
toLabel : '结束时间',
|
|
||||||
daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
|
|
||||||
monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
|
|
||||||
firstDay : 1
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('#filterTime').val( moment(new Date()).format("YYYY-MM-DD 00:00:00") + ' - ' + moment(new Date()).format("YYYY-MM-DD HH:mm:ss") );
|
|
||||||
|
|
||||||
// 搜索按钮
|
// 搜索按钮
|
||||||
$('#searchBtn').on('click', function(){
|
$('#searchBtn').on('click', function(){
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
/*!
|
||||||
|
* jQuery Cookie Plugin v1.4.1
|
||||||
|
* https://github.com/carhartl/jquery-cookie
|
||||||
|
*
|
||||||
|
* Copyright 2013 Klaus Hartl
|
||||||
|
* Released under the MIT license
|
||||||
|
*/
|
||||||
|
(function (factory) {
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
// AMD
|
||||||
|
define(['jquery'], factory);
|
||||||
|
} else if (typeof exports === 'object') {
|
||||||
|
// CommonJS
|
||||||
|
factory(require('jquery'));
|
||||||
|
} else {
|
||||||
|
// Browser globals
|
||||||
|
factory(jQuery);
|
||||||
|
}
|
||||||
|
}(function ($) {
|
||||||
|
|
||||||
|
var pluses = /\+/g;
|
||||||
|
|
||||||
|
function encode(s) {
|
||||||
|
return config.raw ? s : encodeURIComponent(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
function decode(s) {
|
||||||
|
return config.raw ? s : decodeURIComponent(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringifyCookieValue(value) {
|
||||||
|
return encode(config.json ? JSON.stringify(value) : String(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCookieValue(s) {
|
||||||
|
if (s.indexOf('"') === 0) {
|
||||||
|
// This is a quoted cookie as according to RFC2068, unescape...
|
||||||
|
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Replace server-side written pluses with spaces.
|
||||||
|
// If we can't decode the cookie, ignore it, it's unusable.
|
||||||
|
// If we can't parse the cookie, ignore it, it's unusable.
|
||||||
|
s = decodeURIComponent(s.replace(pluses, ' '));
|
||||||
|
return config.json ? JSON.parse(s) : s;
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function read(s, converter) {
|
||||||
|
var value = config.raw ? s : parseCookieValue(s);
|
||||||
|
return $.isFunction(converter) ? converter(value) : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = $.cookie = function (key, value, options) {
|
||||||
|
|
||||||
|
// Write
|
||||||
|
|
||||||
|
if (value !== undefined && !$.isFunction(value)) {
|
||||||
|
options = $.extend({}, config.defaults, options);
|
||||||
|
|
||||||
|
if (typeof options.expires === 'number') {
|
||||||
|
var days = options.expires, t = options.expires = new Date();
|
||||||
|
t.setTime(+t + days * 864e+5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (document.cookie = [
|
||||||
|
encode(key), '=', stringifyCookieValue(value),
|
||||||
|
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
||||||
|
options.path ? '; path=' + options.path : '',
|
||||||
|
options.domain ? '; domain=' + options.domain : '',
|
||||||
|
options.secure ? '; secure' : ''
|
||||||
|
].join(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read
|
||||||
|
|
||||||
|
var result = key ? undefined : {};
|
||||||
|
|
||||||
|
// To prevent the for loop in the first place assign an empty array
|
||||||
|
// in case there are no cookies at all. Also prevents odd result when
|
||||||
|
// calling $.cookie().
|
||||||
|
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
||||||
|
|
||||||
|
for (var i = 0, l = cookies.length; i < l; i++) {
|
||||||
|
var parts = cookies[i].split('=');
|
||||||
|
var name = decode(parts.shift());
|
||||||
|
var cookie = parts.join('=');
|
||||||
|
|
||||||
|
if (key && key === name) {
|
||||||
|
// If second argument (value) is a function it's a converter...
|
||||||
|
result = read(cookie, value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent storing a cookie that we couldn't decode.
|
||||||
|
if (!key && (cookie = read(cookie)) !== undefined) {
|
||||||
|
result[name] = cookie;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
config.defaults = {};
|
||||||
|
|
||||||
|
$.removeCookie = function (key, options) {
|
||||||
|
if ($.cookie(key) === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must not alter options, thus extending a fresh object...
|
||||||
|
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
|
||||||
|
return !$.cookie(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
}));
|
Loading…
Reference in New Issue