incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Maj <>
Subject Re: requiring javascript for plugins
Date Fri, 06 Jul 2012 14:32:24 GMT
I have been thinking about all of these questions for a while, Don.

In my opinion, I do not think that Cordova should mandate a specific way
in which the JavaScript side of a plugin should be written or laid out.
The only requirement really boils down to using the `exec` method.

That said, the core APIs, which are just plugins, are wrapped in a
cordova.define call and use cordova.require to get references to any other
internal Cordova javascript bits, so I would _recommend_ users use this
pattern (exactly how your second phonegap-toast.js link does, Don).

It is cleaner as it does not trample over any globals.

As for where to assign the plugin code, again, I think it is up to the
plugin. I do not think it matters if it is assigned to navigator or to
window.plugins. Whatever works for the user. However, assigning to the
`cordova` object is not recommended as it may trample over
variables/properties that the cordova framework needs to function.

Finally, assigning to plugins.xml. No way to do it programmatically / at
run-time at this time, and I do not think we will do that in the future
(security considerations: you want to vet out which native bits will be
run before build time).

On 7/5/12 7:12 PM, "Don Coleman" <> wrote:

>Is there a new recommended way to include javascript for plugins?
>Previously I just jammed an object onto navigator or a global variable
>    navigator.toast = new Toasty();
>I've rewritten this plugin's javascript as a module and I'm
>recommending that the user requires the module in their code with
>    var toast = cordova.require('toast');
>Is this the recommended way?
>It works fine, it's just an extra step for the user, and different
>from using a builtin cordova function like
>Should I still assign the plugin code to navigator or cordova?
>Is there a way to have my plugin js required by plugin.xml,
>cordova.addPlugin or some other function???
>Are users to need to require built-in cordova for 2.0+?

View raw message