PageSourceSearch

https://riskandinsurance.com/wp-content/themes/riskandinsurance/js/scripts.js?v=5017&ver=1.9

js riskandinsurance.com collected 2026-10-02 02:53:35 UTC 24,962 bytes, 593 lines download raw bytes

1(function ($, root, undefined) {
2
3	$(function () {
4
5		window.addEventListener('load', documentReady);
6		documentReady();
7	});
8
9
10    function documentReady() {
11		'use strict';
12
13		// Setup website smooth scrolling
14
15
16
17		// COOKIE CHECKS
18		// Check to see if the footer has been closed
19		if (!readCookie('footer-newsletter')) {
20			$('.footer').fadeIn();
21		}
22		// HIDE ADVERTISEMENT POPUP FOR MOBILE
23		$( document ).on( 'click', '.js-first-visit-close-modal', function(e) {
24			e.preventDefault();
25			$('#ad-popup').hide();
26		});
27
28		$.fn.isInViewport = function() {
29			var elementTop = $(this).offset().top;
30			var elementBottom = elementTop + $(this).outerHeight();
31
32			var viewportTop = $(window).scrollTop();
33			var viewportBottom = viewportTop + $(window).height();
34
35			return elementBottom > viewportTop && elementTop < viewportBottom;
36		};
37
38		// All of our scroll functions that attach ads and such are listed in here.
39		$(window).scroll(function() {
40
41			// Get the scroll top of the window
42			var windscroll = $(window).scrollTop();
43
44			// For each of the issues that are currently being displayed, we have to iterate through
45			// them in order to detect the currently active issue. We use this active issue to display
46			// the correct advert.
47			$('.main-issue').each(function(i) {
48				if ($(this).position().top <= windscroll && !$(this).hasClass('active')) {
49					$('.main-issue.active').removeClass('active');
50					$('.main-issue').eq(i).addClass('active');
51				}
52			});
53
54			// LEADERBOARD AD STICKY SCROLL
55			// We need to set up the variables that we will be using in order to detect the positioning of
56			// the adverts and their associated elements such as the topRow which is the first row of articles.
57			// This first row of articles needs to be modified to have a margin every time we sticky the advert of the issue.
58			var leaderboardAd = $('.desktop-display .leaderboard-ad');
59
60			// Get the elements of the header that we use for getting height distances.
61			var categoryNav = $('.category-nav'); // This is the sub navigation menu that spans the header.
62			var header = $('.header-2');
63
64			// The top row of content that we need to manipulate after we sticky the advert
65			// If we are on a single page that has no "active" section like the home page's issues, we just get the first
66			// instance of .row-id
67			if ($('.active').length) {
68				var topRow = $('.active .row-id-0');
69			} else {
70				var topRow = $('.row-id-0');
71			}
72			var distanceFromBottom = $(document).height() - ($(document).scrollTop() + $(window).height()); // This is simply to detect where the bottom of the page is.
73			var distanceFromTop = $(document).scrollTop();
74/*
75			if (topRow.length) {
76
77					var topRowOffset = topRow.offset().top;
78				var topRowDistance = (windscroll - topRowOffset); // Get the distance of the top of the first article row to the top of the page.
79
80				// If the distance from the bottom is under 200 OR we can SEE the bottom of the issue, we need to fade out the advert and bring
81				// the category menu back in until they scroll up or scroll down further to bring in the next issue's advert
82
83				if (leaderboardAd.html() !== undefined) {
84                    console.log(2);
85                    if(distanceFromTop < 10) {
86						leaderboardAd.removeClass('sticky');
87						categoryNav.removeClass('sticky');
88						header.removeClass('sticky');
89						topRow.find('.container').css('margin-top', '0px');
90					} else if((distanceFromBottom < 50 || $('.active .issue-bottom').visible(true)) && !$('body').hasClass('single-post')) {
91						leaderboardAd.fadeOut('fast');
92						categoryNav.removeClass('sticky');
93						header.removeClass('sticky');
94					} else {
95						// We add up the top row's distance along with 10px for padding above the advert, the ad's current height (it's dynamic) and the height of the header
96						// After we get all of that, we see if it's greater than 0 and, if it is, we initiate the stickiness :)
97						if ((topRowDistance + header.height() + 10 + leaderboardAd.height()) > 0) {
98							// If the ad already has the sticky, it means that it's currently being hidden and that we need to unhide it with a fadeIn
99							if (leaderboardAd.hasClass('sticky')) {
100								leaderboardAd.fadeIn('fast');
101								header.addClass('sticky');
102								categoryNav.addClass('sticky');
103							} else {
104								leaderboardAd.addClass('sticky');
105								header.addClass('sticky');
106								categoryNav.addClass('sticky');
107								topRow.find('.container').css('margin-top', leaderboardAd.height()+'px');
108							}
109						} else {
110							leaderboardAd.removeClass('sticky');
111							categoryNav.removeClass('sticky');
112							header.removeClass('sticky');
113							topRow.find('.container').css('margin-top', '0px');
114						}
115					}
116				}
117			}*/
118
119
120			// SKYSCRAPER AD STICKY SCROLL
121			// We need to see if the sidebar actually exists before we run the script that will
122			// sticky it to places.
123			var postContent = $('#post-content');
124			var secondSidebar = false;
125			var contentHeight = $('#post-content.sticky-ref-content').height();
126
127			if ($('#secondary-post-content').length) {
128				if ($('#secondary-post-content').isInViewport()) {
129					postContent = $('#secondary-post-content');
130					contentHeight = $('#secondary-post-content.sticky-ref-content').height();
131					secondSidebar = true;
132				}
133			}
134                        
135			
136			if (postContent.length) {
137                             
138				var sidebarContainer = postContent.find('.sidebar-content');
139				var sidebarContainerAll = $('.sidebar-content');
140				var trendingStories = $('.most-popular');
141
142				var secondPostDistanceFromTop = postContent.offset().top - $(window).scrollTop();
143
144				if (sidebarContainer.html() !== undefined) {
145					// This code will hide the skyscraper add 2/3 of the way down the page to make the
146					// rectangle add more prominent
147					var skyscraperAdFirst = sidebarContainer.find('.SLAS-skyscraper.first');
148
149					// IF THERE ARE NO TRENDING STORIES, WE DO NOT WANT TO SLIDE ANY ADS
150                    if (trendingStories.length != 0) {
151						if (secondSidebar) {
152							if (((contentHeight / 2) + postContent.offset().top) <  distanceFromTop) {
153								skyscraperAdFirst.slideUp('slow');
154                                                                sidebarContainer.addClass('sticky-bottom');
155                                                        sidebarContainer.removeClass('sticky');
156							} else {
157								skyscraperAdFirst.slideDown('slow');
158
159							}
160						} else {
161							if (contentHeight / 2 < distanceFromTop) {
162								skyscraperAdFirst.slideUp('slow');
163                                                                      sidebarContainer.addClass('sticky-bottom');
164                                                        sidebarContainer.removeClass('sticky');
165							} else {
166								skyscraperAdFirst.slideDown('slow');
167
168							}
169						}
170                    }
171
172					var rightStickyContentHeight = sidebarContainer.height();
173
174					// newTopScrollCSS is the value that we have to set to the top of the entire sidebarContainer
175					// since the container is position fixed we need to artificially move it down the page to be separated from the header div
176					// 100 is for the spacing between the header and content.
177					var newTopScrollCSS = (header.height() + 140);
178					if (leaderboardAd.html() !== undefined) {
179						// If the leaderboard ad exists, we need to add its height to the variable.
180						newTopScrollCSS = newTopScrollCSS + leaderboardAd.height();
181					}
182
183					// Resize the height of the sidebar to make sure that it's a "full height" element of the window.
184					// This is because it will not stick properly to the bottom of the first article properly
185					var sidebarHeight = $(window).height() - newTopScrollCSS;
186					if (sidebarHeight > 0 && (sidebarContainer.height() < sidebarHeight)) {
187						console.log(sidebarContainer.height());
188						console.log(sidebarHeight);
189						sidebarContainer.height(sidebarContainer.height(sidebarHeight+'px'));
190					}
191
192					// This is for detecting how many pixels are at the bottom of the screen that are currently not in view
193					// like how much height is left of the last box in the side panel off of the page.
194					var rightStickyOffPageHeight = rightStickyContentHeight - ($(window).height()  - newTopScrollCSS);
195					var heightOfFirstContent = distanceFromTop + $(window).height() - header.height() - 18;
196                                        //var rightStickyOffPageHeight = rightStickyContentHeight - ($(window).height()  - 140);
197                                        //var heightOfFirstContent = distanceFromTop + $(window).height() - 18;
198					if (secondSidebar) {
199
200						if ((postContent.offset().top + contentHeight) < (rightStickyContentHeight + $(window).scrollTop()) + 77) {
201							sidebarContainer.addClass('sticky-bottom');
202							sidebarContainer.removeClass('sticky');
203							sidebarContainer.css('top', 'auto');
204						} else if ((secondPostDistanceFromTop - header.height()) < 0) {
205							sidebarContainer.addClass('sticky');
206							sidebarContainer.removeClass('sticky-bottom');
207							sidebarContainer.css('top', newTopScrollCSS+'px');
208						} else if (secondPostDistanceFromTop > 0) {
209							sidebarContainer.removeClass('sticky-bottom');
210							sidebarContainer.removeClass('sticky');
211							sidebarContainer.css('top', '0px');
212						}
213					} else {
214						// If the page is at the bottom, we do some one time uniqueness to funk the side avdert back into the sticky 
214scroll
215
216
217						// IF THERE IS NO TRENDING STORIES - CONTINUE LIKE NORMAL
218                        if (trendingStories.length != 0) {
219                            if(sidebarContainer.hasClass('sticky-bottom') && distanceFromTop > heightOfFirstContent) {
220                                sidebarContainer.removeClass('sticky-bottom');
221                                sidebarContainer.addClass('sticky');
222                                sidebarContainer.css('top', newTopScrollCSS+'px');
223				//console.log('in 1st');
224                                // Sticky the side panel to the bottom of the page if it's close enough to the bottom
225                            } else if(heightOfFirstContent > contentHeight && rightStickyOffPageHeight >= 0) {
226                                sidebarContainerAll.removeClass('sticky');
227                                sidebarContainerAll.addClass('sticky-bottom');
228                                sidebarContainerAll.css('top', 'auto');
229				//console.log('in 2nd')
230                                // Sticky the side banner if the page is scrolling around.
231                            } else {
232                                sidebarContainerAll.removeClass('sticky-bottom');
233                                sidebarContainer.addClass('sticky');
234                                sidebarContainer.css('top', newTopScrollCSS+'px');
235                                
236				//console.log(heightOfFirstContent);
237                                //console.log(contentHeight);
238                                //console.log(rightStickyOffPageHeight);
239                                //console.log(rightStickyContentHeight);
240                            }
241                        } else {
242                            if(sidebarContainer.hasClass('sticky-bottom') && distanceFromTop > heightOfFirstContent) {
243                                sidebarContainer.removeClass('sticky-bottom');
244                                sidebarContainer.addClass('sticky');
245                                sidebarContainer.css('top', newTopScrollCSS+'px');
246                                // Sticky the side panel to the bottom of the page if it's close enough to the bottom
247                            } else if(heightOfFirstContent > (contentHeight - 80) && rightStickyOffPageHeight >= 0) {
248                                sidebarContainerAll.removeClass('sticky');
249                                sidebarContainerAll.addClass('sticky-bottom');
250                                sidebarContainerAll.css('top', 'auto');
251                                // Sticky the side banner if the page is scrolling around.
252                            } else {
253                                sidebarContainerAll.removeClass('sticky-bottom');
254                                sidebarContainer.addClass('sticky');
255                                sidebarContainer.css('top', newTopScrollCSS+'px');
256                            }
257						}
258					}
259
260				} else {
261
262
263					sidebarContainer.removeClass('sticky');
264					sidebarContainer.css('top', '0px');
265				}
266			}
267			
268			
269            if(distanceFromTop > 400) {
270                categoryNav.addClass('sticky');
271            } else {
272                categoryNav.removeClass('sticky');
273            }
274
275		}).scroll();
276	}
277
278    // Open the main website navigation with the hamburger menu
279    $( document ).on( 'click', '#nav-expand', function(event) {
280        $(this).toggleClass('is-active');
281        $('#search-overlay').removeClass('active');
282        $('.search-toggle').removeClass('active');
283        $(".mobile-nav").fadeToggle(500);
284        $(".icon").toggleClass("iconxborder");
285    });
286	// Open the main website navigation with the hamburger menu
287	$( document ).on( 'click', '.search-toggle', function(event) {
288		searchToggle($(this), event);
289	});
290	// Open the main website navigation with the hamburger menu
291	$(document).on('submit','form.search-form',function(event){
292		submitFn($(this), event);
293	});
294	// Fade out the footer on click and set the cookie to not display this for another 7 days.
295	$( document ).on( 'click', '.close-footer .close', function(event) {
296		createCookie('footer-newsletter', true, 7);
297		$('.footer').fadeOut();
298	});
299	// For the Risk Central page, this will select the chosen tab as 'active'
300	$(document).on('click', '#filters li', function() {
301		if (!$(this).hasClass('active')) {
302			$('#filters li.active').removeClass('active');
303			$(this).addClass('active');
304		}
305
306	});
307
308    // For the Risk Central page, this will select the chosen tab as 'active'
309    $(document).on('click', '#filters li', function() {
310        if (!$(this).hasClass('active')) {
311            $('#filters li.active').removeClass('active');
312            $(this).addClass('active');
313        }
314
315    });
316    function isEmail(email) {
317        var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
318        return regex.test(email);
319    }
320    $(document).on("submit", ".postup-form", function (e) {
321        e.preventDefault();
322        var form = $(this);
323        form.find('.email').removeClass('red-border');
324        form.find('input[type=submit]').val('Submitting...');
325        form.find('.message-field').html('').removeClass('red-text');
326        var templateid = form.attr('data-template-id');
327        var email = form.find('.email');
328        if (isEmail(email.val()) == true) {
329            $.ajax({
330                url: loadissues.ajax_url,
331                type: 'post',
332                data: {
333                    action: 'postup_import_email',
334                    templateid: templateid,
335                    email: email.val(),
336                },
337                success: function (response) {
338                    //ga('send', 'event', 'Newsletter', 'Signup');
339                    console.log(response);
340                    $('.signup-home-page').html('<h3>The Daily List:</h3><p>Thank you for subscribing. Please check your email inbox for confirmation.</p>');
341                    form.find('.message-field').html('Success! Thanks for signing up!');
342                    setTimeout(function() {
343                        form.find('.message-field').html('');
344                    }, 3000);
345                    form.find('input[type=submit]').val('Submit');
346                    email.val('');
347
348                },
349                error: function (error) {
350                	console.log(error);
351                    form.find('.email').addClass('red-border');
352                    form.find('input[type=submit]').val('Submit');
353                    form.find('.message-field').addClass('red-text').html('Error occurred. Please contact us.');
354                }
355            });
356
357        } else {
358            form.find('.email').addClass('red-border');
359            form.find('input[type=submit]').val('Submit');
360			form.find('.message-field').addClass('red-text').html('Not a valid email address');
361        }
362	});
363
364	// We need to retrieve the previous issue from the last month.
365	$( document ).on( 'click', '#previous-issue-container', function() {
366		$('.issue-loader').addClass('loading');
367		$('#previous-issue-container').addClass('loading');
368		var post_id = $(this).attr('data-id');
369
370		$.ajax({
371			url : loadissues.ajax_url,
372			type : 'post',
373			data : {
374				action : 'get_monthly_issue',
375				post_id : post_id,
376				ajax : 1,
377			},
378			success : function( response ) {
379				$('.main-issue').last().after(response);
380				$('.main-issue').last().slideDown('slow');
381				$('.main-issue.hidden').removeClass('hidden');
382
383				$('body,html').animate({
384					'scrollTop': $('#issue-'+post_id).offset().top
385				}, 500);
386
387				var current_order = $('.main-issue').last().data('order');
388				var currentIssueID = $('.main-issue').last().data('issue');
389				get_next_monthly_issue(current_order);
390				$('.issue-loader').removeClass('loading');
391
392				$('#previous-issue-container').removeClass('loading');
393			},
394			error : function (error) {
395				$('.issue-loader').removeClass('loading');
396			}
397		});
398
399		return false;
400	})
401
402	// The button that the user will use to copy the link to their clipboard
403	$( document ).on( 'click', '.copy-url', function(event) {
404		copyToClipboard($('.copy-url-area').val());
405		$(this).html('Copied!');
406		$(this).addClass('copied');
407	});
408	$( document ).on( 'click', '.copy-url-area', function(event) {
409		copyToClipboard($(this).val());
410		$(this).parent('.url-share').find('.copy-url').html('Copied!');
411        $(this).parent('.url-share').find('.copy-url').addClass('copied');
412	});
413
414	// Copies a string to the clipboard. Must be called from within an event handler such as click.
415	// May return false if it failed, but this is not always
416	// possible. Browser support for Chrome 43+, Firefox 42+, Edge and IE 10+.
417	// No Safari support, as of (Nov. 2015). Returns false.
418	// IE: The clipboard feature may be disabled by an adminstrator. By default a prompt is
419	// shown the first time the clipboard is used (per session).
420	function copyToClipboard(text) {
421		if (window.clipboardData && window.clipboardData.setData) {
422			// IE specific code path to prevent textarea being shown while dialog is visible.
423			return clipboardData.setData("Text", text);
424
425		} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
426			var textarea = document.createElement("textarea");
427			textarea.textContent = text;
428			textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in MS Edge.
429			document.body.appendChild(textarea);
430			textarea.select();
431			try {
432				return document.execCommand("copy");  // Security exception may be thrown by some browsers.
433			} catch (ex) {
434				console.warn("Copy to clipboard failed.", ex);
435				return false;
436			} finally {
437				document.body.removeChild(textarea);
438			}
439		}
440	}
441
442
443	function get_next_monthly_issue(current_order) {
444		$.ajax({
445			url : loadissues.ajax_url,
446			type : 'post',
447			dataType : 'json',
448			data : {
449				action : 'get_next_monthly_issue',
450				current_order : current_order,
451				ajax: 1,
452			},
453			success : function( response ) {
454				$('#previous-issue-container').attr('data-id', response.ID);
455			},
456			error : function (error) {
457				return error;
458			}
459		});
460	}
461	function searchToggle(obj, evt){
462
463		//var container = $(obj).closest('.search-wrapper');
464        var container = $('#search-overlay');
465		var searchBtn = $('.search-toggle');
466		var searchInput = $('.search-input');
467		if(!container.hasClass('active')){
468            container.addClass('active');
469            searchBtn.addClass('active');
470			searchInput.focus();
471			evt.preventDefault();
472		}
473		else if(container.hasClass('active') && $(obj).closest('.input-holder').length == 0){
474            container.removeClass('active');
475            searchBtn.removeClass('active');
476			// clear input
477			container.find('.search-input').val('');
478			// clear and hide result container when we press close
479			container.find('.result-container').fadeOut(100, function(){$(this).empty();});
480		}
481	}
482
483	function submitFn(obj, evt){
484		var value = $(obj).find('.search-input').val().trim();
485		if (value.length) {
486			return;
487		} else {
488			evt.preventDefault();
489		}
490	}
491
492	// Cookies
493	function createCookie(name, value, days) {
494		if (days) {
495			var date = new Date();
496			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
497			var expires = "; expires=" + date.toGMTString();
498		}
499		else var expires = "";
500
501		document.cookie = name + "=" + value + expires + "; path=/";
502	}
503
504	function readCookie(name) {
505		var nameEQ = name + "=";
506		var ca = document.cookie.split(';');
507		for (var i = 0; i < ca.length; i++) {
508			var c = ca[i];
509			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
510			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
511		}
512		return null;
513	}
514
515	function eraseCookie(name) {
516		createCookie(name, "", -1);
517	}
518	$(document).on('click', '.close-matrix', function() {
519        $('.matrix-popup').remove();
520    });
521	/*$(document).on('hover', 'area', function(e) {
522		var matrixHolder = $('.matrix-holder');
523		if (!matrixHolder.hasClass('hovered')) {
524            matrixHolder.addClass('hovered');
525            tooltipGo($(this), e, 1);
526        }
527	});*/
528    $(document).on('mouseover', 'area', function(e) {
529        e.preventDefault();
530        if ($(window).width() > 500) {
531            tooltipGo($(this), e, 0);
532		}
533    });
534    $(document).on('click', 'area', function(e) {
535        e.preventDefault();
536        if ($(window).width() < 501) {
537            tooltipGo($(this), e, 0);
538        }
539    });
540	$(document).on('ready', function() {
541
542        if ($(window).width() > 500) {
543            var area = $('area:first-child');
544            var coords = area.attr('coords');
545            if (coords !== undefined) {
546                var coords_split = coords.split(",");
547            $('.matrix-holder.desktop').prepend('<span class="matrix-popup hover-matrix" style="left: ' + (coords_split[0] - 120) + 'px;"><span class="close-matrix-popup close-matrix">X</span><h3>Click on the Matrix circles to see more information!</h3><span class="close-matrix-button close-matrix">Got it, thanks!</span> </span>');
548            var height = $('.matrix-popup').height();
549            $('.matrix-popup').css('top',(coords_split[1] - (height + 48)));
550            }
551        }
552    });
553
554    function tooltipGo($this, e, hoverTemp) {
555        e.preventDefault();
556        var area = $this;
557        var coords = area.attr('coords');
558        var coords_split = coords.split(",");
559		$('.matrix-popup').remove();
560        var link = '';
561        if (area.data('link') !== 'undefined') {
562            link = '<a href="'+area.data('link')+'" class="close-matrix-button" target="_blank">Learn More</a>';
563        }
564        if ($(window).width() > 500) {
565
566        	if (hoverTemp == 1) {
567                    $('.matrix-holder.desktop-display').prepend('<span class="matrix-popup hover-matrix" style="left: ' + (coords_split[0] - 120) + 'px;"><span class="close-matrix-popup close-matrix">X</span><h3>Click on the Matrix circles to see more information!</h3></span>');
568
569			} else {
570                $('.matrix-holder.desktop-display').prepend('<span class="matrix-popup" style="left: ' + (coords_split[0] - 120) + 'px;"><span class="close-matrix-popup close-matrix">X</span><h3>'+area.data('popup-content')+ '</h3>' + link +'</span>');
571			}
572
573
574            var height = $('.matrix-popup').height();
575            $('.matrix-popup').css('top',(coords_split[1] - (height + 48)));
576        } else {
577            $('.matrix-holder.mobile-display').before('<span class="matrix-popup" style="left: ' + (coords_split[0] - 120) + 'px; top: ' + (coords_split[1] - 169) + 'px;"><span class="close-matrix-popup close-matrix">X</span><h3>'+area.data('popup-content')+ '</h3>' + link +'</span>');
578
579        }
580        $(window).on('scroll', function() {
581            if ($(window).width() > 500) {
582
583            } else {
584                $('.matrix-popup').remove();
585
586            }
587        });
588    }
589    var image = $('#desktop-image');
590    $('img').mapster();
591
592
593})(jQuery, this);

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.