Advertisement
Guest User

Untitled

a guest
Apr 13th, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Add captions to images
  3. // Derived from http://www.jqueryfun.com/2010/06/20/make-nice-captions-using-image-alternative-tag/
  4.  
  5. jQuery(document).ready(function($){
  6.  
  7. // Adds captions from alt attribute to images with the caption class
  8.     $('img.caption').each(function() {
  9.        
  10.         // Check to see if the caption-wrapper class has already been added to prevent double captioning
  11.         if($(this).hasClass('caption-wrapper')) {
  12.             // Do nothing
  13.         }
  14.         else {
  15.             var direction = $(this).css("float");
  16.             $(this).wrap('<div class="caption-wrapper ' + direction + '" style="width:' + $(this).attr('width') + 'px; ' + $(this).attr('style') + '"></div>');
  17.             $(this).after('<div class="caption"><span class="caption-title">' + $(this).attr('title') + '</span><span class="caption-alt">' + $(this).attr('alt') + '</span></div>');
  18.         }
  19.     });
  20.    
  21. // Captions are not applied to paged ajax content, this function reapplies them
  22. // Idea borrowed from example module's ajax example http://drupal.org/project/examples
  23. // Issue que posing the question of how to handle ajaxed content http://drupal.org/node/1099720
  24.     Drupal.behaviors.recaption_ajaxed_images = {
  25.         attach: function() {
  26.             // If ajax is enabled.
  27.             if (Drupal.ajax) {
  28.                 $('.view-related-tag-listing-node img.caption').each(function() {
  29.                
  30.                     // Check to see if the caption-wrapper class has already been added to prevent double captioning   
  31.                     if($(this).hasClass('caption-wrapper')) {
  32.                         // Do nothing
  33.                     }
  34.                     else {
  35.                         var direction = $(this).css("float");
  36.                         $(this).wrap('<div class="caption-wrapper '
  37.                             + direction
  38.                             + '" style="width:'
  39.                             + $(this).attr('width')
  40.                             + 'px; '
  41.                             + $(this).attr('style')
  42.                             + '"></div>'
  43.                         );
  44.                         $(this).after('<div class="caption"><span class="caption-title">'
  45.                             + $(this).attr('title')
  46.                             + '</span><span class="caption-alt">'
  47.                             + $(this).attr('alt')
  48.                             + '</span></div>'
  49.                         );
  50.                     }
  51.                
  52.                 });
  53.             }
  54.         }
  55.     }; 
  56.  
  57.    
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement