/*! cover-img - v1.0.0 - 2014-07-23
* https://github.com/johannesjo/cover-img
* Copyright (c) 2014 Johannes Millan; Licensed MIT */
(function ($)
{
// fixing jQuery issue with wordpress
if (!$) {
$ = jQuery;
}
(function ($, sr)
{
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap)
{
var timeout;
return function debounced()
{
var obj = this, args = arguments;
function delayed()
{
if (!execAsap) {
func.apply(obj, args);
}
timeout = null;
}
if (timeout) {
clearTimeout(timeout);
} else if (execAsap) {
func.apply(obj, args);
}
timeout = setTimeout(delayed, threshold || 100);
};
};
// smartresize
jQuery.fn[sr] = function (fn)
{
return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
};
})(jQuery, 'smartresize');
(function ($)
{
var CoverImg = function (element, options)
{
var that = this;
this.$el = $(element);
this.options = options;
this.$parent = this.$el.parent();
this.setStyles();
this.setParentStyles();
// IF image
$("") // Make in memory copy of image to avoid css issues
.attr("src", this.$el.attr("src"))
.load(function ()
{
that.real_width = this.width; // Note: $(this).width() will not
that.real_height = this.height; // work for in memory images.
$(window).trigger('resize');
});
$(window).smartresize(function ()
{
that.resizeToCover();
});
};
CoverImg.prototype.setStyles = function ()
{
var cssPosition = this.$el.css('position'),
cssMaxWidth = this.$el.css('max-width'),
cssMaxHeight = this.$el.css('max-height');
if (cssPosition !== 'relative' && cssPosition !== 'absolute') {
this.$el.css('position', 'relative');
}
if (cssMaxWidth !== 'none') {
this.$el.css('max-width', 'none');
}
if (cssMaxHeight !== 'none') {
this.$el.css('max-height', 'none');
}
};
CoverImg.prototype.handleTableCells = function ()
{
this.$parent.css('position', 'relative');
this.$el.wrap('