diff --git a/css/facetbrowser.css b/css/facetbrowser.css deleted file mode 100644 index b527ad6..0000000 --- a/css/facetbrowser.css +++ /dev/null @@ -1,16 +0,0 @@ -.facetbrowser_overlay { - z-index: 10000; - filter: alpha(opacity=50); /*older IE*/ - filter:progid:DXImageTransform.Microsoft.Alpha(opacity=50); /* IE */ - -moz-opacity: .50; /*older Mozilla*/ - -khtml-opacity: 0.5; /*older Safari*/ - opacity: 0.5; /*supported by current Mozilla, Safari, and Opera*/ - background-color:#999; - position:fixed; top:0px; left:0px; width:100%; height:100%; color:#FFFFFF; text-align:center; vertical-align:middle; -} - -.facetbrowser_overlay .spinner { - z-index:10001; - position:fixed; top:0px; left:0px; width:100%; height:100%; color:#FFFFFF; text-align:center; vertical-align:middle; - background: transparent url(../img/spinner.gif) no-repeat 50% 50%; -} diff --git a/ding_facetbrowser.admin.inc b/ding_facetbrowser.admin.inc index a005c4e..9508f91 100644 --- a/ding_facetbrowser.admin.inc +++ b/ding_facetbrowser.admin.inc @@ -14,12 +14,12 @@ function ding_facetbrowser_settings($form_state) { form_load_include($form_state, 'inc', 'ding_facetbrowser', 'ding_facetbrowser.admin'); $form = array(); $facets = variable_get('ding_facetbrowser_facets', array()); - + $form['description'] = array( '#markup' => '
' . t('Configure facets shown in the facetbrowser. Facet names can be found at DBC wiki and is usually named facet.something.') . '
', ); - $showcount = variable_get('ding_facetbrowser_showcount', count($facets)); + $showcount = variable_get('ding_facetbrowser_showcount', 5); $form['ding_facetbrowser_showcount'] = array( '#type' => 'select', '#title' => t('Visible facets amount'), @@ -36,7 +36,7 @@ function ding_facetbrowser_settings($form_state) { '#options' => drupal_map_assoc(range(1, 15)), '#default_value' => $number_of_terms, ); - + $form['ding_facetbrowser_facets'] = array( '#tree' => TRUE, '#weight' => -20, @@ -123,7 +123,6 @@ function ding_facetbrowser_settings($form_state) { ); $i++; - $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( '#type' => 'submit', @@ -179,6 +178,7 @@ function theme_ding_facetbrowser_settings($variables) { $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'facets'))); $output .= drupal_render($form['actions']); $output = drupal_render_children($form) . $output; + return $output; } @@ -206,4 +206,4 @@ function ding_facetbrowser_delete_facet_submit($form, &$form_state) { variable_set('ding_facetbrowser_facets', $facets); drupal_set_message(t('@facet deleted.', array('@facet' => $form_state['values']['facet_id']))); $form_state['redirect'] = 'admin/config/ting/facets'; -} \ No newline at end of file +} diff --git a/ding_facetbrowser.info b/ding_facetbrowser.info index 282c86a..52897cc 100644 --- a/ding_facetbrowser.info +++ b/ding_facetbrowser.info @@ -5,4 +5,4 @@ core = 7.x package = Ding! files[] = ding_facetbrowser.module files[] = ding_facetbrowser.test - +dependencies[] = ting_search diff --git a/ding_facetbrowser.install b/ding_facetbrowser.install index 4f2276a..6258e67 100644 --- a/ding_facetbrowser.install +++ b/ding_facetbrowser.install @@ -1,20 +1,78 @@ t('Ding facetbrowser'), - 'value' => t('One or more facetgroups have been translated.'), + 'title' => $t('Ding facetbrowser'), + 'value' => $t('One or more facetgroups have been translated.'), ); if (variable_get('ding_facetbrowser_facets', FALSE) == FALSE) { - $requirements['ding_facetbrowser']['value'] = t('No facetgroups have been translated. Go to Settings.', array('!link' => '/admin/config/ting/facets')); + $requirements['ding_facetbrowser']['value'] = $t('No facetgroups have been translated. Go to Settings.', array('!link' => '/admin/config/ting/facets')); $requirements['ding_facetbrowser']['severity'] = REQUIREMENT_ERROR; } } return $requirements; } +/** + * Implements hook_install(). + * + * Set default facets during installation. + */ +function ding_facetbrowser_install() { + $facets = array( + 0 => array( + 'name' => 'facet.type', + 'title' => 'Materialetype', + 'sorting' => 'default', + 'weight' => '-10', + ), + 1 => array( + 'name' => 'facet.creator', + 'title' => 'Forfatter', + 'sorting' => 'default', + 'weight' => '-9', + ), + 2 => array( + 'name' => 'facet.subject', + 'title' => 'Emne', + 'sorting' => 'default', + 'weight' => '-8', + ), + 3 => array( + 'name' => 'facet.language', + 'title' => 'Sprog', + 'sorting' => 'default', + 'weight' => '-7', + ), + 4 => array( + 'name' => 'facet.category', + 'title' => 'Målgruppe', + 'sorting' => 'default', + 'weight' => '-6', + ), + 5 => array( + 'name' => 'facet.date', + 'title' => 'Årstal', + 'sorting' => 'numeric_reverse', + 'weight' => '-5', + ), + 6 => array( + 'name' => 'facet.acSource', + 'title' => 'Kilde', + 'sorting' => 'default', + 'weight' => '-4', + ), + ); + + variable_set('ding_facetbrowser_facets', $facets); +} diff --git a/ding_facetbrowser.make b/ding_facetbrowser.make new file mode 100644 index 0000000..c359ba2 --- /dev/null +++ b/ding_facetbrowser.make @@ -0,0 +1,12 @@ +core = 7.x +api = 2 + +; Projects +projects[ctools][subdir] = "contrib" +projects[ctools][version] = "1.9" + +projects[ting][type] = "module" +projects[ting][download][type] = "git" +projects[ting][download][url] = "git@github.com:ding2/ting.git" +projects[ting][download][branch] = "master" + diff --git a/ding_facetbrowser.module b/ding_facetbrowser.module index a19dc0c..7a7583d 100644 --- a/ding_facetbrowser.module +++ b/ding_facetbrowser.module @@ -16,6 +16,8 @@ function ding_facetbrowser_block_info() { * Implements hook_menu(). */ function ding_facetbrowser_menu() { + $items = array(); + $items['admin/config/ting/facets'] = array( 'title' => 'Ting facets', 'description' => 'Configure facets.', @@ -40,8 +42,6 @@ function ding_facetbrowser_menu() { /** * Implements hook_theme(). - * - * @return array */ function ding_facetbrowser_theme() { return array( @@ -92,8 +92,7 @@ function ding_facetbrowser_ctools_plugin_api($module, $api) { function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = FALSE) { global $base_root; - $checkboxes = array(); - $default_values = array(); + $default_values = array(); $selected = array(); $not_selected = array(); @@ -102,16 +101,16 @@ function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = '#value' => $search, ); - // Building the facets fieldsets + // Building the facets field sets. $i = 0; - $facet_show_count = variable_get('ding_facetbrowser_showcount'); + $facet_show_count = variable_get('ding_facetbrowser_showcount', count($facets)); foreach (variable_get('ding_facetbrowser_facets', array()) as $configured_facet) { if (isset($facets[$configured_facet['name']])) { $facet = $facets[$configured_facet['name']]; - // Decide if the facet is to have the hidden class or not - $facet_class = ($i >= $facet_show_count) ? 'hidden' : 'visible'; + // Decide if the facet is to have the hidden class or not. + $facet_class = ($i >= $facet_show_count) ? 'js-hidden' : 'js-visible'; if (count($facet->terms) > 0) { $form[$facet->name] = array( @@ -119,28 +118,37 @@ function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = '#title' => check_plain($configured_facet['title']), '#attributes' => array( 'id' => str_replace('.', '-', $facet->name), - 'data' => array($facet->name), + 'data' => array( + $facet->name, + ), 'count' => count($facet->terms), - 'class' => array($facet_class), + 'class' => array( + $facet_class, + ), ), ); - switch ($configured_facet['sorting']) { - case 'alphabetical': - ksort($facet->terms); - break; - case 'alphabetical_reverse': - krsort($facet->terms); - break; - case 'numeric': - ksort($facet->terms, SORT_NUMERIC); - break; - case 'numeric_reverse': - krsort($facet->terms, SORT_NUMERIC); - break; - default: - - break; + if (!empty($configured_facet['sorting'])) { + switch ($configured_facet['sorting']) { + case 'alphabetical': + ksort($facet->terms); + break; + + case 'alphabetical_reverse': + krsort($facet->terms); + break; + + case 'numeric': + ksort($facet->terms, SORT_NUMERIC); + break; + + case 'numeric_reverse': + krsort($facet->terms, SORT_NUMERIC); + break; + + default: + break; + } } foreach ($facet->terms as $term_name => $term_count) { @@ -149,20 +157,21 @@ function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = $facets_string = $facet->name . ':' . $term_name; $term_name_title = $term_name; // Check if term name is longer than 14 chars, - // if so, short it down to fit facetbrowser + // if so, short it down to fit facet browser. $substr_length = 19 + substr_count(drupal_substr($term_name, 0, 20), 'l') - + drupal_strtolower(substr_count(drupal_substr($term_name, 0, 20), 'i')) + + substr_count(drupal_substr($term_name, 0, 20), 'i') - drupal_strlen((string)$term_count); if (drupal_strlen($term_name) > $substr_length + 3) { $term_name_title = drupal_substr($term_name, 0, $substr_length) . '...'; } - if (_isFacetSet($facet->name, $term_name) === TRUE) { + if (_ding_factbrowser_is_facet_set($facet->name, $term_name) === TRUE) { $default_values[] = $term_name; $facets_string = '-' . $facets_string; - $selected[$term_name] = l($term_name_title . ' (' . $term_count . ')', $base_root . _parseRequestUri(), array( + $uri = $base_root . _ding_factbrowser_parse_request_uri(); + $selected[$term_name] = l($term_name_title . ' (' . $term_count . ')', $uri, array( 'html' => TRUE, 'query' => array( 'facets' => array('' => $facets_string), @@ -173,7 +182,8 @@ function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = )); } else { - $not_selected[$term_name] = l($term_name_title . ' (' . $term_count . ')', $base_root . _parseRequestUri(), array( + $uri = $base_root . _ding_factbrowser_parse_request_uri(); + $not_selected[$term_name] = l($term_name_title . ' (' . $term_count . ')', $uri, array( 'html' => TRUE, 'query' => array( 'facets' => array('' => $facets_string), @@ -185,21 +195,20 @@ function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = } $form[$facet->name][$element_name] = array( - '#type' => 'checkboxes', - '#options' => $selected + $not_selected, + '#type' => 'checkboxes', + '#options' => $selected + $not_selected, '#default_value' => $default_values, ); } } - $i++; // Loop is done so time to up that counter + // Loop is done so time to up that counter. + $i++; } - // Reset previous set variables - $checkboxes = array(); + // Reset previous set variables. $default_values = array(); - $selected = array(); - $not_selected = array(); - + $selected = array(); + $not_selected = array(); } return $form; @@ -213,7 +222,7 @@ function ding_facetbrowser_form($form, &$form_state, $facets = FALSE, $search = * @return Boolean */ -function _isFacetSet($term_cat, $term_name) { +function _ding_factbrowser_is_facet_set($term_cat, $term_name) { $facets = &drupal_static('ding_facetbrowser_facets'); if (!isset($facets)) { $request_uri_parts = explode('?', request_uri()); @@ -233,42 +242,49 @@ function _isFacetSet($term_cat, $term_name) { * * @return String */ -function _parseRequestUri() { +function _ding_factbrowser_parse_request_uri() { $new_query_part = array(); - if (stristr(request_uri(), '?')) { - $request_uri_parts = explode('?', request_uri()); - $query = rawurldecode(end($request_uri_parts)); - $query_parts = explode('&', $query); - foreach ($query_parts as $key => $part) { - if (preg_match('/^page\=/', $part)) { - unset($query_parts[$key]); - continue; - } - $new_query_part[] = $part; - } - $query = $new_query_part; - return $request_uri_parts[0] . '?' . implode('&', $query); - } - else { + if (!stristr(request_uri(), '?')) { return request_uri(); } + + $request_uri_parts = explode('?', request_uri()); + + $query = rawurldecode(end($request_uri_parts)); + $query_parts = explode('&', $query); + foreach ($query_parts as $key => $part) { + if (preg_match('/^page\=/', $part)) { + unset($query_parts[$key]); + continue; + } + if (stristr($part, '=')) { + $decode_part = explode('=', $part); + $decode_part[1] = rawurlencode($decode_part[1]); + $part = implode('=', $decode_part); + } + $new_query_part[] = $part; + } + $query = $new_query_part; + return $request_uri_parts[0] . '?' . implode('&', $query); } /** - * Parse the selected facets from the $form_state to a readable string for the ting_search + * Parse the selected facets from the $form_state to a readable string for the + * ting_search. * * @param array $form_state + * * @return string */ -function _facetString($form_state = NULL) { +function _ding_factbrowser_facet_string($form_state = NULL) { $facets = array(); if (!empty($form_state['values']) && is_array($form_state['values'])) { foreach ($form_state['values'] as $name => $data) { if (is_array($data)) { foreach ($data as $key => $value) { if ($key == $value && $value !== 0) { - $facets[] = 'facet.' . $name . ':' . $value; + $facets[] = 'facet.' . $name . ':' . $value; } } } @@ -278,12 +294,11 @@ function _facetString($form_state = NULL) { } /** - * Facetbrowser theming function. + * Implements theme_facetbrowser(). * - * @param array $all_facets - * @return string + * Default theme function for the facet browser. */ -function theme_facetbrowser($search_result = FALSE) { +function theme_facetbrowser($search_result = array()) { $all_facets = array_shift($search_result); $searchkey = array_shift($search_result); $elements = array(); @@ -296,28 +311,26 @@ function theme_facetbrowser($search_result = FALSE) { /** * Implements hook_block_view(). - * - * @return Array */ function ding_facetbrowser_block_view($delta = FALSE) { - $block = array(); - $block_content = FALSE; - $content_in_facet = FALSE; + $block = array(); + $block_content = FALSE; + $content_in_facet = FALSE; $executed_search_module = FALSE; drupal_add_js(drupal_get_path('module', 'ding_facetbrowser') . '/js/jquery.cookie.min.js'); - drupal_add_js(drupal_get_path('module', 'ding_facetbrowser') . '/js/facetbrowser.js'); - drupal_add_css(drupal_get_path('module', 'ding_facetbrowser') . '/css/facetbrowser.css'); - // TODO: Get the facetbrowser dom id automatic - drupal_add_js( - array('dingFacetBrowser' => array( - 'mainElement' => '.pane-ding-facetbrowser', - 'showCount' => variable_get('ding_facetbrowser_number_of_terms', 5)), - ), 'setting'); - - - // Invoke ding_facetbrowser() from executed search module - $executed_search = menu_get_item(); + drupal_add_js(drupal_get_path('module', 'ding_facetbrowser') . '/js/ding_facetbrowser.js'); + + // @todo: Get the facet browser dom id automatic. + drupal_add_js(array( + 'ding_facetbrowser' => array( + 'selector' => '.js-facet-browser-toggle', + 'number_of_terms' => variable_get('ding_facetbrowser_number_of_terms', 5)), + ), 'setting'); + + + // Invoke ding_facetbrowser() from executed search module. + $executed_search = menu_get_item(); if (!empty($executed_search['page_arguments'])) { list($executed_search_module, ) = $executed_search['page_arguments']; } @@ -334,11 +347,12 @@ function ding_facetbrowser_block_view($delta = FALSE) { $block_content = theme('facetbrowser', array($results->facets, (!empty($results->searchkey) ? $results->searchkey : NULL))); } } + switch ($delta) { - case 'facetbrowser': - $block['subject'] = t('Facet browser'); - $block['content'] = $block_content; - break; + case 'facetbrowser': + $block['subject'] = t('Facet browser'); + $block['content'] = $block_content; + break; } } diff --git a/js/ding_facetbrowser.js b/js/ding_facetbrowser.js new file mode 100644 index 0000000..398d477 --- /dev/null +++ b/js/ding_facetbrowser.js @@ -0,0 +1,195 @@ +/** + * @file + * Implementation of the facet browser front-end to make the facet collapsible. + */ +(function($) { + +Drupal.behaviors.ding_facetbrowser = { + attach: function(context, settings) { + // Fold facet groups as default. + ding_facetbrowser_fold_facet_group(); + + // Select the fact browser(s) HTML element. + var fact_browsers = $(Drupal.settings.ding_facetbrowser.selector); + + // Hide extra facet groups (groups that have js-hidden class). + fact_browsers.each(function(index, facet_browser) { + // Create show more link. + var show_more_groups = $('', { + href: '#', + text: Drupal.t('Show more filters'), + class: 'expand expand-more' + }); + + // Create facet group wrapper. + var wrapper = $('', { + class: 'hidden-facets-group' + }); + + // Add the wrapper and link to the browser. + var browser = $(facet_browser); + browser.find('.js-hidden').wrapAll(wrapper); + wrapper = browser.find('.hidden-facets-group'); + wrapper.after(show_more_groups); + + // Add event handler to show more links. + show_more_groups.click(function(e) { + e.preventDefault(); + + // Get the link clicked. + var self = $(this); + + // Toggle facts groups and update link/button text. + wrapper.toggle('fast', function () { + var cookie = 0; + if (self.hasClass('expand-more')) { + show_more_groups.text(Drupal.t('Show less filters')); + show_more_groups.removeClass('expand-more').addClass('expand-less'); + cookie = 1; + } + else { + show_more_groups.text(Drupal.t('Show more filters')); + show_more_groups.removeClass('expand-less').addClass('expand-more'); + } + + // Set cookie, so to remember if they where shown. + $.cookie('ding_factbrowers_groups_shown', cookie); + }); + + return false; + }); + + // Check the cookie, if facet groups should be hidden or shown as default. + if (parseInt($.cookie('ding_factbrowers_groups_shown'), 10) === 1) { + show_more_groups.trigger('click'); + } + }); + + // Check for click in checkbox, and execute search. + fact_browsers.find('.form-type-checkbox input').change(function(e) { + Drupal.TingSearchOverlay(); + window.location = $(e.target).parent().find('a').attr('href'); + }); + + // Check facet links for click events. + fact_browsers.find('.form-type-checkbox a').click(function(e) { + if ($(this).not('[target="_blank"]').length) { + Drupal.TingSearchOverlay(); + } + }); + } +}; + +/** + * Fold facet groups to show only x unselected checkboxes per group. + */ +function ding_facetbrowser_fold_facet_group() { + // Select the fact browser HTML element. + var fact_browser = $(Drupal.settings.ding_facetbrowser.selector); + + // Add show more button to each facet group and hide some terms. + fact_browser.find('fieldset.form-wrapper').each(function() { + var facetGroup = $(this); + + // Limit the number of visible terms in the group. + var number_of_terms = Drupal.settings.ding_facetbrowser.number_of_terms; + var terms_not_checked = facetGroup.find('.form-type-checkbox input:not(:checked)'); + if (terms_not_checked.size() > number_of_terms) { + terms_not_checked.slice(number_of_terms).parent().hide(); + } + + // Add expand button, if there are more to show. + if (terms_not_checked.length > number_of_terms) { + facetGroup.append('' + Drupal.t('Show more') + ''); + } + + // Add classes to checkbox wrappers used to handle visibility. + facetGroup.find('.form-type-checkbox input:checked').parent().addClass('selected-checkbox'); + facetGroup.find('.form-type-checkbox input:not(:checked)').parent().addClass('unselected-checkbox'); + + // Add div wrappers around selected and unselected checkboxes to handle visibility. + facetGroup.find('.selected-checkbox').wrapAll(''); + facetGroup.find('.unselected-checkbox').wrapAll(''); + + // Add a unselect all link. + if (facetGroup.find('.selected-checkbox-group').length) { + facetGroup.find('.selected-checkbox-group').append('' + Drupal.t('Remove all selected') + ''); + } + + }); + + /** + * Bind click function to show more and show less links. + */ + fact_browser.find('.expand').live('click', function(e) { + e.preventDefault(); + + var clickedKey = $(this); + var facetGroup = $(clickedKey).parent(); + + facetGroup.find('.form-type-checkbox.unselected-checkbox:' + (clickedKey.hasClass('expand-more') ? 'hidden': 'visible')).each(function(count, facetElement) { + if (clickedKey.hasClass('expand-more') && count < Drupal.settings.ding_facetbrowser.number_of_terms) { + $(facetElement).slideDown('fast', function() { + if (facetGroup.find('.form-type-checkbox.unselected-checkbox:visible').size() >= Drupal.settings.ding_facetbrowser.number_of_terms && + facetGroup.find('.expand-less').size() === 0 && + count % Drupal.settings.ding_facetbrowser.number_of_terms === 0) { + facetGroup.append('' + Drupal.t('Show less') + ''); + } + }); + } + else if (clickedKey.hasClass('expand-less') && count >= Drupal.settings.ding_facetbrowser.number_of_terms) { + $(facetElement).slideUp('fast', function() { + if (facetGroup.find('.form-type-checkbox.unselected-checkbox:visible').size() == Drupal.settings.ding_facetbrowser.number_of_terms && + facetGroup.find('.expand-less:visible')) { + facetGroup.find('.expand-less').fadeOut().remove(); + } + }); + } + }); + + // Need to make sure we have the correct amount of unselected checkboxes to check against when wanting to remove the show more link. + var unselectedSize = facetGroup.attr('count')-facetGroup.find('.form-type-checkbox.selected-checkbox').size(); + + if ((facetGroup.find('.form-type-checkbox.unselected-checkbox:visible').size() >= unselectedSize) && (clickedKey.hasClass('expand-more'))) { + facetGroup.find('.expand-more').remove(); + } + + if (clickedKey.hasClass('expand-less')){ + if (!(facetGroup.find('.expand-more').length)) { + facetGroup.append('' + Drupal.t('Show more') + ''); + } + } + + return false; + }); + + /** + * Bind click function to the un-select all selected checkboxes link. + */ + fact_browser.find('.unselect').live('click', function(e) { + e.preventDefault(); + + var clickedKey = this; + var facetGroup = $(clickedKey).parent(); + var checkedFacets = ''; + facetGroup.find('.form-type-checkbox.selected-checkbox').each(function() { + var element = $(this); + // Un-check checkboxes (for the visual effect). + element.find('input').click(); + + // Find the facets to be deselected and generate new URL. + var facetMatch = element.find('a').attr('href').match(/&facets\[\]=-facet.*/); + checkedFacets += facetMatch[0]; + if (checkedFacets) { + Drupal.TingSearchOverlay(); + window.location.href += checkedFacets; + } + }); + + return false; + }); +}; + +})(jQuery); + + diff --git a/js/facetbrowser.js b/js/facetbrowser.js deleted file mode 100644 index dc9c532..0000000 --- a/js/facetbrowser.js +++ /dev/null @@ -1,164 +0,0 @@ - -(function($) { - - Drupal.behaviors.facetbrowser = { - attach: function(context, settings) { - Drupal.FoldFacetGroup(); - - var main_element = $(Drupal.settings.dingFacetBrowser.mainElement); - - // Wrap all facet fieldsets marked as hidden in a container so we can hide - // em. The link text is show less and will be changed to show more if the - // cookie is false. - var show_more = $('' + Drupal.t('Show less filters') + ''); - main_element.find('fieldset.hidden').wrapAll(''); - main_element.find('#hidden-facets').after(show_more); - - // Check the cookie. - if ($.cookie("ding_factbrowers_toggle") != 'true') { - main_element.find('#hidden-facets').hide(); - show_more.text(Drupal.t('Show more filters')); - show_more.removeClass().addClass("expand-facets expand-facets-hidden"); - } - - show_more.click(function(e) { - e.preventDefault(); - - // Toggle facts groups and update link/button text. - main_element.find('#hidden-facets').toggle('fast', function () { - var visible = $(this).is(':visible'); - show_more.text( - visible ? Drupal.t('Show less filters') : Drupal.t('Show more filters') - ); - show_more.removeClass().addClass( - visible ? "expand-facets expand-facets-visible" : "expand-facets expand-facets-hidden" - ); - - // Set cookie, so to remember if they where shown. - $.cookie("ding_factbrowers_toggle", visible); - }); - - return false; - }); - - // Check for click in checkbox, and execute search. - main_element.find('.form-type-checkbox input').change(function(e) { - $('body').prepend(''); - window.location = $(e.target).parent().find('a').attr('href'); - }); - } - }; - - /** - * Fold facet groups to show only x unselected checkboxes per group. - */ - Drupal.FoldFacetGroup = function() { - - var main_element = $(Drupal.settings.dingFacetBrowser.mainElement); - - // Add show more button to each facet group and hide some terms. - main_element.find('fieldset.form-wrapper').each(function() { - var facetGroup = $(this); - - // Limit the number of visible terms in the group. - var number_of_terms = Drupal.settings.dingFacetBrowser.number_of_terms; - var terms_not_checked = facetGroup.find('.form-type-checkbox input:not(:checked)'); - if (terms_not_checked.size() > number_of_terms) { - terms_not_checked.slice(number_of_terms).parent().hide(); - } - - // Add expand button, if there are more to show. - if (terms_not_checked.length > number_of_terms) { - facetGroup.append('' + Drupal.t('Show more') + ''); - } - - // Add some classes to checkbox wrappers. - facetGroup.find('.form-type-checkbox input:checked').parent().addClass('selected-checkbox'); - facetGroup.find('.form-type-checkbox input:not(:checked)').parent().addClass('unselected-checkbox'); - - // Add some div wrappers around selected and unselected checkboxes. - facetGroup.find('.selected-checkbox').wrapAll(''); - facetGroup.find('.unselected-checkbox').wrapAll(''); - - // Add a unselect all link. - if (facetGroup.find('.selected-checkbox-group').length) { - facetGroup.find('.selected-checkbox-group').append('' + Drupal.t('Remove all selected') + ''); - } - - }); - - /** - * Bind click function to show more and show less links. - */ - main_element.find('.expand').live('click', function(e) { - e.preventDefault(); - - var clickedKey = this; - var facetGroup = $(clickedKey).parent(); - - facetGroup.find('.form-type-checkbox.unselected-checkbox:' + (clickedKey.id == 'expand_more' ? 'hidden': 'visible')).each(function(count, facetElement) { - if (clickedKey.id == 'expand_more' && count < Drupal.settings.dingFacetBrowser.number_of_terms) { - $(facetElement).slideDown('fast', function() { - if (facetGroup.find('.form-type-checkbox.unselected-checkbox:visible').size() >= Drupal.settings.dingFacetBrowser.number_of_terms && - facetGroup.find('#expand_less').size() === 0 && - count % Drupal.settings.dingFacetBrowser.number_of_terms === 0) { - facetGroup.append('' + Drupal.t('Show less') + ''); - } - }); - } - else if (clickedKey.id == 'expand_less' && count >= Drupal.settings.dingFacetBrowser.number_of_terms) { - $(facetElement).slideUp('fast', function() { - if (facetGroup.find('.form-type-checkbox.unselected-checkbox:visible').size() == Drupal.settings.dingFacetBrowser.number_of_terms && - facetGroup.find('#expand_less:visible')) { - facetGroup.find('#expand_less').fadeOut().remove(); - } - }); - } - }); - - // Need to make sure we have the correct amount of unselected checkboxes to check against when wanting to remove the show more link. - var unselectedSize = facetGroup.attr('count')-facetGroup.find('.form-type-checkbox.selected-checkbox').size(); - - if ((facetGroup.find('.form-type-checkbox.unselected-checkbox:visible').size() >= unselectedSize) && (clickedKey.id == 'expand_more')) { - facetGroup.find('#expand_more').remove(); - } - - if (clickedKey.id == 'expand_less'){ - if (!(facetGroup.find('#expand_more').length)) { - facetGroup.append(''); - } - } - - return false; - }); - - /** - * Bind click function to the unselect all selected checkboxes link. - */ - main_element.find('.unselect').live('click', function(e) { - e.preventDefault(); - - var clickedKey = this; - var facetGroup = $(clickedKey).parent(); - var checkedFacets = ''; - facetGroup.find('.form-type-checkbox.selected-checkbox').each(function() { - var element = $(this); - // Uncheck checkboxes (for the visual effect). - element.find('input').click(); - - // Find the facets to be deselected and generate new URL. - var facetMatch = element.find('a').attr('href').match(/&facets\[\]=-facet.*/); - checkedFacets += facetMatch[0]; - if (checkedFacets) { - $('body').prepend(''); - window.location.href += checkedFacets; - } - }); - - return false; - }); - }; - -})(jQuery); - - diff --git a/plugins/content_types/ding_facetbrowser/ding_facetbrowser.inc b/plugins/content_types/ding_facetbrowser/ding_facetbrowser.inc index fdc2fd8..45ad9cd 100644 --- a/plugins/content_types/ding_facetbrowser/ding_facetbrowser.inc +++ b/plugins/content_types/ding_facetbrowser/ding_facetbrowser.inc @@ -7,11 +7,11 @@ $plugin = array( 'content_types' => array('ding_facetbrowser'), 'render callback' => 'ding_facetbrowser_content_type_render', 'category' => t('Ting'), - 'render last' => TRUE, # Force the facetbrowser to be generated after the ting_search + 'render last' => TRUE, ); /** - * Callback function for the ctools content_type + * Callback function for the ctools content_type. */ function ding_facetbrowser_content_type_render($subtype, $conf, $panel_args, $context) { $block_content = FALSE; @@ -22,17 +22,17 @@ function ding_facetbrowser_content_type_render($subtype, $conf, $panel_args, $co $block->module = 'ding_facetbrowser'; $block->delta = 'ding_facetbrowser'; - drupal_add_css(drupal_get_path('module', 'ding_facetbrowser') . '/css/facetbrowser.css'); - drupal_add_js(drupal_get_path('module', 'ding_facetbrowser') . '/js/jquery.cookie.min.js'); - drupal_add_js(drupal_get_path('module', 'ding_facetbrowser') . '/js/facetbrowser.js'); + $path = drupal_get_path('module', 'ding_facetbrowser'); + drupal_add_js($path . '/js/jquery.cookie.min.js'); + drupal_add_js($path . '/js/ding_facetbrowser.js'); drupal_add_js(array( - 'dingFacetBrowser' => array( - 'mainElement' => '.pane-ding-facetbrowser', + 'ding_facetbrowser' => array( + 'selector' => '.js-facet-browser-toggle', 'number_of_terms' => variable_get('ding_facetbrowser_number_of_terms', 5), - ) + ), ), 'setting'); - // Invoke ding_facetbrowser() from executed search module + // Invoke ding_facetbrowser() from executed search module. $executed_search = menu_get_item(); if (!empty($executed_search['page_arguments'])) { list($executed_search_module, ) = $executed_search['page_arguments']; @@ -51,13 +51,13 @@ function ding_facetbrowser_content_type_render($subtype, $conf, $panel_args, $co } } $block->title = t('Ding Facetbrowser'); - $block->content = $block_content; + $block->content = '