Skip to content

Commit

Permalink
Code
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Oct 7, 2024
1 parent 7286407 commit 4eb748b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion includes/Data/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct( $container ) {
define( 'NFD_INSTALLER_BUILD_DIR', dirname( __DIR__, 2 ) . '/build/' . NFD_INSTALLER_VERSION );
}
if ( ! defined( 'NFD_INSTALLER_BUILD_URL' && defined( 'NFD_INSTALLER_VERSION' ) ) ) {
define( 'NFD_INSTALLER_BUILD_URL', $container->plugin()->url . '/vendor/newfold-labs/wp-module-pls/build/' . NFD_INSTALLER_VERSION );
define( 'NFD_INSTALLER_BUILD_URL', $container->plugin()->url . '/vendor/newfold-labs/wp-module-installer/build/' . NFD_INSTALLER_VERSION );
}
}
}
1 change: 1 addition & 0 deletions includes/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NewfoldLabs\WP\Module\Installer;

use NewfoldLabs\WP\Module\Installer\RestApi\RestApi;
use NewfoldLabs\WP\Module\Installer\WPAdmin\WPAdmin;
use NewfoldLabs\WP\Module\Installer\TaskManagers\TaskManager;
use NewfoldLabs\WP\ModuleLoader\Container;

Expand Down
3 changes: 1 addition & 2 deletions includes/WPAdmin/Listeners/DataAttrListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function enqueue_data_attr_listener() {
$asset_file = NFD_INSTALLER_BUILD_DIR . '/dataAttrListener.asset.php';

if ( is_readable( $asset_file ) ) {

$asset = include $asset_file;

wp_register_script(
Expand All @@ -43,7 +42,7 @@ public function enqueue_data_attr_listener() {
'before'
);

wp_enqueue_script( 'nfd-pls-data-attr-installer' );
wp_enqueue_script( 'nfd-installer-data-attr-listener' );
}
}
}
2 changes: 1 addition & 1 deletion includes/WPAdmin/WPAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NewfoldLabs\WP\Module\Installer\WPAdmin;

use NewfoldLabs\WP\Module\PLS\WPAdmin\Listeners\DataAttrListener;
use NewfoldLabs\WP\Module\Installer\WPAdmin\Listeners\DataAttrListener;

/**
* Manages all the wp-admin related functionalities for the module.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.1.5",
"name": "@newfold-labs/wp-module-installer",
"description": "An installer for WordPress plugins and themes.",
"license": "GPL-2.0-or-later",
Expand All @@ -12,7 +12,7 @@
"@wordpress/scripts": "^26.10.0"
},
"scripts": {
"build": "wp-scripts build ./src/ ./src/Scripts/dataAttrListener.js",
"start": "wp-scripts start ./src/ ./src/Scripts/dataAttrListener.js"
"build": "wp-scripts build ./src/Scripts/dataAttrListener.js",
"start": "wp-scripts start ./src/Scripts/dataAttrListener.js"
}
}
38 changes: 38 additions & 0 deletions src/Scripts/dataAttrListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,44 @@ import { installerAPI } from '../constants';

domReady( () => {
const domObserver = new window.MutationObserver( ( mutationList ) => {
for ( const mutation of mutationList ) {
if ( mutation.type === 'childList' ) {
for ( const addedNode of mutation.addedNodes ) {
if (
typeof addedNode === 'object' &&
typeof addedNode.querySelectorAll === 'function'
) {
addedNode
.querySelectorAll( '[data-nfd-plugin-provider]' )
.forEach( ( ele ) => {
ele.addEventListener( 'click', function ( e ) {
if (
e.target.getAttribute(
'data-nfd-plugin-slug'
) !== null
) {
apiFetch( {
url: installerAPI,
method: 'POST',
data: {
plugin: this.getAttribute(
'data-nfd-plugin-slug'
),
activate:
this.getAttribute(
'data-nfd-plugin-activate'
) === 'true'
? true
: false,
},
} );
}
} );
} );
}
}
}
}
} );

domObserver.observe( document.body, { childList: true, subtree: true } );
Expand Down

0 comments on commit 4eb748b

Please sign in to comment.