Skip to content

Instantly share code, notes, and snippets.

@xfenix
Created September 19, 2012 13:58
Show Gist options
  • Save xfenix/3749831 to your computer and use it in GitHub Desktop.
Save xfenix/3749831 to your computer and use it in GitHub Desktop.
This script allow dynamically load content with images, that has no height attribute. Nyromodal version.
var secret = $('<div>').attr('id', 'secret-meter'),
loadNow = 0,
loadTotal = 0;
$('body').prepend(secret);
$('.dialog').click(function(){
var url = $(this)[0].href,
loadWindow = function() {
$.nmData(secret.html(), {
closeButton: '<a href="#" class="nyroModalClose nyroModalCloseButton nmReposition" title="close"></a>',
sizes:{
minH: secret.height()
}
});
}
$.get(url, function(data) {
secret.html(data);
// почистим пустые параграфы
secret.find('p').each(function() {
var self = $(this);
if(self.html().replace(/\s|&nbsp;/g, '').length == 0)
self.remove();
});
secret.find('img').each(function() {
loadTotal++;
});
if(loadTotal > 0)
secret.find('img').each(function() {
$(this).load(function(){
loadNow++;
if(loadNow >= loadTotal) {
loadWindow();
}
});
});
else
loadWindow();
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment