11

I want to call a function inside my jquery-plugin (widget-factory based).

Looks like this:

(function( $, window) {
    $.widget("mobile.multiview",$.mobile.widget, {
        stackUp: function (source, event, data) {
             ...
        }
    }
}) (jQuery,this);

I want to call stackUp from outside of the plugin. The problem: I don't know how to pass the parameters correctly. This does not work:

$('#trigger').multiview("stackUp('pagination', fakeEvent, fakeData)");

Can somebody point me to the correcty syntax of calling a public function inside a plugin and passing along parameters?

UPDATE:

I can call the function like this:

$('#trigger').multiview('stackUp');

but how can I pass the parameters?

3 Answers 3

22

Ok, after endless meddling, the parameters or arguments are passed like this:

$("#trigger").multiview('stackUp','pagination', fakeEvent, fakeData );

You just have to add parameters after the function separated by comma. Hope this helps someone else, too.

Sign up to request clarification or add additional context in comments.

2 Comments

what is #trigger referring to here? :S
@OZZIE: element with id of trigger but this was some time ago. Hope still helps
1

I dont really know how that plugin extends and exposes its functions but I would guess you could try one of the following:

$.mobile.widget.stackUp.apply($('#trigger'), ['pagination', fakeEvent, fakeData]);
$.mobile.multiview.apply($('#trigger'), ['pagination', fakeEvent, fakeData]);

However its entirely possible that they don't expose that method. Do you have the code somewhere?

UPDATE

After actually finding out what this plugin is I read up on the docs and you should be able todo:

$('#trigger').stackUp(...)

View source here: http://jqueryui.com/demos/widget/default.html - and look at the random function that is defined.

Alternatively you could just define the function in a more global scope and then use it as part of the config object and when you want to apply it to specific elements.

2 Comments

that returns: result of expression '$.mobile.widget.stackUp'[undefined] is not an object. Hold up. let me try again. Nah. doesn't work.
@frequent see my updated response. Only diff is you're doing $.widget("mobile.multiview",$.mobile.widget, {.. and the example is $.widget("mobile.multiview", {..
1

I'm not very familiar with jquery but try this:

$("#trigger").multiview(function() { stackUp('pagination', fakeEvent, fakeData); });

This is an anonymous function which will be executed on need with your static and dynamic parameters.

3 Comments

hm. can't get stackUp to fire like this.
Maybe it is the missing quotes. I'll add them.
Your allonymous function is nice, but never fired in my script. I found out the widgety way. See my answer. Thanx for help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.