1let bioEp = { 2 // Private variables 3 bgEl: {}, 4 popupEl: {}, 5 closeBtnEl: {}, 6 shown: false, 7 overflowDefault: "visible", 8 transformDefault: "", 9 10 // Popup options 11 id:'1', 12 width: 400, 13 height: 220, 14 html: "", 15 css: "", 16 fonts: [], 17 delay: 5, 18 showOnDelay: false, 19 cookieExp: 30, 20 showOncePerSession: false, 21 elastic: false, 22 onPopup: null, 23 24 // Object for handling cookies, taken from QuirksMode 25 // http://www.quirksmode.org/js/cookies.html 26 cookieManager: { 27 // Create a cookie 28 create: function(name, value, days, sessionOnly) { 29 var expires = ""; 30 31 if(sessionOnly){ 32 expires = "; expires=0" 33 }else if(days) { 34 var date = new Date(); 35 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 36 expires = "; expires=" + date.toGMTString(); 37 } 38 39 document.cookie = name + "=" + value + expires + "; path=/"; 40 }, 41 42 // Get the value of a cookie 43 get: function(name) { 44 var nameEQ = name + "="; 45 var ca = document.cookie.split(";"); 46 47 for(var i = 0; i < ca.length; i++) { 48 var c = ca[i]; 49 while (c.charAt(0) == " ") 50 { 51 c = c.substring(1, c.length); 52 } 53 if (c.indexOf(nameEQ) === 0){ 54 return c.substring(nameEQ.length, c.length); 55 } 56 } 57 58 return null; 59 }, 60 61 // Delete a cookie 62 erase: function(name) { 63 this.create(name, "", -1); 64 } 65 }, 66 67 // Handle the bioep_shown cookie 68 // If present and true, return true 69 // If not present or false, create and return false 70 checkCookie: function() { 71 // Handle cookie reset 72 if(this.cookieExp <= 0) { 73 // Handle showing pop up once per browser session. 74 if(this.showOncePerSession && this.cookieManager.get("bioep_shown_session_"+ this.id) == "true"){ 75 return true; 76 } 77 78 this.cookieManager.erase("bioep_shown_"+ this.id); 79 return false; 80 } 81 82 // If cookie is set to true 83 if(this.cookieManager.get("bioep_shown_"+ this.id) == "true"){ 84 return true; 85 } 86 87 return false; 88 }, 89 90 // Add font stylesheets and CSS for the popup 91 addCSS: function() { 92 // Add font stylesheets 93 for(var i = 0; i < this.fonts.length; i++) { 94 var font = document.createElement("link"); 95 font.href = this.fonts[i]; 96 font.type = "text/css"; 97 font.rel = "stylesheet"; 98 document.head.appendChild(font); 99 } 100 101 var dimensions = this.elastic ? '' : "width: " + this.width + "px; height: " + this.height + "px; "; 102 103 // Base CSS styles for the popup 104 var css = document.createTextNode( 105 "#bio_ep_bg_"+ this.id +" {display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; opacity: 0.3; z-index: 100101;}" + 106 "#bio_ep_"+ this.id +" {display: none; position: fixed; "+ dimensions +"font-family: 'Titillium Web', sans-serif; font-size: 16px; left: 50%; top: 50%; transform: translateX(-50%) translateY(-50%); -webkit-transform: translateX(-50%) translateY(-50%); -ms-transform: translateX(-50%) translateY(-50%); background-color: #fff; box-shadow: 0px 1px 4px 0 rgba(0,0,0,0.5); z-index: 100102;}" + 107 "#bio_ep_close_"+ this.id +" {position: absolute; left: 100%; margin: -8px 0 0 -12px; width: 20px; height: 20px; color: #fff; font-size: 12px; font-weight: bold; text-align: center; border-radius: 50%; background-color: #5c5c5c; cursor: pointer; line-height: 20px; z-index: 102001;}" + 108 this.css 109 ); 110 111 // Create the style element 112 var style = document.createElement("style"); 113 style.appendChild(css); 114 115 // Insert it before other existing style 116 // elements so user CSS isn't overwritten 117 var headFirstChild = document.head.firstElementChild; 118 document.head.insertBefore(style, headFirstChild); 119 }, 120 121 // Add the popup to the page 122 addPopup: function() { 123 124 // Add the background div 125 this.bgEl = document.createElement("div"); 126 this.bgEl.id = "bio_ep_bg_"+ this.id; 127 document.body.appendChild(this.bgEl); 128 129 // Add the popup 130 if(document.getElementById("bio_ep_"+ this.id)){ 131 this.popupEl = document.getElementById("bio_ep_"+ this.id); 132 }else{ 133 this.popupEl = document.createElement("div"); 134 this.popupEl.id = "bio_ep_"+ this.id; 135 this.popupEl.innerHTML = this.html; 136 document.body.appendChild(this.popupEl); 137 } 138 139 // Add the close button 140 if(document.getElementById("bio_ep_close_"+ this.id)){ 141 this.closeBtnEl = document.getElementById("bio_ep_close_"+ this.id); 142 }else{ 143 this.closeBtnEl = document.createElement("div"); 144 this.closeBtnEl.id = "bio_ep_close_"+ this.id; 145 this.closeBtnEl.appendChild(document.createTextNode("X")); 146 this.popupEl.insertBefore(this.closeBtnEl, this.popupEl.firstChild); 147 } 148 }, 149 150 // Show the popup 151 showPopup: function() { 152 if(this.shown){ 153 return; 154 } 155 156 this.bgEl.style.display = "block"; 157 this.popupEl.style.display = "block"; 158 159 // Handle scaling 160 this.scalePopup(); 161 162 // Save body overflow value and hide scrollbars 163 this.overflowDefault = document.body.style.overflow; 164 document.body.style.overflow = "hidden"; 165 166 this.shown = true; 167 168 this.cookieManager.create("bioep_shown_"+ this.id, "true", this.cookieExp, false); 169 this.cookieManager.create("bioep_shown_session_"+ this.id, "true", 0, true); 170 171 if(typeof this.onPopup === "function") { 172 this.onPopup(); 173 } 174 }, 175 176 // Hide the popup 177 hidePopup: function() { 178 this.bgEl.style.display = "none"; 179 this.popupEl.style.display = "none"; 180 181 // Set body overflow back to default to show scrollbars 182 //document.body.style.overflow = this.overflowDefault; 183 // fix for WP 184 document.body.style.overflow = 'visible'; 185 }, 186 187 // Handle scaling the popup 188 scalePopup: function() {
189 let $this = this; 190 var margins = { width: 40, height: 40 }; 191 var popupSize = { width: $this.popupEl.offsetWidth, height: $this.popupEl.offsetHeight }; 192 var windowSize = { width: window.innerWidth, height: window.innerHeight }; 193 var newSize = { width: 0, height: 0 }; 194 var aspectRatio = popupSize.width / popupSize.height; 195 196 // First go by width, if the popup is larger than the window, scale it 197 if(popupSize.width > (windowSize.width - margins.width)) { 198 newSize.width = windowSize.width - margins.width; 199 newSize.height = newSize.width / aspectRatio; 200 201 // If the height is still too big, scale again 202 if(newSize.height > (windowSize.height - margins.height)) { 203 newSize.height = windowSize.height - margins.height; 204 newSize.width = newSize.height * aspectRatio; 205 } 206 } 207 208 // If width is fine, check for height 209 if(newSize.height === 0) { 210 if(popupSize.height > (windowSize.height - margins.height)) { 211 newSize.height = windowSize.height - margins.height; 212 newSize.width = newSize.height * aspectRatio; 213 } 214 } 215 216 // Set the scale amount 217 var scaleTo = newSize.width / popupSize.width; 218 219 // If the scale ratio is 0 or is going to enlarge (over 1) set it to 1 220 if(scaleTo <= 0 || scaleTo > 1){ 221 scaleTo = 1; 222 } 223 224 // Save current transform style 225 if(this.transformDefault === ""){ 226 this.transformDefault = window.getComputedStyle(this.popupEl, null).getPropertyValue("transform"); 227 } 228 229 // Apply the scale transformation 230 this.popupEl.style.transform = this.transformDefault + " scale(" + scaleTo + ")"; 231 }, 232 233 // Event listener initialisation for all browsers 234 addEvent: function (obj, event, callback) { 235 if(obj.addEventListener){ 236 obj.addEventListener(event, callback, false); 237 }else if(obj.attachEvent){ 238 obj.attachEvent("on" + event, callback); 239 } 240 }, 241 242 // Load event listeners for the popup 243 loadEvents: function() { 244 let $this = this; 245 246 // Track mouseout event on document 247 this.addEvent(document, "mouseout", function(e) { 248 e = e ? e : window.event; 249 250 // If this is an autocomplete element. 251 if(e.target.tagName.toLowerCase() == "input"){ 252 return; 253 } 254 255 // Get the current viewport width. 256 var vpWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); 257 258 // If the current mouse X position is within 50px of the right edge 259 // of the viewport, return. 260 if(e.clientX >= (vpWidth - 50)){ 261 return; 262 } 263 264 // If the current mouse Y position is not within 50px of the top 265 // edge of the viewport, return. 266 if(e.clientY >= 50){ 267 return; 268 } 269 270 // Reliable, works on mouse exiting window and 271 // user switching active program 272 var from = e.relatedTarget || e.toElement; 273 if(!from){ 274 $this.showPopup(); 275 } 276 277 }.bind(this)); 278 279 // Handle the popup close button 280 this.addEvent(this.closeBtnEl, "click", function() { 281 $this.hidePopup(); 282 }); 283 284 // Handle window resizing 285 this.addEvent(window, "resize", function() { 286 $this.scalePopup(); 287 }); 288 }, 289 290 // Set user defined options for the popup 291 setOptions: function(opts) { 292 this.id = (typeof opts.id === 'undefined') ? this.id : opts.id; 293 this.width = (typeof opts.width === 'undefined') ? this.width : opts.width; 294 this.height = (typeof opts.height === 'undefined') ? this.height : opts.height; 295 this.html = (typeof opts.html === 'undefined') ? this.html : opts.html; 296 this.css = (typeof opts.css === 'undefined') ? this.css : opts.css; 297 this.fonts = (typeof opts.fonts === 'undefined') ? this.fonts : opts.fonts;
298 this.delay = (typeof opts.delay === 'undefined') ? this.delay : opts.delay; 299 this.showOnDelay = (typeof opts.showOnDelay === 'undefined') ? this.showOnDelay : opts.showOnDelay; 300 this.cookieExp = (typeof opts.cookieExp === 'undefined') ? this.cookieExp : opts.cookieExp; 301 this.showOncePerSession = (typeof opts.showOncePerSession === 'undefined') ? this.showOncePerSession : opts.showOncePerSession; 302 this.elastic = (typeof opts.elastic === 'undefined') ? this.elastic : opts.elastic; 303 this.onPopup = (typeof opts.onPopup === 'undefined') ? this.onPopup : opts.onPopup; 304 }, 305 306 // Ensure the DOM has loaded 307 domReady: function(callback) { 308 (document.readyState === "interactive" || document.readyState === "complete") ? callback() : this.addEvent(document, "DOMContentLoaded", callback); 309 }, 310 311 // Initialize 312 init: function(opts) { 313 314 let $this = this; 315 316 // Handle options 317 if(typeof opts !== 'undefined'){ 318 this.setOptions(opts); 319 } 320 321 // Add CSS here to make sure user HTML is hidden regardless of cookie 322 this.addCSS(); 323 324 // Once the DOM has fully loaded 325 this.domReady(function() { 326 // Handle the cookie 327 if($this.checkCookie()){ 328 return; 329 } 330 331 // Add the popup 332 $this.addPopup(); 333 334 // Load events 335 setTimeout(function() { 336 $this.loadEvents(); 337 338 if($this.showOnDelay){ 339 $this.showPopup(); 340 } 341 342 }, $this.delay * 1000); 343 }); 344 } 345}
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.