Jump to content

JS does not work on production mode!


Go to solution Solved by Martin A.,

Recommended Posts

Posted

I have developed an app and when working in developer mode everything goes well (IN_DEV = TRUE), but in production mode(IN_DEV = FALSE), JS doesn't work at all.

Posted
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.

Posted (edited)
19 minutes ago, Nathan Explosion said:

Show the files, and their locations, then...give more detail than you are providing.

 

Untitled.png.2f49b48e866594e606dc11d3609faece.png

I said before that nothing works. even dbl-click event.

Edited by ReyDev
  • Solution
Posted (edited)
\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.
Posted
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!!

Posted (edited)
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
Posted (edited)

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
Posted
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.

  • Recently Browsing   0 members

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