PluginProbe
Polylang / trunk
Polylang vtrunk
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / js / build / user.js

user.js in Polylang trunk, at js/build/user.js

75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Adds one biography textarea field per language in the user profile.
3 */
4
5 const pllDescription = {
6 /**
7 * Init.
8 */
9 init: () => {
10 if ( ! pllDescriptionData ) {
11 return;
12 }
13 if ( document.readyState !== 'loading' ) {
14 pllDescription.ready();
15 } else {
16 document.addEventListener(
17 'DOMContentLoaded',
18 pllDescription.ready
19 );
20 }
21 },
22
23 /**
24 * Called when the DOM is ready.
25 */
26 ready: () => {
27 const originTextarea = document.getElementById( 'description' );
28
29 if ( ! originTextarea ) {
30 return;
31 }
32
33 const rows = [];
34
35 pllDescriptionData.forEach( ( data ) => {
36 const wrapper = document.createElement( 'div' );
37 wrapper.setAttribute( 'lang', data.lang );
38
39 const label = document.createElement( 'label' );
40 label.setAttribute( 'for', `description_${ data.slug }` );
41 label.setAttribute( 'dir', data.direction );
42
43 if ( data.flag.src ) {
44 const img = document.createElement( 'img' );
45 img.setAttribute( 'alt', '' );
46 img.setAttribute( 'src', data.flag.src );
47 if ( data.flag.width ) {
48 img.setAttribute( 'width', data.flag.width );
49 }
50 if ( data.flag.height ) {
51 img.setAttribute( 'height', data.flag.height );
52 }
53 label.textContent = ` ${ data.name }`;
54 label.prepend( img );
55 } else {
56 label.textContent = data.name;
57 }
58
59 const textarea = originTextarea.cloneNode( true );
60 textarea.setAttribute( 'id', `description_${ data.slug }` );
61 textarea.setAttribute( 'name', `description_${ data.slug }` );
62 textarea.setAttribute( 'dir', data.direction );
63 textarea.innerHTML = data.description;
64
65 wrapper.append( label, document.createElement( 'br' ), textarea );
66 rows.push( wrapper );
67 } );
68
69 originTextarea.replaceWith( ...rows );
70 },
71 };
72
73 pllDescription.init();
74
75