Skip to content

Commit

Permalink
Rename to readmore.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupalrv committed Mar 27, 2013
1 parent 2ef9f27 commit 0b145f9
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 135 deletions.
13 changes: 0 additions & 13 deletions js/more_text.js

This file was deleted.

13 changes: 13 additions & 0 deletions js/readmore.js
Original file line number Diff line number Diff line change
@@ -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);
106 changes: 0 additions & 106 deletions more_text.field.inc

This file was deleted.

3 changes: 0 additions & 3 deletions more_text.info

This file was deleted.

106 changes: 106 additions & 0 deletions readmore.field.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* @file
* Field formatter hooks to implement a readmore.
*/

/**
* Implements hook_field_formatter_info().
*/
function readmore_field_formatter_info() {
return array(
'readmore' => 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('<br />', $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;
}
4 changes: 4 additions & 0 deletions readmore.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = Read more
description = Add "read more" field formatter.
core = 7.x
package = Fields
18 changes: 9 additions & 9 deletions more_text.module → readmore.module
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions theme/more-text.tpl.php → theme/readmore.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* - $other: Text that will be displayed after click 'read more' link.
*/
?>
<div class="more-text">
<div class="readmore-wrapp">
<?php print $summary; ?>
<?php if ($ellipsis): ?>
<span class="more-text-ellips"><?php print t('...'); ?></span>
<span class="readmore-ellipsis"><?php print t('...'); ?></span>
<?php endif; ?>
<a class="read-more" href="#"><?php print t('read more'); ?></a>
<div class="other-text" style="display:none;"><?php print $other; ?></div>
<a class="readmore-link" href="#"><?php print t('read more'); ?></a>
<div class="readmore-other" style="display:none;"><?php print $other; ?></div>
</div>

0 comments on commit 0b145f9

Please sign in to comment.