PageSourceSearch

https://parentzone.org.uk/libraries/drupal-superfish/supersubs.js?tltom8

js parentzone.org.uk collected 2026-09-24 06:54:32 UTC 5,076 bytes, 123 lines download raw bytes

1/*
2 * Supersubs v0.4b - jQuery plugin
3 * Copyright (c) 2013 Joel Birch
4 *
5 * Dual licensed under the MIT and GPL licenses:
6 *  http://www.opensource.org/licenses/mit-license.php
7 *  http://www.gnu.org/licenses/gpl.html
8 *
9 * This plugin automatically adjusts submenu widths of suckerfish-style menus to that of
10 * their longest list item children. If you use this, please expect bugs and report them
11 * to the jQuery Google Group with the word 'Superfish' in the subject line.
12 *
13 */
14/*
15 * This is not the original jQuery Supersubs plugin.
16 * Please refer to the README for more information.
17 */
18
19(function($){ // $ will refer to jQuery within this closure
20  $.fn.supersubs = function(options){
21    const superfish_options = $.extend({}, $.fn.supersubs.defaults, options);
22    let size;
23    let o;
24
25    // return an original object to support chaining,
26    // Although this is unnecessary due to the way the module uses these plugins.
27    for (let a = 0; a < this.length; a++) {
28      // cache selections
29      let $$ = $(this).eq(a);
30      // support metadata
31      o = $.meta ? $.extend({}, superfish_options, $$.data()) : superfish_options;
32      // Jump one level if it's a "NavBar"
33      if ($$.hasClass('sf-navbar')) {
34        $$ = $$.children('li').children('ul');
35      }
36      // cache all ul elements
37      let $ULs = $$.find('ul');
38      if ($ULs.length) {
39        // get the font size of menu.
40        // .css('fontSize') returns various results cross-browser, so measure an em dash instead
41        let fontsize = $('<li id="menu-fontsize">&#8212;</li>');
42        size = fontsize.attr('style','padding:0;position:absolute;top:-99999em;width:auto;')
43        .appendTo($$)[0].clientWidth; //clientWidth is faster than width()
44        // remove em dash
45        fontsize.remove();
46
47        // loop through each ul in a menu
48        for (let b = 0; b < $ULs.length; b++) {
49          // cache this ul
50          let $ul = $ULs.eq(b);
51          // If a multi-column sub-menu, and only if correctly configured.
52          if (o.multicolumn && $ul.hasClass('sf-multicolumn') && $ul.find('.sf-multicolumn-column').length > 0){
53            // Look through each column.
54            let $column = $ul.find('div.sf-multicolumn-column > ol');
55            // Overall width.
56            let mwWidth = 0;
57            for (let d = 0; d < $column.length; d++){
58              resize($column.eq(d));
59              // New column width, in pixels.
60              let colWidth = Math.ceil($column.width());
61              // Just a trick to convert em unit to px.
62              $column.css({width:colWidth})
63              // Making column parents the same size.
64              .parents('.sf-multicolumn-column').css({width:colWidth});
65              // Overall width.
66              mwWidth += colWidth;
67            }
68            // Resizing the columns' container too.
69            $ul.add($ul.find('li.sf-multicolumn-wrapper, li.sf-multicolumn-wrapper > ol')).css({width:mwWidth});
70          }
71          else {
72            resize($ul);
73          }
74        }
75      }
76    }
77    function resize($ul){
78      // get all (li) children of this ul
79      const $LIs = $ul.children();
80      // get all anchor grand-children
81      const $As = $LIs.children('a');
82      // force content to one line and save current float property
83      $LIs.css('white-space','nowrap');
84      // remove width restrictions and floats so elements remain vertically stacked
85      $ul.add($LIs).add($As).css({float:'none',width:'auto'});
86      // this ul will now be shrink-wrapped to the longest li due to position:absolute
87      // so save its width as ems.
88      let emWidth = $ul.get(0).clientWidth / size;
89      // add more width to ensure lines don't turn over at certain sizes in various browsers
90      emWidth += o.extraWidth;
91      // restrict to at least minWidth and at most maxWidth
92      if (emWidth > o.maxWidth) {
93        emWidth = o.maxWidth;
94      }
95      else if (emWidth < o.minWidth) {
96        emWidth = o.minWidth;
97      }
98      emWidth += 'em';
99      // set ul to width in ems
100      $ul.css({width:emWidth});
101      // restore li floats to avoid IE bugs
102      // set li width to full width of this ul
103      // revert white-space to normal
104      $LIs.add($As).css({float:'',width:'',whiteSpace:''});
105      // update offset position of descendant ul to reflect new width of parent.
106      // set it to 100% in case it isn't already set to this in the CSS
107      for (let c = 0; c < $LIs.length; c++) {
108        let $childUl = $LIs.eq(c).children('ul');
109        let offsetDirection = $childUl.css('left') !== undefined ? 'left' : 'right';
110        $childUl.css(offsetDirection,'100%');
111      }
112    }
113    return this;
114  };
115
116  // expose defaults
117  $.fn.supersubs.defaults = {
118    multicolumn: true, // define width for multi-column sub-menus and their columns.
119    minWidth: 12, // requires em unit.
120    maxWidth: 27, // requires em unit.
121    extraWidth: 1 // extra width can ensure lines don't sometimes turn over due to slight browser differences in how they round-off values
122  };
123})(jQuery); // plugin code ends

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.