1/** 2 * AVWP Public JS 3 * 4 * Age Verification for WordPress utilizes the following open source javascript plugin. Thanks Michael! 5 * 6 * Plugin: ageCheck.js 7 * Description: A simple plugin to verify user's age. Uses sessionStorage API to store if user is verified - only kept until browser is closed. 8 * Options can be passed for easy customization. 9 * Author: Michael Soriano 10 * Author's website: http://fearlessflyer.com 11 * 12 */ 13(function ($) { 14 "use strict"; 15 $.ageCheck = function (options) { 16 const settings = $.extend({ 17 minAge: 18, 18 redirectTo: "", 19 redirectOnFail: "", 20 title: "Age Verification", 21 copy: "You must be [age] years old to enter.", 22 btnYes: "YES", 23 btnNo: "NO", 24 successTitle: "Success!", 25 successText: "You are now being redirected back to the site...", 26 successMessage: "show", 27 failTitle: "Sorry", 28 failText: "You are not old enough to view this site...", 29 failMessage: "show", 30 cookieDays: 30, 31 adminDebug: "", 32 beforeContent: "", 33 afterContent: "", 34 logoHeight: "", 35 logoWidth: "", 36 }, options); 37 38 const _this = { 39 age: "", 40 errors: [], 41 setValues() {
42 const month = $(".avwp-av .month").val(); 43 const day = $(".avwp-av .day").val(); 44 _this.month = month; 45 _this.day = day.replace(/^0+/, ""); // remove leading zero 46 _this.year = $(".avwp-av .year").val(); 47 }, 48 validate() { 49 _this.errors = []; 50 if (/^([0-9]|[12]\d|3[0-1])$/.test(_this.day) === false) { 51 _this.errors.push("Day is invalid or empty"); 52 } 53 if (/^(19|20)\d{2}$/.test(_this.year) === false) { 54 _this.errors.push("Year is invalid or empty"); 55 } 56 _this.clearErrors(); 57 _this.displayErrors(); 58 return _this.errors.length < 1; 59 }, 60 clearErrors() { 61 $(".errors").html(""); 62 }, 63 displayErrors() { 64 let html = "<ul>"; 65 for (let i = 0; i < _this.errors.length; i++) { 66 html += `<li><span>x</span>${_this.errors[i]}</li>`; 67 } 68 html += "</ul>"; 69 setTimeout(() => { 70 $(".avwp-av .errors").html(html); 71 }, 200); 72 }, 73 reCenter(b) { 74 b.css("top", `${Math.max(0, (($(window).height() - (b.outerHeight() + 150)) / 2))}px`); 75 b.css("left", `${Math.max(0, (($(window).width() - b.outerWidth()) / 2))}px`); 76 }, 77 buildHtml() { 78 const copy = settings.copy; 79 let html = ""; 80 html += "<div class=\"avwp-av-overlay\"></div>"; 81 html += "<div class=\"avwp-av\">"; 82 if (settings.beforeContent !== "") { 83 html += settings.beforeContent; 84 } 85 if (settings.imgLogo !== "") { 86 html += "<img src=\"" + settings.imgLogo + "\" alt=\"" + settings.title + "\" width=\"" + settings.logoWidth + "\" height=\"" + settings.logoHeight + "\" />"; 87 } 88 if (settings.title !== "") { 89 html += `<h2>${settings.title}</h2>`; 90 } 91 html += `<p>${copy.replace("[age]", `<strong>${settings.minAge}</strong>`)}`; + `</p>`; 92 html += `<p><button class="yes">${settings.btnYes}</button><button class="no">${settings.btnNo}</button></p>`; 93 if (settings.afterContent !== "") { 94 html += settings.afterContent; 95 } 96 html += "</div></div>"; 97 $("body").append(html); 98 99 $(".avwp-av-overlay").animate({ 100 opacity: 1, 101 }, 500, () => { 102 _this.reCenter($(".avwp-av")); 103 $(".avwp-av").css({ 104 opacity: 1, 105 }); 106 }); 107 108 $(".avwp-av .day, .avwp-av .year").focus(function () { 109 $(this).removeAttr("placeholder"); 110 }); 111 }, 112 setAge() { 113 _this.age = ""; 114 _this.age = Math.abs(Date.now() - 1970); 115 }, 116 setSessionStorage(key, val) { 117 try { 118 sessionStorage.setItem(key, val); 119 return true; 120 } catch (e) { 121 return false; 122 } 123 }, 124 handleSuccess() { 125 const successMsg = `<h2>${settings.successTitle}</h2><p>${settings.successText}</p>`; 126 if (settings.messageTime != 0) { 127 $(".avwp-av").html(successMsg); 128 } 129 setTimeout(() => { 130 $(".avwp-av").animate({ 131 top: "-350px", 132 }, settings.successTime, () => { 133 $(".avwp-av-overlay").animate({ 134 opacity: "0", 135 }, settings.messageTime, () => { 136 if (settings.redirectTo !== "") { 137 window.location.replace(settings.redirectTo); 138 } else { 139 $(".avwp-av-overlay, .avwp-av").remove(); 140 } 141 }); 142 }); 143 }, settings.messageTime); 144 }, 145 handleUnderAge() { 146 const underAgeMsg = `<h2>${settings.failTitle}</h2><p>${settings.failText}</p>`; 147 $(".avwp-av").html(underAgeMsg); 148 if (settings.redirectOnFail !== "") { 149 setTimeout(() => { 150 window.location.replace(settings.redirectOnFail); 151 }, settings.messageTime); 152 } 153 }, 154 }; // end _this 155
156 // Check for cookie and reture false if it's set. 157 var cookiereader = readCookie("age-verification"); 158 if (cookiereader) { 159 if (settings.adminDebug !== "") { 160 eraseCookie("age-verification"); 161 } else { 162 return false; 163 } 164 } 165 166 // Create pop up. 167 _this.buildHtml(); 168 169 // Successful "YES" button click. 170 $(".avwp-av button.yes").on("click", () => { 171 createCookie("age-verification", "true", settings.cookieDays); 172 _this.handleSuccess(); 173 }); 174 175 // Successful "NO" button click. 176 $(".avwp-av button.no").on("click", () => { 177 _this.handleUnderAge(); 178 }); 179 180 $(window).resize(() => { 181 _this.reCenter($(".avwp-av")); 182 setTimeout(() => { 183 _this.reCenter($(".avwp-av")); 184 }, 500); 185 }); 186 }; 187}(jQuery)); 188 189jQuery(document).ready(function($) { 190 $.ageCheck({ 191 "bgImage" : object_name.bgImage, 192 "minAge" : object_name.minAge, 193 "imgLogo" : object_name.imgLogo, 194 "logoWidth" : object_name.logoWidth, 195 "logoHeight" : object_name.logoHeight, 196 "title" : object_name.title, 197 "copy" : object_name.copy, 198 "btnYes" : object_name.btnYes, 199 "btnNo" : object_name.btnNo, 200 "redirectOnFail" : object_name.redirectOnFail, 201 "successTitle" : object_name.successTitle, 202 "successText" : object_name.successText, 203 "successMessage" : object_name.successMessage, 204 "failTitle" : object_name.failTitle, 205 "failText" : object_name.failText, 206 "messageTime" : object_name.messageTime, 207 "cookieDays" : object_name.cookieDays, 208 "adminDebug" : object_name.adminDebug, 209 "beforeContent" : object_name.beforeContent, 210 "afterContent" : object_name.afterContent 211 }); 212});
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.