I am trying to better organize my JavaScript by namespacing, although in the process of refactoring and reorganizing my code I seem to have have made some mistakes and I'm not sure what they are. I'm using CodeKit to lint and minify my code and it's throwing up a lot of errors that don't make sense to me.
(function ($) {
var TTB = {
// Display browser dimensions
browserDimensions: function () {
var slide_width = $('#site-wrapper').width();
$(window).resize(function () {
$('.dimensions').html(slide_width);
});
};
// Add line break to headline at breakpoint
lineBreak: function () {
if ($(window).width() < 600) {
$('a.why-different').prepend('<br/>');
}
};
// Display modal on click
modal: function () {
$(".submit-modal").click(function () {
$("#submit-modal").reveal();
});
};
// Scroll To Top on mobile
scrollToTop: function () {
$('.scroll-to-top').on('click',function() {
$('body').animate({scrollTop:0}, 600);
return false;
});
};
// Replace image source for various breakpoints
replaceImageSrc: function () {
var browser_width = $(window).width(),
device_dimensions = {
mobile: [320,585],
mini_tablet: [586,767],
tablet: [768,1023],
desktop: [1024,12800];
},
mobile_img_src = $('.homepage-featured img, .homepage-news img').data('mobile'),
mini_tablet_img_src = $('.homepage-featured img, .homepage-news img').data('small-tablet'),
tablet_img_src = $('.homepage-featured img, .homepage-news img').data('tablet'),
desktop_img_src = $('.homepage-featured img, .homepage-news img').data('desktop');
// Mobile check
if ($.inArray(browser_width, device.dimensions.mobile)) {
$('.post-image').attr({src: mobile_img_src});
}
// Mini Tablet check
if ($.inArray(browser_width, device_dimensions.mini_tablet)) {
$('.post-image').attr({src: mini_tablet_img_src});
}
// Tablet check
if ($.inArray(browser_width, device_dimensions.tablet)) {
$('.post-image').attr({src: tablet_img_src});
}
// Desktop check
if ($.inArray(browser_width, device_dimensions.desktop) {
$('.post-image').attr({src: desktop_img_src});
}
};
siteOverlay: function () {
var docHeight = $(document).height();
$("body").append("<div id='overlay'></div>");
$("#overlay")
.height(docHeight)
.css({
'opacity' : 0.4,
'position': 'absolute',
'top': 0,
'left': 0,
'background-color': 'black',
'width': '100%',
'z-index': 5000
});
};
}
TTB.browserDimensions();
TTB.lineBreak();
TTB.scrollToTop();
TTB.modal();
TTB.replaceImageSrc();
})(jQuery);