Page 1 of 1
Design / folder of Javascript question
Posted: Mon Mar 14, 2022 3:39 pm
by loop
Hi all
1. I need to include a own javascript, which i want to include in multiple modules (index_products, index_nested) so i don't have to maintain same code twice.
In which folder should i save this javascript, so it's correct as it should? ext?
2. I made a class for extending the splitPageResults, where do i have to put my extension so it's autoloaded?
thank you!
Re: Design / folder of Javascript question
Posted: Mon Mar 14, 2022 4:17 pm
by ecartz
loop wrote: ↑Mon Mar 14, 2022 3:39 pm
In which folder should I save this javascript, so it's correct as it should? ext?
Yes, ext is probably the best place.
loop wrote: ↑Mon Mar 14, 2022 3:39 pm
2. I made a class for extending the splitPageResults, where do I have to put my extension so it's autoloaded?
In catalog, includes/system/override
Note that it won't actually be autoloaded until it is invoked by name.
Re: Design / folder of Javascript question
Posted: Mon Mar 14, 2022 4:23 pm
by loop
hi ecartz
the class file is now in includes/system/override
whenn i try now in product_listing.php to initiate i get a error:
Code: Select all
$listing_split = new splitPageResultsInfiniteScrolling($listing_sql, $num_list, 'p.products_id');
Fatal error: Uncaught Error: Class 'splitPageResultsInfiniteScrolling' not found in /mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing_infinite.php:13 Stack trace: #0
..
...
if i have there the " include("includes/system/ovverride/splitPageResultsInfinite.php");" it works....
and a other Pattern question: i made a productfilter module in index_products, which i need also in index_nested, what is the most elegant way to reuse the code? one idea is to add the javascript code in a external file and include it in the header, so the javasript is not duplicated. But most other code would be doubled...which is ugly to maintain...
Re: Design / folder of Javascript question
Posted: Mon Mar 14, 2022 5:01 pm
by ecartz
Name the file split_page_results_infinite_scrolling.php
When I first made the autoloader, we had both snake_case and camelCase class names but only snake_case file names (plus a few exceptions that didn't fit either pattern). So it autoloads camelCase classes from snake_case file names.
Someday, I may go through and rename all the camelCase classes to be snake_case. That would allow me to drop the camelCase to snake_case converter. But since it works (albeit with occasionally confusing behavior), it hasn't been a big priority.
Also, if you have Scrolling in the class name, it needs to be in the file name too.