vendor: 3,364 bytes, lines 1-91
1 2/* 3 * Supersubs v0.3b - jQuery plugin 4 * Copyright (c) 2013 Joel Birch 5 * 6 * Dual licensed under the MIT and GPL licenses: 7 * http://www.opensource.org/licenses/mit-license.php 8 * http://www.gnu.org/licenses/gpl.html 9 * 10 * 11 * This plugin automatically adjusts submenu widths of suckerfish-style menus to that of 12 * their longest list item children. If you use this, please expect bugs and report them 13 * to the jQuery Google Group with the word 'Superfish' in the subject line. 14 * 15 */ 16 17;(function($){ // $ will refer to jQuery within this closure 18 19 $.fn.supersubs = function(options){ 20 var opts = $.extend({}, $.fn.supersubs.defaults, options); 21 // return original object to support chaining 22 return this.each(function() { 23 // cache selections 24 var $$ = $(this); 25 // support metadata 26 var o = $.meta ? $.extend({}, opts, $$.data()) : opts; 27 // cache all ul elements and show them in preparation for measurements 28 var $ULs = $$.find('ul').show(); 29 // get the font size of menu. 30 // .css('fontSize') returns various results cross-browser, so measure an em dash instead 31 var fontsize = $('<li id="menu-fontsize">—</li>').css({ 32 'padding' : 0, 33 'position' : 'absolute', 34 'top' : '-999em', 35 'width' : 'auto' 36 }).appendTo($$)[0].clientWidth; //clientWidth is faster than .width() 37 // remove em dash 38 $('#menu-fontsize').remove(); 39 // loop through each ul in menu 40 $ULs.each(function(i) { 41 // cache this ul 42 var $ul = $(this); 43 // get all (li) children of this ul 44 var $LIs = $ul.children(); 45 // get all anchor grand-children 46 var $As = $LIs.children('a'); 47 // force content to one line and save current float property 48 var liFloat = $LIs.css('white-space','nowrap').css('float'); 49 // remove width restrictions and floats so elements remain vertically stacked 50 $ul.add($LIs).add($As).css({ 51 'float' : 'none', 52 'width' : 'auto' 53 }); 54 // this ul will now be shrink-wrapped to longest li due to position:absolute 55 // so save its width as ems. 56 var emWidth = $ul[0].clientWidth / fontsize; 57 // add more width to ensure lines don't turn over at certain sizes in various browsers 58 emWidth += o.extraWidth; 59 // restrict to at least minWidth and at most maxWidth 60 if (emWidth > o.maxWidth) { emWidth = o.maxWidth; } 61 else if (emWidth < o.minWidth) { emWidth = o.minWidth; } 62 emWidth += 'em'; 63 // set ul to width in ems 64 $ul.css('width',emWidth); 65 // restore li floats to avoid IE bugs 66 // set li width to full width of this ul 67 // revert white-space to normal 68 $LIs.css({ 69 'float' : liFloat, 70 'width' : '100%', 71 'white-space' : 'normal' 72 }) 73 // update offset position of descendant ul to reflect new width of parent. 74 // set it to 100% in case it isn't already set to this in the CSS 75 .each(function(){ 76 var $childUl = $(this).children('ul'); 77 var offsetDirection = $childUl.css('left') !== undefined ? 'left' : 'right'; 78 $childUl.css(offsetDirection,'100%'); 79 }); 80 }).hide(); 81 82 }); 83 }; 84 // expose defaults 85 $.fn.supersubs.defaults = { 86 minWidth : 9, // requires em unit. 87 maxWidth : 25, // requires em unit. 88 extraWidth : 0 // extra width can ensure lines don't sometimes turn over due to slight browser differences in how they round-off values 89 }; 90 91})(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.