Refactor 'js-exec' config entries with JS events #1009
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DeprecateRefactor the integration logic withjs-exec
in the JSON config and prevent embedded JS code in JSON by deprecatingjavascript
, 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 ondocument
. The mainqtx
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
orpost_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
nav-menus
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 toqtranslate-admin-main
to use theqtx
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.