From 0b145f9c611cf6d6010567b218c04032723ae78c Mon Sep 17 00:00:00 2001 From: drupalrv Date: Wed, 27 Mar 2013 22:30:25 +0200 Subject: [PATCH] Rename to readmore. --- js/more_text.js | 13 --- js/readmore.js | 13 +++ more_text.field.inc | 106 ------------------ more_text.info | 3 - readmore.field.inc | 106 ++++++++++++++++++ readmore.info | 4 + more_text.module => readmore.module | 18 +-- theme/{more-text.tpl.php => readmore.tpl.php} | 8 +- 8 files changed, 136 insertions(+), 135 deletions(-) delete mode 100644 js/more_text.js create mode 100644 js/readmore.js delete mode 100644 more_text.field.inc delete mode 100644 more_text.info create mode 100644 readmore.field.inc create mode 100644 readmore.info rename more_text.module => readmore.module (88%) rename theme/{more-text.tpl.php => readmore.tpl.php} (58%) diff --git a/js/more_text.js b/js/more_text.js deleted file mode 100644 index 40caa82..0000000 --- a/js/more_text.js +++ /dev/null @@ -1,13 +0,0 @@ -(function ($) { - Drupal.behaviors.moreText = { - attach : function(context, settings) { - $('.more-text .read-more').click(function(e) { - e.preventDefault(); - $(this).hide(); - var parent = $(this).closest('.more-text'); - parent.find('.more-text-ellips').hide(); - parent.find('.other-text').slideDown(300); - }); - } - }; -})(jQuery); diff --git a/js/readmore.js b/js/readmore.js new file mode 100644 index 0000000..ad94d1c --- /dev/null +++ b/js/readmore.js @@ -0,0 +1,13 @@ +(function ($) { + Drupal.behaviors.readmore = { + attach : function(context, settings) { + $('.readmore-wrapp .readmore-link').click(function(e) { + e.preventDefault(); + $(this).hide(); + var parent = $(this).closest('.readmore-wrapp'); + parent.find('.readmore-ellipsis').hide(); + parent.find('.readmore-other').slideDown(300); + }); + } + }; +})(jQuery); diff --git a/more_text.field.inc b/more_text.field.inc deleted file mode 100644 index eff2ed3..0000000 --- a/more_text.field.inc +++ /dev/null @@ -1,106 +0,0 @@ - array( - 'label' => t('More text'), - 'field types' => array( - 'text', - 'text_long', - 'text_with_summary', - ), - 'settings' => array( - 'trim_length' => 300, - 'ellipsis' => TRUE, - 'wordsafe' => FALSE, - ), - ), - ); -} - -/** - * Implements hook_field_formatter_settings_form(). - */ -function more_text_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $element = array(); - - if ($display['type'] == 'more_text') { - $element['trim_length'] = array( - '#title' => t('Trim length'), - '#type' => 'textfield', - '#size' => 10, - '#default_value' => $settings['trim_length'], - '#element_validate' => array('element_validate_integer_positive'), - '#required' => TRUE, - ); - $element['ellipsis'] = array( - '#type' => 'checkbox', - '#title' => t('Add ellipsis'), - '#default_value' => $settings['ellipsis'], - ); - $element['wordsafe'] = array( - '#type' => 'checkbox', - '#title' => t('Truncate on a word boundary'), - '#default_value' => $settings['wordsafe'], - ); - } - - return $element; -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function more_text_field_formatter_settings_summary($field, $instance, $view_mode) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - $summary = ''; - - if ($display['type'] == 'more_text') { - $summary[] = t('Trim length: @length', array('@length' => $settings['trim_length'])) . "\n"; - $summary[] = $settings['ellipsis'] ? t('Add ellipsis') : t('Do not add ellipsis'); - $summary[] = $settings['wordsafe'] ? t('Safe words') : t('Do not safe words'); - } - - return implode('
', $summary); -} - -/** - * Implements hook_field_formatter_view(). - */ -function more_text_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $element = array(); - switch ($display['type']) { - case 'more_text': - drupal_add_js(MORE_TEXT_MODULE_PATH . '/js/more_text.js'); - foreach ($items as $delta => $item) { - $output = _text_sanitize($instance, $langcode, $item, 'value'); - $output = more_text_divide_string($output, isset($item['format']) ? $item['format'] : NULL, $display['settings']['trim_length'], $display['settings']['wordsafe']); - if (is_array($output)) { - $output['ellipsis'] = $display['settings']['ellipsis']; - $element[$delta] = array( - '#markup' => theme('more_text', $output), - ); - } - else { - $element[$delta] = array( - '#markup' => $output, - ); - } - } - break; - } - - return $element; -} diff --git a/more_text.info b/more_text.info deleted file mode 100644 index 9be4c03..0000000 --- a/more_text.info +++ /dev/null @@ -1,3 +0,0 @@ -name = More text -description = Add "more text" field formatter. -core = 7.x diff --git a/readmore.field.inc b/readmore.field.inc new file mode 100644 index 0000000..606ce89 --- /dev/null +++ b/readmore.field.inc @@ -0,0 +1,106 @@ + array( + 'label' => t('Read more'), + 'field types' => array( + 'text', + 'text_long', + 'text_with_summary', + ), + 'settings' => array( + 'readmore_trim_length' => 500, + 'readmore_ellipsis' => TRUE, + 'readmore_wordsafe' => FALSE, + ), + ), + ); +} + +/** + * Implements hook_field_formatter_settings_form(). + */ +function readmore_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $element = array(); + + if ($display['type'] == 'readmore') { + $element['readmore_trim_length'] = array( + '#title' => t('Trim length'), + '#type' => 'textfield', + '#size' => 10, + '#default_value' => $settings['readmore_trim_length'], + '#element_validate' => array('element_validate_integer_positive'), + '#required' => TRUE, + ); + $element['readmore_ellipsis'] = array( + '#type' => 'checkbox', + '#title' => t('Add ellipsis'), + '#default_value' => $settings['readmore_ellipsis'], + ); + $element['readmore_wordsafe'] = array( + '#type' => 'checkbox', + '#title' => t('Truncate on a word boundary'), + '#default_value' => $settings['readmore_wordsafe'], + ); + } + + return $element; +} + +/** + * Implements hook_field_formatter_settings_summary(). + */ +function readmore_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + $summary = ''; + + if ($display['type'] == 'readmore') { + $summary[] = t('Trim length: @length', array('@length' => $settings['readmore_trim_length'])) . "\n"; + $summary[] = $settings['readmore_ellipsis'] ? t('Add ellipsis') : t('Do not add ellipsis'); + $summary[] = $settings['readmore_wordsafe'] ? t('Safe words') : t('Do not safe words'); + } + + return implode('
', $summary); +} + +/** + * Implements hook_field_formatter_view(). + */ +function readmore_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + $element = array(); + switch ($display['type']) { + case 'readmore': + drupal_add_js(READMORE_MODULE_PATH . '/js/readmore.js'); + foreach ($items as $delta => $item) { + $output = _text_sanitize($instance, $langcode, $item, 'value'); + $output = readmore_divide_string($output, isset($item['format']) ? $item['format'] : NULL, $display['settings']['readmore_trim_length'], $display['settings']['readmore_wordsafe']); + if (is_array($output)) { + $output['ellipsis'] = $display['settings']['readmore_ellipsis']; + $element[$delta] = array( + '#markup' => theme('readmore', $output), + ); + } + else { + $element[$delta] = array( + '#markup' => $output, + ); + } + } + break; + } + + return $element; +} diff --git a/readmore.info b/readmore.info new file mode 100644 index 0000000..2ffe525 --- /dev/null +++ b/readmore.info @@ -0,0 +1,4 @@ +name = Read more +description = Add "read more" field formatter. +core = 7.x +package = Fields diff --git a/more_text.module b/readmore.module similarity index 88% rename from more_text.module rename to readmore.module index 5e27c80..307ed2e 100644 --- a/more_text.module +++ b/readmore.module @@ -2,29 +2,29 @@ /** * @file - * Code for More text module. + * Basic functional for readmore module. */ -define('MORE_TEXT_MODULE_PATH', drupal_get_path('module', 'more_text')); +define('READMORE_MODULE_PATH', drupal_get_path('module', 'readmore')); -include_once DRUPAL_ROOT . '/' . MORE_TEXT_MODULE_PATH . '/more_text.field.inc'; +include_once DRUPAL_ROOT . '/' . READMORE_MODULE_PATH . '/readmore.field.inc'; /** * Implements hook_theme(). */ -function more_text_theme() { +function readmore_theme() { $base = array( - 'path' => MORE_TEXT_MODULE_PATH . '/theme', + 'path' => READMORE_MODULE_PATH . '/theme', ); return array( - 'more_text' => array( + 'readmore' => array( 'variables' => array( 'summary' => NULL, 'other' => NULL, 'ellips' => NULL, ), - 'template' => 'more-text', + 'template' => 'readmore', ) + $base, ); } @@ -45,10 +45,10 @@ function more_text_theme() { * @return array * Return array with truncated string and other text. */ -function more_text_divide_string($text, $format = NULL, $size = NULL, $wordsafe = FALSE) { +function readmore_divide_string($text, $format = NULL, $size = NULL, $wordsafe = FALSE) { if (!isset($size)) { // If size is not set then use default. - $size = 300; + $size = 500; } // We check for the presence of the PHP evaluator filter in the current diff --git a/theme/more-text.tpl.php b/theme/readmore.tpl.php similarity index 58% rename from theme/more-text.tpl.php rename to theme/readmore.tpl.php index 6c42e3b..dfdc0bc 100644 --- a/theme/more-text.tpl.php +++ b/theme/readmore.tpl.php @@ -10,11 +10,11 @@ * - $other: Text that will be displayed after click 'read more' link. */ ?> -
+
- + - - + +