| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
(function($) { |
| 6 |
$.fn.jcaption = function(settings) { |
| 7 |
settings = $.extend({ |
| 8 |
wrapperElement: 'div', |
| 9 |
wrapperClass: 'caption', |
| 10 |
captionElement: 'p', |
| 11 |
imageAttr: 'alt', |
| 12 |
copyStyle: true, |
| 13 |
removeStyle: true, |
| 14 |
removeAlign: true, |
| 15 |
copyAlignmentToClass: true, |
| 16 |
copyFloatToClass: true, |
| 17 |
autoWidth: true, |
| 18 |
animate: false, |
| 19 |
show: {opacity: 'show'}, |
| 20 |
showDuration: 200, |
| 21 |
hide: {opacity: 'hide'}, |
| 22 |
hideDuration: 200 |
| 23 |
}, settings); |
| 24 |
|
| 25 |
$(this).each(function(){ |
| 26 |
|
| 27 |
|
| 28 |
$(this).bind('load', function(){ |
| 29 |
|
| 30 |
|
| 31 |
if($(this).data('loaded')) return false; |
| 32 |
$(this).data('loaded', true); |
| 33 |
|
| 34 |
|
| 35 |
var image = $(this); |
| 36 |
|
| 37 |
|
| 38 |
if(image.attr(settings.imageAttr).length > 0){ |
| 39 |
|
| 40 |
|
| 41 |
image.wrap("<" + settings.wrapperElement + " class='" + settings.wrapperClass + "'></" + settings.wrapperElement + ">"); |
| 42 |
|
| 43 |
|
| 44 |
var imageStyleFloat = image.css('float'); |
| 45 |
|
| 46 |
|
| 47 |
var imageStyle = image.attr('style'); |
| 48 |
if(settings.removeStyle) image.removeAttr('style'); |
| 49 |
|
| 50 |
|
| 51 |
var imageAlign = image.attr('align'); |
| 52 |
if(settings.removeAlign) image.removeAttr('align'); |
| 53 |
|
| 54 |
|
| 55 |
var div = $(this).parent().append('<' + settings.captionElement + '>' + image.attr(settings.imageAttr) + '</' + settings.captionElement + '>'); |
| 56 |
|
| 57 |
if(settings.animate){ |
| 58 |
$(this).next().hide(); |
| 59 |
$(this).parent().hover( |
| 60 |
function(){ |
| 61 |
$(this).find('p').animate(settings.show, settings.showDuration); |
| 62 |
}, |
| 63 |
function(){ |
| 64 |
$(this).find('p').animate(settings.hide, settings.hideDuration); |
| 65 |
}); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
if(settings.copyStyle) div.attr('style',imageStyle); |
| 70 |
|
| 71 |
|
| 72 |
if(settings.copyAlignmentToClass) div.addClass(imageAlign); |
| 73 |
|
| 74 |
|
| 75 |
if(settings.copyFloatToClass && imageStyleFloat.length > 0) div.addClass(imageStyleFloat); |
| 76 |
|
| 77 |
|
| 78 |
if(settings.autoWidth) div.width(image.width()); |
| 79 |
} |
| 80 |
}); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
if (this.complete || this.naturalWidth > 0){ |
| 85 |
$(this).trigger('load'); |
| 86 |
} |
| 87 |
}); |
| 88 |
} |
| 89 |
})(jQuery); |