PageSourceSearch

https://history.house.gov/_js/OHH.carousel.js?nc=092320261821

js house.gov collected 2026-09-24 06:37:48 UTC 3,557 bytes, 160 lines download raw bytes

1// http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
2// http://peter.michaux.ca/articles/wrapping-functions-in-javascript
3
4
5;var OHH = (function(parent, $, UTIL, undefined) {
6	var me = parent.carousel = parent.carousel || {};
7	
8	me.name = parent.name + ".carousel";
9	
10	var MAX_IMAGES = 5;
11	var nimages = 0;
12	var pos = 0;
13	
14	var $headerWrap = null
15	var $controls = null;
16	var $text = null;
17	
18	var $playpause = null;
19	var $buttons = [];
20	
21	function initControls () {
22
23		var $container = $("<div class='container'></div");
24
25		// Add play/pause button...
26		$playpause = $("<span class='replace sprite btn_play_carousel'>Play</span>").on("click", function () {
27			var $this = $(this);
28			
29			if ($this.hasClass("disabled")) return;
30			
31			if ($this.hasClass("btn_pause_carousel")) {
32				$this.removeClass("btn_pause_carousel").addClass("btn_play_carousel");
33				pause();
34			} else {
35				$this.removeClass("btn_play_carousel").addClass("btn_pause_carousel");
36				play();
37			}
38		});
39				
40		$container.append($playpause);
41		
42		// Add pagination...
43		for (var j = 1; j <= nimages; j++) {
44			var $button = $("<span class='replace sprite btn_carousel_image'>" + j + "</span>").data("which", j).on("click", function () {
45				var $this = $(this);
46				
47				if ($this.hasClass("disabled")) return;
48				
49				var which = $this.data("which");
50				
51				showImage(which);
52				
53				pos = which;
54				
55				$playpause.removeClass("btn_pause_carousel").addClass("btn_play_carousel");
56				pause();
57			});
58			
59			$container.append($button);
60		}
61
62		
63		// Add prev/next buttons
64		var $prev = $('<span class="replace previous">Previous</span>').on("click", prevImage)
65		var $next = $('<span class="replace next">Next</span>').on("click", nextImage);
66		$container.append($prev, $next);
67
68		$controls.append($container);
69		
70	}
71
72	var mouseover = null;
73	var tid = null;
74	var delay = 5 * 1000;
75
76	function play () {
77		if (tid) {
78			clearTimeout(tid);
79		}
80		
81		tid = setTimeout(autoAdvance, delay);
82	}
83	
84	function pause () {
85		if (tid) {
86			clearTimeout(tid);
87			tid = null;
88		}
89	}
90	
91	function setupAutoPlayPause () {
92		$("body").on("mousemove", function (e) {
93			mouseover = e.pageY <= 525;
94		});
95		
96		$playpause.trigger("click");
97	}
98	
99	function autoAdvance () {
100		tid = null;
101		
102		nextImage();
103		
104		tid = setTimeout(autoAdvance, delay);
105	}
106	
107	function prevImage () {
108		if (--pos == 0) pos = nimages;
109		
110		showImage(pos);
111	}
112	
113	function nextImage () {
114		if (++pos > nimages) pos = 1;
115		
116		showImage(pos);
117	}
118	
119	function showImage (i) {
120		pos = i;
121		
122		for (var j = 1; j <= MAX_IMAGES; j++) {
123			$headerWrap.removeClass("header-carousel-image-" + j);
124		}
125		
126		$headerWrap.addClass("header-carousel-image-" + pos);
127		
128		$text.addClass("hidden");
129		$text.eq(pos - 1).removeClass("hidden");
130		
131		$(".btn_carousel_image", $controls).removeClass("on");
132		$(".btn_carousel_image", $controls).eq(pos - 1).addClass("on");
133	}	
134	
135	function init () {
136		if ($("body").hasClass("carousel")) {
137			$headerWrap = $(".header-wrap");
138			$controls = $(".header-carousel-controls");
139			$text = $(".header-carousel-text a");
140			
141			nimages = $text.length;
142			
143			console.log(me.name + ".init()", nimages);
144			
145			if (nimages > 1) {
146				initControls();
147				
148				if(window.innerWidth >= 500) {
149					setupAutoPlayPause();
150				}
151			}
152			
153			showImage(1);
154		}
155	};
156	
157	$(document).ready(init);
158	
159	return parent;
160}(OHH || {}, jQuery, UTIL));

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.