File: D:/HostingSpaces/SBogers10/tandartsmaas.komma.pro/wwwroot/js/app/modules/images.js
define('modules/images',[],function()
{
return {
initialize: function()
{
var t = this;
t.fill();
t.preload();
$(window).resize(function()
{
t.fill();
});
},
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 cssSize = {};
// Check new with
if( ratio < (pw/ph))
{
//w = '100%';
//h = w / ratio;
cssSize.width = '100%';
cssSize.height = '';
}
else
{
//h = ph;
//w = h * ratio;
cssSize.width = '';
cssSize.height = '100%';
}
$(this).css(cssSize);
var cssPos = {};
// Check origin
var origins = $(this).attr('data-origin').split(' ');
var originY = origins[0];
var originX = origins[1];
switch(originX)
{
case 'center':
cssPos.left = '50%';
cssPos.marginLeft = ($(this).width() / -2) + 'px';
break;
case 'right':
cssPos.right = 0;
break;
}
switch(originY)
{
case 'center':
cssPos.top = '50%';
cssPos.marginTop = ($(this).height() / -2) + 'px';
break;
case 'top':
cssPos.top = 0;
break;
}
//css.width = w+'px';
//css.height = h+'px';
$(this).css(cssPos);
}).each(function()
{
if(this.complete) $(this).load();
});
},
preload: function()
{
$('img.preload').one('load',function()
{
$(this).addClass('loaded');
}).each(function()
{
if(this.complete) $(this).load();
});
}
}
});