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 / element.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
element.js
39 lines
1 jQuery( document ).ready( function( $ ) {
2 const data = typeof helpdocs_element !== 'undefined' ? helpdocs_element : {};
3 const docs = data.docs || [];
4 const isGutenberg = data.is_gutenberg || false;
5
6 if ( docs.length === 0 ) return;
7
8 /**
9 * The Injection Logic
10 */
11 const injectElementDocs = function() {
12 docs.forEach( function( doc ) {
13 if ( ! doc.css_selector ) return;
14
15 const $target = $( doc.css_selector );
16
17 if ( $target.length ) {
18 // Unique class to prevent the interval from double-injecting
19 const docIdClass = 'helpdocs-el-' + doc.ID;
20
21 if ( ! $target.next( '.' + docIdClass ).length ) {
22 const html = '<div class="helpdocs-element-item ' + docIdClass + '">' + doc.content + '</div>';
23 $target.after( html );
24 }
25 }
26 } );
27 };
28
29 // Initial run for everyone
30 injectElementDocs();
31
32 // If we are in Gutenberg, we need to poll because elements
33 // like .editor-document-bar load after the DOM is "ready"
34 if ( isGutenberg ) {
35 setInterval( function() {
36 injectElementDocs();
37 }, 1000 );
38 }
39 } );