167 lines
6.7 KiB
PHP
167 lines
6.7 KiB
PHP
<script>
|
|
(function () {
|
|
function usePersian() {
|
|
return typeof is_persian_lang !== 'undefined' && is_persian_lang;
|
|
}
|
|
|
|
window.AcDate = {
|
|
initDatepicker: function (selector, options) {
|
|
if (typeof __init_date_field === 'function') {
|
|
__init_date_field(selector, options || {});
|
|
return;
|
|
}
|
|
if (typeof initPersianDatepicker === 'function') {
|
|
initPersianDatepicker(selector, options);
|
|
return;
|
|
}
|
|
if (typeof $.fn.persianDatepicker !== 'undefined') {
|
|
$(selector).each(function () {
|
|
var $input = $(this);
|
|
if ($input.data('ac-shamsi-ready')) {
|
|
return;
|
|
}
|
|
$input.attr('autocomplete', 'off');
|
|
$input.persianDatepicker($.extend({
|
|
calendarType: 'persian',
|
|
format: typeof datepicker_date_format !== 'undefined' ? datepicker_date_format : 'YYYY/MM/DD',
|
|
autoClose: true,
|
|
initialValue: false,
|
|
observer: true,
|
|
calendar: { persian: { locale: 'fa' } },
|
|
}, options || {}));
|
|
$input.data('ac-shamsi-ready', true);
|
|
});
|
|
return;
|
|
}
|
|
$(selector).datepicker($.extend({
|
|
autoclose: true,
|
|
format: typeof datepicker_date_format !== 'undefined' ? datepicker_date_format : 'yyyy/mm/dd',
|
|
}, options || {}));
|
|
},
|
|
|
|
initDatetimepicker: function (selector, options) {
|
|
if (typeof __init_datetime_field === 'function') {
|
|
__init_datetime_field(selector, options || {});
|
|
return;
|
|
}
|
|
if (typeof initPersianDatetimepicker === 'function') {
|
|
initPersianDatetimepicker(selector, options);
|
|
return;
|
|
}
|
|
if (typeof $.fn.persianDatepicker !== 'undefined') {
|
|
var dateFmt = typeof datepicker_date_format !== 'undefined' ? datepicker_date_format : 'YYYY/MM/DD';
|
|
var timeFmt = (typeof moment_time_format !== 'undefined' && moment_time_format.indexOf('A') !== -1) ? ' hh:mm a' : ' HH:mm';
|
|
$(selector).each(function () {
|
|
var $input = $(this);
|
|
if ($input.data('ac-shamsi-ready')) {
|
|
return;
|
|
}
|
|
$input.attr('autocomplete', 'off');
|
|
$input.persianDatepicker($.extend({
|
|
calendarType: 'persian',
|
|
format: dateFmt + timeFmt,
|
|
autoClose: true,
|
|
initialValue: false,
|
|
observer: true,
|
|
timePicker: { enabled: true, second: { enabled: false } },
|
|
calendar: { persian: { locale: 'fa' } },
|
|
}, options || {}));
|
|
$input.data('ac-shamsi-ready', true);
|
|
});
|
|
return;
|
|
}
|
|
if (typeof $.fn.datetimepicker !== 'undefined') {
|
|
$(selector).datetimepicker($.extend({
|
|
format: (typeof moment_date_format !== 'undefined' ? moment_date_format : 'YYYY/MM/DD') + ' ' +
|
|
(typeof moment_time_format !== 'undefined' ? moment_time_format : 'HH:mm'),
|
|
ignoreReadonly: true,
|
|
}, options || {}));
|
|
}
|
|
},
|
|
|
|
initYearPicker: function (selector, onChange) {
|
|
var $input = $(selector);
|
|
if (!$input.length || $input.data('ac-year-ready')) {
|
|
return;
|
|
}
|
|
|
|
if (usePersian() && typeof $.fn.persianDatepicker !== 'undefined') {
|
|
$input.attr('autocomplete', 'off');
|
|
$input.persianDatepicker({
|
|
calendarType: 'persian',
|
|
format: 'YYYY',
|
|
autoClose: true,
|
|
initialValue: !!$input.val(),
|
|
observer: true,
|
|
onlySelectOnDate: true,
|
|
calendar: { persian: { locale: 'fa' } },
|
|
onSelect: function () {
|
|
if (typeof onChange === 'function') {
|
|
onChange($input.val());
|
|
}
|
|
},
|
|
});
|
|
$input.data('ac-year-ready', true);
|
|
return;
|
|
}
|
|
|
|
$input.datepicker({
|
|
format: 'yyyy',
|
|
viewMode: 'years',
|
|
minViewMode: 'years',
|
|
autoclose: true,
|
|
}).on('changeDate', function () {
|
|
if (typeof onChange === 'function') {
|
|
onChange($input.val());
|
|
}
|
|
});
|
|
$input.data('ac-year-ready', true);
|
|
},
|
|
|
|
initDaterangepicker: function (selector, settings, callback) {
|
|
var config = $.extend(true, {}, typeof dateRangeSettings !== 'undefined' ? dateRangeSettings : {}, settings || {});
|
|
$(selector).daterangepicker(config, function (start, end) {
|
|
if (typeof __format_date_range === 'function') {
|
|
$(selector).val(__format_date_range(start, end));
|
|
} else {
|
|
$(selector).val(start.format(moment_date_format) + ' ~ ' + end.format(moment_date_format));
|
|
}
|
|
if (typeof callback === 'function') {
|
|
callback(start, end);
|
|
}
|
|
});
|
|
},
|
|
|
|
rangeStart: function (selector) {
|
|
if (typeof __daterangepicker_start_date === 'function') {
|
|
return __daterangepicker_start_date(selector);
|
|
}
|
|
var picker = $(selector).data('daterangepicker');
|
|
return picker ? picker.startDate.format('YYYY-MM-DD') : '';
|
|
},
|
|
|
|
rangeEnd: function (selector) {
|
|
if (typeof __daterangepicker_end_date === 'function') {
|
|
return __daterangepicker_end_date(selector);
|
|
}
|
|
var picker = $(selector).data('daterangepicker');
|
|
return picker ? picker.endDate.format('YYYY-MM-DD') : '';
|
|
},
|
|
|
|
momentDate: function (date) {
|
|
if (typeof __date_range_moment === 'function') {
|
|
return __date_range_moment(date);
|
|
}
|
|
return moment(date);
|
|
},
|
|
|
|
now: function () {
|
|
if (typeof __date_range_now === 'function') {
|
|
return __date_range_now();
|
|
}
|
|
return moment();
|
|
},
|
|
};
|
|
})();
|
|
</script>
|