-
Notifications
You must be signed in to change notification settings - Fork 104
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
Rework JS integration without code injection #1000
Comments
I used I didn't really understand this idea:
could you explain? |
Great, it would be interesting to see how you use it.
The main logic behind the JSON configurations is selectors / LSB placement / fields selectors + behavior / js code. The first key identifies each block, in this case it's called What I dislike is that this tends to create a single JS file per entry leading to a lot of "fragmentation" with the scripts. When you bundle an app (webpack, rollout, ....) you have this fragmentation in the source files but you don't want this in the target bundle(s). Also code injection with My idea is doing the branching according to these keys (or IDs) directly in JS instead. They are not passed to the client part yet. Currently we have For example it could be:
Maybe there's even a better solution with events or other. But the main goal is to reduce the number of scripts, remove the code injection and move the decision making to the JS scripts. Also this would simplify the A question remains for the main script to load. It can be standardized, for example |
Also note you may have different entries (page configs) linked to the current page, due to overlapping selectors so it's not necessarily a single key. This fusion comes from |
You are right. Now my JSON looks like this: "post":{
"pages":{
"post.php":"",
"post-new.php":"",
"term.php":"",
"edit-tags.php":"action=edit"
},
"anchors":{"post-body-content":{"where":"first"}},
"forms":{
"post":{
"fields":{
"wpcf-start-point":{ "jquery": "#wpcf-group-event-attributes input[data-wpt-id='wpcf-start-point']"}
}
}
},
"js-exec": {
"tplus-post-exec" : {
"src": "plugins/translate-plus/js/tplus-admin-posteditor.min.js"
}
}
}
,
"edit":{
"pages":{
"edit.php": ""
},
"anchors": {
"posts-filter": {
"where": "first"
}
},
"forms":{
"posts-filter":{
"fields":{
"column-title":{
"jquery": ".column-title.page-title .hidden .post_title",
"encode": "display"
},
"tags":{
"jquery": ".tags.column-tags a",
"encode": "display"
},
"focuskw":{
"jquery": ".wpseo-focuskw.column-wpseo-focuskw",
"encode": "display"
},
"metadesc":{
"jquery": ".wpseo-metadesc.column-wpseo-metadesc",
"encode": "display"
},
"qtx-seo":{
"jquery": ".column-qtx_seo span",
"encode": "display"
},
"comments-view":{
"jquery": ".comments-view-item-link",
"encode": "display"
},
"notice-b":{
"jquery": ".notice b",
"encode": "display"
}
}
}
},
"js-exec": {
"tplus-edit-exec" : {
"src": "plugins/translate-plus/js/tplus-admin-edit.min.js"
}
}
}
,
"widgets": {
"pages": {
"widgets.php": ""
},
"forms": {
"widgets-right": {
"fields": {
"widget-text_title": {
"jquery": ".text-widget-fields input.title"
},
"widget-text_text": {
"jquery": ".text-widget-fields textarea.text"
},
"widget-custom_html-content": {
"jquery": "textarea[id^='widget-custom_html-'][id$='-content']"
}
}
}
},
"js-exec": {
"tplus-widgets-exec" : {
"src": "plugins/translate-plus/js/tplus-admin-widgets.min.js"
}
}
}
,
"upload": {
"pages": {
"upload.php": ""
},
"js-exec": {
"tplus-upload-exec" : {
"src": "plugins/translate-plus/js/tplus-admin-upload.min.js"
}
}
} that is, for each page its own JS file is loaded. I got your idea. I'm also prefer the idea of having one JS file instead of 4. As for identification, I suggest WP terminology. For the action |
Changes merged in master regarding the configuration files and integration with JS code:
Note these keys are just deprecated but they still work the same except there will be a warning raised in the admin panels. These keys will be removed in future versions so this gives us time to adjust any problem. I believe the new approach is a better design, safer and giving a structure, still flexible but with safeguards. |
@picasso I reverted the deprecation of It turns out it was much more complicated than expected to replace |
Changes discussed above released in 3.10.0. |
@herrvigg sorry for the delay in answering, I was on a business trip.
Good idea, I like it.
That is, you were unable to use the events? |
The events work fine! They are already in use in QTX's own scripts for example: qtranslate-xt/admin/js/pages/post.js Line 15 in a49f284
I still kept the So you could definitely regroup all your JS code into a single script (as a final bundle or a conventional source file). But I also realized there could be some very nasty conflicts when integrating JSON files, see #1013. That's not a new problem with the JS refactoring, it's always been the case. Seeing the example of JSON you provided, I recommend you prefix all the main page keys with a prefix corresponding to your plugin, theme or any identifier. For example:
Doing so you ensure there won't be any overwriting with the native configuration of QTX.
In the future we'd need to find a better solution to prevent this kind of JSON conflicts but for now the simplest is to do like this. |
Ok, I see. Although, if it were possible to specify the prefix once (but where?) for all pluggable configurations, it would be easier to work with and manage. Well, this is my wish. I know from my expirience that if the prefix needs to be repeated more than 10 times, then it will definitely get lost in one place and this will lead to a nightmare when debugging later. |
A major rehaul of the JS part is currently going on with webpack and babel. I'm realizing now there are a few issues with the
i18n-config.json
:js-conf
andjs-exec
for execution before and after qTranslate respectively. No one usesjs-conf
it seems.js-exec
deciding which script to load, an idea could be to use the keys of the pages instead and it should be up to the JS scripts to do the branching internally.I don't think many people use the JS integration since it's been so cumbersome. The main plugins are now integrated as modules and the first concerned is ACF that we can handle directly (that was the idea of taking the plugins as modules internally, allowing easier refactoring). Perhaps I'll have a phase of deprecation but i'm tempted to break the
js-exec
config entry.Any comments welcome.
The text was updated successfully, but these errors were encountered: