Topic: Confusing way to use events

Got this from http://www.plupload.com/punbb/viewtopic.php?id=1653.

Use postinit event:

preinit: {
                PostInit: function(up) {
                    //your code here
                }
            }

This code works, so I assume it's correct, but I find it very confusing – PostInit is inside preinit. Can anyone explain the rationale behind this?

Re: Confusing way to use events

the preinit is a section and the postinit is an event.

all events inside the "preinit" section will be executed before the event defined by plupload. In this case the "postInit" event is already defined inside the runtimes html5, gears and browserplus. So if your postinit event must run before the defined plupload code, you should put it inside the preinit section

Re: Confusing way to use events

Thanks for the explanation, Leandro. But what is a "section" here? Is it a JavaScript concept or something plupload devs have come up with?

It would be good if somebody wrote a set of documentation articles explaining things like that.

Re: Confusing way to use events

the term "section" is something that I came up with to explain this for you.

the http://www.plupload.com/documentation.php already have an explanation about the "preinit"

Re: Confusing way to use events

I saw it. Firstly, that article is too deficient in details. Secondly, here's what it says:

preinit
    Function callback that enables you to bind events before the uploader is initialized.

I wanted, for example, to change text in the queue widget, so doing that "before the uploader is initialized" didn't make sense, yet this is exactly where it worked.

Still, this area is confusing. Good docs would help, but they don't exist. People have been inquiring about basic things that should've been covered by documentation.

Now I feel I might be interpreted as an ungrateful SOB. I am not. I am thankful for this software and that it's free. Good docs would help, though smile

Re: Confusing way to use events

you didn't read it right. let me change the bold font position

preinit
    Function callback that enables you to bind events before the uploader is initialized.

so you're not executing code on preinit, but only binding the events to plupload before the native events are bound

and thinking a little more deeply, why someone will define a section that executes any code before the plupload is initialized? if we need this, we just put our code before calling the plupload initialization code. Right?

Re: Confusing way to use events

That makes more sense now. Thanks.

why someone will define a section that executes any code before the plupload is initialized? if we need this, we just put our code before calling the plupload initialization code. Right?

Sounds right, but I want to know if I got you correctly. For example, I needed to change the header text and remove a button from the queue widget, so I did the following:

preinit: {
    PostInit: function(up) {
        $(".plupload_header_text").html("Add files to the upload queue and click the Save button.");
        $(".plupload_start").hide();
    }
}

Can you think of another way that would work and make more sense?

8 (edited by LeandroJF 2012-11-05 17:37:38)

Re: Confusing way to use events

the only way to define events handlers are:
- in preinit
- in init
- and with the bind method

Re: Confusing way to use events

Do you mean to define events or to define event handlers?

Re: Confusing way to use events

event handlers