PageSourceSearch

https://www.sabima.no/wp-content/themes/sabima/library/js/scripts.js?ver=1710259697

js sabima.no collected 2026-10-02 09:55:03 UTC 8,373 bytes, 318 lines download raw bytes

1/*
2 * Bones Scripts File
3 * Author: Eddie Machado
4 *
5 * This file should contain any js scripts you want to add to the site.
6 * Instead of calling it in the header or throwing it inside wp_head()
7 * this file will be called automatically in the footer so as not to
8 * slow the page load.
9 *
10 * There are a lot of example functions and tools in here. If you don't
11 * need any of it, just remove it. They are meant to be helpers and are
12 * not required. It's your world baby, you can do whatever you want.
13*/
14
15
16/*
17 * Get Viewport Dimensions
18 * returns object with viewport dimensions to match css in width and height properties
19 * ( source: http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript )
20*/
21function updateViewportDimensions() {
22	var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight;
23	return { width:x,height:y };
24}
25// setting the viewport width
26var viewport = updateViewportDimensions();
27
28
29/*
30 * Throttle Resize-triggered Events
31 * Wrap your actions in this function to throttle the frequency of firing them off, for better performance, esp. on mobile.
32 * ( source: http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed )
33*/
34var waitForFinalEvent = (function () {
35	var timers = {};
36	return function (callback, ms, uniqueId) {
37		if (!uniqueId) { uniqueId = "Don't call this twice without a uniqueId"; }
38		if (timers[uniqueId]) { clearTimeout (timers[uniqueId]); }
39		timers[uniqueId] = setTimeout(callback, ms);
40	};
41})();
42
43// how long to wait before deciding the resize has stopped, in ms. Around 50-100 should work ok.
44var timeToWaitForLast = 100;
45
46
47/*
48 * Here's an example so you can see how we're using the above function
49 *
50 * This is commented out so it won't work, but you can copy it and
51 * remove the comments.
52 *
53 *
54 *
55 * If we want to only do it on a certain page, we can setup checks so we do it
56 * as efficient as possible.
57 *
58 * if( typeof is_home === "undefined" ) var is_home = $('body').hasClass('home');
59 *
60 * This once checks to see if you're on the home page based on the body class
61 * We can then use that check to perform actions on the home page only
62 *
63 * When the window is resized, we perform this function
64 * $(window).resize(function () {
65 *
66 *    // if we're on the home page, we wait the set amount (in function above) then fire the function
67 *    if( is_home ) { waitForFinalEvent( function() {
68 *
69 *	// update the viewport, in case the window size has changed
70 *	viewport = updateViewportDimensions();
71 *
72 *      // if we're above or equal to 768 fire this off
73 *      if( viewport.width >= 768 ) {
74 *        console.log('On home page and window sized to 768 width or more.');
75 *      } else {
76 *        // otherwise, let's do this instead
77 *        console.log('Not on home page, or window sized to less than 768.');
78 *      }
79 *
80 *    }, timeToWaitForLast, "your-function-identifier-string"); }
81 * });
82 *
83 * Pretty cool huh? You can create functions like this to conditionally load
84 * content and other stuff dependent on the viewport.
85 * Remember that mobile devices and javascript aren't the best of friends.
86 * Keep it light and always make sure the larger viewports are doing the heavy lifting.
87 *
88*/
89
90/*
91 * We're going to swap out the gravatars.
92 * In the functions.php file, you can see we're not loading the gravatar
93 * images on mobile to save bandwidth. Once we hit an acceptable viewport
94 * then we can swap out those images since they are located in a data attribute.
95*/
96function loadGravatars() {
97  // set the viewport using the function above
98  viewport = updateViewportDimensions();
99  // if the viewport is tablet or larger, we load in the gravatars
100  if (viewport.width >= 768) {
101  jQuery('.comment img[data-gravatar]').each(function(){
102    jQuery(this).attr('src',jQuery(this).attr('data-gravatar'));
103  });
104	}
105} // end function
106
107
108/*
109 * Put all your regular jQuery in here.
110*/
111jQuery(document).ready(function($) {
112
113  /*
114   * Let's fire off the gravatar function
115   * You can remove this if you don't need it
116  */
117  loadGravatars();
118
119
120}); /* end of as page load scripts */
121
122// ACF Google Maps-script
123(function($) {
124
125/* new_map*/
126
127function new_map( $el ) {
128	
129	// var
130	var $markers = $el.find('.marker');
131	
132	// vars
133	var args = {
134		zoom		: 16,
135		center		: new google.maps.LatLng(0, 0),
136		mapTypeId	: google.maps.MapTypeId.ROADMAP,
137		scrollwheel: false,
138		navigationControl	: false,
139		mapTypeControl	: false,
140		scaleControl	: false,
141		draggable	: false
142	};
143	
144	// create map	        	
145	var map = new google.maps.Map( $el[0], args);
146	
147	
148	// add a markers reference
149	map.markers = [];
150	
151	
152	// add markers
153	$markers.each(function(){
154		
155    	add_marker( $(this), map );
156		
157	});
158	
159	// center map
160	center_map( map );
161	
162	// return
163	return map;
164}
165
166/* add_marker */
167
168function add_marker( $marker, map ) {
169
170	// var
171	var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
172
173	// create marker
174	var marker = new google.maps.Marker({
175		position	: latlng,
176		map			: map
177	});
178
179	// add to array
180	map.markers.push( marker );
181
182	// if marker contains HTML, add it to an infoWindow
183	if( $marker.html() )
184	{
185		// create info window
186		var infowindow = new google.maps.InfoWindow({
187			content		: $marker.html()
188		});
189
190		// show info window when marker is clicked
191		google.maps.event.addListener(marker, 'click', function() {
192
193			infowindow.open( map, marker );
194
195		});
196	}
197
198}
199
200/* center_map */
201
202function center_map( map ) {
203
204	// vars
205	var bounds = new google.maps.LatLngBounds();
206
207	// loop through all markers and create bounds
208	$.each( map.markers, function( i, marker ){
209
210		var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
211
212		bounds.extend( latlng );
213
214	});
215
216	// only 1 marker?
217	if( map.markers.length === 1 )
218	{
219		// set center of map
220	    map.setCenter( bounds.getCenter() );
221	    map.setZoom( 16 );
222	}
223	else
224	{
225		// fit to bounds
226		map.fitBounds( bounds );
227	}
228}
229
230/* document ready */
231// global var
232var map = null;
233
234$(document).ready(function(){
235
236	$('.acf-map').each(function(){
237
238		// create map
239		map = new_map( $(this) );
240
241	});
242});
243
244})(jQuery);
245
246jQuery(document).ready(function($) {
247	var iframeModules = document.querySelectorAll( '.iframe-form' );
248
249    for (var i = 0; i < iframeModules.length; i++) {
250        var iframe = iframeModules[i].querySelector('iframe');
251
252        if (iframe.id) {
253			iFrameResize({ checkOrigin: false }, `#${iframe.id}`);
254        }
255    }
256});
257
258// overlay samme høyde som bilde på skjematopp
259jQuery(".skjemaoverlay").css({'height':(jQuery(".bilde img").height()+'px')});
260
261jQuery(".skjemaoverlay").height(jQuery(".bilde img").height());
262
263var highestCol = Math.max(jQuery('.skjemaoverlay').height(),jQuery('.bilde img').height());
264jQuery('.skjemaoverlay').height(highestCol);
265
266
267// Resizes navigasjon
268jQuery(document).ready(function($) {
269	
270	// Returns width of browser viewport
271    if ( $( window ).width() < 1030) {
272		// meny toggle
273		$('.navtoggle').click(function() {
274			$('.navigasjon').slideToggle("slow");
275		});
276		
277		$(".navigasjon").css("display", "none");
278    } else {
279	    $(".navtoggle").css("display", "none");
280    }
281    
282    $('.headertoggle').click(function() {
283		$('.headersearch').slideToggle("slow");
284	});
285	
286	$(".headersearch").css("display", "none");
287	
288	
289	$( ".kartleggingsoverskrift" ).first().toggleClass( "notat-open" );
290	$( ".notatwrap" ).first().addClass( "notatwrap-open" );
291	
292	$('.kartleggingsoverskrift').on('click', function() {
293		var $parent_box = $(this).closest('.notater');
294
295		$parent_box.siblings().find('.notatwrap').slideUp(700);
296		
297		$parent_box.find('.notatwrap').slideToggle(700, function() { 
298			
299			var $scroll = $(this).closest('.notatwrap');
300			
301			$('html, body').animate({
302			    scrollTop: $scroll.offset().top + (-140)
303			}, 700);
304		
305		});
306		
307		$parent_box.click().find(".kartleggingsoverskrift").toggleClass("notat-open");	
308		$parent_box.siblings().find(".kartleggingsoverskrift").removeClass("notat-open");
309		
310		$( ".notat-open" ).slideDown( "slow" );
311		
312	});
313	
314	var $all_oembed_videos = $("iframe[src*='youtube'], iframe[src*='vimeo']");
315	$all_oembed_videos.each(function() {
316		$(this).removeAttr('height').removeAttr('width').wrap( "<div class='youtube-container'></div>" );
317	});	
318});

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.