Reputation: 8047
Have tried a few options with no luck. I am using jQuery 1.9.1
Here is my function's code:
(function ($) {
$.fn.createGallery = function(options) {
var theObject = $(this);
var settings = $.extend({
// These are the defaults.
server: 'http://localhost/jQuery%20Gallery/images/galleries/',
galleryName: 'Test',
galleryWidth: 800,
galleryImageMargin: 20,
galleryImageColumns: 2,
galleryTargetFolder: 'homepage_gallery',
imageQuality: 100
}, options);
var galleryImageWidth = settings.galleryWidth / settings.galleryImageColumns;
var imageUrl = settings.server+settings.galleryTargetFolder;
var otherMargin = Math.round(settings.galleryImageMargin / 2);
var finalImageWidth = Math.round(galleryImageWidth - settings.galleryImageMargin);
var finalImageHeight = Math.round(galleryImageWidth / 1.4);
var finalGalleryWidth = settings.galleryWidth - settings.galleryImageMargin;
$(this).before('<style>'+$(this).selector+' li:nth-child('+settings.galleryImageColumns+'n+1) { margin-left: 0; } '+$(this).selector+' li:first-child { margin-left: 0; } '+$(this).selector+' { width: '+finalGalleryWidth+'px; margin: 0px; } '+$(this).selector+' li { display: inline-block; list-style: none; margin-left: '+settings.galleryImageMargin+'px; margin-bottom: '+otherMargin+'px; } </style>');
$.ajax({
url: imageUrl,
success: function(data){
var extension = '.jpg';
$(data).find("a:contains("+extension+")").each(function(){
// will loop through
var filename = $(this).attr("href");
$('<li></li>').html('<a href="'+imageUrl+'/'+filename+'" class="fancybox"><img src="thumbnail.php?src='+imageUrl+'/'+filename+'&q='+settings.imageQuality+'&h='+finalImageHeight+'&w='+finalImageWidth+'"/></a>').appendTo(theObject);
});
}
});
};
}(jQuery));
Which is called like this, and works perfectly:
HTML: <ul id="images"></ul>
jQuery:
$('#images').createGallery({
server: 'http://localhost/jQuery%20Gallery/images/galleries/',
galleryName: 'Test',
galleryWidth: 800,
galleryImageMargin: 20,
galleryImageColumns: 2,
galleryTargetFolder: 'homepage_gallery',
imageQuality: 100
});
Now, what i want to do is add a class to the new elements so that i can target them in ie8 to add a class to it. I have tried this:
$(document).on('DOMNodeInserted', function(e) {
$(e.target).addClass('triggerMargin');
});
Which i have placed in the bottom of the function and it works fine in firefox and chrome etc, yet it is totally ignored in ie8. Any ideas?
Upvotes: 0
Views: 208
Reputation: 8047
This was fixed by doing the following
theObject.children('li:nth-child(2n+1)').addClass('triggerMargin');
where theObject
is equal to $(this)
for the object being targeted to add a class to it's children
Upvotes: 1