Cleanup Javascript #2185
| @@ -1,8 +1,7 @@ | |||||||
| document.querySelectorAll(".onclick-select").forEach(element => { | document.querySelectorAll(".onclick-select").forEach((element) => { | ||||||
|   element.addEventListener("click", element.select); |   element.addEventListener("click", element.select); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  |  | ||||||
| // Navbar dropdowns | // Navbar dropdowns | ||||||
| const navSections = document.querySelectorAll(".nav-details"); | const navSections = document.querySelectorAll(".nav-details"); | ||||||
|  |  | ||||||
| @@ -11,23 +10,25 @@ navSections.forEach(navSection => { | |||||||
| }); | }); | ||||||
| document.addEventListener("click", navSectionsClose); | document.addEventListener("click", navSectionsClose); | ||||||
|  |  | ||||||
| function navSectionsToggle() { | const navSectionsToggle = () => { | ||||||
|   // When opening next dropdown, hide previous |   // When opening next dropdown, hide previous | ||||||
|   if (this.open) { |   if (this.open) { | ||||||
|     navSections.forEach(navSection => { |     navSections.forEach((navSection) => { | ||||||
|       if (navSection != this && navSection.open) navSection.open = !open; |       if (navSection != this && navSection.open) { | ||||||
|  |         navSection.open = !open; | ||||||
|  |       } | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| function navSectionsClose(event) { | const navSectionsClose = (event) => { | ||||||
|   // Hide all dropdowns when clicking in different place |   // Hide all dropdowns when clicking in different place | ||||||
|   if ( |   if ( | ||||||
|     event.target.matches(".nav-summary") || |     event.target.matches(".nav-summary") || | ||||||
|     event.target.parentNode.matches(".nav-summary") |     event.target.parentNode.matches(".nav-summary") | ||||||
|   ) |   ) | ||||||
|     return; |     return; | ||||||
|   navSections.forEach(navSection => { |   navSections.forEach((navSection) => { | ||||||
|     navSection.open = !open; |     navSection.open = !open; | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
| @@ -37,11 +38,11 @@ function navSectionsClose(event) { | |||||||
| document.querySelector("#nav-switch-theme").style.display = "inline"; | document.querySelector("#nav-switch-theme").style.display = "inline"; | ||||||
| document.querySelector("#nav-switch-theme").addEventListener("click", changeColorScheme); | document.querySelector("#nav-switch-theme").addEventListener("click", changeColorScheme); | ||||||
|  |  | ||||||
| function changeColorScheme() { | const changeColorScheme = () => { | ||||||
|   // Use whatever users want |   // Use whatever users want | ||||||
|   if (localStorage.getItem("colorScheme") === "dark") { |   if (localStorage.getItem("colorScheme") === "dark") { | ||||||
|     // Change to light theme |     // Change to light theme | ||||||
|     if (window.matchMedia("(prefers-color-scheme: dark)").matches === false) { |     if (!window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||||||
|       document.querySelector("#dark-css").setAttribute("media", "(prefers-color-scheme: dark)"); |       document.querySelector("#dark-css").setAttribute("media", "(prefers-color-scheme: dark)"); | ||||||
|       localStorage.removeItem("colorScheme"); |       localStorage.removeItem("colorScheme"); | ||||||
|     } else { |     } else { | ||||||
| @@ -52,7 +53,7 @@ function changeColorScheme() { | |||||||
|   } |   } | ||||||
|   // Change to dark theme |   // Change to dark theme | ||||||
|   else if (localStorage.getItem("colorScheme") === "light") { |   else if (localStorage.getItem("colorScheme") === "light") { | ||||||
|     if (window.matchMedia("(prefers-color-scheme: dark)").matches === true) { |     if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||||||
|       document.querySelector("#dark-css").setAttribute("media", "(prefers-color-scheme: dark)"); |       document.querySelector("#dark-css").setAttribute("media", "(prefers-color-scheme: dark)"); | ||||||
|       localStorage.removeItem("colorScheme"); |       localStorage.removeItem("colorScheme"); | ||||||
|     } else { |     } else { | ||||||
| @@ -63,7 +64,7 @@ function changeColorScheme() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Just use whatever browsers want |   // Just use whatever browsers want | ||||||
|   else if (window.matchMedia("(prefers-color-scheme: dark)").matches === true) { |   else if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||||||
|     // Change to light Theme |     // Change to light Theme | ||||||
|     document.querySelector("#dark-css").setAttribute("media", "invalid"); |     document.querySelector("#dark-css").setAttribute("media", "invalid"); | ||||||
|     localStorage.setItem("colorScheme", "light"); |     localStorage.setItem("colorScheme", "light"); | ||||||
| @@ -78,16 +79,15 @@ function changeColorScheme() { | |||||||
|  |  | ||||||
| // Fix images in dark theme | // Fix images in dark theme | ||||||
| function fixThemeImages() { | function fixThemeImages() { | ||||||
|   document.querySelectorAll('[data-theme-src]').forEach(function(image) { |   document.querySelectorAll('[data-theme-src]').forEach((image) => { | ||||||
|     tempSrc = image.src; |     const tempSrc = image.src; | ||||||
|     image.src = image.getAttribute("data-theme-src"); |     image.src = image.getAttribute("data-theme-src"); | ||||||
|     image.setAttribute("data-theme-src", tempSrc); |     image.setAttribute("data-theme-src", tempSrc); | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
| if ( | if (localStorage.getItem("colorScheme") === "dark" || | ||||||
|   (localStorage.getItem("colorScheme") === "dark") || |     window.matchMedia("(prefers-color-scheme: dark)").matches ^ | ||||||
|   (window.matchMedia("(prefers-color-scheme: dark)").matches ^ |     localStorage.getItem("colorScheme") === "light" | ||||||
|     localStorage.getItem("colorScheme") === "light") |  ) { | ||||||
| ) { |  | ||||||
|   fixThemeImages(); |   fixThemeImages(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,33 +1,38 @@ | |||||||
| if (window.location == 'https://www.privacytools.io/#ukusa') {	window.location = 'https://www.privacytools.io/providers/';} | const redirectLinks = { | ||||||
| if (window.location == 'https://www.privacytools.io/#vpn') {	window.location = 'https://www.privacytools.io/providers/vpn/';} |     'https://www.privacytools.io/#ukusa': 'https://www.privacytools.io/providers/', | ||||||
| if (window.location == 'https://www.privacytools.io/#email') {	window.location = 'https://www.privacytools.io/providers/email/';} |     'https://www.privacytools.io/#vpn': 'https://www.privacytools.io/providers/vpn/', | ||||||
| if (window.location == 'https://www.privacytools.io/#cloud') {	window.location = 'https://www.privacytools.io/providers/cloud-storage/';} |     'https://www.privacytools.io/#email': 'https://www.privacytools.io/providers/email/', | ||||||
| if (window.location == 'https://www.privacytools.io/#social') {	window.location = 'https://www.privacytools.io/providers/social-networks/';} |     'https://www.privacytools.io/#cloud': 'https://www.privacytools.io/providers/cloud-storage/', | ||||||
| if (window.location == 'https://www.privacytools.io/#dns') {	window.location = 'https://www.privacytools.io/providers/dns/';} |     'https://www.privacytools.io/#social': 'https://www.privacytools.io/providers/social-networks/', | ||||||
| if (window.location == 'https://www.privacytools.io/#search') {	window.location = 'https://www.privacytools.io/providers/search-engines/';} |     'https://www.privacytools.io/#dns': 'https://www.privacytools.io/providers/dns/', | ||||||
| if (window.location == 'https://www.privacytools.io/#host') {	window.location = 'https://www.privacytools.io/providers/hosting/';} |     'https://www.privacytools.io/#search': 'https://www.privacytools.io/providers/search-engines/', | ||||||
| if (window.location == 'https://www.privacytools.io/#paste') {	window.location = 'https://www.privacytools.io/providers/paste';} |     'https://www.privacytools.io/#host': 'https://www.privacytools.io/providers/hosting/', | ||||||
| if (window.location == 'https://www.privacytools.io/#browser') {	window.location = 'https://www.privacytools.io/browsers/';} |     'https://www.privacytools.io/#paste': 'https://www.privacytools.io/providers/paste', | ||||||
| if (window.location == 'https://www.privacytools.io/#fingerprint') {	window.location = 'https://www.privacytools.io/browsers/#fingerprint';} |     'https://www.privacytools.io/#browser': 'https://www.privacytools.io/browsers/', | ||||||
| if (window.location == 'https://www.privacytools.io/#webrtc') {	window.location = 'https://www.privacytools.io/browsers/#webrtc';} |     'https://www.privacytools.io/#fingerprint': 'https://www.privacytools.io/browsers/#fingerprint', | ||||||
| if (window.location == 'https://www.privacytools.io/#addons') {	window.location = 'https://www.privacytools.io/browsers/#addons';} |     'https://www.privacytools.io/#webrtc': 'https://www.privacytools.io/browsers/#webrtc', | ||||||
| if (window.location == 'https://www.privacytools.io/#about_config') {	window.location = 'https://www.privacytools.io/browsers/#about_config';} |     'https://www.privacytools.io/#addons': 'https://www.privacytools.io/browsers/#addons', | ||||||
| if (window.location == 'https://www.privacytools.io/#clients') {	window.location = 'https://www.privacytools.io/software/email/';} |     'https://www.privacytools.io/#about_config': 'https://www.privacytools.io/browsers/#about_config', | ||||||
| if (window.location == 'https://www.privacytools.io/#messaging') {	window.location = 'https://www.privacytools.io/software/email/#messaging';} |     'https://www.privacytools.io/#clients': 'https://www.privacytools.io/software/email/', | ||||||
| if (window.location == 'https://www.privacytools.io/#im') {	window.location = 'https://www.privacytools.io/software/im/';} |     'https://www.privacytools.io/#messaging': 'https://www.privacytools.io/software/email/#messaging', | ||||||
| if (window.location == 'https://www.privacytools.io/#voip') {	window.location = 'https://www.privacytools.io/software/voip/';} |     'https://www.privacytools.io/#im': 'https://www.privacytools.io/software/im/', | ||||||
| if (window.location == 'https://www.privacytools.io/#filesharing') {	window.location = 'https://www.privacytools.io/software/file-sharing/';} |     'https://www.privacytools.io/#voip': 'https://www.privacytools.io/software/voip/', | ||||||
| if (window.location == 'https://www.privacytools.io/#mycloud') {	window.location = 'https://www.privacytools.io/software/cloud/';} |     'https://www.privacytools.io/#filesharing': 'https://www.privacytools.io/software/file-sharing/', | ||||||
| if (window.location == 'https://www.privacytools.io/#sync') {	window.location = 'https://www.privacytools.io/software/file-sync/';} |     'https://www.privacytools.io/#mycloud': 'https://www.privacytools.io/software/cloud/', | ||||||
| if (window.location == 'https://www.privacytools.io/#pw') {	window.location = 'https://www.privacytools.io/software/passwords/';} |     'https://www.privacytools.io/#sync': 'https://www.privacytools.io/software/file-sync/', | ||||||
| if (window.location == 'https://www.privacytools.io/#calendar_contacts') {	window.location = 'https://www.privacytools.io/software/calendar-contacts/';} |     'https://www.privacytools.io/#pw': 'https://www.privacytools.io/software/passwords/', | ||||||
| if (window.location == 'https://www.privacytools.io/#encrypt') {	window.location = 'https://www.privacytools.io/software/encryption-tools/';} |     'https://www.privacytools.io/#calendar_contacts': 'https://www.privacytools.io/software/calendar-contacts/', | ||||||
| if (window.location == 'https://www.privacytools.io/#darknets') {	window.location = 'https://www.privacytools.io/software/networks/';} |     'https://www.privacytools.io/#encrypt': 'https://www.privacytools.io/software/encryption-tools/', | ||||||
| if (window.location == 'https://www.privacytools.io/#notebook') {	window.location = 'https://www.privacytools.io/software/notebooks/';} |     'https://www.privacytools.io/#darknets': 'https://www.privacytools.io/software/networks/', | ||||||
| if (window.location == 'https://www.privacytools.io/#productivity') {	window.location = 'https://www.privacytools.io/software/productivity/';} |     'https://www.privacytools.io/#notebook': 'https://www.privacytools.io/software/notebooks/', | ||||||
| if (window.location == 'https://www.privacytools.io/#os') {	window.location = 'https://www.privacytools.io/operating-systems/';} |     'https://www.privacytools.io/#productivity': 'https://www.privacytools.io/software/productivity/', | ||||||
| if (window.location == 'https://www.privacytools.io/#live_os') {	window.location = 'https://www.privacytools.io/operating-systems/#live_os';} |     'https://www.privacytools.io/#os': 'https://www.privacytools.io/operating-systems/', | ||||||
| if (window.location == 'https://www.privacytools.io/#mobile_os') {	window.location = 'https://www.privacytools.io/operating-systems/#mobile_os';} |     'https://www.privacytools.io/#live_os': 'https://www.privacytools.io/operating-systems/#live_os', | ||||||
| if (window.location == 'https://www.privacytools.io/#aaddons') {	window.location = 'https://www.privacytools.io/operating-systems/#aaddons';} |     'https://www.privacytools.io/#mobile_os': 'https://www.privacytools.io/operating-systems/#mobile_os', | ||||||
| if (window.location == 'https://www.privacytools.io/#firmware') {	window.location = 'https://www.privacytools.io/operating-systems/#firmware';} |     'https://www.privacytools.io/#aaddons': 'https://www.privacytools.io/operating-systems/#aaddons', | ||||||
| if (window.location == 'https://www.privacytools.io/#win10') {	window.location = 'https://www.privacytools.io/operating-systems/#win10';} |     'https://www.privacytools.io/#firmware': 'https://www.privacytools.io/operating-systems/#firmware', | ||||||
|  |     'https://www.privacytools.io/#win10': 'https://www.privacytools.io/operating-systems/#win10' | ||||||
|  | } | ||||||
|  | if (redirectLinks[window.location]) { | ||||||
|  |     window.location = redirectLinks[window.location]; | ||||||
|  | } | ||||||
| @@ -1,145 +0,0 @@ | |||||||
| (function() { |  | ||||||
|   var SELECTOR, clickEvent, numberRegExp, sortable, touchDevice, trimRegExp; |  | ||||||
|  |  | ||||||
|   SELECTOR = 'table[data-sortable]'; |  | ||||||
|  |  | ||||||
|   numberRegExp = /^-?[£$¤]?[\d,.]+%?$/; |  | ||||||
|  |  | ||||||
|   trimRegExp = /^\s+|\s+$/g; |  | ||||||
|  |  | ||||||
|   touchDevice = 'ontouchstart' in document.documentElement; |  | ||||||
|  |  | ||||||
|   clickEvent = touchDevice ? 'touchstart' : 'click'; |  | ||||||
|  |  | ||||||
|   sortable = { |  | ||||||
|     init: function() { |  | ||||||
|       var table, tables, _i, _len, _results; |  | ||||||
|       tables = document.querySelectorAll(SELECTOR); |  | ||||||
|       _results = []; |  | ||||||
|       for (_i = 0, _len = tables.length; _i < _len; _i++) { |  | ||||||
|         table = tables[_i]; |  | ||||||
|         _results.push(sortable.initTable(table)); |  | ||||||
|       } |  | ||||||
|       return _results; |  | ||||||
|     }, |  | ||||||
|     initTable: function(table) { |  | ||||||
|       var i, th, ths, _i, _len; |  | ||||||
|       if (table.tHead.rows.length !== 1) { |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|       if (table.getAttribute('data-sortable-initialized') === 'true') { |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|       table.setAttribute('data-sortable-initialized', 'true'); |  | ||||||
|       ths = table.querySelectorAll('th'); |  | ||||||
|       for (i = _i = 0, _len = ths.length; _i < _len; i = ++_i) { |  | ||||||
|         th = ths[i]; |  | ||||||
|         if (th.getAttribute('data-sortable') !== 'false') { |  | ||||||
|           sortable.setupClickableTH(table, th, i); |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       return table; |  | ||||||
|     }, |  | ||||||
|     setupClickableTH: function(table, th, i) { |  | ||||||
|       var type; |  | ||||||
|       type = sortable.getColumnType(table, i); |  | ||||||
|       return th.addEventListener(clickEvent, function(e) { |  | ||||||
|         var newSortedDirection, row, rowArray, rowArrayObject, sorted, sortedDirection, tBody, ths, _i, _j, _k, _len, _len1, _len2, _ref, _results; |  | ||||||
|         sorted = this.getAttribute('data-sorted') === 'true'; |  | ||||||
|         sortedDirection = this.getAttribute('data-sorted-direction'); |  | ||||||
|         if (sorted) { |  | ||||||
|           newSortedDirection = sortedDirection === 'ascending' ? 'descending' : 'ascending'; |  | ||||||
|         } else { |  | ||||||
|           newSortedDirection = type.defaultSortDirection; |  | ||||||
|         } |  | ||||||
|         ths = this.parentNode.querySelectorAll('th'); |  | ||||||
|         for (_i = 0, _len = ths.length; _i < _len; _i++) { |  | ||||||
|           th = ths[_i]; |  | ||||||
|           th.setAttribute('data-sorted', 'false'); |  | ||||||
|           th.removeAttribute('data-sorted-direction'); |  | ||||||
|         } |  | ||||||
|         this.setAttribute('data-sorted', 'true'); |  | ||||||
|         this.setAttribute('data-sorted-direction', newSortedDirection); |  | ||||||
|         tBody = table.tBodies[0]; |  | ||||||
|         rowArray = []; |  | ||||||
|         _ref = tBody.rows; |  | ||||||
|         for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { |  | ||||||
|           row = _ref[_j]; |  | ||||||
|           rowArray.push([sortable.getNodeValue(row.cells[i]), row]); |  | ||||||
|         } |  | ||||||
|         if (sorted) { |  | ||||||
|           rowArray.reverse(); |  | ||||||
|         } else { |  | ||||||
|           rowArray.sort(type.compare); |  | ||||||
|         } |  | ||||||
|         _results = []; |  | ||||||
|         for (_k = 0, _len2 = rowArray.length; _k < _len2; _k++) { |  | ||||||
|           rowArrayObject = rowArray[_k]; |  | ||||||
|           _results.push(tBody.appendChild(rowArrayObject[1])); |  | ||||||
|         } |  | ||||||
|         return _results; |  | ||||||
|       }); |  | ||||||
|     }, |  | ||||||
|     getColumnType: function(table, i) { |  | ||||||
|       var row, text, _i, _len, _ref; |  | ||||||
|       _ref = table.tBodies[0].rows; |  | ||||||
|       for (_i = 0, _len = _ref.length; _i < _len; _i++) { |  | ||||||
|         row = _ref[_i]; |  | ||||||
|         text = sortable.getNodeValue(row.cells[i]); |  | ||||||
|         if (text !== '' && text.match(numberRegExp)) { |  | ||||||
|           return sortable.types.numeric; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       return sortable.types.alpha; |  | ||||||
|     }, |  | ||||||
|     getNodeValue: function(node) { |  | ||||||
|       if (!node) { |  | ||||||
|         return ''; |  | ||||||
|       } |  | ||||||
|       if (node.getAttribute('data-value') !== null) { |  | ||||||
|         return node.getAttribute('data-value'); |  | ||||||
|       } |  | ||||||
|       if (typeof node.innerText !== 'undefined') { |  | ||||||
|         return node.innerText.replace(trimRegExp, ''); |  | ||||||
|       } |  | ||||||
|       return node.textContent.replace(trimRegExp, ''); |  | ||||||
|     }, |  | ||||||
|     types: { |  | ||||||
|       numeric: { |  | ||||||
|         defaultSortDirection: 'descending', |  | ||||||
|         compare: function(a, b) { |  | ||||||
|           var aa, bb; |  | ||||||
|           aa = parseFloat(a[0].replace(/[^0-9.-]/g, '')); |  | ||||||
|           bb = parseFloat(b[0].replace(/[^0-9.-]/g, '')); |  | ||||||
|           if (isNaN(aa)) { |  | ||||||
|             aa = 0; |  | ||||||
|           } |  | ||||||
|           if (isNaN(bb)) { |  | ||||||
|             bb = 0; |  | ||||||
|           } |  | ||||||
|           return bb - aa; |  | ||||||
|         } |  | ||||||
|       }, |  | ||||||
|       alpha: { |  | ||||||
|         defaultSortDirection: 'ascending', |  | ||||||
|         compare: function(a, b) { |  | ||||||
|           var aa, bb; |  | ||||||
|           aa = a[0].toLowerCase(); |  | ||||||
|           bb = b[0].toLowerCase(); |  | ||||||
|           if (aa === bb) { |  | ||||||
|             return 0; |  | ||||||
|           } |  | ||||||
|           if (aa < bb) { |  | ||||||
|             return -1; |  | ||||||
|           } |  | ||||||
|           return 1; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   setTimeout(sortable.init, 0); |  | ||||||
|  |  | ||||||
|   window.Sortable = sortable; |  | ||||||
|  |  | ||||||
| }).call(this); |  | ||||||
		Reference in New Issue
	
	Block a user