jQuery(function($){
function setFullWidth() {
var no_content = $('.tpb-stretch-row');
var with_content = $('.tpb-stretch-row-content');
var content_and_padding = $('.tpb-stretch-row-content-no-padding');
// tpb-stretch-row
if(no_content.length > 0) {
no_content.each(function(){
$el = $(this);
var calc = getCalcStretch($el);
// apply new css
$el.css({
'position': 'relative',
'left': calc.left + 'px',
'width': calc.width + 'px',
'padding-left': calc.offset + 'px',
'padding-right': calc.offset + 'px',
'box-sizing': 'border-box'
});
});
}
// tpb-stretch-row-content
if(with_content.length > 0) {
with_content.each(function(){
$el = $(this);
var calc = getCalcStretch($el);
// apply new css
$el.css({
'position': 'relative',
'left': calc.left + 'px',
'width': calc.width + 'px',
'padding-left': '15px',
'padding-right': '15px',
'box-sizing': 'border-box'
});
});
}
// tpb-stretch-row-content-no-padding
if(content_and_padding.length > 0) {
content_and_padding.each(function(){
$el = $(this);
var calc = getCalcStretch($el);
// apply new css
$el.css({
'position': 'relative',
'left': calc.left + 'px',
'width': calc.width + 'px'
});
});
}
}
function getCalcStretch($el) {
// neutralize
$el.css({
'position': '',
'left': '',
'width': '',
'padding': '',
'padding-left': '',
'padding-right': '',
'box-sizing': '',
});
// get outer container
if($('body > div#wrapper').length > 0) {
$outer = $('body > div#wrapper');
}
else {
$outer = $('body');
}
var outerOffset = $outer.offset();
var offset = $el.offset();
var offsetLeft = offset.left - outerOffset.left;
var width = $outer.outerWidth();
// set vars
var vars = {
offset: offsetLeft,
left: offsetLeft * -1,
width: width
}
return vars;
}
function getCalcStretchOld($el) {
// neutralize
$el.css({
'position': '',
'left': '',
'width': '',
'padding': '',
'padding-left': '',
'padding-right': '',
'box-sizing': '',
});
var offset = $el.offset();
// set vars
var vars = {
offset: offset.left,
left: offset.left * -1,
width: $(window).width()
}
return vars;
}
$(window).resize(function() {
setFullWidth();
});
setFullWidth();
});