PageSourceSearch

https://ama-csail.github.io/vendor/globalassets/scripts/breadcrumb.js

js ama-csail.github.io collected 2026-10-03 08:36:51 UTC 5,735 bytes, 147 lines download raw bytes

1+ function($) {
2	'use strict';
3	var Breadcrumb = function(element, options) {
4		this.options = options;
5		this.element = $(element);
6		this.window = $(window);
7		this.create();
8	}
9
10	Breadcrumb.DEFAULTS = {
11		leftControlClass: 'glyphicon glyphicon-chevron-left',
12		rightControlClass: 'glyphicon glyphicon-chevron-right'
13	}
14
15	Breadcrumb.prototype.create = function() {
16		// Add wrappers
17		this.element.wrap('<div class="breadcrumb-responsive"></div>').wrap('<div class="breadcrumb-container"></div>');
18
19		// Set this.element to responsive div
20		this.element = this.element.parents('.breadcrumb-responsive');
21
22		// Add controls
23		this.element.prepend('<div class="breadcrumb-left"><a href="javascript:void()"><em class="' + this.options.leftControlClass + '"><span aria-hidden="true" class="adobeBlank">Previous</span></em></a></div>');
24		this.element.append('<div class="breadcrumb-right"><a href="javascript:void()"><em class="' + this.options.rightControlClass + '"><span aria-hidden="true" class="adobeBlank">Next</span></em></a></div>');
25
26		// Give the active class, an sr-only text to indicate that it is active
27		//this.element.find('li.active a').append('<span class="sr-only"> - you are here</span>');
28
29		// Initial toggle
30		this.toggleControls(this);
31
32		var self = this;
33		this.window.on('resize', function() {
34			self.toggleControls(self);
35			self.resetPos(self);
36		});
37
38		this.element.find('.breadcrumb-left > a').on('click', function(e) {
39			self.navigateLeft();
40			e.preventDefault();
41		});
42
43		this.element.find('.breadcrumb-right > a').on('click', function(e) {
44			self.navigateRight();
45			e.preventDefault();
46		});
47
48		this.element.find('.breadcrumb > li > a').on('focus', function(e) {
49			if ($(this).parent('li').is(':first-child')) {
50				self.resetPos(self);
51			} else if ($(this).parent('li').is(':last-child')) {
52				self.element.find('.breadcrumb-container').scrollLeft(self.breadcrumbWidth() - self.element.outerWidth() + parseInt(self.element.find('.breadcrumb').css('padding-left')) + parseInt(self.element.find('.breadcrumb').css('padding-right')));
53			}
54			self.toggleControls(self);
55		});
56	}
57
58	Breadcrumb.prototype.toggleControls = function(self) {
59		if (self.breadcrumbWidth() > self.element.outerWidth()) {
60			// Show controls && set width
61			var controlWidth = 0;
62			// Left controller
63			if (self.getPos() > 0) {
64				self.element.addClass('control-left-visible');
65				controlWidth += this.element.find('.breadcrumb-left').outerWidth();
66			} else {
67				self.element.removeClass('control-left-visible');
68			}
69
70			// Right controller
71			if (self.getPos() < (self.breadcrumbWidth() - self.element.outerWidth() + parseInt(self.element.find('.breadcrumb').css('padding-left')))) {
72				self.element.addClass('control-right-visible');
73				controlWidth += this.element.find('.breadcrumb-right').outerWidth();
74			} else {
75				self.element.removeClass('control-right-visible');
76				self.element.find('.breadcrumb-left>a').focus();
77			}
78
79			var calculation = self.element.outerWidth() - controlWidth - 1;
80			self.element.find('.breadcrumb-container').width(calculation);
81
82
83		} else {
84			self.element.removeClass('control-left-visible');
85			self.element.removeClass('control-right-visible');
86			self.element.find('.breadcrumb-container').width('auto');
87		}
88	}
89
90	Breadcrumb.prototype.breadcrumbWidth = function() {
91		var width = 0;
92
93		this.element.find('.breadcrumb > li').each(function() {
94			width += $(this).outerWidth();
95		});
96
97		var padding = parseInt(this.element.find('.breadcrumb').css('padding-left')) + parseInt(this.element.find('.breadcrumb').css('padding-right'));
98		var inlineSpace = 4 * (this.element.find('.breadcrumb > li').length - 1);
99		return (width + padding + inlineSpace);
100	}
101
102	Breadcrumb.prototype.controlsWidth = function() {
103		var width = this.element.find('.breadcrumb-left').outerWidth() + this.element.find('.breadcrumb-right').outerWidth();
104
105		return width;
106	}
107
108	Breadcrumb.prototype.navigateLeft = function(e) {
109		var calculation = (this.getPos() - 50 < 0) ? 0 : this.getPos() - 50;
110
111		if (this.getPos() > 0) {
112			this.element.find('.breadcrumb-container').scrollLeft(calculation);
113			this.toggleControls(this);
114		}
115	}
116
117	Breadcrumb.prototype.navigateRight = function() {
118		var calculation = (this.getPos() + 50 > this.breadcrumbWidth() - this.element.outerWidth() + parseInt(this.element.find('.breadcrumb').css('padding-right'))) ? (this.breadcrumbWidth() - this.element.outerWidth() + parseInt(this.element.find('.breadcrumb').css('padding-left')) + parseInt(this.element.find('.breadcrumb').css('padding-right'))) : this.getPos() + 50;
119
120		if (this.getPos() < (this.breadcrumbWidth() - this.element.outerWidth() + parseInt(this.element.find('.breadcrumb').css('padding-right')))) {
121			this.element.find('.breadcrumb-container').scrollLeft(calculation);
122			this.toggleControls(this);
123		}
124	}
125
126	Breadcrumb.prototype.resetPos = function(self) {
127		self.element.find('.breadcrumb-container').scrollLeft(0);
128	}
129
130	Breadcrumb.prototype.getPos = function() {
131		return parseInt(this.element.find('.breadcrumb-container').scrollLeft());
132	}
133
134	$.fn.breadcrumb = function(option, _relatedTarget) {
135		return this.each(function() {
136			var $this = $(this)
137			var data = $this.data('bs.breadcrumb')
138			var options = $.extend({}, Breadcrumb.DEFAULTS, $this.data(), typeof option == 'object' && option)
139
140			if (!data) $this.data('bs.breadcrumb', (data = new Breadcrumb(this, options)))
141			if (typeof option == 'string') data[option](_relatedTarget)
142			else if (options.show) data.show(_relatedTarget)
143		})
144	};
145
146	$.fn.breadcrumb.Constructor = Breadcrumb
147}(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.