-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
drupalrv
committed
Mar 27, 2013
1 parent
2ef9f27
commit 0b145f9
Showing
8 changed files
with
136 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters