ReyDev Posted December 6, 2020 Posted December 6, 2020 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.
Nathan Explosion Posted December 6, 2020 Posted December 6, 2020 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) Martin A. 1
Martin A. Posted December 6, 2020 Posted December 6, 2020 Whether you're just switching IN_DEV off, or building and installing it elsewhere is also going to make a difference.
ReyDev Posted December 6, 2020 Author Posted December 6, 2020 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.
Nathan Explosion Posted December 6, 2020 Posted December 6, 2020 5 minutes ago, ReyDev said: I have stored some files in the JS Admin controller folder and some in the front section. Show the files, and their locations, then...give more detail than you are providing.
ReyDev Posted December 6, 2020 Author Posted December 6, 2020 (edited) 19 minutes ago, Nathan Explosion said: Show the files, and their locations, then...give more detail than you are providing. I said before that nothing works. even dbl-click event. Edited December 6, 2020 by ReyDev
Solution Martin A. Posted December 6, 2020 Solution Posted December 6, 2020 (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 December 6, 2020 by Martin A. ReyDev 1
ReyDev Posted December 6, 2020 Author Posted December 6, 2020 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!!
Nathan Explosion Posted December 6, 2020 Posted December 6, 2020 (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 December 6, 2020 by Nathan Explosion ReyDev 1
ReyDev Posted December 7, 2020 Author Posted December 7, 2020 (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 : Edited December 7, 2020 by ReyDev
ReyDev Posted December 7, 2020 Author Posted December 7, 2020 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.
Recommended Posts