The Yahoo! User Interface Library or YUI is a handy collection of JavaScript for DOM scripting, DHTML and AJAX applications. And since JavaScript along with Python is one of the languages for Google’s App Engine, it’s useful to look at how hard it is to use the Yahoo! UI library on App Engine.
At least to throw together a simple donut slider.
To get started look at the starter page on the YUI slider page. Download the minimum slider components which is some JavaScript, some images files and some CSS. In your /static/js directory you’ll want to add dragdrop-min.js, slider-min.js and yahoo-dom-event.js. Then you’ll have to code up a simple the-slider.js file which looks like the example but contains arrays for the link titles and the link urls. This JavaScript should also include a function to update the div with the dynamic content, in this case referred to as endvalue, when the slideEnd is triggered.
slider.subscribe("slideEnd", function() {
YAHOO.log("slideEnd fired", "warn");
var endvalue = Dom.get(contentarea);
var i = slider.getRealValue();
if (i < minPosts) i = minPosts;
if (i > maxPosts) i = maxPosts;
endvalue.innerHTML = '';
for (j = 0; j < 10; j++)
{
if ((i+j) < maxPosts) {
endvalue.innerHTML += '<a class="rt" href="' + theURLs[i+j] + '" target="_blank">' + theTitles[i+j] + '</a><br>';
}
}
});
Next up you can optionally update the graphics for your slider. The default .gif files are in an /assets folder. In this I added a donut image for the knob. You can use anything you want just remember to update your app.yaml file or it won’t work.
- url: /assets/ static_dir: static/assets
Next use the .css file (path also added to the app.yaml) and finally add another class to the python code to create the page. In this case add a class sliderPage that maps to /slider and import the javascript, css and some default urls and titles. That’s it. Pretty straightforward.
class sliderPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write('<script src="/js/yahoo-dom-event.js"></script>')
self.response.out.write('<script src="/js/dragdrop-min.js"></script>')
self.response.out.write('<script src="/js/slider-min.js"></script>')
self.response.out.write('<link rel="stylesheet" type="text/css" href="/css/s.css" />')
self.response.out.write('<script src="/js/the-slider.js"></script>')
self.response.out.write('')
self.response.out.write('<p><table> <tr> <td>Older</td> <td>')
self.response.out.write('<div id="slider-bg" tabindex="-1" title="Slider">')
self.response.out.write('<div id="slider-thumb"><img src="/assets/thumb-n.gif"></div>')
self.response.out.write('</div> </td> <td>Newer</td> </tr> </table>')
self.response.out.write('')
self.response.out.write('<p><div id="the-content">')
self.response.out.write('<a class="rt" href="http://boldlentil.wordpress.com/2007/05/05/hello-world/" target="_blank">Remembering Gerald</a><br>')
(... other starting titles and urls here... )
self.response.out.write('</div>')
self.response.out.write('<p>-<p>')
self.response.out.write('<a class="rt" href="http://boldlentil.wordpress.com/" target="_blank">Bold Lentil</a><br>')
self.response.out.write('')
self.response.out.write('</html>')
Now what would be handy would be a /sstatic or shared static directory for assets, like the donut slider, to be shared across all my future applications…
Tags: ajax, App Engine, donut slider, yui

May 22, 2008 at 3:16 pm
Donut sliders are child’s play. Creating a feral pumpkin slider would be impressive, but a donut…
May 22, 2008 at 10:54 pm
OK you challenge me to move beyond donut sliders to feral pumpkin sliders? Fine, here it is:
http://1boldlentil.appspot.com/feral-pumpkin-slider
(I even did it as a PNG instead of a GIF )
May 23, 2008 at 1:54 pm
Nice.
Why is a PNG a ping? Why can’t is be a pong or a pang or a puh-nug?
May 26, 2008 at 9:37 pm
Yeah well I did prep for this comment by checking the PNG page at:
http://www.libpng.org/pub/png/
where they helpfully note that:
“Portable Network Graphics - An Open, Extensible Image Format with Lossless Compression
(Not Related to Papua New Guinea, the Pawnee National Grassland,
the Professional Numismatists Guild or the “Pack ‘N’ Go” format)”
May 30, 2008 at 10:06 am
[...] Bold Lentil shows you how to get YUI working on the Google App Engine: The Google App Engine, Google’s new cloud-computing platform, is framework-agnostic on the JavaScript side, so if YUI is your framework of choice you’ll be happy to see this quick tutorial from Bold Lentil that shows you how to get a YUI-driven donut slider (and, alas, a feral pumpkin slider) going in the Google environment. [...]