fonts
1 month ago
img
1 month ago
rtl
1 month ago
akismet-admin.css
1 month ago
akismet-admin.js
2 months ago
akismet-frontend.js
2 months ago
akismet.css
6 months ago
akismet.js
1 month ago
akismet-admin.js
70 lines
| 1 | document.addEventListener( 'DOMContentLoaded', function() { |
| 2 | // Prevent aggressive iframe caching in Firefox |
| 3 | var statsIframe = document.getElementById( 'stats-iframe' ); |
| 4 | if ( statsIframe ) { |
| 5 | statsIframe.contentWindow.location.href = statsIframe.src; |
| 6 | } |
| 7 | |
| 8 | initCompatiblePluginsShowMoreToggle(); |
| 9 | initApiKeyCopyButton(); |
| 10 | } ); |
| 11 | |
| 12 | function initApiKeyCopyButton() { |
| 13 | const button = document.querySelector( '.akismet-api-key-copy' ); |
| 14 | if ( ! button ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | button.addEventListener( 'click', function() { |
| 19 | const input = document.getElementById( 'key' ); |
| 20 | if ( ! input || ! input.value ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | if ( navigator.clipboard && navigator.clipboard.writeText ) { |
| 25 | navigator.clipboard.writeText( input.value ).then( function() { |
| 26 | const svg = button.querySelector( 'svg' ); |
| 27 | const original = svg.innerHTML; |
| 28 | svg.innerHTML = '<polyline points="20 6 9 17 4 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'; |
| 29 | setTimeout( function() { |
| 30 | svg.innerHTML = original; |
| 31 | }, 2000 ); |
| 32 | } ).catch( function() { |
| 33 | input.select(); |
| 34 | document.execCommand( 'copy' ); |
| 35 | } ); |
| 36 | } else { |
| 37 | input.select(); |
| 38 | document.execCommand( 'copy' ); |
| 39 | } |
| 40 | } ); |
| 41 | } |
| 42 | |
| 43 | function initCompatiblePluginsShowMoreToggle() { |
| 44 | const section = document.querySelector( '.akismet-compatible-plugins' ); |
| 45 | const list = document.querySelector( '.akismet-compatible-plugins__list' ); |
| 46 | const button = document.querySelector( '.akismet-compatible-plugins__show-more' ); |
| 47 | |
| 48 | if ( ! section || ! list || ! button ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | function isElementInViewport( element ) { |
| 53 | const rect = element.getBoundingClientRect(); |
| 54 | return rect.top >= 0 && rect.bottom <= window.innerHeight; |
| 55 | } |
| 56 | |
| 57 | function toggleCards() { |
| 58 | list.classList.toggle( 'is-expanded' ); |
| 59 | const isExpanded = list.classList.contains( 'is-expanded' ); |
| 60 | button.textContent = isExpanded ? button.dataset.labelOpen : button.dataset.labelClosed; |
| 61 | button.setAttribute( 'aria-expanded', isExpanded.toString() ); |
| 62 | |
| 63 | if ( ! isExpanded && ! isElementInViewport( section ) ) { |
| 64 | section.scrollIntoView( { block: 'start' } ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | button.addEventListener( 'click', toggleCards ); |
| 69 | } |
| 70 |