Automatically detects document files (PDF, TXT, CSV, HTML etc.) on pages and provides AI-generated summaries in tooltips on hover.
This module was built with AI assistance.
Sponsored by https://www.drupal.org/tag1-consulting
- Automatic document (PDF, TXT etc.) link detection on web pages
- AI-powered summarization using Drupal's AI module
- Hover tooltips with document summaries
- Caching system for improved performance
- Mobile-responsive design
- Configurable AI models and prompts
- Dark mode support
- Accessibility features
- Drupal 10.3+ or Drupal 11+
- PHP 8.1+
- AI module (drupal/ai)
- An AI provider configured (e.g., OpenAI)
-
Install the module and its dependencies:
composer require drupal/ai
-
Enable the module:
drush pm:install docs_summarizer_tooltip
-
Configure the AI provider at
/admin/config/ai
-
Configure the Document Summarizer at
/admin/config/ai/docs-summarizer-tooltip
Visit Administration » Configuration » AI » PDF Summarizer Settings to configure:
- Enable/disable the module
- Select AI model for summaries
- Customize the summary prompt
- Set maximum summary length
- etc.
Once enabled and configured, the module automatically:
-
Detects PDF links on pages using patterns like:
href$=".pdf"
href*=".pdf?"
href*=".pdf#"
-
Adds a PDF icon indicator next to detected links
-
Shows AI-generated summaries in tooltips when users hover over PDF links
-
Caches summaries for improved performance
To prevent tooltips on specific PDF links, add the data-no-summarizer="true"
attribute:
<a href="document.pdf" data-no-summarizer="true">Download PDF</a>
.docs-summarizer-link
- Applied to detected document links.docs-summarizer-tooltip
- Main tooltip container.docs-tooltip-header
- Tooltip header with filename.docs-tooltip-content
- Tooltip content area.docs-loading
- Loading state styles.docs-error
- Error state styles
The module uses Drupal behaviors and can be extended through custom JavaScript.
- Summaries are cached by default for 1 hour
- Only processes non-admin pages
- Uses efficient CSS selectors for PDF detection
- Implements request deduplication
- Supports reduced motion preferences
The PDF Summarizer module follows WCAG 2.1 AA accessibility standards:
- Tab Navigation: PDF links are focusable with Tab key
- Activation: Press Enter or Space to show/hide tooltips
- Escape Key: Close tooltip and return focus to trigger link
- Focus Management: Proper focus indicators and management
- ARIA Attributes: Tooltips use proper ARIA roles and properties
- Live Regions: Status announcements for loading, success, and errors
- Screen Reader Text: Hidden text provides context for icons and states
- Semantic Structure: Proper heading hierarchy and landmark roles
- High Contrast Mode: Enhanced borders and colors for better visibility
- Focus Indicators: Clear visual focus rings for keyboard users
- Reduced Motion: Respects user motion preferences, disables animations
- Color Independence: Information not conveyed through color alone
role="tooltip"
on tooltip containersaria-describedby
linking tooltips to trigger elementsaria-live="polite"
for status updatesrole="status"
for loading statesrole="alert"
for error messagesrole="region"
for summary content areas
- Check if the module is enabled at
/admin/config/ai/docs-summarizer-tooltip
- Verify AI provider is configured at
/admin/config/ai
- Check browser console for JavaScript errors
- Ensure document links match the supported file extensions
- Verify AI provider credentials
- Check Drupal logs for error messages
- Test AI provider configuration
- Review summary prompt configuration