Index: fivestar-admin.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/Attic/fivestar-admin.css,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 fivestar-admin.css
--- fivestar-admin.css 10 Mar 2008 01:44:41 -0000 1.1.2.1
+++ fivestar-admin.css 12 Mar 2008 05:36:08 -0000
@@ -1,5 +1,5 @@
/* Fivestar Settings Preview */
-iframe.fivestar-preview {
+div.fivestar-star-preview {
border: none;
width: 200px;
height: 32px;
@@ -25,3 +25,71 @@
border: 1px solid #CCC;
padding: 10px;
}
+
+/* Farbtastic placement */
+.color-form {
+ max-width: 50em;
+ position: relative;
+}
+#placeholder {
+ position: absolute;
+ top: 0;
+ right: 0;
+}
+
+/* Palette */
+.color-form .form-item {
+ height: 2em;
+ line-height: 2em;
+ padding-left: 1em;
+ margin: 0.5em 0;
+}
+.color-form label {
+ float: left;
+ clear: left;
+ width: 10em;
+}
+.color-form .form-text, .color-form .form-select {
+ float: left;
+}
+.color-form .form-text {
+ text-align: center;
+ margin-right: 5px;
+ cursor: pointer;
+}
+
+#palette .hook {
+ float: left;
+ margin-top: 3px;
+ width: 16px;
+ height: 16px;
+}
+#palette .down, #palette .up, #palette .both {
+ background: url(images/hook.png) no-repeat 100% 0;
+}
+#palette .up {
+ background-position: 100% -27px;
+}
+#palette .both {
+ background-position: 100% -54px;
+}
+
+#palette .lock {
+ float: left;
+ position: relative;
+ top: -1.4em;
+ left: -10px;
+ width: 20px;
+ height: 25px;
+ background: url(images/lock.png) no-repeat 50% 2px;
+ cursor: pointer;
+}
+#palette .unlocked {
+ background-position: 50% -22px;
+}
+#palette .form-item {
+ width: 20em;
+}
+#palette .item-selected {
+ background: #eee;
+}
Index: fivestar.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.module,v
retrieving revision 1.2.2.73
diff -u -r1.2.2.73 fivestar.module
--- fivestar.module 10 Mar 2008 06:24:07 -0000 1.2.2.73
+++ fivestar.module 12 Mar 2008 05:36:09 -0000
@@ -37,8 +37,8 @@
'access' => user_access('administer site configuration'),
);
$items[] = array(
- 'path' => 'fivestar/preview/widget',
- 'callback' => 'fivestar_preview_page',
+ 'path' => 'fivestar/preview/color',
+ 'callback' => 'fivestar_preview_color',
'type' => MENU_CALLBACK,
'access' => user_access('administer site configuration'),
);
@@ -374,14 +374,49 @@
*/
function fivestar_settings() {
$form = array();
- $form['fivestar_widget'] = array(
- '#type' => 'radios',
+
+ $form['widget'] = array(
+ '#tree' => FALSE,
+ '#type' => 'fieldset',
'#title' => t('Widget display'),
- '#options' => array('default' => t('Default')) + module_invoke_all('fivestar_widgets'),
+ '#description' => t('Choose a widget set to be used on your site. Classic widgets will be displayed exactly as shown, while widgets supporting custom colors can be further customized using the color settings below.'),
+ '#weight' => -2,
+ );
+
+ $widgets = module_invoke_all('fivestar_widgets');
+ $classic_widgets = array();
+ $color_widgets = array();
+ foreach ($widgets as $path => $name) {
+ $directory = dirname($path);
+ $matches = file_scan_directory($directory, '-mask.');
+ if (empty($matches)) {
+ $classic_widgets[$path] = $name;
+ }
+ else {
+ $color_widgets[$path] = $name;
+ }
+ }
+ $form['widget']['fivestar_widget'] = array(
+ '#type' => 'radios',
+ '#title' => t('Classic widgets'),
+ '#options' => array('default' => t('Default')) + $classic_widgets,
'#default_value' => variable_get('fivestar_widget', 'default'),
- '#description' => t('Choose a widget set to be used on your site.'),
- '#attributes' => array('class' => 'fivestar-widgets clear-block'),
+ '#attributes' => array('class' => 'fivestar-widgets'),
);
+
+ $form['widget']['fivestar_color_widget'] = array(
+ '#type' => 'radios',
+ '#title' => t('Custom color widgets'),
+ '#options' => $color_widgets,
+ '#default_value' => variable_get('fivestar_widget', 'default'),
+ '#attributes' => array('class' => 'fivestar-widgets'),
+ // Put these radios into the same group as the classic widgets.
+ '#parents' => array('fivestar_widget'),
+ );
+
+ include_once(drupal_get_path('module', 'fivestar') .'/fivestar_color.inc');
+ $form['color'] = fivestar_color_form();
+
$form['fivestar_anonymous_vote_interval'] = array(
'#type' => 'select',
'#title' => t('Anonymous vote interval'),
@@ -393,43 +428,61 @@
}
function theme_fivestar_settings($form) {
- fivestar_add_css();
drupal_add_css(drupal_get_path('module', 'fivestar') .'/fivestar-admin.css', 'module', 'all', FALSE);
drupal_set_title(t('Fivestar Settings'));
// Default preview.
- $form['fivestar_widget']['default']['#description'] = 'Default '. t('Preview') .':
';
+ $form['widget']['fivestar_widget']['default']['#description'] = 'Default '. t('Preview') .':
'. theme('fivestar_preview_widget', 'default');
- // Preview for each widget.
+ // Preview for each classic widget.
$widget_number = 0;
- foreach (element_children($form['fivestar_widget']) as $widget_key) {
+ foreach (element_children($form['widget']['fivestar_widget']) as $widget_key) {
if ($widget_key != 'default') {
- $form['fivestar_widget'][$widget_key]['#description'] = $form['fivestar_widget'][$widget_key]['#title'] .' '. t('Preview') .':
';
+ $form['widget']['fivestar_widget'][$widget_key]['#description'] = $form['widget']['fivestar_widget'][$widget_key]['#title'] .' '. t('Preview') .':
'. theme('fivestar_preview_widget', $widget_key);
$widget_number++;
}
}
- return drupal_render($form);
-}
-/**
- * Callback function for fivestar/preview/widget. Outputs an entire page
- * containing a preview of the passed in fivestar widget format.
- */
-function fivestar_preview_page($widget_number = NULL) {
- $widgets = module_invoke_all('fivestar_widgets');
- $css_files = array_keys($widgets);
- if (isset($css_files[$widget_number])) {
- fivestar_add_css($css_files[$widget_number]);
- }
- else {
- fivestar_add_css('default');
+ // Preview for each color-enabled widget.
+ $widget_number = 0;
+ foreach (element_children($form['widget']['fivestar_color_widget']) as $widget_key) {
+ if ($widget_key != 'default') {
+ $form['widget']['fivestar_color_widget'][$widget_key]['#description'] = $form['widget']['fivestar_color_widget'][$widget_key]['#title'] .' '. t('Preview') .':
'. theme('fivestar_preview_widget', $widget_key);
+ $widget_number++;
+ }
}
- fivestar_add_js();
- print theme('fivestar_preview_page');
- exit;
+
+ $form['widget']['fivestar_widget']['#attributes']['class'] .= ' clear-block';
+ $form['widget']['fivestar_color_widget']['#attributes']['class'] .= ' fivestar-color-widgets clear-block';
+
+ return drupal_render($form);
}
-function theme_fivestar_preview_page() {
+function theme_fivestar_preview_widget($css_file) {
+ static $default_css_added = FALSE;
+
+ // Add the default CSS to the page to ensure the defaults take precedence.
+ if (!$default_css_added) {
+ $css = file_get_contents(drupal_get_path('module', 'fivestar') .'/fivestar.css');
+ // Prepend the classes with the unique widget div.
+ $css = preg_replace('/((div)?\.fivestar-widget)/', 'div.fivestar-widgets $1', $css);
+ // Update relative URLs with absolute locations.
+ $css = preg_replace('/url\((.*?)\)/', 'url('. base_path() . drupal_get_path('module', 'fivestar') .'/$1)', $css);
+ drupal_set_html_head("");
+ $default_css_added = TRUE;
+ }
+
+ // Add widget specific CSS to the page.
+ $widget_name = str_replace('.css', '', basename($css_file));
+ $widget_path = dirname($css_file);
+ if ($widget_name != 'default') {
+ $css = file_get_contents($css_file);
+ // Prepend the classes with the unique widget div.
+ $css = preg_replace('/((div)?\.fivestar-widget)/', 'div#fivestar-preview-'. $widget_name .' $1', $css);
+ // Update relative URLs with absolute locations.
+ $css = preg_replace('/url\((.*?)\)/', 'url('. base_path() . $widget_path .'/$1)', $css);
+ drupal_set_html_head('');
+ }
$form = array();
$form['vote'] = array(
@@ -441,22 +494,52 @@
$form = form_builder('fivestar_preview', $form);
- $output = "\n";
- $output .= '';
- $output .= '