Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add captions to images
- // Derived from http://www.jqueryfun.com/2010/06/20/make-nice-captions-using-image-alternative-tag/
- jQuery(document).ready(function($){
- // Adds captions from alt attribute to images with the caption class
- $('img.caption').each(function() {
- // Check to see if the caption-wrapper class has already been added to prevent double captioning
- if($(this).hasClass('caption-wrapper')) {
- // Do nothing
- }
- else {
- var direction = $(this).css("float");
- $(this).wrap('<div class="caption-wrapper ' + direction + '" style="width:' + $(this).attr('width') + 'px; ' + $(this).attr('style') + '"></div>');
- $(this).after('<div class="caption"><span class="caption-title">' + $(this).attr('title') + '</span><span class="caption-alt">' + $(this).attr('alt') + '</span></div>');
- }
- });
- // Captions are not applied to paged ajax content, this function reapplies them
- // Idea borrowed from example module's ajax example http://drupal.org/project/examples
- // Issue que posing the question of how to handle ajaxed content http://drupal.org/node/1099720
- Drupal.behaviors.recaption_ajaxed_images = {
- attach: function() {
- // If ajax is enabled.
- if (Drupal.ajax) {
- $('.view-related-tag-listing-node img.caption').each(function() {
- // Check to see if the caption-wrapper class has already been added to prevent double captioning
- if($(this).hasClass('caption-wrapper')) {
- // Do nothing
- }
- else {
- var direction = $(this).css("float");
- $(this).wrap('<div class="caption-wrapper '
- + direction
- + '" style="width:'
- + $(this).attr('width')
- + 'px; '
- + $(this).attr('style')
- + '"></div>'
- );
- $(this).after('<div class="caption"><span class="caption-title">'
- + $(this).attr('title')
- + '</span><span class="caption-alt">'
- + $(this).attr('alt')
- + '</span></div>'
- );
- }
- });
- }
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement