diff --git a/js/theia-sticky-sidebar.js b/js/theia-sticky-sidebar.js index fee2306..d6cb94b 100755 --- a/js/theia-sticky-sidebar.js +++ b/js/theia-sticky-sidebar.js @@ -17,7 +17,9 @@ 'updateSidebarHeight': true, 'minWidth': 0, 'disableOnResponsiveLayouts': true, - 'sidebarBehavior': 'modern' + 'sidebarBehavior': 'modern', + 'defaultPosition': 'relative', + 'namespace': 'TSS' }; options = $.extend(defaults, options); @@ -34,7 +36,7 @@ if (!success) { console.log('TSS: Body width smaller than options.minWidth. Init is delayed.'); - $(document).scroll(function (options, $that) { + $(document).on('scroll.' + options.namespace, function (options, $that) { return function (evt) { var success = tryInit(options, $that); @@ -43,7 +45,7 @@ } }; }(options, $that)); - $(window).resize(function (options, $that) { + $(window).on('resize.' + options.namespace, function (options, $that) { return function (evt) { var success = tryInit(options, $that); @@ -75,7 +77,10 @@ options.initialized = true; // Add CSS - $('head').append($('')); + var existingStylesheet = $('#theia-sticky-sidebar-stylesheet-' + options.namespace); + if (existingStylesheet.length === 0) { + $('head').append($('')); + } $that.each(function () { var o = {}; @@ -94,7 +99,7 @@ // 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', + 'position': o.options.defaultPosition, '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', @@ -298,12 +303,12 @@ o.onScroll(o); // Recalculate the sidebar's position on every scroll and resize. - $(document).scroll(function (o) { + $(document).on('scroll.' + o.options.namespace, function (o) { return function () { o.onScroll(o); }; }(o)); - $(window).resize(function (o) { + $(window).on('resize.' + o.options.namespace, function (o) { return function () { o.stickySidebar.css({'position': 'static'}); o.onScroll(o); @@ -360,5 +365,7 @@ return width; } + + return this; } })(jQuery);