custom javascript

edited March 2011 in Modules
create an adv module with controller , let's say i just want to add in some javascript so that when the admin user choose from the dropdown, it will redirect to another page, do i need to use jqx ? or i can just add in some custom javascript ?

how should i do it ?
1. create the js function on modulename/asset/js/custom.js
2. load the js in controller ? is it using $this->js='custom' ?

Comments

  • edited 9:21PM
    or am i thinking too complicated ? just dump the js function in the view will do ?
  • edited 9:21PM
    It depends on how your advance module is setup. I think any of those option would work but probably the easiest would be to just include it the view file that your advanced module has. With regards to using jqx or not, I tend to use it when I have a lot of a javascript, however, you aren't required to and often times it may be easier to just use a simple javascript file instead.
  • edited 9:21PM
    noted, i have done it by putting the js in the views , if possible can add some how to use the jqx in the user guide with some real case example , i keen to learn but can't make it work for my case ^_^
  • edited 9:21PM
    Yeah, the documentation for that is not great. I've put it on the list.
  • edited 9:21PM
    Is there an unobtrusive/easy to upgrade method of loading other JS files for the admin when not in one of our own modules?

    I'd like to overwrite some functionality in _iniAssets() in BaseFuelController.js with my own behavior without hacking at the existing Fuel code.

    Or is $config['fuel_javascript'] down in /fuel/modules/fuel/config/fuel.php the place to add?
  • edited 9:21PM
    Ahh never mind.. an array_push to $config['fuel_javascript'] in MY_fuel.php gets it done...
  • edited 9:21PM
    Adding a javascript file in fuel_javascript is probably the best way for you to insert javascript globally without hacking FUEL code. However, overwriting that particular method may be tricky since your javascript would be inserted before the BaseFuelController and not after (so you can't overwrite the object). Long story short, I'm not sure of an easy way at the moment. I do have it on the list to make extending and writing jQx controllers easier hopefully in the next release (which will probably been in a couple months) as well as some modifications to creating/overwriting different field types.
  • edited 9:21PM
    Cool, and yeah it didn't overwrite that method.

    Coming changes sound great too.
  • edited 9:21PM
    Maybe this is relevant...
    Why is it that a css file within an advanced module's assets folder will be autoloaded, but the same thing won't happen with js files? I.e.:

    /modules/my_module/assets/css/my_module.css is loaded and available within the backend

    /modules/my_module/assets/js/my_module.js is not

    Maybe this might be a nice thing to have...?
  • edited 9:21PM
    I think the origins of that decision came down to the need of needing the CSS for the left menu item icons to be loaded on every page whereas the javascript didn't need to be. We may look into changing that in the future.
  • edited 9:21PM
    Actually imho the best would be to have the js loaded only when you enter the module's sections (list_items, form_fields)
  • edited July 2011
    Anyway, I'm still struggling as to how I'm supposed to load a javascript file from within the resulting view of form_fields - all i want is to add some custom ajax stuff to an add/edit form from within my advanced module...
    [SOLVED] answer here: http://www.getfuelcms.com/forums/discussion/comment/1534/#Comment_1534
Sign In or Register to comment.