bottom.js
3 months ago
contextual.js
3 months ago
element.js
3 months ago
side.js
3 months ago
top.js
3 months ago
bottom.js
50 lines
| 1 | jQuery( document ).ready( function( $ ) { |
| 2 | const data = typeof helpdocs_bottom !== 'undefined' ? helpdocs_bottom : {}; |
| 3 | const isGutenberg = data.is_gutenberg || false; |
| 4 | const docs = data.docs || []; |
| 5 | const template = data.template || ''; |
| 6 | |
| 7 | // Target the class instead of ID |
| 8 | const $wrappers = $( '.helpdocs-bottom-wrapper' ); |
| 9 | |
| 10 | if ( isGutenberg ) { |
| 11 | const renderGutenbergDocs = function() { |
| 12 | const $target = $( '.interface-interface-skeleton__content' ); |
| 13 | |
| 14 | if ( $target.length && docs.length && template ) { |
| 15 | // Check if we've already injected to prevent duplicates |
| 16 | if ( $target.find( '.helpdocs-gutenberg-bottom' ).length ) return; |
| 17 | |
| 18 | let html = '<div class="helpdocs-bottom-wrapper helpdocs-gutenberg-bottom">'; |
| 19 | |
| 20 | docs.forEach( function( doc ) { |
| 21 | let docHtml = template |
| 22 | .replace( '{doc_title}', doc.title ) |
| 23 | .replace( '{doc_content}', doc.content ); |
| 24 | |
| 25 | html += docHtml; |
| 26 | } ); |
| 27 | |
| 28 | html += '</div>'; |
| 29 | $target.append( html ); |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | const checkGutenberg = setInterval( function() { |
| 34 | if ( $( '.interface-interface-skeleton__content' ).length ) { |
| 35 | renderGutenbergDocs(); |
| 36 | clearInterval( checkGutenberg ); |
| 37 | } |
| 38 | }, 500 ); |
| 39 | |
| 40 | } else { |
| 41 | const $target = $( '#wpbody-content' ); |
| 42 | |
| 43 | // Loop through all found wrappers and move them |
| 44 | if ( $wrappers.length && $target.length ) { |
| 45 | $wrappers.each( function() { |
| 46 | $( this ).detach().appendTo( $target ).show(); |
| 47 | }); |
| 48 | } |
| 49 | } |
| 50 | } ); |