PageSourceSearch

https://neubad.org/libraries/drupal-superfish/supposition.js?tk4syc

js neubad.org collected 2026-09-24 20:45:38 UTC 3,950 bytes, 99 lines download raw bytes

1/*
2 * Supposition v0.2 - an optional enhancer for Superfish jQuery menu widget.
3 *
4 * Copyright (c) 2008 Joel Birch - based mostly on work by Jesse Klaasse and credit goes largely to him.
5 * Special thanks to Karl Swedberg for valuable input.
6 *
7 * Dual licensed under the MIT and GPL licenses:
8 *  http://www.opensource.org/licenses/mit-license.php
9 *  http://www.gnu.org/licenses/gpl.html
10 */
11/*
12 * This is not the original jQuery Supposition plugin.
13 * Please refer to the README for more information.
14 */
15
16(function($){
17  $.fn.supposition = function(){
18    const $w = $(window); /*do this once instead of every onBeforeShow call*/
19
20    const _offset = function(dir) {
21      return window[dir === 'y' ? 'pageYOffset' : 'pageXOffset']
22      || document.documentElement && document.documentElement[dir === 'y' ? 'scrollTop' : 'scrollLeft']
23      || document.body[dir === 'y' ? 'scrollTop' : 'scrollLeft'];
24    };
25
26    const onHide = function(){
27      this.css({bottom:''});
28    };
29
30    const onBeforeShow = function(){
31      this.each(function(){
32        const $u = $(this);
33        $u.css('display','block');
34        const $mul = $u.closest('.sf-menu');
35        const level = $u.parents('ul').length;
36        const menuWidth = $u.width();
37        const menuParentWidth = $u.closest('li').outerWidth(true);
38        const menuParentLeft = $u.closest('li').offset().left;
39        const totalRight = $w.width() + _offset('x');
40        const menuRight = $u.offset().left + menuWidth;
41        const exactMenuWidth = menuRight > (menuParentWidth + menuParentLeft) ? menuWidth - (menuRight - (menuParentWidth + menuParentLeft)) : menuWidth;
42
43        if ($u.parents('.sf-js-enabled').hasClass('rtl')) {
44          if (menuParentLeft < exactMenuWidth) {
45            if ($mul.hasClass('sf-horizontal') && level === 1 || $mul.hasClass('sf-navbar') && level === 2){
46              $u.css({left: 0, right: 'auto'});
47            }
48            else {
49              $u.css({left: menuParentWidth + 'px', right: 'auto'});
50            }
51            $u.parent().addClass('sf-supposition-active');
52          }
53        }
54        else {
55          if (menuRight > totalRight && menuParentLeft > menuWidth) {
56            if ($mul.hasClass('sf-horizontal') && level === 1 || $mul.hasClass('sf-navbar') && level === 2){
57              $u.css({right: 0, left: 'auto'});
58            }
59            else {
60              $u.css({right: menuParentWidth + 'px', left: 'auto'});
61            }
62            $u.parent().addClass('sf-supposition-active');
63          }
64        }
65
66        const windowHeight = $w.height();
67        const offsetTop = $u.offset().top;
68        const menuParentShadow = $mul.hasClass('sf-shadow') && $u.css('padding-bottom').length > 0 ? parseInt($u.css('padding-bottom').slice(0,-2)) : 0;
69        const menuParentHeight = $mul.hasClass('sf-vertical') ? '-' + menuParentShadow : $u.parent().outerHeight(true) - menuParentShadow;
70        const menuHeight = $u.height();
71        const baseline = windowHeight + _offset('y');
72        const expandUp = (offsetTop + menuHeight > baseline) && (offsetTop > menuHeight);
73        if (expandUp) {
74          $u.css({bottom:menuParentHeight + 'px',top:'auto'});
75        }
76        $u.css('display','none');
77      });
78    };
79
80    return this.each(function() {
81      const options = $.fn.superfish.optionsList[this.serial]; /* get this menu's options */
82
83      /* if callbacks already set, store them */
84      const _onBeforeShow = options.onBeforeShow;
85      const _onHide = options.onHide;
86
87      $.extend($.fn.superfish.optionsList[this.serial],{
88        onBeforeShow: function() {
89          onBeforeShow.call(this); /* fire our Supposition callback */
90          _onBeforeShow.call(this); /* fire stored callbacks */
91        },
92        onHide: function() {
93          onHide.call(this); /* fire our Supposition callback */
94          _onHide.call(this); /* fire stored callbacks */
95        }
96      });
97    });
98  };
99})(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.