Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted December 6, 20204 yr 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.
December 6, 20204 yr 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)
December 6, 20204 yr Whether you're just switching IN_DEV off, or building and installing it elsewhere is also going to make a difference.
December 6, 20204 yr Author 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.
December 6, 20204 yr 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.
December 6, 20204 yr Author 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, 20204 yr by ReyDev
December 6, 20204 yr 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 December 6, 20204 yr by Martin A.
December 6, 20204 yr Author 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!!
December 6, 20204 yr 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, 20204 yr by Nathan Explosion
December 7, 20204 yr Author 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, 20204 yr by ReyDev
December 7, 20204 yr Author 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.