PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.15
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / js / plugin-search.js

plugin-search.js in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.15, at js/plugin-search.js

78 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Handles replacing the bottom row
3 * of the card with customized content.
4 */
5
6 /* global frmPlugSearch, JSON */
7
8 var FormidablePSH = {};
9
10 function frmPS() {
11 FormidablePSH = {
12 $pluginFilter: document.getElementById( 'plugin-filter' ),
13
14 /**
15 * Get parent search hint element.
16 * @returns {Element | null}
17 */
18 getCard: function () {
19 return document.querySelector( '.plugin-card-frm-plugin-search' );
20 },
21
22 /**
23 * Replace bottom row of the card to insert logo, text and link to dismiss the card.
24 */
25 replaceCardBottom: function () {
26 var hint = FormidablePSH.getCard();
27 if ( 'object' === typeof hint && null !== hint ) {
28 hint.querySelector( '.plugin-card-bottom' ).outerHTML =
29 '<div class="plugin-card-bottom frm-plugin-search__bottom">' +
30 '<p class="frm-plugin-search__text">' +
31 frmPlugSearch.legend +
32 '</p>' +
33 '</div>';
34
35 // Remove link and parent li from action links and move it to bottom row
36 var dismissLink = document.querySelector( '.frm-plugin-search__dismiss' );
37 dismissLink.parentNode.parentNode.removeChild( dismissLink.parentNode );
38 document.querySelector( '.frm-plugin-search__bottom' ).appendChild( dismissLink );
39 }
40 },
41
42
43 /**
44 * Check if plugin card list nodes changed. If there's a Formidable PSH card, replace the title and the bottom row.
45 * @param {array} mutationsList
46 */
47 replaceOnNewResults: function ( mutationsList ) {
48 mutationsList.forEach( function ( mutation ) {
49 if (
50 'childList' === mutation.type &&
51 1 === document.querySelectorAll( '.plugin-card-frm-plugin-search' ).length
52 ) {
53 FormidablePSH.replaceCardBottom();
54 }
55 } );
56 },
57
58 /**
59 * Start suggesting.
60 */
61 init: function () {
62 if ( FormidablePSH.$pluginFilter === null ) {
63 return;
64 }
65
66 // Replace PSH bottom row on page load
67 FormidablePSH.replaceCardBottom();
68
69 // Listen for changes in plugin search results
70 var resultsObserver = new MutationObserver( FormidablePSH.replaceOnNewResults );
71 resultsObserver.observe( FormidablePSH.$pluginFilter, { childList: true } );
72 },
73 };
74
75 FormidablePSH.init();
76 }
77 FormidablePS = frmPS();
78