From 319b80bd9c92ee6b141e3eb5334445abe12d2bcc Mon Sep 17 00:00:00 2001 From: Adrian Bruinhout Date: Sat, 3 Dec 2016 01:11:32 +1100 Subject: [PATCH 1/3] Setting a configurable element position --- js/theia-sticky-sidebar.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/theia-sticky-sidebar.js b/js/theia-sticky-sidebar.js index fee2306..38ea95f 100755 --- a/js/theia-sticky-sidebar.js +++ b/js/theia-sticky-sidebar.js @@ -17,7 +17,8 @@ 'updateSidebarHeight': true, 'minWidth': 0, 'disableOnResponsiveLayouts': true, - 'sidebarBehavior': 'modern' + 'sidebarBehavior': 'modern', + 'defaultPosition': 'relative' }; options = $.extend(defaults, options); @@ -94,7 +95,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', From 5c1dac2880913cf79c7481dcb3f513f704763b8e Mon Sep 17 00:00:00 2001 From: Adrian Bruinhout Date: Fri, 9 Dec 2016 20:12:42 +1100 Subject: [PATCH 2/3] Namespacing events for unbinding --- js/theia-sticky-sidebar.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/js/theia-sticky-sidebar.js b/js/theia-sticky-sidebar.js index 38ea95f..98727d3 100755 --- a/js/theia-sticky-sidebar.js +++ b/js/theia-sticky-sidebar.js @@ -18,7 +18,8 @@ 'minWidth': 0, 'disableOnResponsiveLayouts': true, 'sidebarBehavior': 'modern', - 'defaultPosition': 'relative' + 'defaultPosition': 'relative', + 'namespace': 'TSS' }; options = $.extend(defaults, options); @@ -35,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); @@ -44,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); @@ -299,12 +300,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); @@ -361,5 +362,7 @@ return width; } + + return this; } })(jQuery); From 4348e797679ea3f9fe29a8a52884abef5eff43dc Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 24 Apr 2017 16:19:22 -0400 Subject: [PATCH 3/3] Only append style tag if it doesn't already exist --- js/theia-sticky-sidebar.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/theia-sticky-sidebar.js b/js/theia-sticky-sidebar.js index 98727d3..d6cb94b 100755 --- a/js/theia-sticky-sidebar.js +++ b/js/theia-sticky-sidebar.js @@ -77,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 = {};