Jump to content

JS does not work on production mode!


ReyDev
Go to solution Solved by Martin A.,

Recommended Posts

13 minutes ago, Martin A. said:

Whether you're just switching IN_DEV off, or building and installing it elsewhere is also going to make a difference.

It does not work in both cases

19 minutes ago, Nathan Explosion said:

That statement only isn't going to get much of a response - you're going to have to show your code (how you are calling the JS file, where it is stored etc)

\IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('script.js', 'myAppName', 'front'));

I have stored some files in the JS Admin controller folder and some in the front section.

Link to comment
Share on other sites

  • Solution
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_scriptfile.js', 'myAppName', 'admin' ) );
Quote

Javascript Files

Javascript files are handled in a similar way to CSS files; that is, they are created as .js files in the appropriate directory, and then loaded on-demand in your code. There is one slight difference: because of the way javascript files are bundled, when include your javascript file you should specify the bundle name rather than the specific javascript file. Javascript files are bundled by location and group, and that forms the filename of the resulting bundle.

For example, if we created javascript files in dev/js/front/mygroup/somefile.js, then the bundle name would be front_mygroup.js (location, underscore, groupname), and loaded as follows:


\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_mygroup.js', 'app', 'location' ) );

 

 

Edited by Martin A.
Link to comment
Share on other sites

37 minutes ago, Martin A. said:

\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_scriptfile.js', 'myAppName', 'admin' ) );

I did it according to the instructions you said and I am sure it is correct, but it still does not work.

I think the problem could be from permission or something!!

Link to comment
Share on other sites

15 minutes ago, ReyDev said:

but it still does not work.

Do you see the files called in the page source or not? Forget about what the script itself is going to do - check the page source. If they are loading there, then worry about the content...if they aren't, then you haven't got the call to them correct.

Edited by Nathan Explosion
Link to comment
Share on other sites

Thanks, it worked. Works on ACP, but does not work on widgets. Can I attach JS files to widgets in the same way?
Another question, should all JavaScript files be registered?
And can we use regular JavaScript files? . Like :

js-simple-event.png.4556ccc269bd5db473341bf924710904.png

 

Edited by ReyDev
Link to comment
Share on other sites

19 hours ago, ReyDev said:

\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_scriptfile.js', 'myAppName', 'admin' ) );

 

19 hours ago, Nathan Explosion said:

Do you see the files called in the page source or not? Forget about what the script itself is going to do - check the page source. If they are loading there, then worry about the content...if they aren't, then you haven't got the call to them correct.

Thanks , it was finally done.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...