function calendar_systems_add_js_date_picker in Calendar Systems 8
Same name and namespace in other branches
- 7 calendar_systems.module \calendar_systems_add_js_date_picker()
- 7.2 calendar_systems.module \calendar_systems_add_js_date_picker()
Add javascript date picker for a field or set of fields
File
- ./
calendar_systems.module, line 649 - Contains Calendar Systems hook implementations and helpers.
Code
function calendar_systems_add_js_date_picker($css_class_id_type, $calendar_system = NULL, $language = NULL) {
calendar_systems_load_js_date_picker_library();
static $used_ids;
if (module_exists('jquery_calendar') && !isset($used_ids[$css_class_id_type])) {
$alignment = 'topLeft';
if (is_null($language)) {
$language = _calendar_systems_languages_active();
}
$languages = language_list();
if (isset($languages[$language])) {
if ($languages[$language]->direction) {
$alignment = 'topRight';
}
}
if (is_null($calendar_system)) {
$calendar_system = calendar_systems_get_calendar_system_name($language);
}
if ($calendar_system == 'default') {
$calendar_system = 'gregorian';
}
$calendar_system_name_map = array(
'arabic' => 'islamic',
'iranian' => 'persian',
'gregorian' => 'gregorian',
);
$date_format = 'yyyy-mm-dd';
$time_format = '';
if ($css_class_id_type == '.calendar_systems_js_date_picker_date_module') {
$date_format = 'mm/dd/yyyy';
$time_format = '';
}
if ($css_class_id_type == '.calendar_systems_js_date_picker_force_time') {
$time_format = 'H:i:s';
}
$time = '';
if (!empty($time_format)) {
$time = calendar_systems_format_date(time(), 'custom', $time_format);
}
$calendar_system = $calendar_system_name_map[$calendar_system];
$js = <<<EOT
(function(\$) {
\$('{<span class="php-variable">$css_class_id_type</span>}').calendarsPicker({
calendar: \$.calendars.instance('{<span class="php-variable">$calendar_system</span>}', '{<span class="php-variable">$language</span>}'),
dateFormat: '{<span class="php-variable">$date_format</span>}',
alignment: '{<span class="php-variable">$alignment</span>}',
onShow: function (picker, calendar, inst) {
if (picker) {
picker_parts =\$(this).val().split(' ');
}
},
onSelect: function (dates) {
if (dates) {
if (picker_parts[1]) {
dates = dates + ' ' + picker_parts[1];
} else if ('' != '{<span class="php-variable">$time</span>}') {
dates = dates + ' ' + '{<span class="php-variable">$time</span>}';
}
if ('' != '{<span class="php-variable">$time_format</span>}') {
if (picker_parts[2]) {
dates = dates + ' ' + picker_parts[2];
}
\$(this).val(dates);
}
}
}
});
})(jQuery);
EOT;
//alert(dates);\$('$css_class_id_type').calendarsPicker('setDate', '1350/10/10');
//onDate: function (date) {alert(date);}
//altField: function (date) {alert(date);}
drupal_add_js($js, array(
'type' => 'inline',
'scope' => 'footer',
'weight' => 5,
));
$used_ids[$css_class_id_type] = TRUE;
}
}