PageSourceSearch

https://source.aacei.org/wp-content/plugins/mystickysidebar/js/theia-sticky-sidebar.js?ver=1.2.3

js aacei.org collected 2026-09-24 09:36:29 UTC 17,493 bytes, 411 lines download raw bytes

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

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.