(function( $ ){
var methods = {
init : function( options ) {
//console.log( $(this) );
var settings = {'source_path' : '','speed' : 1000};
if ( options ) { $.extend( settings, options );}
//var ref_view = $(this).width();
//var reference = this;
//var reference_in = $('
').attr('id','run').css({'position' : 'relative'}); //,'width':0
//reference.append(reference_in);
//$(this).css({'position':'relative'});
//var size_ = 0;
$(this).each(function(){
//$(this).show('slow');
$(this).blockBGimage('imageload');
});
/*v$.each(settings.logos, function(index, value) {
ar img = new Image();
img.src = settings.source_path + value;
$(img).load(function(){
//$('#run').append('
');
//$('#run .logo:last').append($(this)).width( $(this).width() );
//$(this).css({'width': $(this).width()+'px' });
//size_ = size_ + $(this).width();
//console.log( $(this).width() );
//$('#run').width(size_);
}).error(function(){
//do something if image cannot load
//console.error('error: ' + value);
});
//setTimeout( function(){
//$('#run').reference_running('logo_run',settings.speed);
//},1500 );
});*/
},
imageload : function( ) {
var bimg = $(this);
/*if( bimg.attr('title')=="" || typeof(bimg.attr('title'))=="undefined" ){
}else{
console.log( bimg.attr('title') );
bimg.attr('src', $(bimg).attr('title') );
//bimg.attr('title','');
}
*/
var img = new Image();
img.src = bimg.attr('src') + "?" + new Date().getTime();
//img.onLoad = bannersize();
$(img).load(function(){
//console.log(0);
//img.width
//img.height
//console.log( img.width );
bimg.blockBGimage('imagesize', { imgw : img.width,imgh : img.height });
//console.log( img );
});
//.error(function(){
//do something if image cannot load
//console.error('error: ' + value);
//});
},
imagesize: function( bimgset ) {
var bimg = $(this);
var parent = $(this).parent();
var parent_w = parent.width();
var parent_h = parent.height();
//console.log(parent_h);
// Calculate resize ratios for resizing
var rw = ( parent_w / bimgset.imgw );
var rh = ( parent_h / bimgset.imgh );
// smaller ratio will ensure that the image fits in the view
var ratio = rw > rh ? rw : rh;
//var ratio = rw;
var newWidth = bimgset.imgw*ratio;
var newHeight = bimgset.imgh*ratio;
$(bimg).blockBGimage('imageposition', { imgw : newWidth, imgh : newHeight });
//console.log(newWidth, newHeight);
//$(bimg).blockBGimage('imageposition', { imgw : bimgset.imgw,imgh : bimgset.imgh });
//console.log( bimg );
//console.log( bimgset );
},
imageposition: function( bimgset ) {
var bimg = $(this);
/*if( bimg.attr('title')=='' or bimg.attr('title')=='undefined' ){
}else{
bimg.attr('src',bimg.attr('title'));
}*/
var image_w_pos = ( bimg.parent().width() - bimgset.imgw ) / 2;
var image_h_pos = ( bimg.parent().height() - bimgset.imgh ) / 2;
//console.log(image_w_pos);
$(bimg).css({
'position' : 'absolute',
'top' : image_h_pos + 'px',
'left' : image_w_pos + 'px',
'width' : bimgset.imgw + 'px',
'height' : bimgset.imgh + 'px'
});
//$(bimg).fadeIn(3000);
$(bimg).show();
//console.log( bimg );
//console.log( bimgset );
}
};
$.fn.blockBGimage = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.plugin' );
}
};
})( jQuery );