abstract class field_timer_jquery_countdown_js_base in Field Timer 7.2
Base class for jquery_countdown formatters.
Hierarchy
- class \field_timer_formatter_base implements field_timer_formatter_interface
Expanded class hierarchy of field_timer_jquery_countdown_js_base
File
- includes/
field_timer_base.inc, line 145 - Contains base help classes to perform field formatter related actions.
View source
abstract class field_timer_jquery_countdown_js_base extends field_timer_formatter_js_base {
/**
* @inheritdoc
*/
public function enableFormatter() {
$library = libraries_detect('jquery.countdown');
return $library && !empty($library['installed']);
}
/**
* @inheritdoc
*/
protected function loadLibrary() {
if (!$this->library_loaded) {
$library = libraries_load('jquery.countdown');
$this->library_loaded = $library && !empty($library['loaded']);
$js_name = 'jquery.countdown.js';
$js_name_min = 'jquery.countdown.min.js';
$base_path = 'sites/all/libraries/jquery.countdown';
if (!$this->library_loaded) {
drupal_set_message(t("Can't load jQuery Countdown library. Please download !url plugin and extract it to @path, so @js and @js_min can be found at @full_path and @full_path_min.", array(
'!url' => l(t('jQuery Countdown'), 'http://keith-wood.name/countdown.html', array(
'absolute' => TRUE,
)),
'@path' => $base_path,
'@js' => $js_name,
'@js_min' => $js_name_min,
'@full_path' => $base_path . '/' . $js_name,
'@full_path_min' => $base_path . '/' . $js_name_min,
)), 'error');
}
}
return $this->library_loaded;
}
/**
* @inheritdoc
*/
protected function generateJSSettings($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$info = entity_get_info($entity_type);
$id_key = $info['entity keys']['id'];
$js_settings = array();
$settings = $display['settings'];
foreach ($items as $delta => $item) {
$key = $entity_type . '_' . $entity->{$id_key} . '_' . $field['field_name'] . '_' . $delta;
$timestamp = $this
->getTimestamp($item, $field);
$js_settings += $this
->generateJSSettingsArray($key, $timestamp, $settings['type'], $settings);
}
return $js_settings;
}
/**
* @inheritdoc
*/
protected function loadJSandCSS($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
parent::loadJSandCSS($entity_type, $entity, $field, $instance, $langcode, $items, $display);
drupal_add_css(drupal_get_path('module', 'field_timer') . '/css/field_timer.css', 'file');
}
protected function generateJSSettingsArray($key, $timestamp, $type, $settings) {
$js_settings = array();
$js_settings[$key]['timestamp'] = $timestamp;
$js_settings[$key]['options'] = $settings;
if ($type == 'timer' || $type == 'auto' && $timestamp <= REQUEST_TIME) {
$js_settings[$key]['options']['until'] = FALSE;
$js_settings[$key]['options']['since'] = TRUE;
}
elseif ($type == 'countdown' || $type == 'auto' && $timestamp > REQUEST_TIME) {
$js_settings[$key]['options']['until'] = TRUE;
$js_settings[$key]['options']['since'] = FALSE;
}
$js_settings[$key]['plugin'] = $this
->getPluginName();
return $js_settings;
}
protected function formatterTypes() {
return array(
'auto' => t('Auto'),
'timer' => t('Timer'),
'countdown' => t('Countdown'),
);
}
}