PageSourceSearch

https://loewener.dk/wp-content/themes/loewener/js/responsive-tabs.js?ver=1.2

js loewener.dk collected 2026-10-07 19:36:14 UTC 5,799 bytes, 195 lines download raw bytes

1var fakewaffle = ( function ( $, fakewaffle ) {
2	'use strict';
3
4	fakewaffle.responsiveTabs = function ( collapseDisplayed ) {
5
6		fakewaffle.currentPosition = 'tabs';
7
8		var tabGroups = $( '.nav-tabs.responsive' );
9		var hidden    = '';
10		var visible   = '';
11		var activeTab = '';
12
13		if ( collapseDisplayed === undefined ) {
14			collapseDisplayed = [ 'xs', 'sm' ];
15		}
16
17		$.each( collapseDisplayed, function () {
18			hidden  += ' hidden-' + this;
19			visible += ' visible-' + this;
20		} );
21
22		$.each( tabGroups, function () {
23			var $tabGroup   = $( this );
24			var tabs        = $tabGroup.find( 'li a' );
25			var collapseDiv = $( '<div></div>', {
26				'class' : 'panel-group responsive' + visible,
27				'id'    : 'collapse-' + $tabGroup.attr( 'id' )
28			} );
29
30			$.each( tabs, function () {
31				var $this          = $( this );
32				var oldLinkClass   = $this.attr( 'class' ) === undefined ? '' : $this.attr( 'class' );
33				var newLinkClass   = 'accordion-toggle';
34				var oldParentClass = $this.parent().attr( 'class' ) === undefined ? '' : $this.parent().attr( 'class' );
35				var newParentClass = 'panel panel-default';
36				var newHash        = $this.get( 0 ).hash.replace( '#', 'collapse-' );
37
38				if ( oldLinkClass.length > 0 ) {
39					newLinkClass += ' ' + oldLinkClass;
40				}
41
42				if ( oldParentClass.length > 0 ) {
43					oldParentClass = oldParentClass.replace( /\bactive\b/g, '' );
44					newParentClass += ' ' + oldParentClass;
45					newParentClass = newParentClass.replace( /\s{2,}/g, ' ' );
46					newParentClass = newParentClass.replace( /^\s+|\s+$/g, '' );
47				}
48
49				if ( $this.parent().hasClass( 'active' ) ) {
50					activeTab = '#' + newHash;
51				}
52
53				collapseDiv.append(
54					$( '<div>' ).attr( 'class', newParentClass ).html(
55						$( '<div>', {
56							'data-toggle' : 'collapse',
57							'data-parent' : '#collapse-' + $tabGroup.attr( 'id' ),
58							'href'        : '#' + newHash,
59						} ).attr( 'class', 'panel-heading' ).html(
60							$( '<h4>' ).attr( 'class', 'panel-title' ).html(
61								$( '<a>', {
62									'class'       : newLinkClass,
63									// 'data-toggle' : 'collapse',
64									// 'data-parent' : '#collapse-' + $tabGroup.attr( 'id' ),
65									// 'href'        : '#' + newHash,
66									'html'        : $this.html()
67								} )
68							)
69						)
70					).append(
71						$( '<div>', {
72							'id'    : newHash,
73							'class' : 'panel-collapse collapse'
74						} )
75					)
76				);
77			} );
78
79			$tabGroup.next().after( collapseDiv );
80			$tabGroup.addClass( hidden );
81			$( '.tab-content.responsive' ).addClass( hidden );
82		} );
83
84
85		fakewaffle.checkResize();
86		fakewaffle.bindTabToCollapse();
87
88		if ( activeTab ) {
89			$( activeTab ).collapse( 'show' );
90		}
91	};
92
93	fakewaffle.checkResize = function () {
94
95		if ( $( '.panel-group.responsive' ).is( ':visible' ) === true && fakewaffle.currentPosition === 'tabs' ) {
96			fakewaffle.tabToPanel();
97			fakewaffle.currentPosition = 'panel';
98		} else if ( $( '.panel-group.responsive' ).is( ':visible' ) === false && fakewaffle.currentPosition === 'panel' ) {
99			fakewaffle.panelToTab();
100			fakewaffle.currentPosition = 'tabs';
101		}
102
103	};
104
105	fakewaffle.tabToPanel = function () {
106
107		var tabGroups = $( '.nav-tabs.responsive' );
108
109		$.each( tabGroups, function ( index, tabGroup ) {
110
111			// Find the tab
112			var tabContents = $( tabGroup ).next( '.tab-content' ).find( '.tab-pane' );
113
114			$.each( tabContents, function ( index, tabContent ) {
115				// Find the id to move the element to
116				var destinationId = $( tabContent ).attr( 'id' ).replace ( /^/, '#collapse-' );
117				var cloned = $(tabContent).clone();
118				// Convert tab to panel and move to destination
119				$( cloned )
120					.removeClass( 'tab-pane' )
121					.addClass( 'panel-body' )
122					.appendTo( $( destinationId ) );
123
124			} );
125
126		} );
127
128	};
129
130	fakewaffle.panelToTab = function () {
131
132		var panelGroups = $( '.panel-group.responsive' );
133
134		$.each( panelGroups, function ( index, panelGroup ) {
135
136			var destinationId = $( panelGroup ).attr( 'id' ).replace( 'collapse-', '#' );
137			var destination   = $( destinationId ).next( '.tab-content' )[ 0 ];
138
139			// Find the panel contents
140			var panelContents = $( panelGroup ).find( '.panel-body' );
141			panelContents.parent().html('');
142			// Convert to tab and move to destination
143			// panelContents
144			// 	.removeClass( 'panel-body' )
145			// 	.addClass( 'tab-pane' )
146			// 	.appendTo( $( destination ) );
147
148		} );
149
150	};
151
152	fakewaffle.bindTabToCollapse = function () {
153
154		var tabs     = $( '.nav-tabs.responsive' ).find( 'li a' );
155		var collapse = $( '.panel-group.responsive' ).find( '.panel-collapse' );
156		var t = $('.panel-group.responsive').find('.panel-heading');
157
158		t.on('click', function() {
159			// Do nothing - but fix ios toggle error somehow XD
160		});
161
162		console.log('bind');
163		// Toggle the panels when the associated tab is toggled
164		tabs.on( 'shown.bs.tab', function ( e ) {
165			console.log('tab');
166			var $current  = $( e.currentTarget.hash.replace( /#/, '#collapse-' ) );
167			$current.collapse( 'show' );
168
169			if ( e.relatedTarget ) {
170				var $previous = $( e.relatedTarget.hash.replace( /#/, '#collapse-' ) );
171				$previous.collapse( 'hide' );
172			}
173		} );
174
175		// Toggle the tab when the associated panel is toggled
176		collapse.on( 'shown.bs.collapse', function ( e ) {
177			if ($(e.target).context == null) return;
178			// Activate current tabs
179			var current = $( e.target ).context.id.replace( /collapse-/g, '#' );
180			$( 'a[href="' + current + '"]' ).tab( 'show' );
181
182			// Update the content with active
183			var panelGroup = $( e.currentTarget ).closest( '.panel-group.responsive' );
184			$( panelGroup ).find( '.panel-body' ).removeClass( 'active' );
185			$( e.currentTarget ).find( '.panel-body' ).addClass( 'active' );
186
187		} );
188	};
189
190	$( window ).resize( function () {
191		fakewaffle.checkResize();
192	} );
193
194	return fakewaffle;
195}( window.jQuery, fakewaffle || { } ) );

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.