1/** FOXIZ_CORE_SCRIPT */ 2var FOXIZ_CORE_SCRIPT = (function (Module, $) { 3 "use strict"; 4 5 Module.init = function () { 6 this.yesStorage = this.isStorageAvailable(); 7 this._body = $('body'); 8 this.themeSettings = foxizCoreParams || {}; 9 this.darkModeID = this.themeSettings.darkModeID || 'RubyDarkMode'; 10 this.mSiteID = this.themeSettings.mSiteID || null; 11 this.isCMode = document.body.classList.contains("is-cmode"); 12 this.personalizeUID = this.getUserUUID(); 13 this.initDarkModeCookie(); 14 this.switchDarkMode(); 15 this.noteToggle(); 16 this.passwordToggle(); 17 this.emailToDownload(); 18 } 19 20 /** 21 * generate UUID 22 * @returns {string} 23 */ 24 Module.generateUUID = function () { 25 const alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'; 26 let id = ''; 27 for (let i = 0; i < 7; i++) { 28 const randomIndex = Math.floor(Math.random() * alphabet.length); 29 id += alphabet[randomIndex]; 30 } 31 return id; 32 } 33 34 /** 35 * set cookies 36 * @param name 37 * @param value 38 * @param days 39 */ 40 Module.setCookie = function (name, value, days = 60) { 41 42 const date = new Date(); 43 date.setTime(date.getTime() + Math.round(days * 24 * 60 * 60 * 1000)); 44 45 const expires = '; expires=' + date.toUTCString(); 46 const cookieDomain = this.themeSettings.cookieDomain || ''; 47 const cookiePath = this.themeSettings.cookiePath || '/'; 48 49 document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=' + cookiePath + '; domain=' + cookieDomain; 50 } 51 52 /** 53 * get cookie 54 * @param name 55 * @returns {string|null} 56 */ 57 Module.getCookie = function (name) { 58 const nameEQ = name + '='; 59 const cookies = document.cookie.split(';'); 60 for (let i = 0; i < cookies.length; i++) { 61 let cookie = cookies[i]; 62 while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length); 63 if (cookie.indexOf(nameEQ) == 0) return decodeURIComponent(cookie.substring(nameEQ.length, cookie.length)); 64 } 65 return null; 66 } 67 68 /** 69 * delete cookies 70 * @param name 71 */ 72 Module.deleteCookie = function (name) { 73 const cookieDomain = this.themeSettings.cookieDomain || ''; 74 const cookiePath = this.themeSettings.cookiePath || '/'; 75 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=' + cookiePath + '; domain=' + cookieDomain; 76 } 77 78 /** 79 * 80 * @returns {boolean} 81 */ 82 Module.isStorageAvailable = function () { 83 let storage; 84 try { 85 storage = window['localStorage']; 86 storage.setItem('__rbStorageSet', 'x'); 87 storage.removeItem('__rbStorageSet'); 88 return true; 89 } catch (e) { 90 return false; 91 } 92 } 93 94 /** 95 * set localStorage 96 * @param key 97 * @param data 98 */ 99 Module.setStorage = function (key, data) { 100 this.yesStorage && localStorage.setItem(key, typeof data === 'string' ? data : JSON.stringify(data)); 101 } 102 103 /** 104 * get localStorage 105 * @param key 106 * @param defaultValue 107 * @returns {any} 108 */ 109 Module.getStorage = function (key, defaultValue) { 110 if (!this.yesStorage) return null; 111 const data = localStorage.getItem(key); 112 if (data === null) return defaultValue; 113 try { 114 return JSON.parse(data); 115 } catch (e) { 116 return data; 117 } 118 } 119 120 /** 121 * delelte localStorage 122 * @param key 123 */ 124 Module.deleteStorage = function (key) { 125 this.yesStorage && localStorage.removeItem(key); 126 } 127 128 /** 129 * create UUID 130 * @returns {string|*} 131 */ 132 Module.getUserUUID = function () { 133 134 let uuid; 135 if (this.getCookie('RBUUID')) { 136 uuid = this.getCookie('RBUUID'); 137 } else { 138 uuid = this.getStorage('RBUUID', null); 139 if (null === uuid) { 140 uuid = this.generateUUID(); 141 this.setStorage('RBUUID', uuid); 142 this.themeSettings.yesPersonalized && this.setCookie('personalize_sync', 'yes', 1); 143 } 144 this.themeSettings.yesPersonalized && this.setCookie('RBUUID', uuid); 145 } 146 147 if (this.mSiteID) { 148 uuid = this.mSiteID + uuid; 149 } 150 151 return uuid; 152 } 153 154 Module.initDarkModeCookie = function () { 155 if (this.isCMode && !this.getCookie(this.darkModeID)) { 156 this.setCookie(this.darkModeID, document.body.getAttribute('data-theme')); 157 } 158 } 159 160 Module.setDarkModeCookie = function (name, value) { 161 if (this.isCMode) { 162 this.setCookie(name, value); 163 } 164 } 165 166 Module.switchDarkMode = function () { 167 const self = this; 168 const toggleSelector = '.dark-mode-toggle'; 169 const iconDefault = $('.mode-icon-default'); 170 const iconDark = $('.mode-icon-dark'); 171 172 $(toggleSelector).off('click').on('click', function (e) { 173 e.preventDefault(); 174 e.stopPropagation(); 175 176 const target = $(this); 177 if (!target.hasClass('triggered')) { 178 target.addClass('triggered'); 179 } 180 181 const useStorage = !self.isCMode && self.yesStorage; 182 const currentMode = useStorage 183 ? self.getStorage(self.darkModeID) 184 : document.body.getAttribute('data-theme'); 185 186 const isDark = currentMode === 'dark'; 187 const nextMode = isDark ? 'default' : 'dark'; 188 189 if (useStorage) { 190 self.setStorage(self.darkModeID, nextMode); 191 } 192 self.setDarkModeCookie(self.darkModeID, nextMode); 193 self._body.attr('data-theme', nextMode).addClass('switch-smooth'); 194 195 iconDefault.toggleClass('activated', nextMode === 'default'); 196 iconDark.toggleClass('activated', nextMode === 'dark'); 197 }); 198 }; 199 200 201 /** share action */ 202 Module.shareTrigger = function () { 203 204 $('a.share-trigger').off('click').on('click', function (e) { 205 e.preventDefault(); 206 e.stopPropagation(); 207 window.open($(this).attr('href'), '_blank', 'width=600, height=350'); 208 return false;
209 }); 210 211 const copyButton = $('a.copy-trigger'); 212 if (navigator.clipboard) { 213 copyButton.off('click').on('click', function (e) { 214 e.preventDefault(); 215 e.stopPropagation(); 216 const target = $(this); 217 const link = target.data('link'); 218 const copied = target.data('copied'); 219 if (link) { 220 navigator.clipboard.writeText(link).then( 221 function () { 222 $('body').find('.tipsy-inner').html((copied)); 223 }).catch(function () { 224 }); 225 } 226 }); 227 } else { 228 copyButton.hide(); 229 } 230 231 const shareButton = $('a.native-share-trigger'); 232 if (navigator.share) { 233 shareButton.on('click', function (e) { 234 e.preventDefault(); 235 e.stopPropagation(); 236 237 const target = $(this); 238 const link = target.data('link'); 239 const title = target.data('ptitle'); 240 navigator.share({ 241 title: title, 242 url: link 243 }) 244 }); 245 } else { 246 shareButton.hide(); 247 } 248 }; 249 250 /** single infinite load */ 251 Module.loadGoogleAds = function (response) { 252 const googleAds = $(response).find('.adsbygoogle'); 253 if (typeof window.adsbygoogle !== 'undefined' && googleAds.length) { 254 var adsbygoogle; 255 googleAds.each(function () { 256 (adsbygoogle = window.adsbygoogle || []).push({}); 257 }); 258 } 259 } 260 261 Module.loadInstagram = function (response) { 262 let instEmbed = $(response).find('.instagram-media'); 263 if ('undefined' !== typeof window.instgrm) { 264 window.instgrm.Embeds.process(); 265 } else if (instEmbed.length && 'undefined' === typeof window.instgrm) { 266 const embedJS = document.createElement('script'); 267 embedJS.src = '//platform.instagram.com/en_US/embeds.js'; 268 embedJS.onload = function () { 269 window.instgrm.Embeds.process(); 270 }; 271 this._body.append(embedJS); 272 } 273 } 274 275 Module.loadTwttr = function () { 276 if (typeof twttr !== 'undefined' && typeof twttr.widgets !== 'undefined') { 277 twttr.ready(function (twttr) { 278 twttr.widgets.load(); 279 }); 280 } 281 } 282 283 Module.updateGA = function (article) { 284 const gaURL = article.postURL.replace(/https?:\/\/[^\/]+/i, ''); 285 if (typeof _gaq !== 'undefined' && _gaq !== null) { 286 _gaq.push(['_trackPageview', gaURL]); 287 } 288 if (typeof ga !== 'undefined' && ga !== null) { 289 ga('send', 'pageview', gaURL); 290 } 291 if (typeof __gaTracker !== 'undefined' && __gaTracker !== null) { 292 __gaTracker('send', 'pageview', gaURL); 293 } 294 295 if (window.googletag && googletag.pubadsReady) { 296 googletag.pubads().refresh(); 297 } 298 } 299 300 Module.noteToggle = function () { 301 $('.yes-toggle > .note-header').on('click', function () { 302 let wrapper = $(this).parent(); 303 let timing = wrapper.hasClass('is-inline') ? 0 : 300; 304 305 wrapper.toggleClass('explain'); 306 wrapper.find('.note-content').slideToggle(timing); 307 }); 308 } 309 310 Module.passwordToggle = function () { 311 $('.rb-password-toggle').on('click', function () { 312 const $this = $(this); 313 const $input = $this.prev('input'); 314 const $icon = $this.find('i'); 315 316 if ($input.attr('type') === 'password') { 317 $input.attr('type', 'text'); 318 $icon.removeClass('rbi-show').addClass('rbi-hide'); 319 } else { 320 $input.attr('type', 'password'); 321 $icon.removeClass('rbi-hide').addClass('rbi-show'); 322 } 323 }); 324 } 325 326 Module.isValidEmail = function (email) { 327 const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 328 return emailRegex.test(email); 329 } 330 331 Module.emailToDownload = function () { 332 const self = this; 333 334 $('.download-form').each(function () { 335 const form = $(this); 336 const acceptTermsCheckbox = form.find('input[name="acceptTerms"]'); 337 const submitButton = form.find('input[type="submit"]'); 338 const noticeText = form.find('.notice-text'); 339 340 if (acceptTermsCheckbox.length > 0) { 341 acceptTermsCheckbox.change(function () { 342 submitButton.prop('disabled', !this.checked); 343 }); 344 } 345 346 form.submit(function (event) { 347 event.preventDefault(); 348 349 const emailInput = form.find('input[name="EMAIL"]'); 350 const email = emailInput.val(); 351 const label = form.find('input[type="submit"]').val(); 352 noticeText.empty(); 353 354 if (!self.isValidEmail(email)) { 355 const errorNotice = 'Please enter a valid email address.'; 356 noticeText.text(errorNotice); 357 return; 358 } 359 360 const wrapper = form.parents('.gb-download'); 361 wrapper.addClass('submitting'); 362 363 $.ajax({ 364 url: self.themeSettings.ajaxurl || null, 365 method: 'POST', 366 data: form.serialize(), 367 success: function (response) { 368 const fileURL = response.file; 369 if (fileURL) { 370 const link = document.createElement('a'); 371 link.href = fileURL; 372 link.setAttribute('download', ''); 373 link.click(); 374 const newContent = `<div class="fallback-info">${response.message}</div><a href="${response.file}" download="" rel="nofollow" class="is-btn gb-download-btn fallback-download-btn">${label}</a>`; 375 form.replaceWith(newContent); 376 } else { 377 noticeText.text(response.message); 378 } 379 wrapper.removeClass('submitting'); 380 } 381 }); 382 }); 383 }); 384 }; 385 386 return Module; 387 388}(FOXIZ_CORE_SCRIPT || {}, jQuery)); 389 390jQuery(document).ready(function () {
391 FOXIZ_CORE_SCRIPT.init(); 392}); 393 394jQuery(window).on('load', function () { 395 FOXIZ_CORE_SCRIPT.shareTrigger(); 396});
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.