• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Plone Interactivity
 

Plone Interactivity

on

  • 1,395 views

Using KSS and jQuery to extend your Plone site.

Using KSS and jQuery to extend your Plone site.

Statistics

Views

Total Views
1,395
Views on SlideShare
1,392
Embed Views
3

Actions

Likes
2
Downloads
8
Comments
0

1 Embed 3

http://www.slideshare.net 3

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • So what kind of stuff are we going to talk about? <br /> <br /> We&#x2019;ll get the boring stuff out of the way first <br /> <br /> and then we&#x2019;ll move on to more interesting things like KSS and jQuery. <br /> <br /> There&#x2019;s a lot to cover, we&#x2019;ll hold questions until the end. And any of these slides that I don&#x2019;t get to, I&#x2019;ll just cut out of Plone 4.
  • So what kind of stuff are we going to talk about? <br /> <br /> We&#x2019;ll get the boring stuff out of the way first <br /> <br /> and then we&#x2019;ll move on to more interesting things like KSS and jQuery. <br /> <br /> There&#x2019;s a lot to cover, we&#x2019;ll hold questions until the end. And any of these slides that I don&#x2019;t get to, I&#x2019;ll just cut out of Plone 4.
  • Plone considers
  • You might use a block of code like this to include a script in your Plone template if <br /> <br /> you only need it on one page or one template <br /> <br /> or performance isn&#x2019;t really something you&#x2019;re concerned about.
  • You might use a block of code like this to include a script in your Plone template if <br /> <br /> you only need it on one page or one template <br /> <br /> or performance isn&#x2019;t really something you&#x2019;re concerned about.
  • Plone, however, provides Resource Registries for keeping track of things like CSS, JavaScript, and KSS.
  • So what makes resource registries useful? <br /> <br /> Control which scripts are included on a page and in what order they&#x2019;ll render. <br /> <br /> It gives you automatic merging and compression of your scripts. <br /> <br /> And makes JavaScript more cacheable.
  • So what makes resource registries useful? <br /> <br /> Control which scripts are included on a page and in what order they&#x2019;ll render. <br /> <br /> It gives you automatic merging and compression of your scripts. <br /> <br /> And makes JavaScript more cacheable.
  • So what makes resource registries useful? <br /> <br /> Control which scripts are included on a page and in what order they&#x2019;ll render. <br /> <br /> It gives you automatic merging and compression of your scripts. <br /> <br /> And makes JavaScript more cacheable.
  • And its easy for third-party products to add scripts to portal_javascript using Generic Setup. <br /> <br /> We can control all of the settings from here and even specify where it should wind up in the ordering.
  • And now, in Plone 3.3, we can use portal_javascript to include JavaScript being hosted on external servers.
  • And now, in Plone 3.3, we can use portal_javascript to include JavaScript being hosted on external servers.
  • And now, in Plone 3.3, we can use portal_javascript to include JavaScript being hosted on external servers.
  • And that&#x2019;s handy because of sites like Google&#x2019;s AJAX libraries API. <br /> <br /> Google hosts the libraries, you pull them into your site as needed. They&#x2019;ve got a number of the more-popular JavaScript libraries.
  • And that&#x2019;s handy because of sites like Google&#x2019;s AJAX libraries API. <br /> <br /> Google hosts the libraries, you pull them into your site as needed. They&#x2019;ve got a number of the more-popular JavaScript libraries.
  • These can be registered with the resource registries in the same manner as before. This time we&#x2019;ll use that ++resource++ path to point to the file we&#x2019;re after.
  • We can also register these to be available only for specific content types or browser layers so that they&#x2019;ll only appear in certain portions of a site.
  • We can also register these to be available only for specific content types or browser layers so that they&#x2019;ll only appear in certain portions of a site.
  • There&#x2019;s also a resourceDirectory ZCML directive that will allow you to register an entire folder of files, rather than registering each one individually. <br /> <br /> The url would look like this.
  • There&#x2019;s also a resourceDirectory ZCML directive that will allow you to register an entire folder of files, rather than registering each one individually. <br /> <br /> The url would look like this.
  • So, what are Javascript libraries?
  • So why might we use one? <br /> <br /> It&#x2019;s faster. You&#x2019;ve got better things to do with your time. <br /> <br /> Chances are someone&#x2019;s already done what you want to do, and done it better. <br /> <br /> It removes the need to know everything there is to know about writing JavaScript. <br /> <br /> And you can largely ignore browser compatibility issues.
  • So why might we use one? <br /> <br /> It&#x2019;s faster. You&#x2019;ve got better things to do with your time. <br /> <br /> Chances are someone&#x2019;s already done what you want to do, and done it better. <br /> <br /> It removes the need to know everything there is to know about writing JavaScript. <br /> <br /> And you can largely ignore browser compatibility issues.
  • So why might we use one? <br /> <br /> It&#x2019;s faster. You&#x2019;ve got better things to do with your time. <br /> <br /> Chances are someone&#x2019;s already done what you want to do, and done it better. <br /> <br /> It removes the need to know everything there is to know about writing JavaScript. <br /> <br /> And you can largely ignore browser compatibility issues.
  • So why might we use one? <br /> <br /> It&#x2019;s faster. You&#x2019;ve got better things to do with your time. <br /> <br /> Chances are someone&#x2019;s already done what you want to do, and done it better. <br /> <br /> It removes the need to know everything there is to know about writing JavaScript. <br /> <br /> And you can largely ignore browser compatibility issues.
  • So let&#x2019;s start with Plone&#x2019;s built-in library, KSS.
  • This is what a typical KSS rule might look like. Note that it looks very much like something we&#x2019;d see in a stylesheet.
  • One of the things you&#x2019;ll use most when writing KSS rules will be this bit. <br /> <br /> Essentially, we&#x2019;re telling KSS that we want to ignore the default click event of whatever element the rule applies to.
  • This means that if our rule applies to this link, we&#x2019;ll ignore the default action &#x2013;&#xA0;actually going to the front-page &#x2013;&#xA0;and instead apply our own actions, which in this case would be popping up a &#x201C;Hello World!&#x201D; alert message.
  • And that&#x2019;d look something like this.
  • So in that example, we used the &#x201C;alert&#x201D; client action. There are others we can use too.
  • So in that example, we used the &#x201C;alert&#x201D; client action. There are others we can use too.
  • So in that example, we used the &#x201C;alert&#x201D; client action. There are others we can use too.
  • So in that example, we used the &#x201C;alert&#x201D; client action. There are others we can use too.
  • So in that example, we used the &#x201C;alert&#x201D; client action. There are others we can use too.
  • So in that example, we used the &#x201C;alert&#x201D; client action. There are others we can use too.
  • Parameter providers let us pull data out of the current page so that we can use it in an action. <br /> <br /> NodeAttr lets you pull out the value of an HTML attribute of the selected element. <br /> <br /> NodeContent will return the text content of the selected element. <br /> <br /> currentFormVar and formVar pull values out of form fields.
  • Parameter providers let us pull data out of the current page so that we can use it in an action. <br /> <br /> NodeAttr lets you pull out the value of an HTML attribute of the selected element. <br /> <br /> NodeContent will return the text content of the selected element. <br /> <br /> currentFormVar and formVar pull values out of form fields.
  • Parameter providers let us pull data out of the current page so that we can use it in an action. <br /> <br /> NodeAttr lets you pull out the value of an HTML attribute of the selected element. <br /> <br /> NodeContent will return the text content of the selected element. <br /> <br /> currentFormVar and formVar pull values out of form fields.
  • Parameter providers let us pull data out of the current page so that we can use it in an action. <br /> <br /> NodeAttr lets you pull out the value of an HTML attribute of the selected element. <br /> <br /> NodeContent will return the text content of the selected element. <br /> <br /> currentFormVar and formVar pull values out of form fields.
  • So let&#x2019;s tie all of these concepts together. <br /> <br /> I&#x2019;ve created a simple html page with a form that accepts a color name and has a submit button. There&#x2019;s also a div that will tell the user what they&#x2019;ve just typed in. Complex stuff, I know. <br /> <br /> The KSS is rule says that when the user clicks on the submit button in our form, it&#x2019;ll ignore the default action (which would be to submit the form) and instead replace the content of the page element with the id #selectedColor with the value of the color field. <br /> <br /> Let&#x2019;s see this in action.
  • So let&#x2019;s tie all of these concepts together. <br /> <br /> I&#x2019;ve created a simple html page with a form that accepts a color name and has a submit button. There&#x2019;s also a div that will tell the user what they&#x2019;ve just typed in. Complex stuff, I know. <br /> <br /> The KSS is rule says that when the user clicks on the submit button in our form, it&#x2019;ll ignore the default action (which would be to submit the form) and instead replace the content of the page element with the id #selectedColor with the value of the color field. <br /> <br /> Let&#x2019;s see this in action.
  • So let&#x2019;s tie all of these concepts together. <br /> <br /> I&#x2019;ve created a simple html page with a form that accepts a color name and has a submit button. There&#x2019;s also a div that will tell the user what they&#x2019;ve just typed in. Complex stuff, I know. <br /> <br /> The KSS is rule says that when the user clicks on the submit button in our form, it&#x2019;ll ignore the default action (which would be to submit the form) and instead replace the content of the page element with the id #selectedColor with the value of the color field. <br /> <br /> Let&#x2019;s see this in action.
  • So what happens if JavaScript is disabled for whatever reason? <br /> <br /> KSS makes sure that if that&#x2019;s the case, then the click event override we&#x2019;ve created doesn&#x2019;t get registered and the page will fall back to its default functionality. <br /> <br /> So disabling javascript on this page, reloading and trying again, we get the same result. <br /> <br /> KSS makes this very easy, with only a minimal amount of planning on my part.
  • Alright, now let&#x2019;s get into some actual AJAX. Doing things on the client side is fine, but what if we want to do something a bit more involved with the data. <br /> <br /> So in this example, I&#x2019;m going to switch to using action-server. We&#x2019;ll call a python script I&#x2019;ve created. This could also be a browser view if we were creating this as a filesystem product. <br /> <br /> The script is expecting a parameter named &#x201C;color&#x201D;, so we&#x2019;ll need to pass that along as well. <br /> <br /> Looking at the script itself, there&#x2019;s a lot of boilerplate that you don&#x2019;t really need to be concerned about. Just trust that it&#x2019;s there for a reason and move on with your life. The important bits are the remaining three lines. First of all, we&#x2019;ll do a simple bit of Python and change the color name the script has received into uppercase. Next we&#x2019;ll grab the core kss commandset. Core essentially holds all of those action-client methods we could call directly from KSS, and provides them to Python. So in this case, we&#x2019;re going to replace the inner HTML of the element with the selectedColor id with the capitalized color name. <br /> <br /> Looking at this in action, we see that providing &#x2018;blue&#x2019; displays it in the page in uppercase, all without reloading the page.
  • Alright, now let&#x2019;s get into some actual AJAX. Doing things on the client side is fine, but what if we want to do something a bit more involved with the data. <br /> <br /> So in this example, I&#x2019;m going to switch to using action-server. We&#x2019;ll call a python script I&#x2019;ve created. This could also be a browser view if we were creating this as a filesystem product. <br /> <br /> The script is expecting a parameter named &#x201C;color&#x201D;, so we&#x2019;ll need to pass that along as well. <br /> <br /> Looking at the script itself, there&#x2019;s a lot of boilerplate that you don&#x2019;t really need to be concerned about. Just trust that it&#x2019;s there for a reason and move on with your life. The important bits are the remaining three lines. First of all, we&#x2019;ll do a simple bit of Python and change the color name the script has received into uppercase. Next we&#x2019;ll grab the core kss commandset. Core essentially holds all of those action-client methods we could call directly from KSS, and provides them to Python. So in this case, we&#x2019;re going to replace the inner HTML of the element with the selectedColor id with the capitalized color name. <br /> <br /> Looking at this in action, we see that providing &#x2018;blue&#x2019; displays it in the page in uppercase, all without reloading the page.
  • Alright, now let&#x2019;s get into some actual AJAX. Doing things on the client side is fine, but what if we want to do something a bit more involved with the data. <br /> <br /> So in this example, I&#x2019;m going to switch to using action-server. We&#x2019;ll call a python script I&#x2019;ve created. This could also be a browser view if we were creating this as a filesystem product. <br /> <br /> The script is expecting a parameter named &#x201C;color&#x201D;, so we&#x2019;ll need to pass that along as well. <br /> <br /> Looking at the script itself, there&#x2019;s a lot of boilerplate that you don&#x2019;t really need to be concerned about. Just trust that it&#x2019;s there for a reason and move on with your life. The important bits are the remaining three lines. First of all, we&#x2019;ll do a simple bit of Python and change the color name the script has received into uppercase. Next we&#x2019;ll grab the core kss commandset. Core essentially holds all of those action-client methods we could call directly from KSS, and provides them to Python. So in this case, we&#x2019;re going to replace the inner HTML of the element with the selectedColor id with the capitalized color name. <br /> <br /> Looking at this in action, we see that providing &#x2018;blue&#x2019; displays it in the page in uppercase, all without reloading the page.
  • We saw that &#x201C;getCommandSet&#x201D; line... there are 3 different command sets that come with KSS out of the box. I mentioned &#x2018;core&#x2019;, that essentially provides all of the action-client calls available in our KSS rules. <br /> <br /> The second is the Zope command set, which allows us to redraw providers -- things like viewlet managers and portlet managers -- or to redraw individual viewlets. <br /> <br /> Third is the Plone command set, which lets us do things like display portal messages or refresh portlets. <br /> <br /> All of these let us interact with the browser window from Python. So KSS has allowed JavaScript to talk to Python and Python to talk to JavaScript.
  • So how do we register a kss file? <br /> <br /> We&#x2019;re going to use one of the resource registries we talked about earlier -- portal_kss.
  • Typically, that&#x2019;s done from GenericSetup, using an kssregistry.xml file. <br /> <br /> This looks almost exactly like the JavaScript registration we looked at earlier.
  • So how do you go about debugging KSS? <br /> <br /> Firebug. Firebug. Firebug. <br /> <br /> Or, if you&#x2019;re debugging in something that&#x2019;s not Firefox, try Firebug Lite.
  • So how do you go about debugging KSS? <br /> <br /> Firebug. Firebug. Firebug. <br /> <br /> Or, if you&#x2019;re debugging in something that&#x2019;s not Firefox, try Firebug Lite.
  • So how do you go about debugging KSS? <br /> <br /> Firebug. Firebug. Firebug. <br /> <br /> Or, if you&#x2019;re debugging in something that&#x2019;s not Firefox, try Firebug Lite.
  • So how do you go about debugging KSS? <br /> <br /> Firebug. Firebug. Firebug. <br /> <br /> Or, if you&#x2019;re debugging in something that&#x2019;s not Firefox, try Firebug Lite.
  • A side-effect of KSS&#x2019;s no-javascript failover is that if there&#x2019;s an error, your page&#x2019;s KSS will fail to load. Which means that it will typically fail silently. So, essentially, all of the KSS functionality on that page will fail to work if there is a syntax error. I spent a day chasing down what turned out to be a missing semicolon in my ruleset. <br /> <br /> But, if you turn on javascript debugging in portal_javascript, KSS debugging information will appear in Firebug&#x2019;s console window. And there&#x2019;s a lot of it.
  • And this is what that debugging output will look like. Firebug will show all of the rules being processed, any XMLRPC calls being passed around, and detailed error messages that may crop up.
  • There&#x2019;s also &#x201C;Firekiss&#x201D;, a Firebug extension from the KSS folks. It&#x2019;ll show your KSS rules and allow you to change debug mode and log level from within Firebug.
  • There are a number of KSS addons available. <br /> <br /> kss.plugin.cacheability which enables KSS requests to be cached. <br /> kss.plugin.cns provides a number of new client actions. <br /> kss.plugin.fadeeffect adds image fading and substitution. <br /> kss.plugin.history allows you to modify the browser location in an effort to add backward and forward navigation to a javascript application. <br /> kss.plugin.jsmath uses the jsmath library to display complex mathematical functions. <br /> kss.plugin.timer displays a timer. <br /> kss.plugin.yuidnd integrates the Yahoo User Interface drag-and-drop library.
  • Quick recap: What is KSS? <br /> <br /> It uses a simple, css-style syntax. <br /> Basically, it&#x2019;s Javascript, without the JavaScript, which for someone like me who hates writing Javascript, is really awesome.
  • It&#x2019;s not really the best solution.
  • So now you&#x2019;re thinking
  • Why?
  • So here&#x2019;s why... <br /> It&#x2019;s huge. The relevant scripts check in at over 100 k. <br /> It&#x2019;s been slow to catch on, both within and outside of the Plone project. <br /> And the documentation is somewhat lacking. <br /> <br /> I really like KSS and relied on it heavily to build GloWorm. I think I made it about 90% of the way through to the final release before I actually had to write a line of JavaScript code myself, KSS handled the large majority of what I wanted to do. KSS was revolutionary when it was introduced, but since then there have been some fantastic developments in other areas. <br /> <br /> Because of that and the fact that the current direction that Plone core development is taking is to make Plone itself ship as a much leaner product, KSS will probably be dropped as a core component in the near future. Most likely in Plone 5.
  • So here&#x2019;s why... <br /> It&#x2019;s huge. The relevant scripts check in at over 100 k. <br /> It&#x2019;s been slow to catch on, both within and outside of the Plone project. <br /> And the documentation is somewhat lacking. <br /> <br /> I really like KSS and relied on it heavily to build GloWorm. I think I made it about 90% of the way through to the final release before I actually had to write a line of JavaScript code myself, KSS handled the large majority of what I wanted to do. KSS was revolutionary when it was introduced, but since then there have been some fantastic developments in other areas. <br /> <br /> Because of that and the fact that the current direction that Plone core development is taking is to make Plone itself ship as a much leaner product, KSS will probably be dropped as a core component in the near future. Most likely in Plone 5.
  • So here&#x2019;s why... <br /> It&#x2019;s huge. The relevant scripts check in at over 100 k. <br /> It&#x2019;s been slow to catch on, both within and outside of the Plone project. <br /> And the documentation is somewhat lacking. <br /> <br /> I really like KSS and relied on it heavily to build GloWorm. I think I made it about 90% of the way through to the final release before I actually had to write a line of JavaScript code myself, KSS handled the large majority of what I wanted to do. KSS was revolutionary when it was introduced, but since then there have been some fantastic developments in other areas. <br /> <br /> Because of that and the fact that the current direction that Plone core development is taking is to make Plone itself ship as a much leaner product, KSS will probably be dropped as a core component in the near future. Most likely in Plone 5.
  • So here&#x2019;s why... <br /> It&#x2019;s huge. The relevant scripts check in at over 100 k. <br /> It&#x2019;s been slow to catch on, both within and outside of the Plone project. <br /> And the documentation is somewhat lacking. <br /> <br /> I really like KSS and relied on it heavily to build GloWorm. I think I made it about 90% of the way through to the final release before I actually had to write a line of JavaScript code myself, KSS handled the large majority of what I wanted to do. KSS was revolutionary when it was introduced, but since then there have been some fantastic developments in other areas. <br /> <br /> Because of that and the fact that the current direction that Plone core development is taking is to make Plone itself ship as a much leaner product, KSS will probably be dropped as a core component in the near future. Most likely in Plone 5.
  • So that brings us to jQuery, the JavaScript library with which we&#x2019;re slowly replacing KSS functionality in Plone core.
  • So why use jQuery <br /> <br /> It&#x2019;s a DOM-focused library, and by that, I mean that it&#x2019;s less of a &#x201C;make JavaScript a real language&#x201D; library, and more of a &#x201C;get stuff done&#x201D; library. <br /> <br /> It&#x2019;s got a very simple syntax. <br /> <br /> It&#x2019;s easy to add on to the core functionality and there are lots of plugins available that do so. <br /> <br /> It&#x2019;s quite small. <br /> <br /> And there&#x2019;s a large amount of good documentation.
  • So why use jQuery <br /> <br /> It&#x2019;s a DOM-focused library, and by that, I mean that it&#x2019;s less of a &#x201C;make JavaScript a real language&#x201D; library, and more of a &#x201C;get stuff done&#x201D; library. <br /> <br /> It&#x2019;s got a very simple syntax. <br /> <br /> It&#x2019;s easy to add on to the core functionality and there are lots of plugins available that do so. <br /> <br /> It&#x2019;s quite small. <br /> <br /> And there&#x2019;s a large amount of good documentation.
  • So why use jQuery <br /> <br /> It&#x2019;s a DOM-focused library, and by that, I mean that it&#x2019;s less of a &#x201C;make JavaScript a real language&#x201D; library, and more of a &#x201C;get stuff done&#x201D; library. <br /> <br /> It&#x2019;s got a very simple syntax. <br /> <br /> It&#x2019;s easy to add on to the core functionality and there are lots of plugins available that do so. <br /> <br /> It&#x2019;s quite small. <br /> <br /> And there&#x2019;s a large amount of good documentation.
  • So why use jQuery <br /> <br /> It&#x2019;s a DOM-focused library, and by that, I mean that it&#x2019;s less of a &#x201C;make JavaScript a real language&#x201D; library, and more of a &#x201C;get stuff done&#x201D; library. <br /> <br /> It&#x2019;s got a very simple syntax. <br /> <br /> It&#x2019;s easy to add on to the core functionality and there are lots of plugins available that do so. <br /> <br /> It&#x2019;s quite small. <br /> <br /> And there&#x2019;s a large amount of good documentation.
  • So why use jQuery <br /> <br /> It&#x2019;s a DOM-focused library, and by that, I mean that it&#x2019;s less of a &#x201C;make JavaScript a real language&#x201D; library, and more of a &#x201C;get stuff done&#x201D; library. <br /> <br /> It&#x2019;s got a very simple syntax. <br /> <br /> It&#x2019;s easy to add on to the core functionality and there are lots of plugins available that do so. <br /> <br /> It&#x2019;s quite small. <br /> <br /> And there&#x2019;s a large amount of good documentation.
  • The basis of all jQuery calls is known as the jQuery factory function. <br /> <br /> Typically shortened as a dollar sign. <br /> <br /> In Plone, it&#x2019;s aliased as &#x201C;jq&#x201D;. We&#x2019;ll get into that a bit more later, but for now all of my examples will use the &#x201C;jq&#x201D; alias since that&#x2019;s what you can expect to use when writing scripts for Plone.
  • We can pass all sorts of selectors to the factory function. Most of the time, we&#x2019;ll use a CSS selector, like a tag, id, or class. <br /> <br /> But can also use XPath statements to select particular elements of the HTML document we&#x2019;re interacting with.
  • We can pass all sorts of selectors to the factory function. Most of the time, we&#x2019;ll use a CSS selector, like a tag, id, or class. <br /> <br /> But can also use XPath statements to select particular elements of the HTML document we&#x2019;re interacting with.
  • We can pass all sorts of selectors to the factory function. Most of the time, we&#x2019;ll use a CSS selector, like a tag, id, or class. <br /> <br /> But can also use XPath statements to select particular elements of the HTML document we&#x2019;re interacting with.
  • We can pass all sorts of selectors to the factory function. Most of the time, we&#x2019;ll use a CSS selector, like a tag, id, or class. <br /> <br /> But can also use XPath statements to select particular elements of the HTML document we&#x2019;re interacting with.
  • We can pass all sorts of selectors to the factory function. Most of the time, we&#x2019;ll use a CSS selector, like a tag, id, or class. <br /> <br /> But can also use XPath statements to select particular elements of the HTML document we&#x2019;re interacting with.
  • jQuery is fully CSS3 compliant, so we get all sorts of new CSS pseudo-selectors. <br /> <br /> We can select the first or last instance of a selector. <br /> <br /> We can get content that does not meet certain criteria. <br /> <br /> We can get the first, last, or nnth element of a group. <br /> <br /> And also defines some of its own (:even/:odd).
  • jQuery is fully CSS3 compliant, so we get all sorts of new CSS pseudo-selectors. <br /> <br /> We can select the first or last instance of a selector. <br /> <br /> We can get content that does not meet certain criteria. <br /> <br /> We can get the first, last, or nnth element of a group. <br /> <br /> And also defines some of its own (:even/:odd).
  • jQuery is fully CSS3 compliant, so we get all sorts of new CSS pseudo-selectors. <br /> <br /> We can select the first or last instance of a selector. <br /> <br /> We can get content that does not meet certain criteria. <br /> <br /> We can get the first, last, or nnth element of a group. <br /> <br /> And also defines some of its own (:even/:odd).
  • jQuery is fully CSS3 compliant, so we get all sorts of new CSS pseudo-selectors. <br /> <br /> We can select the first or last instance of a selector. <br /> <br /> We can get content that does not meet certain criteria. <br /> <br /> We can get the first, last, or nnth element of a group. <br /> <br /> And also defines some of its own (:even/:odd).
  • Whether our selector finds one, many, or no page elements, jQuery&#x2019;s &#x201C;Implicit Iteration&#x201D; means that methods assume that the selector&#x2019;s result is a set of elements and will run accordingly. That lets us call methods without worrying about the number of results.
  • Whether our selector finds one, many, or no page elements, jQuery&#x2019;s &#x201C;Implicit Iteration&#x201D; means that methods assume that the selector&#x2019;s result is a set of elements and will run accordingly. That lets us call methods without worrying about the number of results.
  • Whether our selector finds one, many, or no page elements, jQuery&#x2019;s &#x201C;Implicit Iteration&#x201D; means that methods assume that the selector&#x2019;s result is a set of elements and will run accordingly. That lets us call methods without worrying about the number of results.
  • Operations on an element will always return a result. That result could be the same element, another element, or a set of elements. <br /> <br /> So instead of calling methods on an object over and over. <br /> <br /> We can chain commands, performing operations on the previous command&#x2019;s result.
  • Operations on an element will always return a result. That result could be the same element, another element, or a set of elements. <br /> <br /> So instead of calling methods on an object over and over. <br /> <br /> We can chain commands, performing operations on the previous command&#x2019;s result.
  • Operations on an element will always return a result. That result could be the same element, another element, or a set of elements. <br /> <br /> So instead of calling methods on an object over and over. <br /> <br /> We can chain commands, performing operations on the previous command&#x2019;s result.
  • We can chain as much as we like, doing it all on one line, <br /> <br /> or several. Splitting it across several lines allows us to provide much more in the way of comments.
  • We can chain as much as we like, doing it all on one line, <br /> <br /> or several. Splitting it across several lines allows us to provide much more in the way of comments.
  • Typically, in JavaScript land, we might define a function that would run once the page has finished loading. <br /> <br /> The problem is that if we do it this way, each new function we add <br /> <br /> would overwrite the others and prevent them from running.
  • Typically, in JavaScript land, we might define a function that would run once the page has finished loading. <br /> <br /> The problem is that if we do it this way, each new function we add <br /> <br /> would overwrite the others and prevent them from running.
  • Typically, in JavaScript land, we might define a function that would run once the page has finished loading. <br /> <br /> The problem is that if we do it this way, each new function we add <br /> <br /> would overwrite the others and prevent them from running.
  • Using jQuery, we could rewrite the this function like this, by assigning a new function to jQuery&#x2019;s document ready event. <br /> <br /> And since jQuery implements an event queue, we can do this <br /> <br /> as many <br /> <br /> times as <br /> <br /> we&#x2019;d like without worrying that registering one will override another.
  • Using jQuery, we could rewrite the this function like this, by assigning a new function to jQuery&#x2019;s document ready event. <br /> <br /> And since jQuery implements an event queue, we can do this <br /> <br /> as many <br /> <br /> times as <br /> <br /> we&#x2019;d like without worrying that registering one will override another.
  • Using jQuery, we could rewrite the this function like this, by assigning a new function to jQuery&#x2019;s document ready event. <br /> <br /> And since jQuery implements an event queue, we can do this <br /> <br /> as many <br /> <br /> times as <br /> <br /> we&#x2019;d like without worrying that registering one will override another.
  • Using jQuery, we could rewrite the this function like this, by assigning a new function to jQuery&#x2019;s document ready event. <br /> <br /> And since jQuery implements an event queue, we can do this <br /> <br /> as many <br /> <br /> times as <br /> <br /> we&#x2019;d like without worrying that registering one will override another.
  • Using jQuery, we could rewrite the this function like this, by assigning a new function to jQuery&#x2019;s document ready event. <br /> <br /> And since jQuery implements an event queue, we can do this <br /> <br /> as many <br /> <br /> times as <br /> <br /> we&#x2019;d like without worrying that registering one will override another.
  • Using jQuery, we could rewrite the this function like this, by assigning a new function to jQuery&#x2019;s document ready event. <br /> <br /> And since jQuery implements an event queue, we can do this <br /> <br /> as many <br /> <br /> times as <br /> <br /> we&#x2019;d like without worrying that registering one will override another.
  • If you remember back to that first KSS action we wrote, we created an action that overrode a link with the id &#x201C;mykssbutton&#x201D; and instead popped up a &#x201C;hello world&#x201D; alert box. <br /> <br /> Let&#x2019;s rewrite that in jQuery....
  • So it&#x2019;ll look like this... <br /> <br /> We&#x2019;ll use the document ready event to signal that a new function should be assigned to click event of the element with an id of #mykssbutton. That new function will present an alert window stating &#x201C;Hello World!&#x201D;
  • Example... create a script that adds a pdf icon to all links on the page pointing to pdfs.
  • And we can do our AJAX calls too. <br /> <br /> This was our KSS AJAX script.
  • And we can do our AJAX calls too. <br /> <br /> This was our KSS AJAX script.
  • And this is how it&#x2019;d look in jQuery. <br /> <br /> Our python script is going to be a lot simpler, now it just returns the data we&#x2019;re after instead of handling the changing of the page content. <br /> <br /> Then, we&#x2019;ll tell the selectedColor element to load the response from our jq_transformColor script. <br /> <br /> Our jQuery will override the submit method of the form. We&#x2019;ll grab the value of the color field. <br /> <br /> <br /> <br /> The last line is a bit of voodoo... In order to prevent the form from actually submitting, we return a false value. If we returned true, it&#x2019;d go ahead and complete the action.
  • jQuery core is now included with Plone as of version 3.1. <br /> <br /> Plone uses jq instead of the dollar sign shortcut to avoid potential conflicts with other javascript libraries. <br /> <br /> And if you&#x2019;ve been using &#x2018;cssQuery&#x2019; or &#x2018;registerPloneFunction&#x2019;, you should now be using &#x2018;jq&#x2019; instead.
  • There are over a thousand jQuery plugins available to handle things like animation, layout, forms, and AJAX.
  • So how might you integrate one of these into Plone? <br /> <br /> If the plugin uses the &#x2018;$&#x2019; factory alias, you&#x2019;ll need to place it between jquery.js and jquery-integration.js in the portal_javascript registry. Using GenericSetup, that&#x2019;d look something like this -- specifying that the script should be inserted before jquery-integration.js in the ordering. <br /> <br /> Or you can wrap it in a function like this.
  • So how might you integrate one of these into Plone? <br /> <br /> If the plugin uses the &#x2018;$&#x2019; factory alias, you&#x2019;ll need to place it between jquery.js and jquery-integration.js in the portal_javascript registry. Using GenericSetup, that&#x2019;d look something like this -- specifying that the script should be inserted before jquery-integration.js in the ordering. <br /> <br /> Or you can wrap it in a function like this.
  • So how might you integrate one of these into Plone? <br /> <br /> If the plugin uses the &#x2018;$&#x2019; factory alias, you&#x2019;ll need to place it between jquery.js and jquery-integration.js in the portal_javascript registry. Using GenericSetup, that&#x2019;d look something like this -- specifying that the script should be inserted before jquery-integration.js in the ordering. <br /> <br /> Or you can wrap it in a function like this.
  • So let&#x2019;s look at some existing behaviors that Plone provides through jQuery...
  • And there are quite a few Plone products currently making use of jQuery.
  • collective.flowplayer will turn links to flash videos or mp3s into inline players.
  • Deco, which will be the content layout and editing tool in Plone 5 makes extensive use of jQuery to handle layout and interaction.
  • jQuery has some excellent documentation available. I highly recommend checking it out.
  • I&#x2019;m a fan of the &#x201C;Learning jQuery&#x201D; book from Packt.
  • And I just want to mention a few other libraries that you can use with Plone. They&#x2019;re each focused on different tasks or approaches to writing interactive applications.
  • If you&#x2019;re not comfortable with JavaScript or are pressed for time, KSS is the way to go. It&#x2019;s easy. <br /> Otherwise, your best bet is to use JQuery.
  • If you&#x2019;re not comfortable with JavaScript or are pressed for time, KSS is the way to go. It&#x2019;s easy. <br /> Otherwise, your best bet is to use JQuery.
  • Any questions?

Plone Interactivity Plone Interactivity Presentation Transcript