| 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 |
|