File: D:/HostingSpaces/SBogers10/topswtw.komma.pro/wwwroot/js/plugins/backgroundImagePlugin.js
define([],function()
{
$.backgroundImage = function(element, options) {
// Default options
var defaults = {};
// Reference to this
var t = this;
var $parent = $(element);
var $image = $parent.children('img');
var imageLoaded = false;
t.boot = function ()
{
// Extend the defaults with options, save in settings
t.settings = $.extend({}, defaults, options);
// Reset parent height
var $header = $('#header');
$parent.css({ top: $header.height() ,height: ($(window).height() - $header.height())+'px' });
// Wait until image is loaded
$($image).one('load', function() {
imageLoaded = true;
t.adjust();
}).each(function() {
if(this.complete) $(this).load();
});
};
t.adjust = function()
{
// Get parent width and height
var parentSize = {
width: $parent.width(),
height: $parent.height()
};
if(imageLoaded) {
// Images adjust in full-width or full-height,
// depending on ratio and parent dimensions
var ratioI = $image.width() / $image.height();
var ratioP = parentSize.width / parentSize.height;
if (ratioP >= ratioI) {
// Make image as wide as parent
$image.width(parentSize.width);
$image.height(parentSize.width / ratioI);
}
else {
// Make image as high as parent
$image.height(parentSize.height);
$image.width(parentSize.height * ratioI);
}
var ml = $image.width() / -2;
//var mt = $img.height() / -2;
$image.css({display: 'block', marginLeft: ml + 'px'});
// Show slider
if (!$parent.hasClass('show')) {
$parent.addClass('show');
}
}
};
// Run plugin
t.boot();
};
$.fn.backgroundImage = function(options)
{
return this.each(function()
{
// if plugin has not already been attached to the element
if ($(this).data('backgroundImage') == undefined)
{
// create a new instance of the plugin
$(this).data('backgroundImage', new $.backgroundImage(this, options));
}
});
}
});