PageSourceSearch

https://diereferenz.de/sites/all/libraries/superfish/sfautomaticwidth.js?tlx44c

js diereferenz.de collected 2026-10-02 18:48:13 UTC 2,834 bytes, 73 lines download raw bytes

1/*
2 * sf-AutomaticWidth v1.0b - Automatically adjusts the menu width for the jQuery Superfish plugin.
3 *
4 * Developer's note:
5 * Built as a part of the Superfish project for Drupal (http://drupal.org/project/superfish)
6 * Found any bug? have any cool ideas? contact me right away! http://drupal.org/user/619294/contact
7 *
8 * jQuery version: 1.3.x or higher.
9 *
10 * Dual licensed under the MIT and GPL licenses:
11 *  http://www.opensource.org/licenses/mit-license.php
12 *  http://www.gnu.org/licenses/gpl.html
13 */
14
15(function($){
16  $.fn.sfautomaticwidth = function(){
17    function automaticWidth(menu){
18      // This plugin is not useful for vertical menus.
19      if (menu.hasClass('sf-horizontal') || menu.hasClass('sf-navbar')){
20        // Adding a helper class.
21        // Making the main UL as wide as its container.
22        menu.addClass('sf-automatic-width').css('width','100%');
23        var
24        // We need the inner width of the main UL.
25        menuWidth = menu[0].clientWidth,
26        // Selecting only the first level parents.
27        children = menu.children('li'),
28        // Number of children.
29        childrenNumber = children.length,
30        // Calculating the total width of the children based on their outer width.
31        childrenWidth = 0;
32        for (var a = 0; a < childrenNumber; a++) {
33          // Resetting the children width and getting its outer width then.
34          childrenWidth += children.eq(a).css({width:''}).outerWidth(true);
35        }
36        // Is the menu container wider than the menu?
37        // (It'll be more flexible in later versions.)
38        if (menuWidth > childrenWidth) {
39          var
40          // Calculating how much width should be added to each first level parent.
41          difference = (((menuWidth - childrenWidth) * 100) / menuWidth) / childrenNumber;
42          for (var a = 0; a < childrenNumber; a++){
43            var
44            child = children.eq(a),
45            // Calculating and applying the new width to the item.
46            autoWidth = (((child[0].clientWidth * 100) / menuWidth) + difference) + '%';
47            child.css({width:autoWidth});
48          }
49        }
50        // Reset the widths if the menu became narrower than its children.
51        if (menuWidth < childrenWidth) {
52          for (var a = 0; a < childrenNumber; a++){
53            children.eq(a).css({width:''});
54          }
55        }
56      }
57    }
58    // Return original object to support chaining.
59    // Although unnecessary because of the way the module uses these plugins.
60    for (var b = 0; b < this.length; b++) {
61      var menu = $(this).eq(b);
62      automaticWidth(menu);
63      var timer;
64      $(window).resize(function(){
65        clearTimeout(timer);
66        timer = setTimeout(function(){
67          automaticWidth(menu);
68        }, 100);
69      });
70    }
71    return this;
72  };
73})(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.