Return-Path: X-Original-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 12C93D75A for ; Fri, 6 Jul 2012 17:41:58 +0000 (UTC) Received: (qmail 372 invoked by uid 500); 6 Jul 2012 17:41:57 -0000 Delivered-To: apmail-incubator-callback-dev-archive@incubator.apache.org Received: (qmail 334 invoked by uid 500); 6 Jul 2012 17:41:57 -0000 Mailing-List: contact callback-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-dev@incubator.apache.org Received: (qmail 325 invoked by uid 99); 6 Jul 2012 17:41:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jul 2012 17:41:57 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FSL_FREEMAIL_1,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of alunny@gmail.com designates 209.85.160.175 as permitted sender) Received: from [209.85.160.175] (HELO mail-gh0-f175.google.com) (209.85.160.175) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Jul 2012 17:41:51 +0000 Received: by ghbz2 with SMTP id z2so8296845ghb.6 for ; Fri, 06 Jul 2012 10:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=cBhOBlLSrtaLq+xiz1eQ3FfsPTuvJ0/BsoHrWY8ekcM=; b=MVF6yWcgMC958heA2MTsWm1hpmqst5PM9r2ls+p/gqPbJiisr6gR59Zh969dnfMllb ORnvfUH65HaPiTzsXhSTjN1PwcXisK85J3w6ygYuq7wYbKv3oTKh2tv517D8vOolK8uO reOMDPae/IaLD+hhYzo6cnncCb2fkBzqRVY1nMSSZjl3AwSDJ1smnYfgSTLYg6jbwFds QIaCAd9BHjtHO0DaVwCK0aBJ97PgVKzvRMZTb6UHdSw+RRtCamr997/KcqyNfh5HKvf1 +mnJy+GNOqX6Y/eAfYyHSmDMXATLFb5rlSNUk5vcDR5PjYGSacDLiE8AqlTCq+4A+Syi Lk1Q== MIME-Version: 1.0 Received: by 10.43.59.71 with SMTP id wn7mr5173553icb.0.1341596489833; Fri, 06 Jul 2012 10:41:29 -0700 (PDT) Received: by 10.64.50.40 with HTTP; Fri, 6 Jul 2012 10:41:29 -0700 (PDT) Reply-To: alunny@gmail.com In-Reply-To: References: Date: Fri, 6 Jul 2012 10:41:29 -0700 Message-ID: Subject: Re: requiring javascript for plugins From: Andrew Lunny To: callback-dev@incubator.apache.org Content-Type: multipart/alternative; boundary=bcaec51ddaa7355c8b04c42cc6a2 --bcaec51ddaa7355c8b04c42cc6a2 Content-Type: text/plain; charset=ISO-8859-1 +1 to everything Fil says. On 6 July 2012 07:32, Filip Maj wrote: > 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(); > > > > > https://github.com/m00sey/Toasty/blob/f9dbf58e11cf4ecf386f70331960d33e8756 > >6dd9/assets/www/phonegap-toast.js > > > >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'); > > > > > https://github.com/don/Toasty/blob/bf61ff3c738cebcd285f82490920cf713ac095a > >a/assets/www/phonegap-toast.js > > > >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 > >navigator.notification.vibrate. > > > >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+? > > --bcaec51ddaa7355c8b04c42cc6a2--