PluginProbe
Parse.ly / 3.8.4
Parse.ly v3.8.4
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / js / admin-settings.ts

admin-settings.ts in Parse.ly 3.8.4, at src/js/admin-settings.ts

55 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 document.addEventListener( 'DOMContentLoaded', (): void => {
2 setActiveTab();
3 window.addEventListener( 'hashchange', setActiveTab );
4 document.querySelector( '.media-single-image button.browse' )?.addEventListener( 'click', selectImage );
5 } );
6
7 function setActiveTab(): void {
8 const activeTab = location.hash !== '' ? location.hash.substring( 1 ) : 'basic-section';
9
10 document.querySelectorAll( '.nav-tab' )?.forEach( ( t: Element ): void => {
11 if ( t.classList.contains( activeTab + '-tab' ) ) {
12 t.classList.add( 'nav-tab-active' );
13 } else {
14 t.classList.remove( 'nav-tab-active' );
15 }
16 } );
17
18 document.querySelectorAll( '.tab-content' )?.forEach( ( t: Element ): void => {
19 if ( t.classList.contains( activeTab ) ) {
20 t.setAttribute( 'style', 'display: initial' );
21 } else {
22 t.setAttribute( 'style', 'display: none' );
23 }
24 } );
25
26 const form = document.querySelector( 'form' );
27 if ( form ) {
28 form.removeAttribute( 'hidden' );
29 form.setAttribute( 'action', `options.php#${ activeTab }` );
30 }
31 }
32
33 function selectImage( event: Event ) {
34 const optionName = ( event.target as HTMLButtonElement ).dataset.option;
35
36 const imageFrame = window.wp.media( {
37 multiple: false,
38 library: {
39 type: 'image',
40 },
41 } );
42
43 imageFrame.on( 'select', function() {
44 const url = imageFrame.state().get( 'selection' ).first().toJSON().url;
45 const inputSelector: string = '#media-single-image-' + optionName + ' input.file-path';
46
47 const inputElement: HTMLInputElement | null = document.querySelector( inputSelector );
48 if ( inputElement ) {
49 inputElement.value = url;
50 }
51 } );
52
53 imageFrame.open();
54 }
55