File: D:/HostingSpaces/SBogers96/smilefotografie.nl/wwwroot/js/app/core/images.js
define('core/images',[],function()
{
return {
initialize: function()
{
var t = this;
t.fill();
t.fit();
t.preload();
$(window).resize(function()
{
t.fill();
t.fit();
});
},
fill : function()
{
$('img.fill').one('load',function()
{
// Sizes
var w = $(this).width();
var h = $(this).height();
var pw = $(this).parent().width();
var ph = $(this).parent().height();
var ratio = w/h;
var css = {};
// Check new with
if( ratio < (pw/ph))
{
css.width = pw;
css.height = pw / ratio;
}
else
{
css.height = ph;
css.width = ph * ratio;
}
css.marginLeft = (css.width / -2) + 'px';
css.marginTop = (css.height / -2) + 'px';
css.left = '50%';
css.top = '50%';
$(this).css(css);
}).each(function()
{
if(this.complete) $(this).load();
});
},
fit : function()
{
$('img.fit').one('load',function()
{
// Sizes
var w = $(this).width();
var h = $(this).height();
var pw = $(this).parent().width();
var ph = $(this).parent().height();
var ratio = w/h;
var css = {};
// Check new with
if( ratio < (pw/ph))
{
css.height = ph;
css.width = ph * ratio;
}
else
{
css.width = pw;
css.height = pw / ratio;
}
css.marginLeft = (css.width / -2) + 'px';
css.marginTop = (css.height / -2) + 'px';
css.left = '50%';
css.top = '50%';
$(this).css(css);
}).each(function()
{
if(this.complete) $(this).load();
});
},
preload: function()
{
$('img.preload').one('load',function()
{
$(this).addClass('loaded');
}).each(function()
{
if(this.complete) $(this).load();
});
}
}
});