PluginProbe ʕ •ᴥ•ʔ
Admin Help Docs / 2.0.0.1
Admin Help Docs v2.0.0.1
2.0.1.1 trunk 1.4.3.2 2.0.0 2.0.0.1 2.0.0.2 2.0.1
admin-help-docs / inc / docs / page-locations / js / side.js
admin-help-docs / inc / docs / page-locations / js Last commit date
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
side.js
42 lines
1 jQuery( document ).ready( function( $ ) {
2 const data = typeof helpdocs_side !== 'undefined' ? helpdocs_side : {};
3 const docs = data.docs || [];
4 const template = data.template || '';
5
6 if ( docs.length === 0 ) return;
7
8 /**
9 * Gutenberg Sidebar Injection
10 */
11 const renderGutenbergSideDocs = function() {
12 // Targets the settings sidebar (Inspector)
13 const $target = $( '.interface-complementary-area' );
14
15 if ( $target.length && docs.length && template ) {
16 // Prevent duplicate injections
17 if ( $target.find( '.helpdocs-gutenberg-side' ).length ) return;
18
19 let html = '<div class="helpdocs-side-wrapper helpdocs-gutenberg-side">';
20
21 $.each( docs, function( index, doc ) {
22 let docHtml = template
23 .replace( '{doc_title}', doc.title )
24 .replace( '{doc_content}', doc.content );
25
26 html += docHtml;
27 } );
28
29 html += '</div>';
30
31 // Prepend to the top of the sidebar
32 $target.prepend( html );
33 }
34 };
35
36 // Gutenberg sidebars unmount/remount when toggled, so we monitor it
37 const checkGutenbergSide = setInterval( function() {
38 if ( $( '.interface-complementary-area' ).length ) {
39 renderGutenbergSideDocs();
40 }
41 }, 1000 );
42 } );