My very first experiments with elgg. elgg_view('input/date' uses the datepicker function, but I need to add some options.
In my plugin (called "help") initialization function (start.php) I declared elgg_extend_view('js/elgg', 'help/js'); Then, in \mod\help\views\default\help\js.php I copied the elgg.ui.initDatePicker function from the elgg core and I added my options to it. Also I added
elgg.provide('elgg.help');
on the top and
elgg.register_hook_handler('init', 'system', elgg.ui.initDatePicker);
on the bottom, like this:
-- begin of \mod\help\views\default\help\js.php code
elgg.provide('elgg.help');
elgg.ui.initDatePicker = function() {
var loadDatePicker = function() {
$('.elgg-input-date').datepicker({
// MY OPTIONS ADDED
yearRange: "-100:+0",
changeYear: true,
changeMonth: true,
// ISO-8601
dateFormat: 'yy-mm-dd',
onSelect: function(dateText) {
if ($(this).is('.elgg-input-timestamp')) {
// convert to unix timestamp
var dateParts = dateText.split("-");
var timestamp = Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2]);
timestamp = timestamp / 1000;
var id = $(this).attr('id');
$('input[name="' + id + '"]').val(timestamp);
}
}
});
};
if ($('.elgg-input-date').length && elgg.get_language() == 'en') {
loadDatePicker();
} else if ($('.elgg-input-date').length) {
elgg.get({
url: elgg.config.wwwroot + 'vendors/jquery/i18n/jquery.ui.datepicker-'+ elgg.get_language() +'.js',
dataType: "script",
cache: true,
success: loadDatePicker,
error: loadDatePicker // english language is already loaded.
});
}
}
elgg.register_hook_handler('init', 'system', elgg.ui.initDatePicker);
--- end of \mod\help\views\default\help\js.php code
It does indeed open a calendar, but it does not apply my yearRange,changeYear and changeMonth options. Though, if I just add the options in elgg\js\lib\ui.js it works fine. Since I don't want to mess with the core file I ask for hints here. Thank you
Use
FOR elgg 1.8.16