/*!
* Theia Sticky Sidebar v1.4.0
* https://github.com/WeCodePixels/theia-sticky-sidebar
*
* Glues your website's sidebars, making them permanently visible while scrolling.
*
* Copyright 2013-2016 WeCodePixels and other contributors
* Released under the MIT license
*/
(function ($) {
$.fn.theiaStickySidebar = function (options) {
var defaults = {
'containerSelector': '',
'additionalMarginTop': 0,
'additionalMarginBottom': 0,
'updateSidebarHeight': true,
'minWidth': 0,
'disableOnResponsiveLayouts': true,
'sidebarBehavior': 'modern'
};
options = $.extend(defaults, options);
// Validate options
options.additionalMarginTop = parseInt(options.additionalMarginTop) || 0;
options.additionalMarginBottom = parseInt(options.additionalMarginBottom) || 0;
tryInitOrHookIntoEvents(options, this);
// Try doing init, otherwise hook into window.resize and document.scroll and try again then.
function tryInitOrHookIntoEvents(options, $that) {
var success = tryInit(options, $that);
if (!success) {
console.log('TST: Body width smaller than options.minWidth. Init is delayed.');
$(document).scroll(function (options, $that) {
return function (evt) {
var success = tryInit(options, $that);
if (success) {
$(this).unbind(evt);
}
};
}(options, $that));
$(window).resize(function (options, $that) {
return function (evt) {
var success = tryInit(options, $that);
if (success) {
$(this).unbind(evt);
}
};
}(options, $that))
}
}
// Try doing init if proper conditions are met.
function tryInit(options, $that) {
if (options.initialized === true) {
return true;
}
if ($('body').width() < options.minWidth) {
return false;
}
init(options, $that);
return true;
}
// Init the sticky sidebar(s).
function init(options, $that) {
options.initialized = true;
// Add CSS
$('head').append($(''));
$that.each(function () {
var o = {};
o.sidebar = $(this);
// Save options
o.options = options || {};
// Get container
o.container = $(o.options.containerSelector);
if (o.container.size() == 0) {
o.container = o.sidebar.parent();
}
// Create sticky sidebar
o.sidebar.parents().css('-webkit-transform', 'none'); // Fix for WebKit bug - https://code.google.com/p/chromium/issues/detail?id=20574
o.sidebar.css({
'position': 'relative',
'overflow': 'visible',
// The "box-sizing" must be set to "content-box" because we set a fixed height to this element when the sticky sidebar has a fixed position.
'-webkit-box-sizing': 'border-box',
'-moz-box-sizing': 'border-box',
'box-sizing': 'border-box'
});
// Get the sticky sidebar element. If none has been found, then create one.
o.stickySidebar = o.sidebar.find('.theiaStickySidebar');
if (o.stickySidebar.length == 0) {
o.sidebar.find('script').remove(); // Remove