PageSourceSearch

https://dstecheetah.com/wp-content/themes/salient/js/stickkit.js?ver=1.0

js dstecheetah.com collected 2026-10-08 22:19:42 UTC 16,868 bytes, 375 lines download raw bytes

1/*!
2 * Theia Sticky Sidebar v1.7.0
3 * https://github.com/WeCodePixels/theia-sticky-sidebar
4 *
5 * Glues your website's sidebars, making them permanently visible while scrolling.
6 *
7 * Copyright 2013-2016 WeCodePixels and other contributors
8 * Released under the MIT license
9 */
10
11(function ($) {
12    $.fn.theiaStickySidebar = function (options) {
13        var defaults = {
14            'containerSelector': '',
15            'additionalMarginTop': 0,
16            'additionalMarginBottom': 0,
17            'updateSidebarHeight': true,
18            'minWidth': 0,
19            'disableOnResponsiveLayouts': true,
20            'sidebarBehavior': 'modern',
21            'defaultPosition': 'relative',
22            'namespace': 'TSS'
23        };
24        options = $.extend(defaults, options);
25
26        // Validate options
27        options.additionalMarginTop = parseInt(options.additionalMarginTop) || 0;
28        options.additionalMarginBottom = parseInt(options.additionalMarginBottom) || 0;
29
30        tryInitOrHookIntoEvents(options, this);
31
32        // Try doing init, otherwise hook into window.resize and document.scroll and try again then.
33        function tryInitOrHookIntoEvents(options, $that) {
34            var success = tryInit(options, $that);
35
36            if (!success) {
37                console.log('TSS: Body width smaller than options.minWidth. Init is delayed.');
38
39                $(document).on('scroll.' + options.namespace, function (options, $that) {
40                    return function (evt) {
41                        var success = tryInit(options, $that);
42
43                        if (success) {
44                            $(this).unbind(evt);
45                        }
46                    };
47                }(options, $that));
48                $(window).on('resize.' + options.namespace, function (options, $that) {
49                    return function (evt) {
50                        var success = tryInit(options, $that);
51
52                        if (success) {
53                            $(this).unbind(evt);
54                        }
55                    };
56                }(options, $that))
57            }
58        }
59
60        // Try doing init if proper conditions are met.
61        function tryInit(options, $that) {
62            if (options.initialized === true) {
63                return true;
64            }
65
66            if ($('body').width() < options.minWidth) {
67                return false;
68            }
69
70            init(options, $that);
71
72            return true;
73        }
74
75        // Init the sticky sidebar(s).
76        function init(options, $that) {
77            options.initialized = true;
78
79            // Add CSS
80            var existingStylesheet = $('#theia-sticky-sidebar-stylesheet-' + options.namespace);
81            if (existingStylesheet.length === 0) {
82                $('head').append($('<style id="theia-sticky-sidebar-stylesheet-' + options.namespace + '">.theiaStickySidebar:after {content: ""; display: table; clear: both;}</style>'));
83            }
84
85            $that.each(function () {
86                var o = {};
87
88                o.sidebar = $(this);
89
90                // Save options
91                o.options = options || {};
92
93                // Get container
94                o.container = $(o.options.containerSelector);
95                if (o.container.length == 0) {
96                    o.container = o.sidebar.parent();
97                }
98
99                // Create sticky sidebar
100                o.sidebar.parents().css('-webkit-transform', 'none'); // Fix for WebKit bug - https://code.google.com/p/chromium/issues/detail?id=20574
101                o.sidebar.css({
102                    'position': o.options.defaultPosition,
103                    'overflow': 'visible',
104                    // The "box-sizing" must be set to "content-box" because we set a fixed height to this element when the sticky 
104sidebar has a fixed position.
105                    '-webkit-box-sizing': 'border-box',
106                    '-moz-box-sizing': 'border-box',
107                    'box-sizing': 'border-box'
108                });
109
110                // Get the sticky sidebar element. If none has been found, then create one.
111                o.stickySidebar = o.sidebar.find('.theiaStickySidebar');
112                if (o.stickySidebar.length == 0) {
113                    // Remove <script> tags, otherwise they will be run again when added to the stickySidebar.
114                    var javaScriptMIMETypes = /(?:text|application)\/(?:x-)?(?:javascript|ecmascript)/i;
115                    o.sidebar.find('script').filter(function (index, script) {
116                        return script.type.length === 0 || script.type.match(javaScriptMIMETypes);
117                    }).remove();
118
119                    o.stickySidebar = $('<div>').addClass('theiaStickySidebar').append(o.sidebar.children());
120                    o.sidebar.append(o.stickySidebar);
121                }
122
123                // Get existing top and bottom margins and paddings
124                o.marginBottom = parseInt(o.sidebar.css('margin-bottom'));
125                o.paddingTop = parseInt(o.sidebar.css('padding-top'));
126                o.paddingBottom = parseInt(o.sidebar.css('padding-bottom'));
127
128                // Add a temporary padding rule to check for collapsable margins.
129                var collapsedTopHeight = o.stickySidebar.offset().top;
130                var collapsedBottomHeight = o.stickySidebar.outerHeight();
131                o.stickySidebar.css('padding-top', 1);
132                o.stickySidebar.css('padding-bottom', 1);
133                collapsedTopHeight -= o.stickySidebar.offset().top;
134                collapsedBottomHeight = o.stickySidebar.outerHeight() - collapsedBottomHeight - collapsedTopHeight;
135                if (collapsedTopHeight == 0) {
136                    o.stickySidebar.css('padding-top', 0);
137                    o.stickySidebarPaddingTop = 0;
138                }
139                else {
140                    o.stickySidebarPaddingTop = 1;
141                }
142
143                if (collapsedBottomHeight == 0) {
144                    o.stickySidebar.css('padding-bottom', 0);
145                    o.stickySidebarPaddingBottom = 0;
146                }
147                else {
148                    o.stickySidebarPaddingBottom = 1;
149                }
150
151                // We use this to know whether the user is scrolling up or down.
152                o.previousScrollTop = null;
153
154                // Scroll top (value) when the sidebar has fixed position.
155                o.fixedScrollTop = 0;
156
157                // Set sidebar to default values.
158                resetSidebar();
159
160                o.onScroll = function (o) {
161
162                    // Stop if the sidebar isn't visible.
163                    //nectar addition of the ocm and search
164                    if (!o.stickySidebar.is(":visible") || $('.ocm-effect-wrap.material-ocm-open').length > 0 ) {
165                        return;
166                    }
167
168                    // Stop if the window is too small.
169                    if ($('body').width() < o.options.minWidth) {
170                        resetSidebar();
171                        return;
172                    }
173
174                    // Stop if the sidebar width is larger than the container width (e.g. the theme is responsive and the sidebar is now below the content)
175                    if (o.options.disableOnResponsiveLayouts) {
176                        var sidebarWidth = o.sidebar.outerWidth(o.sidebar.css('float') == 'none');
177
178                        if (sidebarWidth + 50 > o.container.width()) {
179                            resetSidebar();
180                            return;
181                        }
182                    }
183
184                    var scrollTop = $(document).scrollTop();
185                    var position = 'static';
186
187                    // If the user has scrolled down enough for the sidebar to be clipped at the top, then we can consider changing its position.
188                    if (scrollTop >= o.sidebar.offset().top + (o.paddingTop - o.options.additionalMarginTop)) {
189                        // The top and bottom offsets, used in various calculations.
190                        var offsetTop = o.paddingTop + options.additionalMarginTop;
191                        var offsetBottom = o.paddingBottom + o.marginBottom + options.additionalMarginBottom;
192
193                        // All top and bottom positions are relative to the window, not to the parent elemnts.
194                        var containerTop = o.sidebar.offset().top;
195                        var containerBottom = o.sidebar.offset().top + getClearedHeight(o.container);
196
197                        // The top and bottom offsets relative to the window screen top (zero) and bottom (window height).
198                        var windowOffsetTop = 0 + options.additionalMarginTop;
199                        var windowOffsetBottom;
200
201                        var sidebarSmallerThanWindow = (o.stickySidebar.outerHeight() + offsetTop + offsetBottom) < $(window).height();
202                        if (sidebarSmallerThanWindow) {
203                            windowOffsetBottom = windowOffsetTop + o.stickySidebar.outerHeight();
204                        }
205                        else {
206                            windowOffsetBottom = $(window).height() - o.marginBottom - o.paddingBottom - options.additionalMarginBottom;
207                        }
208
209                        var staticLimitTop = containerTop - scrollTop + o.paddingTop;
210                        var staticLimitBottom = containerBottom - scrollTop - o.paddingBottom - o.marginBottom;
211
212                        var top = o.stickySidebar.offset().top - scrollTop;
213                        var scrollTopDiff = o.previousScrollTop - scrollTop;
214
215                        // If the sidebar position is fixed, then it won't move up or down by itself. So, we manually adjust the top coordinate.
216                        if (o.stickySidebar.css('position') == 'fixed') {
217                            if (o.options.sidebarBehavior == 'modern') {
218                                top += scrollTopDiff;
219                            }
220                        }
221
222                        if (o.options.sidebarBehavior == 'stick-to-top') {
223                            top = options.additionalMarginTop;
224                        }
225
226                        if (o.options.sidebarBehavior == 'stick-to-bottom') {
227                            top = windowOffsetBottom - o.stickySidebar.outerHeight();
228                        }
229
230                        if (scrollTopDiff > 0) { // If the user is scrolling up.
231                            top = Math.min(top, windowOffsetTop);
232                        }
233                        else { // If the user is scrolling down.
234                            top = Math.max(top, windowOffsetBottom - o.stickySidebar.outerHeight());
235                        }
236
237                        top = Math.max(top, staticLimitTop);
238
239                        top = Math.min(top, staticLimitBottom - o.stickySidebar.outerHeight());
240
241                        // If the sidebar is the same height as the container, we won't use fixed positioning.
242                        var sidebarSameHeightAsContainer = o.container.height() == o.stickySidebar.outerHeight();
243
244                        if (!sidebarSameHeightAsContainer && top == windowOffsetTop) {
245                            position = 'fixed';
246                        }
247                        else if (!sidebarSameHeightAsContainer && top == windowOffsetBottom - o.stickySidebar.outerHeight()) {
248                            position = 'fixed';
249                        }
250                        else if (scrollTop + top - o.sidebar.offset().top - o.paddingTop <= options.additionalMarginTop) {
251                            // Stuck to the top of the page. No special behavior.
252                            position = 'static';
253                        }
254                        else {
255                            // Stuck to the bottom of the page.
256                            position = 'absolute';
257                        }
258                    }
259
260                    /*
261                     * Performance notice: It's OK to set these CSS values at each resize/scroll, even if they don't change.
262                     * It's way slower to first check if the values have changed.
263                     */
264                    if (position == 'fixed') {
265                        var scrollLeft = $(document).scrollLeft();
266
267                        o.stickySidebar.css({
268                            'position': 'fixed',
269                            'width': getWidthForObject(o.stickySidebar) + 'px',
270                            'transform': 'translateY(' + top + 'px)',
271                            'left': (o.sidebar.offset().left + parseInt(o.sidebar.css('padding-left')) - scrollLeft) + 'px',
272                            'top': '0px'
273                        });
274                    }
275                    else if (position == 'absolute') {
276                        var css = {};
277
278                        if (o.stickySidebar.css('position') != 'absolute') {
279                            css.position = 'absolute';
280                            css.transform = 'translateY(' + (scrollTop + top - o.sidebar.offset().top - o.stickySidebarPaddingTop - o.stickySidebarPaddingBottom) + 'px)';
281                            css.top = '0px';
282                        }
283
284                        css.width = getWidthForObject(o.stickySidebar) + 'px';
285                        css.left = '';
286
287                        o.stickySidebar.css(css);
288                    }
289                    else if (position == 'static') {
290                        resetSidebar();
291                    }
292
293                    if (position != 'static') {
294                        if (o.options.updateSidebarHeight == true) {
295                            o.sidebar.css({
296                                'min-height': o.stickySidebar.outerHeight() + o.stickySidebar.offset().top - o.sidebar.offset().top + o.paddingBottom
297                            });
298                        }
299                    }
300
301                    o.previousScrollTop = scrollTop;
302                };
303
304                // Initialize the sidebar's position.
305                o.onScroll(o);
306
307                // Recalculate the sidebar's position on every scroll and resize.
308                $(document).on('scroll.' + o.options.namespace, function (o) {
309                    return function () {
310                        o.onScroll(o);
311                    };
312                }(o));
313                $(window).on('resize.' + o.options.namespace, function (o) {
314                    return function () {
315                        o.stickySidebar.css({'position': 'static'});
316                        o.onScroll(o);
317                    };
318                }(o));
319
320                // Recalculate the sidebar's position every time the sidebar changes its size.
321                if (typeof ResizeSensor !== 'undefined') {
322                    new ResizeSensor(o.stickySidebar[0], function (o) {
323                        return function () {
324                            o.onScroll(o);
325                        };
326                    }(o));
327                }
328
329                // Reset the sidebar to its default state
330                function resetSidebar() {
331                    o.fixedScrollTop = 0;
332                    o.sidebar.css({
333                        'min-height': '1px'
334                    });
335                    o.stickySidebar.css({
336                        'position': 'static',
337                        'width': '',
338                        'transform': 'none'
339                    });
340                }
341
342                // Get the height of a div as if its floated children were cleared. Note that this function fails if the floats are more than one level deep.
343                function getClearedHeight(e) {
344                    var height = e.height();
345
346                    e.children().each(function () {
347                        height = Math.max(height, $(this).height());
348                    });
349
350                    return height;
351                }
352            });
353        }
354
355        function getWidthForObject(object) {
356            var width;
357
358            try {
359                width = object[0].getBoundingClientRect().width;
360            }
361            catch (err) {
362            }
363
364            if (typeof width === "undefined") {
365                width = object.width();
366            }
367
368            return width;
369        }
370
371        return this;
372    }
373})(jQuery);
374
375//# sourceMappingURL=maps/theia-sticky-sidebar.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.