-
blue-canoe
-
-
Offline
-
Senior Member
-
- Posts: 57
- Thank you received: 16
-
Karma: 7
-
|
Hello all,
I have a quick question. In my component I have a few ajax based lookups. Now I want to execute a particular javascript function as soon as these combos appear on the screen (and are part of the DOM). I guess I will need to add that in the JDom files and I was thinking myself in the load.php in the ajax folder, but it does not quite work.
The function expects the dom element (in this case the combo) to be there and wherever I put it, it is always to early, so the element is not there yet. Of course I can do a setTimeout, but that is not ideal.
Anybody any idea?
Kind regards,
Misha
|
|
-
JoomGuy
-
-
Offline
-
Moderator
-
-
Joomla Enthusiast, Lover of Cooking
- Posts: 1115
- Thank you received: 195
-
Karma: 64
-
|
I think you need to add a script to the document object that is called on ready. Then, inside that script, call your function. I had this recently.
Hope it helps,
Gez
|
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
|
-
JoomGuy
-
-
Offline
-
Moderator
-
-
Joomla Enthusiast, Lover of Cooking
- Posts: 1115
- Thank you received: 195
-
Karma: 64
-
|
like: $doc = JFactory::getDocument();
$js = 'jQuery(document).ready(function(){
myFunction();
});';
//Then, if not already included...
$doc->addScript("path/to/myFunctions.js");
$doc->addScriptDeclaration($js);
BTW, if you need to be able to chain functions/methods, always add a in your functions. This way, whenever your method is called on an object/collection, it will be passed into subsequent methods.
Gez
|
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 05 Feb 2013 12:22 by JoomGuy. Reason: Added $doc
|
-
blue-canoe
-
-
Offline
-
Senior Member
-
- Posts: 57
- Thank you received: 16
-
Karma: 7
-
|
Hi Gez,
Not exactly sure if I get you. Basically I have a form, which contains an ajax lookup. So this might appear on the screen later (possibly after the domReady event). Ideally I want to find the place where it is added to the form, so I can fire an event on that added element).
If I add it to the view it does not work as the element is not there yet. A work around is setting a timeout, but really prefer to add it somewhere in JDom so it is fired properly.
Kind regards,
Misha
|
|
-
JoomGuy
-
-
Offline
-
Moderator
-
-
Joomla Enthusiast, Lover of Cooking
- Posts: 1115
- Thank you received: 195
-
Karma: 64
-
|
Hmm, detect a change on the element, then fire?
Gotta head out...
Will check back on this later.
Gez
|
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
|
-
blue-canoe
-
-
Offline
-
Senior Member
-
- Posts: 57
- Thank you received: 16
-
Karma: 7
-
|
Well that would not work. If the form is loaded with the combos initially, no change event is fired.
Will continue looking....
|
|
-
JoomGuy
-
-
Offline
-
Moderator
-
-
Joomla Enthusiast, Lover of Cooking
- Posts: 1115
- Thank you received: 195
-
Karma: 64
-
|
Hi Misha,
Could you give a few more specifics about what you're trying to achieve and exactly where you're adding your function and call to it please?
Thanks,
Gez
|
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
|
-
blue-canoe
-
-
Offline
-
Senior Member
-
- Posts: 57
- Thank you received: 16
-
Karma: 7
-
|
Hi Gez,
What I am trying to do is the following: I have one form with three (linked) filters. It is sports league component, so for example when I am opening the fixtures view I have 3 linked filters to respectively select the season, then competition, and competition round.
I am currently working on the mobile version of the site and I am using jQuery mobile. On of the features of jQuery mobile is that it replaces certain form elements with more mobile friendly versions of those controls, for example select boxes. This is my default done on 'domready', but these 3 filters I am talking about might not be on the form yet when that event is fired. With jQuery mobile you have to fire a create event on the elements, if you want to render those later.
So what I am trying to do is to fire a create event, i.e. jQuery('#element').trigger('create'), on those filters as soon as they are actually physically added to the form. So logically I was thinking to add this somewhere in one of the JDom classes... I have been trying to add this to the html.form.input.ajax.load, but without any success yet.
Kind regards,
Misha
|
|
-
JoomGuy
-
-
Offline
-
Moderator
-
-
Joomla Enthusiast, Lover of Cooking
- Posts: 1115
- Thank you received: 195
-
Karma: 64
-
|
Aha, OK.. That gives a bit of context...
Ok, I think that the solution will be to add your call inside of the Ajax success callback.
Hope it helps!
Gez
|
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
|
-
blue-canoe
-
-
Offline
-
Senior Member
-
- Posts: 57
- Thank you received: 16
-
Karma: 7
-
|
Hi Gez,
I was at the same moment thinking exactly the same. I was just looking at the wrong copy of ajax.js (:-S). Now I used the right file it works. I just added $(object).trigger('create'); in the successHTML (within the $(object).ready() function).
Thanks again!
Misha
|
|
-
JoomGuy
-
-
Offline
-
Moderator
-
-
Joomla Enthusiast, Lover of Cooking
- Posts: 1115
- Thank you received: 195
-
Karma: 64
-
|
No probs!
I'd (and I'm sure others would too) really appreciate it if you have 10mins at some point to share your experience with jQMobile in the context of setting up in a component. I'm OK with jQuery but I've never handled any of the mobile stuff myself, its always been handled by the template. Therefore, any hints would be great!
Thanks,
Gez
|
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
|
|