PageSourceSearch

https://bcd.bzh/becedia/sites/all/modules/jcaption/jcaption.js?titv3j

js bcd.bzh collected 2026-10-02 07:41:12 UTC 5,505 bytes, 137 lines download raw bytes

1/*
2* Based on the work of
3* Copyright (C) 2009 Joel Sutherland
4* Licenced under the MIT license
5* http://www.newmediacampaigns.com/page/jcaption-a-jquery-plugin-for-simple-image-captions
6*/
7Drupal.behaviors.jcaption = {
8  attach: function(context, settings) {
9      (function($) {
10      
11      var captionSelectors = Drupal.settings.jcaption.jcaption_selectors;
12      
13    	$.fn.jcaption = function(settings) {
14    		settings = $.extend({
15    			wrapperElement: 'span',
16    			wrapperClass: 'caption',
17    			captionElement: 'p',
18    			imageAttr: Drupal.settings.jcaption.jcaption_alt_title,
19    			requireText: Drupal.settings.jcaption.jcaption_requireText,
20    			copyStyle: Drupal.settings.jcaption.jcaption_copyStyle,
21    			removeStyle: Drupal.settings.jcaption.jcaption_removeStyle,
22    			removeClass: Drupal.settings.jcaption.jcaption_removeClass,
23    			removeAlign: Drupal.settings.jcaption.jcaption_removeAlign,
24    			copyAlignmentToClass: Drupal.settings.jcaption.jcaption_copyAlignmentToClass,
25    			copyFloatToClass: Drupal.settings.jcaption.jcaption_copyFloatToClass,
26    			copyClassToClass: Drupal.settings.jcaption.jcaption_copyClassToClass,
27    			autoWidth: Drupal.settings.jcaption.jcaption_autoWidth,
28    			keepLink: Drupal.settings.jcaption.jcaption_keepLink,
29          styleMarkup: Drupal.settings.jcaption.jcaption_styleMarkup,
30    			animate: Drupal.settings.jcaption.jcaption_animate,
31    			show: {opacity: 'show'},
32    			showDuration: Drupal.settings.jcaption.jcaption_showDuration,
33    			hide: {opacity: 'hide'},
34    			hideDuration: Drupal.settings.jcaption.jcaption_hideDuration	
35    		}, settings);
36    
37    		return $(this).each(function(){
38    			//Only add the caption after the image has been loaded.  This makes sure we can know the width of the caption.
39    			
40    			$(this).bind('load', function(){
41    				
42    				//Make sure the captioning isn't applied twice when the IE fix at the bottom is applied
43    				if($(this).data('loaded')) return false;
44    				$(this).data('loaded', true);
45    			
46    				//Shorthand for the image we will be applying the caption to
47    				if($(this).parent("a").length > 0 && !settings.keepLink) {
48    				  var image = $(this).parent("a");
49      			  var cleanimage = $(this);    				
50      			  } 
51    				else {
52      			  var image = $(this);
53      			  var cleanimage = $(this);    				
54    				}
55
56    				//Only create captions if there is content for the caption
57    				if(cleanimage.attr(settings.imageAttr) != undefined && (cleanimage.attr(settings.imageAttr).length > 0 || !settings.requireText)){
58    					
59    					//Wrap the image with the caption span
60    					image.wrap("<" + settings.wrapperElement + " class='" + settings.wrapperClass + "'></" + settings.wrapperElement + ">");
61    					
62    					//Save Image Float
63    					var imageFloat = cleanimage.css('float')
64    					
65    					//Save Image Class
66    					var imageClass = cleanimage.attr('class');
67    					if(settings.removeClass) cleanimage.removeAttr('class');
68
69    					//Save Image Style
70    					var imageStyle = cleanimage.attr('style');
71    					if(settings.removeStyle) cleanimage.removeAttr('style');
72    					
73    					//Save Image Align
74    					var imageAlign = cleanimage.attr('align');
75    					if(settings.removeAlign) cleanimage.removeAttr('align');
76    					
77    					//Put Caption in the Wrapper span
78    					var span = image.parent().append('<' + settings.captionElement + '>' + cleanimage.attr(settings.imageAttr) + '</' + settings.captionElement + '>');
79    					
80              //Add css if there is style markup for the paragraph in the settings
81              //if(settings.styleMarkup) 
82              
83              if(settings.styleMarkup) {
84                $('.caption p').attr('style', function() {
85                  return settings.styleMarkup; 
86                });
87              }
88              
89    					if(settings.animate){
90    						$(this).next().hide();
91    						$(this).parent().hover(
92    						function(){
93    							$(this).find('p').animate(settings.show, settings.showDuration);
94    						},
95    						function(){
96    							$(this).find('p').animate(settings.hide, settings.hideDuration);
97    						});
98    					}
99    					
100    					//Copy Image Style to span
101    					if(settings.copyStyle) span.attr('style',imageStyle);
102    					
103    					//If there is an alignment on the image (for example align="left") add "left" as a class on the caption.  This helps deal with older Text Editors like TinyMCE
104    					if(settings.copyAlignmentToClass) span.addClass(imageAlign);
105    					
106    					//Transfers the float style from the image to the caption container
107    					if(settings.copyFloatToClass) span.addClass(imageFloat);
108    					
109     					//Transfers the class from the image to the caption container
110    					if(settings.copyClassToClass) span.addClass(imageClass);
111    					
112    					//Properly size the caption span based on the loaded image's size
113    					if(settings.autoWidth) span.width(image.width());
114    				}
115    			});
116    			
117    			// Thanks to Captify for this bit!
118    			//if the image has already loaded (due to being cached), force the load function to be called
119    			if (this.complete || this.naturalWidth > 0){
120    				$(this).trigger('load');
121    			}
122    		});
123    	}
124    	
125    	$(captionSelectors.join(",")).each(function(index, elem){
126    	  $(elem).jcaption();
127    	});
128    
129    })(jQuery);
130  }
131};
132
133(function ($) {
134  $(document).ready(function(){
135
136  });
137})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.