Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
how do I add jQuery fucntion in module
MONEE



Joined: 28 Oct 2007
Posts: 433

Posted: 06/23/13 08:23 
how can I include this function into my module? It works if I add to meta.tpl but I want to call it from module

<script>
(function($){
$(document).ready( function() {
/*
$(".test_module_wrapper").test();
or
*/
$(".test_module_wrapper").test({
opening_speed: 300,
closing_speed: 500,
easing: 'swing'
});


$('.new-skin-tango').new();

});
})(jQuery);
</script>

Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 06/23/13 08:44 
In JR5 all JS, CSS, etc. that needs to be included from a module goes through the "jrCore_create_page_element()" function. So in this case it would be:


Code

$_js = array("$(".test_module_wrapper").test({ opening_speed: 300, closing_speed: 500, easing: 'swing' }); $('.new-skin-tango').new();");
jrCore_create_page_element('javascript_ready_function',$_js);


So basically we:
- create a new single element array that contains the Javascript you want to execute in the page ready function
- add that Javascript to the page using the "jrCore_create_page_element()" function. This function adds items such as CSS, Javascript, etc. to a page that is going to be rendered. Here we tell it we want to add it to the "javascript_ready_function".

Note that in your JS you do not include "$(document).ready( function() {" (or the closing brace) as that is handled by the core. You just add your setup and function call.

Let me know if that helps.

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
MONEE



Joined: 28 Oct 2007
Posts: 433

Posted: 06/23/13 09:11 

Brian:



Code

$_js = array("$(".test_module_wrapper").test({ opening_speed: 300, closing_speed: 500, easing: 'swing' }); $('.new-skin-tango').new();");
jrCore_create_page_element('javascript_ready_function',$_js);


- Brian


Where do I add this?

Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 06/23/13 09:13 
In your module view function.

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
MONEE



Joined: 28 Oct 2007
Posts: 433

Posted: 06/23/13 09:52 

Brian:
In your module view function.

- Brian


This is my first module and I'm not sure what you mean. Is this correct and what file do I include in? right now I'm in include.php

function test_view()
{

$_js = array("$(".test_module_wrapper").test({ opening_speed: 300, closing_speed: 500, easing: 'swing' }); $('.new-skin-tango').new();");
jrCore_create_page_element('javascript_ready_function',$_js);

}

Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 06/23/13 10:00 
All view functions go inside your index.php file. You would name it like:

view_exModule_test

Where "exModule" is your module directory name. I would highly recommend looking at an existing module (say jrBlog) to get an idea of what you need to setup.

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
MONEE



Joined: 28 Oct 2007
Posts: 433

Posted: 06/23/13 11:13 

Brian:
All view functions go inside your index.php file. You would name it like:

view_exModule_test

Where "exModule" is your module directory name. I would highly recommend looking at an existing module (say jrBlog) to get an idea of what you need to setup.

- Brian


This is what I got in index.php. still doesn't work. what am I doing wrong?

function view_myModule_test{

$_js = array("$(".test_module_wrapper").test({ opening_speed: 300, closing_speed: 500, easing: 'swing' }); $('.new-skin-tango').new();");

jrCore_create_page_element('javascript_ready_function',$_js);

}

Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 06/23/13 13:00 
Take a look at jrBlog, it's a really good example of the things that you need to do to make a module. Understanding how a module like jrBlog works will still be the first step once this stuff is documented.

Are you sure that you want this in a module? Would it also work if you just added it to the skin meta (with some smarty logic to check which page you are on)? Or just as a script link in the specific template you are working in?


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
MONEE



Joined: 28 Oct 2007
Posts: 433

Posted: 06/23/13 14:11 

SteveX:
Take a look at jrBlog, it's a really good example of the things that you need to do to make a module. Understanding how a module like jrBlog works will still be the first step once this stuff is documented.

Are you sure that you want this in a module? Would it also work if you just added it to the skin meta (with some smarty logic to check which page you are on)? Or just as a script link in the specific template you are working in?


yes it works fine if I put in meta.tpl. What I'm tring to do is keep all the resources in module and not have to add anything to the meta.tpl if possible

Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 06/24/13 00:31 
Ok, so you have a module.

If you need the js to be available everywhere put it into the module js directory and register it like this:

Code
    jrCore_register_module_feature('jrCore','javascript','xxModule','xxModule.js');

Take a look at jrAudio for an example of this - it adds a jquery plugin which is available everywhere.

If you need it to be available in your module forms and views use jrCore_create_page_element like Brian showed above. You can see this in action in jrOneAll index.php at around line 255.

You can also make the script links into a smarty function if you need that js to be in other forms and views, but you'd still need to add the smarty call to your skin or module templates, depending on where you need it.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
MONEE



Joined: 28 Oct 2007
Posts: 433

Posted: 06/24/13 09:50 
I got it worked out
thanks Cool

Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.