PageSourceSearch

https://hoosiervalley.org/application/themes/hvrm/js/accordion.js

js hoosiervalley.org collected 2026-10-02 11:47:31 UTC 10,536 bytes, 422 lines download raw bytes

vendor: 9,742 bytes, lines 1-383
1/**
2 * Plugin Name : Accordion.JS
3 * Version     : 2.1.1
4 * Author      : ZeroWP Team
5 * Author URL  : http://zerowp.com/
6 * Plugin URL  : http://accordionjs.zerowp.com/
7 * License     : MIT
8 */
9;(function ( $ ) {
10
11	"use strict";
12
13	$.fn.accordionjs = function( options ) {
14
15		// Select all accordions that match a CSS selector
16		if (this.length > 1){
17			this.each(function() {
18				$(this).accordionjs(options);
19			});
20			return this;
21		}
22
23		// Current accordion instance
24		var accordion = this;
25
26		// Setup utility functions
27		var util = {
28
29			/**
30			 * Is integer
31			 *
32			 * Check if a value is a valid integer number
33			 *
34			 * @param {number} value
35			 * @return {bool}
36			 */
37			isInteger:  function(value) {
38				return typeof value === 'number' &&
39					isFinite(value) &&
40					Math.floor(value) === value;
41			},
42
43			//------------------------------------//--------------------------------------//
44
45			/**
46			 * Is array
47			 *
48			 * Check if a value is a valid array.
49			 *
50			 * @param {Array} arg
51			 * @return {bool}
52			 */
53			isArray: function(arg) {
54				return Object.prototype.toString.call(arg) === '[object Array]';
55			},
56
57			//------------------------------------//--------------------------------------//
58
59			/**
60			 * Is object
61			 *
62			 * Check if a value is a valid object.
63			 *
64			 * @param {Object} arg
65			 * @return {bool}
66			 */
67			isObject: function isObject(arg) {
68				return Object.prototype.toString.call(arg) === '[object Object]';
69			},
70
71			//------------------------------------//--------------------------------------//
72
73			/**
74			 * Sections is open
75			 *
76			 * Check if a section from current accordion is open.
77			 *
78			 * @param {Object}(jQuery) section
79			 * @return {bool}
80			 */
81			sectionIsOpen: function( section ){
82				return section.hasClass( 'acc_active' );
83			},
84
85
86			//------------------------------------//--------------------------------------//
87
88			/**
89			 * Get hash
90			 *
91			 * Get hash substring without # or false if the window does not have one.
92			 *
93			 * @return {string|bool(false)}
94			 */
95			getHash: function(){
96				if(window.location.hash) {
97					return window.location.hash.substring(1);
98				}
99
100				return false;
101			},
102		};
103
104		/* Setup options
105		---------------------*/
106		var settings = $.extend({
107			// Allow self close.
108			closeAble   : false,
109
110			// Close other sections.
111			closeOther  : true,
112
113			// Animation Speed.
114			slideSpeed  : 150,
115
116			// The section open on first init. A number from 1 to X or false.
117			activeIndex : 1,
118
119			// Callback when a section is open
120			openSection: false, // function( section ){}
121
122			// Callback before a section is open
123			beforeOpenSection: false, // function( section ){}
124		}, options );
125
126		// Assign to accordion options data-* attributes if they exists
127		$.each(settings, function( option ) {
128			var data_attr = option.replace(/([A-Z])/g, '-$1').toLowerCase().toString(), //`optionsName` becomes `option-name`
129			new_val       =  accordion.data( data_attr );
130
131			if( new_val || false === new_val ){
132				settings[ option ] = new_val;
133			}
134		});
135
136		/*
137		If the activeIndex is false then all sections are closed by default.
138		If the closeOther is false then other section will not be closed when
139		this is opened. That means, in both cases, sections should be able
140		to be closed independently.
141		*/
142		if( settings.activeIndex === false || settings.closeOther === false ){
143			settings.closeAble = true;
144		}
145
146		//------------------------------------//--------------------------------------//
147
148		/**
149		 * "Constructor"
150		 *
151		 * @return void
152		 */
153		var init = function() {
154			accordion.create();
155			accordion.openOnClick();
156
157			$(window).on( 'load', function(){
158				accordion.openOnHash();
159			});
160
161			$(window).on( 'hashchange', function(){
162				accordion.openOnHash();
163			});
164		};
165
166		//------------------------------------//--------------------------------------//
167
168		/**
169		 * Open section
170		 *
171		 * Open a single section.
172		 *
173		 * @param {Object}(jQuery) section The section to open
174		 * @param {number} speed
175		 * @return void
176		 */
177		this.openSection = function(section, speed){
178			// Event before a section is opened
179			$(document).trigger('accjs_before_open_section', [
180				section,
181			]);
182
183			// Callback before a section is opened
184			if( typeof settings.beforeOpenSection === "function" ){
185				settings.beforeOpenSection.call(this, section);
186			}
187
188			// Setup the collapse speed
189			speed = ( speed >= 0 ) ? speed : settings.slideSpeed;
190
191			// Get the section content
192			var section_content = section.children().eq(1); // .acc_content
193
194			// Open the section
195			section_content.slideDown( speed, function(){
196				// Event when a section is opened
197				$(document).trigger('accjs_open_section', [
198					section,
199				]);
200
201				// Callback when a section is opened
202				if( typeof settings.openSection === "function" ){
203					settings.openSection.call(this, section);
204				}
205			} );
206
207			// Make active
208			section.addClass('acc_active');
209
210			// Set aria-expanded on section header
211			section.children().eq(0).attr('aria-expanded', true);
212		};
213
214		//------------------------------------//--------------------------------------//
215
216		/**
217		 * Close section
218		 *
219		 * Close a single section.
220		 *
221		 * @param {Object}(jQuery) section The section to close
222		 * @param {number} speed
223		 * @return void
224		 */
225		this.closeSection = function(section, speed){
226			// Event before a section is closed
227			$(document).trigger('accjs_before_close_section', [
228				section,
229			]);
230
231			// Callback before a section is closed
232			if( typeof settings.beforeCloseSection === "function" ){
233				settings.beforeCloseSection.call(this, section);
234			}
235
236			// Setup the collapse speed
237			speed = ( speed >= 0 ) ? speed : settings.slideSpeed;
238
239			// Get the section content
240			var section_content = section.children().eq(1); // .acc_content
241
242			// Open the section
243			section_content.slideUp( speed, function(){
244				// Event when a section is closed
245				$(document).trigger('accjs_close_section', [
246					section,
247				]);
248
249				// Callback when a section is closed
250				if( typeof settings.closeSection === "function" ){
251					settings.closeSection.call(this, section);
252				}
253
254			} );
255
256			// Make inactive
257			section.removeClass('acc_active');
258
259			// Set aria-expanded on section header
260			section.children().eq(0).attr('aria-expanded', false);
261
262		};
263
264		//------------------------------------//--------------------------------------//
265
266		/**
267		 * Close other sections except this one
268		 *
269		 * @param {Object}(jQuery) section The section to exclude
270		 * @param {number} speed
271		 * @return void
272		 */
273		this.closeOtherSections = function(section, speed){
274			var this_acc = section.closest('.accordionjs').children();
275			$(this_acc).each(function() {
276				accordion.closeSection( $(this).not(section), speed );
277			});
278		};
279
280		//------------------------------------//--------------------------------------//
281
282		/**
283		 * Create the accordion
284		 *
285		 * Create the accordion structure. Add the necessary CSS classes and other stuff.
286		 *
287		 * @return void
288		 */
289		this.create = function() {
290
291			//Add Main CSS Class
292			accordion.addClass('accordionjs');
293
294			// Get all current accordion sections
295			var accordion_sections = accordion.children();
296
297			//Add classes to accordion head and content for each section
298			$.each( accordion_sections, function(index, elem){
299				accordion.createSingleSection( $(elem) );
300			});
301
302			// //Active index
303			if( util.isArray( settings.activeIndex ) ){
304				var indexes = settings.activeIndex;
305				for (var i = 0; i < indexes.length; i++) {
306					accordion.openSection( accordion_sections.eq( indexes[i] - 1 ), 0 );
307				}
308			}
309			else if( settings.activeIndex > 1 ){
310				accordion.openSection( accordion_sections.eq( settings.activeIndex - 1 ), 0 );
311			}
312			else if( false !== settings.activeIndex ){
313				accordion.openSection( accordion_sections.eq( 0 ), 0 );
314			}
315
316		};
317
318		//------------------------------------//--------------------------------------//
319
320		/**
321		 * Create a single section
322		 *
323		 * Create the structure of a single section by adding the necessary CSS classes.
324		 *
325		 * @param {string} section The section to create. jQuery object.
326		 * @return void
327		 */
328		this.createSingleSection = function( section ) {
329			var childs = section.children();
330
331			// Create sections if they were not created already
332			section.addClass('acc_section');
333
334			// Add the necessary CSS classes and attributes
335			$(childs[0]).addClass('acc_head');
336			$(childs[0]).attr('role', 'button');
337			$(childs[1]).addClass('acc_content');
338			$(childs[1]).attr('role', 'region');
339
340			// Collapse section content.
341			// Only if it does not have `.acc_active` CSS class set by default.
342			if( ! section.hasClass('acc_active') ) {
343				section.children('.acc_content').hide();
344			}
345		};
346
347		//------------------------------------//--------------------------------------//
348
349		/**
350		 * Open on click
351		 *
352		 * Open a section when its header get a click.
353		 *
354		 * @return void
355		 */
356		this.openOnClick = function() {
357
358			accordion.on('click', '.acc_head', function( event ){
359				event.stopImmediatePropagation();
360
361				var section = $(this).closest('.acc_section');
362				if( util.sectionIsOpen( section ) ) {
363
364					// If closeAble, then close this section but do not touch other.
365					if( settings.closeAble ) {
366						accordion.closeSection( section );
367					}
368
369					// If the accordion contains only one section, act like a toggle.
370					else if( accordion.children().length === 1 ) {
371						accordion.closeSection( section );
372					}
373
374				}
375
376				// Section is closed
377				else {
378					// If closeOther, then close other sections when this is opened.
379					if( settings.closeOther ) {
380						accordion.closeOtherSections( section );
381						accordion.openSection( section );
382					}
383
384					// Else open only this section and do not touch other sections.
385					else {
386						accordion.openSection( section );
387					}
388				}
389
390			});
391
392		};
393
394		//------------------------------------//--------------------------------------//
395
396		/**
397		 * Open a section if a hash is present in URL and scroll to it.
398		 *
399		 * @return void
400		 */
401		this.openOnHash = function() {
402			if( util.getHash() ) {
403				var section = $( '#' + util.getHash() );
404				if( section.hasClass('acc_section') ) {
405					accordion.openSection( section );
406					if( settings.closeOther ) {
407						accordion.closeOtherSections( section );
408					}
409					$("html, body").animate({
410						scrollTop: parseInt( section.offset().top ) - 50,
411					}, 150);
412				}
413			}
414		};
415
416		//"Constructor" init
417		init();
418		return this;
419
420	};
421
422}( 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.