diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 15b6619..54f6f07 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,6 @@ +Betterselect 7.x-1.x, 2013-06-23 +---------------------------------- +- #488520: Port Better Select module to drupal 7 -- Starting porting to Drupal 7 Betterselect 6.x-1.0-beta3, 2011-01-16 ---------------------------------- diff --git a/README.txt b/README.txt index abb2011..9552976 100644 --- a/README.txt +++ b/README.txt @@ -39,9 +39,9 @@ INSTALLATION 1. Copy the betterselect directory to your sites/SITENAME/modules directory. -2. Enable the module at Administer >> Site building >> Modules. +2. Enable the module at Administration >> Modules. -3. Configure the module at admin/settings/betterselect. +3. Configure the module at admin/config/content/betterselect. That's it! This module will automatically attempt to convert any multiselect HTML elements to use the new stylized checkboxes. diff --git a/betterselect.css b/betterselect.css index 2a7d764..c9767e6 100644 --- a/betterselect.css +++ b/betterselect.css @@ -1,15 +1,15 @@ -.better-select div.form-checkboxes { +.better-select div.form-type-checkboxes { margin: 0; } -.better-select div.form-checkboxes-scroll { +.better-select.form-checkboxes-scroll { border: 1px solid #666; max-height: 150px; overflow: auto; } -.better-select div.form-checkboxes-noscroll { +.better-select.form-checkboxes-noscroll { overflow: hidden; } diff --git a/betterselect.info b/betterselect.info index 27e8da6..65fc581 100644 --- a/betterselect.info +++ b/betterselect.info @@ -1,3 +1,4 @@ name = Better Select description = Use stylized checkboxes instead of the default multiple select HTML element in forms. -core = 6.x +configure = admin/config/content/betterselect +core = 7.x diff --git a/betterselect.install b/betterselect.install index 1b29e39..40587f4 100644 --- a/betterselect.install +++ b/betterselect.install @@ -7,5 +7,4 @@ function betterselect_uninstall() { variable_del('betterselect_scroll'); variable_del('betterselect_save_lineage'); variable_del('betterselect_node_form_only'); -} - +} \ No newline at end of file diff --git a/betterselect.js b/betterselect.js index 8a64d02..19cf826 100644 --- a/betterselect.js +++ b/betterselect.js @@ -1,7 +1,11 @@ +(function ($) { -Drupal.behaviors.initBetterSelect = function(context) { - $('.better-select .form-checkboxes input[type="checkbox"]').click(function(){ - this.checked ? $(this).parent().parent().addClass('hilight') : $(this).parent().parent().removeClass('hilight'); - }).filter(":checked").parent().parent().addClass('hilight'); +Drupal.behaviors.initBetterSelect = { + attach: function(context) { + $('.better-select .form-type-checkbox input[type="checkbox"]').click(function(){ + this.checked ? $(this).parent().addClass('hilight') : $(this).parent().removeClass('hilight'); + }).filter(":checked").parent().addClass('hilight'); + } } +})(jQuery); diff --git a/betterselect.module b/betterselect.module index 954387b..c67a612 100644 --- a/betterselect.module +++ b/betterselect.module @@ -8,12 +8,12 @@ */ /** - * Implementation of hook_menu(). + * Implements hook_menu(). */ function betterselect_menu() { $items = array(); - $items['admin/settings/betterselect'] = array( - 'title' => t('Better select'), + $items['admin/config/content/betterselect'] = array( + 'title' => 'Better select', 'description' => t('Configure better select settings.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('betterselect_admin_settings'), @@ -69,11 +69,11 @@ function betterselect_admin_settings() { } /** - * Implementation of hook_elements(). + * Implements hook_element_info(). */ -function betterselect_elements() { +function betterselect_element_info() { $type = array(); - $type['select']['#process'] = array('betterselect_process'); + $type['select']['#process'] = array('betterselect_process_element'); return $type; } @@ -81,33 +81,10 @@ function betterselect_elements() { /** * Form process callback; translates multiselect fields into checkboxes. */ -function betterselect_process($element, $edit, $form_state, $complete_form) { +function betterselect_process_element($element, &$form_state, $complete_form) { if (isset($element['#multiple']) && $element['#multiple'] == TRUE && !(variable_get('betterselect_node_form_only', FALSE) == TRUE && $complete_form['#id'] != 'node-form')) { - // If we're dealing with taxonomy, fix the option titles. - if (is_object($element['#options'][0])) { - // Build new array of options in format that theme_checkboxes expects. - $options = array(); - $defaults = array(); - foreach ($element['#options'] as $option) { - if (is_array($option->option)) { - foreach ($option->option as $tid => $name) { - $options[$tid] = check_plain($name); - } - } - } - $element['#options'] = $options; - } - - // We now check that the element's options are correct. If they're not in - // the right format, we abort. - foreach($element['#options'] as $key => $val) { - if (!is_numeric($key) || !is_string($val)) { - return $element; - } - } - - // The default value should be an array, if it isn't expand_checkboxes() + // The default value should be an array, if it isn't form_process_checkboxes() // will make it one. if (isset($element['#default_value']) && is_array($element['#default_value']) && count($element['#default_value'])) { // Fix the value arrays; checkboxes are the exact inverse of multiselect, @@ -124,26 +101,22 @@ function betterselect_process($element, $edit, $form_state, $complete_form) { // Place options in a scrollable or non-scrollable div $div_class = variable_get('betterselect_scroll', FALSE) ? 'form-checkboxes-scroll' : 'form-checkboxes-noscroll'; - $element['#attributes'] = array('class' => $div_class); + //$element['#attributes'] = array('class' => array($div_class)); // Switch display to checkboxes instead. $element['#type'] = 'checkboxes'; unset($element['#theme']); - $element = expand_checkboxes($element); + $element = form_process_checkboxes($element); // Hide the silly "None" option. (assumes array element with a blank key is the "None" option) - if (!$element['#required'] && is_array($element[''])) { - $element['']['#prefix'] = '
'; - $element['']['#suffix'] = '
'; + if (isset($element['#required']) && !$element['#required'] && is_array($element['_none'])) { + $element['_none']['#prefix'] = '
'; + $element['_none']['#suffix'] = '
'; } // Include the JS and CSS files. - static $path; - if (!isset($path)) { - $path = drupal_get_path('module', 'betterselect'); - drupal_add_css($path . '/betterselect.css'); - drupal_add_js($path . '/betterselect.js'); - } + drupal_add_css(drupal_get_path('module', 'betterselect') . '/betterselect.css'); + drupal_add_js(drupal_get_path('module', 'betterselect') . '/betterselect.js'); // Add classes to items that indicate depth, for taxonomy, useful for // styling parent terms differently. @@ -180,14 +153,14 @@ function betterselect_process($element, $edit, $form_state, $complete_form) { $suffix = isset($element['#suffix']) ? $element['#suffix'] : ''; $fixheight = count($element['#options']) > $size ? ' betterfixed' : ''; $id = 'better-select-' . $element['#id']; - $element['#prefix'] = '
' . $prefix; + $element['#prefix'] = '
' . $prefix; $element['#suffix'] = $suffix . '
'; } return $element; } /** - * Implementation of hook_form_alter(). + * Implements hook_form_alter(). */ function betterselect_form_alter(&$form, $form_state, $form_id) { // Taxonomy stores its #options in a weird way; we need to move it back once we're done.