diff --git a/includes/jplayer.theme.inc b/includes/jplayer.theme.inc index f3e8715..55dbe85 100644 --- a/includes/jplayer.theme.inc +++ b/includes/jplayer.theme.inc @@ -174,4 +174,42 @@ function jplayer_sort_files($raw_files = array(), $player_id, $type = 'single') } return array('files' => $files, 'extensions' => implode(',', $extensions), 'playlist' => $playlist, 'type' => $player_type); -} \ No newline at end of file +} + +/** + * Preprocess function for jplayer.tpl.php when displaying a view as a playlist. + */ +function template_preprocess_jplayer_view_playlist(&$vars) { + // @TODO This is the ugliest hack ever, it has to be possible to do this better. + jplayer_add(); + $pseudo_element = array('#attached' => jplayer_add()); + drupal_process_attached($pseudo_element); + + $view = $vars['view']; + $vars['settings'] = $view->style_plugin->options; + $vars['mode'] = 'playlist'; + $vars['player_id'] = 'jplayer-view-' . str_replace('_', '-', check_plain($view->name)); + + $player = jplayer_sort_files($vars['items'], $vars['player_id'], $vars['mode']); + + $vars['playlist'] = theme('jplayer_item_list', array('items' => $player['playlist'])); + $vars['type'] = $player['type']; + + // Add player settings + $player = array( + 'jplayerInstances' => array( + $vars['player_id'] => array( + 'files' => $player['files'], + 'solution' => $vars['settings']['solution'], + 'supplied' => $player['extensions'], + 'preload' => $vars['settings']['preload'], + 'volume' => $vars['settings']['volume'] / 100, + 'muted' => (boolean)$vars['settings']['muted'], + 'autoplay' => (boolean)$vars['settings']['autoplay'], + 'repeat' => $vars['settings']['repeat'], + 'backgroundColor' => $vars['settings']['backgroundColor'], + ), + ), + ); + drupal_add_js($player, 'setting'); +} diff --git a/includes/jplayer_style_plugin.inc b/includes/jplayer_style_plugin.inc index 8d0b968..693eb29 100644 --- a/includes/jplayer_style_plugin.inc +++ b/includes/jplayer_style_plugin.inc @@ -14,6 +14,14 @@ class jplayer_style_plugin extends views_plugin_style { $options = parent::option_definition(); $options['path_field'] = array('default' => NULL); $options['label_field'] = array('default' => NULL); + + // Get the formatter default settings into the option_definition. + $formatter = jplayer_field_formatter_info(); + $settings = $formatter['jplayer_player']['settings']; + foreach ($settings as $name => $default_value) { + $options[$name] = array('default' => $default_value); + } + return $options; } @@ -46,6 +54,19 @@ class jplayer_style_plugin extends views_plugin_style { '#description' => t('Select the fields that will contain a file path to an mp3 file. If multiple fields are selected, the first one that contains a value will be used. This field will be hidden from view unless there are no other fields visible'), '#weight' => -5, ); + + // Get the formatter settings into the options form. + $field = 'jplayer_view_pseudo_field'; + $instance = array( + 'display' => array( + 'view' => array( + 'type' => 'jplayer_player', + 'settings' => $this->options, + ), + ), + ); + + $form += jplayer_field_formatter_settings_form($field, $instance, 'view', $form, $form_state); } // Ensure we have all the settings necessary to render into tabs. diff --git a/jplayer.module b/jplayer.module index ce97d5d..ec1b093 100644 --- a/jplayer.module +++ b/jplayer.module @@ -35,6 +35,8 @@ function jplayer_theme() { 'player_id' => NULL, 'items' => array(), 'settings' => array(), + 'type' => '', + 'playlist' => '', ), 'template' => 'theme/jplayer', 'file' => 'includes/jplayer.theme.inc', @@ -49,6 +51,11 @@ function jplayer_theme() { 'attributes' => array(), ), ), + 'jplayer_view_playlist' => array( + 'arguments' => array('view' => NULL, 'items' => NULL), + 'template' => 'theme/jplayer', + 'file' => 'includes/jplayer.theme.inc', + ), ); } @@ -314,4 +321,14 @@ function jplayer_get_version($directory = NULL) { $parts = explode('.', $version); return array('version' => $version, 'major' => $parts[0], 'minor' => $parts[1]); -} \ No newline at end of file +} + +/** + * Implements hook_views_api(). + */ +function jplayer_views_api() { + return array( + 'path' => drupal_get_path('module', 'jplayer') . '/includes', + 'api' => 3.0, + ); +}