PageSourceSearch

https://ambrosiaforheads.com/wp-content/themes/ambrosiaforheads_v2/js/behavior.js?ver=1.2

js ambrosiaforheads.com collected 2026-10-02 08:20:11 UTC 13,553 bytes, 476 lines download raw bytes

1var timeout; // Used for slidedown function below.
2
3//resize mobile YouTube iframes
4function youtubeResponsive(){
5	
6	window.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
7	var $ = jQuery;
8	
9	if (window.width < 768) {
10		$('.entry .video.container.embed iframe').each(function(e){
11		    if ($(this).attr('src').indexOf('youtube') > -1){
12		        var $this = $(this), iHeight;
13		        $this.css('width','100%')
14		        iHeight = ($this.width()/1.7778)
15		        $this.css('height',iHeight+'px')
16		    }
17		})
18	}
19	
20}
21
22jQuery(document).ready(function($) {
23	
24  youtubeResponsive();
25  
26  $(window).on('resize', function(){
27		youtubeResponsive();
28	});
29	
30  // Mobile navigation
31  $("select.menu").change(function() {
32    document.location = $(this).val();
33  });
34
35  // Custom Widgets
36  $(".carousel-wrapper").bxSlider({
37    slideWidth: $(this).innerWidth() / 2,
38    minSlides: 2,
39    maxSlides: 2,
40    slideMargin: 10,
41    pager: false
42  });
43
44  $(".large-image-slidedown-post").each(function() {
45    $(this).css({ height: $(".text-content", this).outerHeight() });
46  });
47
48  $(".large-image-slidedown-post").on("mouseenter", function() {
49    var thisElement = $(this);
50
51    if (timeout != null) {
52      clearTimeout(timeout);
53    }
54
55    timeout = setTimeout(function() {
56      thisElement.animate({ height: "200px" }, 700);
57    }, 1000);
58  });
59
60  $(".large-image-slidedown-post").on("mouseleave", function() {
61    var thisElement = $(this);
62
63    if (timeout != null) {
64      clearTimeout(timeout);
65      timeout = null;
66    }
67
68    thisElement.animate(
69      { height: $(".text-content", this).outerHeight() },
70      700
71    );
72  });
73
74  // Dilemma customization
75  $(".dilimage")
76    .mouseenter(function() {
77      $(this).addClass("dilhover");
78    })
79    .mouseleave(function() {
80      $(this).removeClass("dilhover");
81    });
82
83  // Share prompt settings
84  $(".dilimage").click(function(e) {
85    var el_parent = $(this).parents(".dil_wrap");
86
87    if ($(".dilema-share", el_parent).length == 0) {
88      var clicked = $(this).attr("data-dil-clicked"),
89        single_url = $(el_parent).attr("data-single-post-url"),
90        current_url = document.URL,
91        voted_for = $(".dil", this).text(),
92        voted_against = $(
93          ".dil",
94          $(this)
95            .parents(".choice")
96            .siblings(".choice")
97        ).text(),
98        share_message =
99          "Who's a better rapper between " +
100          voted_for +
101          " and " +
102          voted_against +
103          "? I chose " +
104          voted_for +
105          ". Who you got? ";
106
107      console.log(single_url);
108      if (single_url) {
109        current_url = single_url;
110      }
111      var fb_share_url =
112          "http://www.facebook.com/sharer.php?u=" +
113          current_url +
114          "&t=" +
115          share_message,
116        twitter_share_url =
117          "https://twitter.com/home?status=" + share_message + current_url,
118        message = "Thanks for voting!";
119
120      if (clicked == "yes") {
121        message = "You already voted!";
122      }
123
124      var insert_element =
125        '<div class="dilema-share">' +
126        "<h3>" +
127        message +
128        "</h3>" +
129        '<div class="share-links">Share your vote on <a href="' +
130        fb_share_url +
131        '" target="_blank">Facebook</a> and <a href="' +
132        twitter_share_url +
133        '" target="_blank">Twitter</a>!</div>' +
134        "</div>";
135
136      el_parent.append(insert_element);
137    }
138  });
139
140  $(".featured-video-selector").click(function(e) {
141    e.preventDefault();
142    var videoID = $(this).attr("data-video-id");
143    $(".featured-video").hide();
144    var video_wrapper = $("#" + videoID);
145    video_wrapper.show();
146    var iframeEl = $("iframe", video_wrapper);
147    if (iframeEl.attr("src") === "about:blank") {
148      iframeEl.attr("src", iframeEl.attr("data-iframe-source"));
149    }
150    $(".videos-navigation li").removeClass("active");
151    $(this)
152      .parents("li")
153      .addClass("active");
154  });
155
156  $(".mobile-featured-video-slider").slick({
157    dots: true,
158    arrows: false,
159    onBeforeChange: function(slickObj, prevSlide, nextSlide) {
160      var slideEl = $("#slick-slide-" + nextSlide);
161      var iframeEl = $("iframe", slideEl);
162      if (iframeEl.attr("src") === "about:blank") {
163        iframeEl.attr("src", iframeEl.attr("data-iframe-source"));
164      }
165    }
166  });
167
168  var ua = navigator.userAgent.toLowerCase();
169  if (ua.indexOf("safari") != -1) {
170    if (ua.indexOf("chrome") == -1) {
171      // strange safari issue with first video player on home page
172      var first_video_origin = $("#featured-video-1 iframe").attr("src");
173      // $('#featured-video-1 iframe').attr('src', 'about:blank');
174      $("#featured-video-1 iframe").attr("src", first_video_origin);
175    }
176  }
177
178  // Prepare
179  var History = window.History; // Note: We are using a capital H instead of a lower h
180  if (!History.enabled) {
181    // History.js is disabled for this browser.
182    // This is because we can optionally choose to support HTML4 browsers or not.
183    // return false;
184  }
185
186  // Bind to StateChange Event
187  History.Adapter.bind(window, "statechange", function() {
188    // Note: We are using statechange instead of popstate
189    var State = History.getState();
190  });
191
192  // Load more posts via AJAX
193  if ($(".load-more-posts").length > 0) {
194    var articles_waypoint = new Waypoint({
195      element: $(".load-more-posts"),
196      handler: function(direction) {
197        if (direction === "down" && $(".load-more-posts").is(":visible")) {
198          loadMore();
199        }
200      },
201      offset: "bottom-in-view"
202    });
203
204    var moreLinkEl = $(".load-more-posts");
205    var runningAjax = false;
206    function loadMore() {
207      if (moreLinkEl && runningAjax === false) {
208        runningAjax = true;
209        $.ajax({
210          type: "get",
211          dataType: "html",
212          url:
213            afhAJAX.ajaxurl +
214            "?action=load_more_posts&exclude_ids=" +
215            moreLinkEl.attr("data-exclude-ids") +
216            "&page=" +
217            moreLinkEl.attr("data-next-page"),
218          success: function(response) {
219            $(moreLinkEl.attr("data-append-container")).append(response);
220            var nextPage = parseInt(moreLinkEl.attr("data-next-page"), 10);
221            moreLinkEl.attr("data-next-page", ++nextPage);
222            Waypoint.refreshAll();
223            runningAjax = false;
224          }
225        });
226      }
227    }
228  }
229
230  function loadNextPost() {
231    var _gaq = window._gaq || [];
232    var runningAjax = false;
233
234    $(".ajax-next-post-loading-image").show();
235    if (runningAjax === false) {
236      runningAjax = true;
237      var exclude_ids = $(".entry-content-wrapper")
238        .map(function() {
239          id_parts = $(this)
240            .attr("id")
241            .split("-");
242          return id_parts[1];
243        })
244        .get();
245      var article_count = $(".entry-content-wrapper").length;
246
247      $.ajax({
248        type: "get",
249        dataType: "html",
250        url:
251          afhAJAX.ajaxurl +
252          "?action=load_next_post&exclude_ids=" +
253          exclude_ids.join(",") +
254          "&article_count=" +
255          article_count,
256        success: function(response) {
257          $(".next-post-wrapper").append(response);
258          $(".ajax-next-post-loading-image").hide();
259
260          Waypoint.refreshAll();
261          History.pushState(
262            null,
263            $("h1.entry-title", response).text(),
264            $("h1.entry-title a", response).attr("href")
265          );
266          FB.XFBML.parse();
267          twttr.widgets.load();
268
269          if (typeof _gaq !== "undefined" && _gaq !== null) {
270            $(document).ajaxSend(function(event, xhr, settings) {
271              console.log("_trackPageview");
272              _gaq.push([
273                "_trackPageview",
274                $("h1.entry-title a", response).attr("href")
275              ]);
276            });
277          } else {
278            var _gaq = window._gaq || [];
279            console.log(_gaq);
280            console.log("_trackPageview not fired");
281          }
282        }
283      });
284    }
285  }
286
287  $(".pds-answer-group a").click(function(e) {
288    e.preventDefault();
289    var parent = $(this).parents(".PDS_Poll"),
290      input_parent = $(this).parents(".pds-answer-group"),
291      input = $(".pds-radiobutton", input_parent);
292    $(".pds-answer-span").removeClass("active-pd-selection");
293    $(".pds-answer-span", input_parent).addClass("active-pd-selection");
294    input.attr("checked", true);
295  });
296
297  $(".pds-answer-group").each(function() {
298    $(this).css({
299      "background-image": "url(" + $("p a img", this).attr("src") + ")"
300    });
301  });
302
303  $(".PDS_Poll").each(function() {
304    var cookie_id = $(this)
305      .attr("id")
306      .replace("PDI_container", "");
307    var existing_cookie = Cookies.get("PD_poll_" + cookie_id);
308    if (existing_cookie === undefined) {
309      $(".pds-vote-button", this).show();
310      $(".pds-view-results", this).hide();
311    } else {
312      $(".pds-view-results", this).show();
313      $(".pds-vote-button", this).hide();
314    }
315  });
316
317  /**
318   * will return how much of an element is visible as a decimal
319   * @returns {number}
320   */
321  function howVisibleIsElement($element) {
322    var screenTop =
323      document.body.scrollTop || document.documentElement.scrollTop;
324    var screenBottom =
325      (document.body.scrollTop || document.documentElement.scrollTop) +
326      $(window).height();
327    var boxTop = $element.offset().top;
328    var boxHeight = $element.height();
329    var boxBottom = boxTop + boxHeight;
330
331    if (boxTop > screenTop) {
332      if (boxBottom < screenBottom) {
333        //fully visible
334        return 1;
335      } else if (boxTop < screenBottom) {
336        //partial (bottom)
337        return (screenBottom - boxTop) / boxHeight;
338      }
339    } else if (boxBottom > screenTop) {
340      //partial (top)
341      return (boxBottom - screenTop) / boxHeight;
342    }
343
344    return 0;
345  }
346
347  /**
348   * start refresh timer and only refresh ad if at least 50% viewable
349   * @param element
350   */
351  var refreshAd = 0;
352  var timerStarted = false;
353
354  function startRefreshTimer(elementVisibility, adTagId, adTag, timeout) {
355    console.log("visibility", elementVisibility);
356    if (elementVisibility > 0.5 && !timerStarted && !refreshAd) {
357      refreshAd = setInterval(
358        function(adTagId, adTag) {
359          if (!timerStarted) {
360            console.log("timer started");
361          }
362
363          timerStarted = true;
364
365          //only make refresh request if document has focus
366          if (document.hasFocus()) {
367            refreshBid(adTagId, adTag);
368          }
369        },
370        timeout,
371        adTagId,
372        adTag
373      );
374    }
375
376    if (elementVisibility < 0.5 && refreshAd && timerStarted) {
377      console.log("timer stopped");
378      clearInterval(refreshAd);
379      timerStarted = false;
380      refreshAd = 0;
381    }
382  }
383
384  //Header height calculation if ads are taller than 184px
385  function calculateNecessaryContentHeight() {
386    if ($("#content-height-spacer").is(":visible")) {
387      // $('#content-height-spacer').height( $('.header').outerHeight() );
388      $(".sticky-sidebar").css("top", $(".header").outerHeight());
389    }
390  }
391
392  //css spacer height is set anticipating an ad in the header 188px tall since more often than not they will be 188px. only recalculate if not 188px
393  $(window).on("load", function() {
394    if ($(".header").outerHeight() !== 184) {
395      calculateNecessaryContentHeight();
396    }
397
398    setUpMobileRefresh();
399    setUpSidebarRefresh();
400  });
401
402  //mobileRefresh is set where "/33196227/AFH_Mobile_ROS_Leaderboard" is defined in Options
403  var $mobileRefreshTagHook = $(".mobile-refresh-ad"); //this class needs to be added to ad html tag hook
404  var $mobileRefreshwrapper = $(".mobile-sticky-wrapper");
405
406  function setUpMobileRefresh() {
407    if (
408      !!$mobileRefreshTagHook &&
409      !$mobileRefreshwrapper.is(":hidden") &&
410      !!window.mobileRefresh
411    ) {
412      console.log("inside if block mobile", $mobileRefreshTagHook);
413
414      var elementVisibility = howVisibleIsElement($mobileRefreshTagHook);
415      startRefreshTimer(
416        elementVisibility,
417        $mobileRefreshTagHook.attr("id"),
418        window.mobileRefresh,
419        60 * 1000
420      );
421    }
422  }
423
424  //sidebarRefresh is set where "/33196227/AFH_Article_LR2" is defined in widgets
425  var $sidebarRefreshTagHook = $(".sidebar-refresh-ad"); //this class needs to be added to ad html tag hook
426  var $stickySidebar = $(".sticky-sidebar");
427
428  function setUpSidebarRefresh() {
429    if (
430      !!$sidebarRefreshTagHook &&
431      !$stickySidebar.is(":hidden") &&
432      !!window.sidebarRefresh
433    ) {
434      console.log("inside if block side bar", $sidebarRefreshTagHook);
435
436      var elementVisibility = howVisibleIsElement($sidebarRefreshTagHook);
437      startRefreshTimer(
438        elementVisibility,
439        $sidebarRefreshTagHook.attr("id"),
440        window.sidebarRefresh,
441        60 * 1000
442      );
443    }
444  }
445
446  $(window).on(
447    "scroll",
448    _.throttle(function(e) {
449      setUpMobileRefresh();
450
451      setUpSidebarRefresh();
452    }, 250)
453  );
454});
455function refreshBid(tagId, tagObj) {
456  if (!!pbjs) {
457    pbjs.que.push(function() {
458      pbjs.requestBids({
459        timeout: PREBID_TIMEOUT,
460        adUnitCodes: [tagId],
461        bidsBackHandler: function() {
462          console.log("refresh called", tagObj);
463
464          pbjs.setTargetingForGPTAsync([tagId]);
465          googletag.pubads().refresh([tagObj]);
466        }
467      });
468    });
469  } else {
470    if (!!googletag) {
471      googletag.cmd.push(function() {
472        googletag.pubads().refresh([tagObj]);
473      });
474    }
475  }
476}

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.