Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var mobileBreak = 770;
- var imgSuffix = {
- mobile : '_mobile_',
- desktop : '_desktop_'
- }
- var adGroups = {
- header : '.g-1',
- sidebar : '.g-2',
- sidebarInt :'.g-col',
- footer : '.g-3'
- }
- function centerAdvertAmnt(obj) {
- var a = obj.width();
- var b = obj.parent().width();
- return (b * 0.5) - (a * 0.5);
- }
- function swapAdvertImage(obj) {
- $(obj).children('img').each(function() {
- var img = $(this).attr('src');
- if ($(window).width() > mobileBreak) {
- if (img.indexOf(imgSuffix.desktop) == -1)
- img = img.replace(imgSuffix.mobile, imgSuffix.desktop);
- }
- if ($(window).width() <= mobileBreak) {
- if (img.indexOf(imgSuffix.mobile) == -1)
- img = img.replace(imgSuffix.desktop, imgSuffix.mobile);
- }
- $(this).attr('src', img);
- });
- }
- function resizeAdvert(obj) {
- $(obj).each(function() {
- if ($(this).children('img').length > 0) {
- var h = $(this).children('img').first().height();
- var w = $(this).children('img').first().width();
- $(this).css({'height' : h + 'px','width' : w + 'px'});
- $(this).children('img').toggle();
- $(this).parent().css('padding-left', centerAdvertAmnt($(this)));
- }
- });
- }
- $(function() {
- console.log('Testing');
- $.each(adGroups, function(k,v) {
- swapAdvertImage(v + ' a');
- });
- });
- $(window).load(function() {
- $(adGroups.sidebar).css('width', $('#sidebar').width() + 'px');
- $.each(adGroups, function(k,v) {
- resizeAdvert(v + ' a');
- });
- });
- $(window).resize(function() {
- $.each(adGroups, function(k,v) {
- swapAdvertImage(v + ' a');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment