Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 'js-exec' config entries with JS events #1009

Merged
merged 10 commits into from
Apr 23, 2021
Merged

Conversation

herrvigg
Copy link
Collaborator

@herrvigg herrvigg commented Apr 18, 2021

Deprecate Refactor the integration logic with js-exec in the JSON config and prevent embedded JS code in JSON by deprecating javascript, see #1000. This simplifies qTranslate, improves security and the integration framework.
Events are now triggered from the core module during JS execution. This also gives a much better control of the loading sequence.

Execution

New events named 'qtxLoadAdmin:[page-key]' are now triggered from the core module on document. The main qtx object is passed as parameter.

Example of handler: $(document).on('qtxLoadAdmin:post', function( event, qtx ) { /*...*/ } );.

The page keys come from the admin-config entry in the i18n-config.json. Only the active keys for the page currently visited are passed, they could be several keys corresponding to different page selectors.

There must be some pages or post_type selector making the current page specific for the event to be fired. Entries without specific selector are irrelevant since they would apply to all pages.

More detailed examples:

post

// i18n-config.json
"admin-config": {
    "post": {   // <--- page key
      "pages": {
        "post.php": "",
        "post-new.php": ""
      },
    // "js-exec" --> obsolete, remove this entry
// JS handler for exec (ES5)
$(document).on('qtxLoadAdmin:post', function(event, qtx) {
   // do exec for this entry...
});

nav-menus

// i18n-config.json
"admin-config": {
    "nav-menus": { // <--- page key
      "pages": {
        "nav-menus.php": "action=edit|menu=\\d+|^$"
      },
    // "js-exec" --> obsolete, remove this entry
// JS handler for exec (with ES6 arrow function)
$(document).on('qtxLoadAdmin:nav-menus', (event, qtx) => {
   // do exec for this entry...
});

Loading scripts

Custom scripts should not be loaded by qTranslate anymore. The third-party plugins or themes should handle this, there could be some specificities that are not part of qTranslate and these scripts don't belong to qTranslate. They should be loaded in the footer. The only constraint is the dependency to qtranslate-admin-main to use the qtx API.
Still we might have a default script to load to facilitate basic JS functionalities for simple plugins and themes.

Front config

Since qTranslate has no JS script running on the front-end, nothing is done. Custom scripts should also be handled by third-party components.

@herrvigg herrvigg added the core Core functionalities, including the admin section label Apr 18, 2021
@herrvigg herrvigg added enhancement New feature or request plugin: others Concerns integration with other plugins labels Apr 18, 2021
@herrvigg herrvigg changed the title Refactor JS exec with qtranslate_load_admin event Refactor 'js-exec' config entries with JS events Apr 23, 2021
@herrvigg herrvigg changed the title Refactor 'js-exec' config entries with JS events Deprecate 'js-exec' and 'js-conf', refactor with JS events Apr 23, 2021
@herrvigg herrvigg changed the title Deprecate 'js-exec' and 'js-conf', refactor with JS events Refactor 'js-exec' config entries with JS events Apr 23, 2021
@herrvigg herrvigg merged commit f47fc2e into master Apr 23, 2021
@herrvigg herrvigg deleted the refactor/js-exec branch April 23, 2021 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionalities, including the admin section enhancement New feature or request plugin: others Concerns integration with other plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant