Hey Rebecca, > Does it mean that I need to add jquery namespace to every jQuery function in > the plugin?
You shouldn't have to change the plug-in at all, I would just leave it as is. > What 's more, how do you find out my plugins don't support AMD. It looks > like if I can find a slideshow plugin which support AMD , then I just need to > change one line code as your first email mentioned: You can usually look at the source code [1] to find out whether a plug-in supports it or not (searching for "define(" or amd). Even if it doesn't, it should just work. > require(['jquery', > 'sakai/sakai.api.core','/devwidgets/[widget]/javascript/slides.js'], > function($, sakai, slidesjs) { That looks right to me. Just realize that the variable "slidesjs" will be undefined, but that shouldn't be an issue since you won't/shouldn't be using it. The conventional/old way of communicating between different JavaScript files is to use global variables. The issue with that is having conflicts (for instance if you use the same global variable in multiple files). RequireJS solves this for us and it should work with plug-ins that do and don't support AMD. - Christian [1] https://github.com/nathansearles/Slides/blob/master/source/slides.js On Jul 27, 2012, at 1:55 PM, Rebecca juanwang wrote: > Hi Scot: > > Does it mean that I need to add jquery namespace to every jQuery > function in the plugin? > What 's more, how do you find out my plugins don't support AMD. It > looks like if I can find a slideshow plugin which support AMD , then I just > need to change one line code as your first email mentioned: > > require(['jquery', > 'sakai/sakai.api.core','/devwidgets/[widget]/javascript/slides.js'], > function($, sakai, slidesjs) { > > right? > > > Thanks for your time > > Rebecca > > > > > On Mon, Jul 23, 2012 at 3:28 PM, Scot Hacker <shac...@berkeley.edu> wrote: > On Jul 23, 2012, at 11:42 AM, Scot Hacker wrote: > > > Juan - Although most documentation out there demonstrates using jquery > > directly in the HTML page/template, OAE does not allow this. There is a > > very strict separation of concerns, and script tags will be stripped out > > when the page is rendered. You must place all code in your [widget].js, > > attaching it via IDs and classes in the HTML. > > > > To invoke the script for the plugin from your [widget].js, you'll need to > > use the "require" mechanism at the top of the widget js. So if you put the > > plugin at /devwidgets/[widget]/javascript/slides.js, you'll need to change > > the require line from e.g. > > > > require(['jquery', 'sakai/sakai.api.core'], function($, sakai) { > > > > to > > > > require(['jquery', > > 'sakai/sakai.api.core','/devwidgets/[widget]/javascript/slides.js'], > > function($, sakai, slidesjs) { > > > > You can then reference the plugin's methods from within the widget js by > > the name "slidesj". > > Just amending this a bit after talking with Christian... The example above > will work for any plugins that support AMD: > > https://github.com/amdjs/amdjs-api/wiki/AMD > > (your plugin does not). In the absence of AMD, the plugin may append to the > jQuery namespace, which is the case with slidesjs. So in your case you would > reference its methods with something like: > > $(".selector").slidesjs.some_method() > > I.e. it gets added to the jquery namespace, not the global. Other plugins may > behave differently. > > ./s > > __________________________ > Scot Hacker > Senior Software Developer @ CalCentral > Educational Technology Services, UC Berkeley > > shac...@berkeley.edu > (510) 292-5586 > __________________________ > > > > > > > > _______________________________________________ > oae-dev mailing list > oae-dev@collab.sakaiproject.org > http://collab.sakaiproject.org/mailman/listinfo/oae-dev > > _______________________________________________ > oae-dev mailing list > oae-dev@collab.sakaiproject.org > http://collab.sakaiproject.org/mailman/listinfo/oae-dev
_______________________________________________ oae-dev mailing list oae-dev@collab.sakaiproject.org http://collab.sakaiproject.org/mailman/listinfo/oae-dev