-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,77 @@ | ||
function transOption(option) { | ||
if(!option)return {}; | ||
var newopt={}; | ||
for(var i in option){ | ||
switch (i){ | ||
case 'viewmode': | ||
newopt['viewMode']=option[i]; | ||
break; | ||
case 'keepopen': | ||
newopt['keepOpen']=option[i]; | ||
break; | ||
default: | ||
newopt[i]=option[i]; | ||
} | ||
if (!option) return {}; | ||
var newopt = {}; | ||
for (var i in option) { | ||
newopt[i.replace(/(_|-)[a-z]/g, function (d) { | ||
return d.substring(1).toUpperCase() | ||
})] = option[i]; | ||
} | ||
return newopt; | ||
} | ||
|
||
//日期组件 | ||
if($.fn.datetimepicker) { | ||
var tooltips= { | ||
today: '定位当前日期', | ||
clear: '清除已选日期', | ||
close: '关闭选择器', | ||
selectMonth: '选择月份', | ||
prevMonth: '上个月', | ||
nextMonth: '下个月', | ||
selectYear: '选择年份', | ||
prevYear: '上一年', | ||
nextYear: '下一年', | ||
selectDecade: '选择年份区间', | ||
selectTime:'选择时间', | ||
prevDecade: '上一区间', | ||
nextDecade: '下一区间', | ||
prevCentury: '上个世纪', | ||
nextCentury: '下个世纪' | ||
}; | ||
var tooltips = window.datetimepickerTooltips ? window.datetimepickerTooltips : { | ||
today: '定位当前日期', | ||
clear: '清除已选日期', | ||
close: '关闭选择器', | ||
selectMonth: '选择月份', | ||
prevMonth: '上个月', | ||
nextMonth: '下个月', | ||
selectYear: '选择年份', | ||
prevYear: '上一年', | ||
nextYear: '下一年', | ||
selectDecade: '选择年份区间', | ||
selectTime: '选择时间', | ||
prevDecade: '上一区间', | ||
nextDecade: '下一区间', | ||
prevCentury: '上个世纪', | ||
nextCentury: '下个世纪' | ||
}; | ||
|
||
function datetimeConfig(input) { | ||
return $.extend({ | ||
tooltips: tooltips, | ||
format: 'YYYY-MM-DD', | ||
locale: 'zh-cn', | ||
showClear: true, | ||
showTodayButton: true, | ||
showClose: true, | ||
keepInvalid: true | ||
}, transOption($(input).data())); | ||
} | ||
|
||
$('.datepicker').each(function(){ | ||
var config=$.extend({ | ||
tooltips:tooltips, | ||
format: 'YYYY-MM-DD', | ||
locale: 'zh-cn', | ||
showClear:true, | ||
showTodayButton:true, | ||
showClose:true, | ||
keepInvalid:true | ||
},transOption($(this).data())); | ||
function daterangeConfig(input) { | ||
return $.extend({ | ||
tooltips: tooltips, | ||
format: 'YYYY-MM-DD', | ||
locale: 'zh-cn', | ||
showClear: true, | ||
showTodayButton: true, | ||
showClose: true, | ||
keepInvalid: true | ||
}, transOption($(input).data())); | ||
} | ||
|
||
$(this).datetimepicker(config); | ||
}); | ||
jQuery(function ($) { | ||
|
||
$('.date-range').each(function () { | ||
var from = $(this).find('[name=fromdate],.fromdate'), to = $(this).find('[name=todate],.todate'); | ||
var options = $.extend({ | ||
tooltips:tooltips, | ||
format: 'YYYY-MM-DD', | ||
locale:'zh-cn', | ||
showClear:true, | ||
showTodayButton:true, | ||
showClose:true, | ||
keepInvalid:true | ||
},$(this).data()); | ||
from.datetimepicker(options).on('dp.change', function () { | ||
if (from.val()) { | ||
to.data('DateTimePicker').minDate(from.val()); | ||
} | ||
//日期组件 | ||
if ($.fn.datetimepicker) { | ||
$('.datepicker').each(function () { | ||
$(this).datetimepicker(datetimeConfig(this)); | ||
}); | ||
to.datetimepicker(options).on('dp.change', function () { | ||
if (to.val()) { | ||
from.data('DateTimePicker').maxDate(to.val()); | ||
} | ||
|
||
$('.date-range').each(function () { | ||
var from = $(this).find('[name=fromdate],.fromdate'), to = $(this).find('[name=todate],.todate'); | ||
var options = daterangeConfig(this); | ||
from.datetimepicker(options).on('dp.change', function () { | ||
if (from.val()) { | ||
to.data('DateTimePicker').minDate(from.val()); | ||
} | ||
}); | ||
to.datetimepicker(options).on('dp.change', function () { | ||
if (to.val()) { | ||
from.data('DateTimePicker').maxDate(to.val()); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
}) |