1/** 2 * This script adds the jquery effects to the Monochrome Pro Theme. 3 * 4 * @package Monochrome\JS 5 * @author StudioPress 6 * @license GPL-2.0-or-later 7 */ 8(function ($) { 9 // Cache DOM selectors. 10 var $header = $(".site-header"), 11 $hsToggle = $(".toggle-header-search"), 12 $hsWrap = $("#header-search-wrap"), 13 $hsInput = $hsWrap.find('input[type="search"]'), 14 $footer = $(".site-footer"), 15 $container = $(".site-container"); 16 17 // Make sure JS class is added. 18 $(document).ready(function () { 19 $("body").addClass("js"); 20 }); 21 22 // Run on page scroll. 23 $(window).scroll(function () { 24 // Toggle header class after threshold point. 25 if (50 < $(document).scrollTop()) { 26 $(".site-container").addClass("shadow"); 27 } else { 28 $(".site-container").removeClass("shadow"); 29 } 30 }); 31 32 // Set the container margin to the footer height for effect. 33 $container.css("margin-bottom", $footer.outerHeight()); 34 35 // Handler for click a show/hide button. 36 $hsToggle.on("click", function (event) { 37 event.preventDefault(); 38 39 if ($(this).hasClass("close")) { 40 hideSearch(); 41 } else { 42 showSearch(); 43 } 44 }); 45 46 // Handler for pressing show/hide button. 47 $hsToggle.on("keydown", function (event) { 48 // If tabbing from toggle button, and search is hidden, exit early. 49 if (9 === event.keyCode && !$header.hasClass("search-visible")) { 50 return; 51 } 52 53 event.preventDefault(); 54 handleKeyDown(event); 55 }); 56 57 // Hide search when tabbing or escaping out of the search bar. 58 $hsInput.on("keydown", function (event) { 59 // Tab: 9, Esc: 27. 60 if (9 === event.keyCode || 27 === event.keyCode) { 61 hideSearch(event.target); 62 } 63 }); 64 65 // Hide search on blur, such as when clicking outside it. 66 $hsInput.on("blur", hideSearch); 67 68 // Helper function to show the search form. 69 function showSearch() { 70 $header.addClass("search-visible"); 71 $hsWrap.fadeIn("fast").find('input[type="search"]').focus(); 72 $hsToggle.attr("aria-expanded", true); 73 } 74 75 // Helper function to hide the search form. 76 function hideSearch() { 77 $hsWrap 78 .fadeOut("fast") 79 .parents(".site-header") 80 .removeClass("search-visible"); 81 $hsToggle.attr("aria-expanded", false); 82 } 83 84 // Keydown handler function for toggling search field visibility. 85 function handleKeyDown(event) { 86 // Enter/Space, respectively. 87 if (13 === event.keyCode || 32 === event.keyCode) { 88 event.preventDefault(); 89 90 if ($(event.target).hasClass("close")) { 91 hideSearch(); 92 } else { 93 showSearch(); 94 } 95 } 96 } 97 98 if ($("body.single-project .foogallery")) { 99 imgOrientation(); 100 } 101 102 function imgOrientation() { 103 var pics = document.querySelectorAll("img"); 104 var pic; 105 for (i = 0; i < pics.length; i++) { 106 pic = pics[i]; 107 if (pic.complete) { 108 // The image is already loaded, call handler 109 checkImage(pic); 110 } else { 111 // The image is not loaded yet, set load event handler 112 pic.addEventListener("load", function () { 113 checkImage(this); 114 }); 115 } 116 } 117 118 function checkImage(img) { 119 if (img.naturalHeight > img.naturalWidth) { 120 img.classList.add("portrait"); 121 $(img).closest(".fg-item").addClass("portrait"); 122 } else { 123 img.classList.add("landscape"); 124 $(img).closest(".fg-item").addClass("landscape"); 125 } 126 } 127 } 128 129 if ($("body.blog") || $("body.archive.category")) { 130 addAllCatsLink(); 131 } 132 133 function addAllCatsLink() { 134 $(".widget_categories nav > ul").prepend( 135 '<li class="cat-item cat-item-all"><a href="/journal">All Posts</a></li>' 136 ); 137 } 138})(jQuery);
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.