PageSourceSearch

https://www.creditorinfo.com/Scripts/js/developr.accordions.js

js creditorinfo.com collected 2026-10-06 12:50:00 UTC 4,094 bytes, 164 lines download raw bytes

1/**
2 *
3 * '||''|.                            '||
4 *  ||   ||    ....  .... ...   ....   ||    ...   ... ...  ... ..
5 *  ||    || .|...||  '|.  |  .|...||  ||  .|  '|.  ||'  ||  ||' ''
6 *  ||    || ||        '|.|   ||       ||  ||   ||  ||    |  ||
7 * .||...|'   '|...'    '|     '|...' .||.  '|..|'  ||...'  .||.
8 *                                                  ||
9 * --------------- By Display:inline ------------- '''' -----------
10 *
11 * Accordions plugin
12 *
13 * Structural good practices from the article from Addy Osmani 'Essential jQuery plugin patterns'
14 * @url http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns/
15 */
16
17/*
18 * The semi-colon before the function invocation is a safety
19 * net against concatenated scripts and/or other plugins
20 * that are not closed properly.
21 */
22;(function($, window, document)
23{
24	/*
25	 * document is passed through as local variable rather than as global, because this (slightly)
26	 * quickens the resolution process and can be more efficiently minified.
27	 */
28
29		// Objects cache
30	var win = $(window),
31		doc = $(document);
32
33	// Event binding
34	doc.on('click', '.accordion > dt', function(event)
35	{
36		var dt = $(this),
37			dl = dt.parent();
38
39		// Equalize height when needed
40		if (dl.hasClass('.same-height'))
41		{
42			dl.refreshAccordion();
43		}
44
45		// Check if closed
46		if (dt.hasClass('closed'))
47		{
48			// Close previous
49			dl.children('dt').not('.closed').each(function(i)
50			{
51				$(this).addClass('closed').next('dd').stop(true).slideUp();
52			});
53
54			// Open
55			dt.removeClass('closed');
56			dt.next('dd').stop(true).slideDown();
57		}
58	});
59
60	/**
61	 * Refresh accordions height
62	 */
63	$.fn.refreshAccordion = function()
64	{
65		this.each(function(i)
66		{
67				// Accordions
68			var dl = $(this).closest('.accordion'),
69				sections = dl.children('dd'),
70
71				// Hidden parents
72				hidden,
73
74				// Processing vars
75				datas = [],
76				maxHeight = 0;
77
78			// If not found or not valid
79			if (dl.length === 0 || !dl.hasClass('same-height') || sections.length === 0)
80			{
81				return;
82			}
83
84			// Reveal hidden parents if needed for correct height processing
85			hidden = dl.tempShow();
86
87			// Gather sections blocks and infos
88			sections.each(function(i)
89			{
90				var section = $(this).show(),
91					topMargin, height;
92
93				// Get total height
94				height = section.css('height', '').outerHeight();
95
96				// Get first element's top-margin, because it affects the block height if it is negative
97				topMargin = Math.min(0, section.children(':first').parseCSSValue('margin-top'));
98
99				// Check if this is the tallest element
100				maxHeight = Math.max(maxHeight, height+topMargin);
101
102				// Store for equalization loop below
103				datas[i] = [height, topMargin];
104			});
105
106			// Set equalized height
107			sections.each(function(i)
108			{
109				var section = $(this),
110					dt = section.prev(),
111					height = datas[i][0],
112					topMargin = datas[i][1];
113
114				// Set height depending on margins
115				section.height(maxHeight-(height-section.height())-topMargin);
116
117				// Hide if not current one
118				if (dt && dt.hasClass('closed'))
119				{
120					section.hide();
121				}
122			});
123
124			// Hide previously hidden parents
125			hidden.tempShowRevert();
126		});
127
128		return this;
129	};
130
131	// Add template setup function
132	$.template.addSetupFunction(function(self, children)
133	{
134		var accordions = this.findIn(self, children, '.accordion');
135
136		// Equalize height when needed
137		accordions.filter('.same-height').refreshAccordion();
138
139		// Show only active tab
140		accordions.each(function(i)
141		{
142			var dts = $(this).children('dt'),
143				active;
144
145			// Active section
146			active = dts.filter('.open');
147			if (active.length === 0)
148			{
149				active = dts.not('.closed').first();
150			}
151			if (active.length === 0)
152			{
153				active = dts.first();
154			}
155
156			// Tag and show/hide
157			active.removeClass('closed').next('dd').show();
158			active.siblings('dt').addClass('closed').next('dd').hide();
159		});
160
161		return this;
162	});
163
164})(jQuery, window, document);

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.