View Issue Details

IDProjectCategoryView StatusLast Update
0032227mantisbtjavascriptpublic2023-04-08 14:11
Reportergatis Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionwon't fix 
Product Version2.25.6 
Summary0032227: Feature to override the default javascript path in require_js function of html_api.php
Description

Currently there is no way to override the default path for javascript that is registered with require_js function.

That means that if some plug-in has its own javascript file it has to be included in EVENT_LAYOUT_RESOURCES, which means that every single page will have js file for plug-in included.

My suggestion would be to change the html_javascript_link function in the html_api.php to act the same as html_css_link and skip prepending the js directory to the script when specified script has path.

Additional Information

PR https://github.com/mantisbt/mantisbt/pull/1872

TagsNo tags attached.

Activities

dregad

dregad

2023-03-24 05:45

developer   ~0067520

The way I have dealt with this situation in the past myself, is to code the plugin's hook on EVENT_LAYOUT_RESOURCES to only include the javascript when the required conditions are met.

See for example, https://github.com/mantisbt-plugins/source-integration/blob/8ef983dfb48b87b848f652bfce40d5bb575bc204/SourceGithub/SourceGithub.php#L52-L63

How do you propose to actually use the modified html_javascript_link() function to conditionally include javascript in the context of a plugin ?

atrol

atrol

2023-03-24 09:01

developer   ~0067521

@dregad see "Additional Informatikon", there is PR https://github.com/mantisbt/mantisbt/pull/1872

dregad

dregad

2023-03-24 10:19

developer   ~0067522

Last edited: 2023-03-24 10:20

see "Additional Informatikon", there is PR https://github.com/mantisbt/mantisbt/pull/1872

I know, I'm the one who added the link there ;-)

The PR describes the change to MantisBT core function, but does not say anything about how the modified function is expected to be used.

gatis

gatis

2023-03-27 05:17

reporter   ~0067581

Yeah.. I guess there is no way I will be able to use the function in the way I intended to..
My Intention was to extend the project management page with plug-in, but by the time I get to the event where the extension happens the HTML head is already done printing..

So I guess @dregad proposed solution 0032227:0067520 is the way to go..

dregad

dregad

2023-03-27 06:52

developer   ~0067582

That's what I thought ;-)

There is still some room for improvement though. I have not thought this all the way through, but we could introduce a new plugin_require_js() function, taking a script name, and maybe an optional list of pages where script should be included.

In any case, based on your feedback, I guess your PR should be closed without merging ?

gatis

gatis

2023-03-27 06:56

reporter   ~0067583

Yes it should be closed. Sorry for trouble..

dregad

dregad

2023-03-27 07:51

developer   ~0067584

Thanks for the feedback. Closing as won't fix, feel free to reopen if you feel there is some use for this feature.

And if you'd like to further analyze the idea of a new plugin API function and contribute a pull request, please open a separate issue.