PageSourceSearch

https://www.collegefactual.com/_dir-static/js/flexmenu.js?v=20240425

js collegefactual.com collected 2026-09-24 09:09:24 UTC 7,868 bytes, 153 lines download raw bytes

1/*	jQuery.flexMenu 1.4.2
2	https://github.com/352Media/flexMenu
3	Description: If a list is too long for all items to fit on one line, display a popup menu instead.
4	Dependencies: jQuery, Modernizr (optional). Without Modernizr, the menu can only be shown on click (not hover). */
5
6(function (factory) {
7	if (typeof define === 'function' && define.amd) {
8		// AMD. Register as an anonymous module.
9		define(['jquery'], factory);
10	} else {
11		// Browser globals
12		factory(jQuery);
13	}
14}(function ($) {
15	var windowWidth = $(window).width(); // Store the window width
16  	var windowHeight = $(window).height(); // Store the window height
17	var flexObjects = [], // Array of all flexMenu objects
18		resizeTimeout;
19	// When the page is resized, adjust the flexMenus.
20	function adjustFlexMenu() {
21		if ($(window).width() !== windowWidth || $(window).height() !== windowHeight) {
22			$(flexObjects).each(function () {
23				$(this).flexMenu({
24					'undo' : true
25				}).flexMenu(this.options);
26			});
27			windowWidth = $(window).width(); // Store the window width if it changed
28			windowHeight = $(window).height(); // Store the window height if it changed
29		}
30	}
31	function collapseAllExcept($menuToAvoid) {
32		var $activeMenus,
33			$menusToCollapse;
34		$activeMenus = $('li.flexMenu-viewMore.active');
35		$menusToCollapse = $activeMenus.not($menuToAvoid);
36		$menusToCollapse.removeClass('active').find('> ul').hide();
37	}
38	$(window).resize(function () {
39		clearTimeout(resizeTimeout);
40		resizeTimeout = setTimeout(function () {
41			adjustFlexMenu();
42		}, 200);
43	});
44	$.fn.flexMenu = function (options) {
45		var checkFlexObject,
46			s = $.extend({
47				'threshold' : 2, // [integer] If there are this many items or fewer in the list, we will not display a "Vie
47w More" link and will instead let the list break to the next line. This is useful in cases where adding a "view more" link would actually cause more things to break  to the next line.
48				'cutoff' : 2, // [integer] If there is space for this many or fewer items outside our "more" popup, just move everything into the more menu. In that case, also use linkTextAll and linkTitleAll instead of linkText and linkTitle. To disable this feature, just set this value to 0.
49				'linkText' : 'More', // [string] What text should we display on the "view more" link?
50				'linkTitle' : 'View More', // [string] What should the title of the "view more" button be?
51				'linkTextAll' : 'Menu', // [string] If we hit the cutoff, what text should we display on the "view more" link?
52				'linkTitleAll' : 'Open/Close Menu', // [string] If we hit the cutoff, what should the title of the "view more" button be?
53				'showOnHover' : true, // [boolean] Should we we show the menu on hover? If not, we'll require a click. If we're on a touch device - or if Modernizr is not available - we'll ignore this setting and only show the menu on click. The reason for this is that touch devices emulate hover events in unpredictable ways, causing some taps to do nothing.
54				'popupAbsolute' : true, // [boolean] Should we absolutely position the popup? Usually this is a good idea. That way, the popup can appear over other content and spill outside a parent that has overflow: hidden set. If you want to do something different from this in CSS, just set this option to false.
55				'popupClass' : '', // [string] If this is set, this class will be added to the popup
56				'undo' : false // [boolean] Move the list items back to where they were before, and remove the "View More" link.
57			}, options);
58		this.options = s; // Set options on object
59		checkFlexObject = $.inArray(this, flexObjects); // Checks if this object is already in the flexObjects array
60		if (checkFlexObject >= 0) {
61			flexObjects.splice(checkFlexObject, 1); // Remove this object if found
62		} else {
63			flexObjects.push(this); // Add this object to the flexObjects array
64		}
65		return this.each(function () {
66			var $this = $(this),
67				$items = $this.find('> li'),
68				$firstItem = $items.first(),
69				$lastItem = $items.last(),
70				numItems = $this.find('li').length,
71				firstItemTop = Math.floor($firstItem.offset().top),
72				firstItemHeight = Math.floor($firstItem.outerHeight(true)),
73				$lastChild,
74				keepLooking,
75				$moreItem,
76				$moreLink,
77				numToRemove,
78				allInPopup = false,
79				$menu,
80				i;
81			function needsMenu($itemOfInterest) {
82				var result = (Math.ceil($itemOfInterest.offset().top) >= (firstItemTop + firstItemHeight)) ? true : false;
83				// Values may be calculated from em and give us something other than round numbers. Browsers may round these inconsistently. So, let's round numbers to make it easier to trigger flexMenu.
84				return result;
85			}
86			if (needsMenu($lastItem) && numItems > s.threshold && !s.undo && $this.is(':visible')) {
87				var $popup = $('<ul class="flexMenu-popup" style="display:none;' + ((s.popupAbsolute) ? ' position: absolute;' : '') + '"></ul>');
88				// Add class if popupClass option is set
89				$popup.addClass(s.popupClass);
90				// Move all list items after the first to this new popup ul
91        for (i = numItems; i > 1; i--) {
92					// Find all of the list items that have been pushed below the first item. Put those items into the popup menu. Put one additional item into the popup menu to cover situations where the last item is shorter than the "more" text.
93					$lastChild = $this.find('> li:last-child');
94					keepLooking = (needsMenu($lastChild));
95					// If there only a few items left in the navigation bar, move them all to the popup menu.
96					if ((i - 1) <= s.cutoff) { // We've removed the ith item, so i - 1 gives us the number of items remaining.
97						$($this.children().get().reverse()).appendTo($popup);
98						allInPopup = true;
99						break;
100					}
101					if (!keepLooking) {
102						break;
103					} else {
104						$lastChild.appendTo($popup);
105					}
106				}
107				if (allInPopup) {
108					$this.append('<li class="flexMenu-viewMore flexMenu-allInPopup"><a href="#" title="' + s.linkTitleAll + '">' + s.linkTextAll + '</a></li>');
109				} else {
110				    $this.append('<li class="flexMenu-viewMore"><a href="#" title="' + s.linkTitle + '">' + s.linkText + '<b class="caret"></b></a></li>');
111				}
112				$moreItem = $this.find('> li.flexMenu-viewMore');
113				/// Check to see whether the more link has been pushed down. This might happen if the link immediately before it is especially wide.
114				if (needsMenu($moreItem)) {
115					$this.find('> li:nth-last-child(2)').appendTo($popup);
116				}
117				// Our popup menu is currently in reverse order. Let's fix that.
118				$popup.children().each(function (i, li) {
119					$popup.prepend(li);
120				});
121				$moreItem.append($popup);
122				$moreLink = $this.find('> li.flexMenu-viewMore > a');
123				$moreLink.click(function (e) {
124					// Collapsing any other open flexMenu
125					collapseAllExcept($moreItem);
126					//Open and Set active the one being interacted with.
127					$popup.toggle();
128					$moreItem.toggleClass('active');
129					e.preventDefault();
130				});
131				if (s.showOnHover && (typeof Modernizr !== 'undefined') && !Modernizr.touch) { // If requireClick is false AN
131D touch is unsupported, then show the menu on hover. If Modernizr is not available, assume that touch is unsupported. Through the magic of lazy evaluation, we can check for Modernizr and start using it in the same if statement. Reversing the order of these variables would produce an error.
132					$moreItem.hover(
133						function () {
134							$popup.show();
135							$(this).addClass('active');
136						},
137						function () {
138							$popup.hide();
139							$(this).removeClass('active');
140						});
141				}
142			} else if (s.undo && $this.find('ul.flexMenu-popup')) {
143				$menu = $this.find('ul.flexMenu-popup');
144				numToRemove = $menu.find('li').length;
145				for (i = 1; i <= numToRemove; i++) {
146					$menu.find('> li:first-child').appendTo($this);
147				}
148				$menu.remove();
149				$this.find('> li.flexMenu-viewMore').remove();
150			}
151		});
152	};
153}));

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.