Home | Blog Roll |  Link Roll |  Colophon/About| |


Archive for the ‘Web’ Category

Tab interface for static content using JavaScript Prototype

Thursday, October 9th, 2008

I wanted to make a simple as possible Tab interface, using the Prototype JavaScript library (version 1.6.0.3 in this case using the Goggle AJAX Libraries API).  Further adventures is modern javascripting….

Real world uses for this would include any time you have big long page with static chucks of text, or other content, that you want to reveal only  a bit at the time.   As demonstrated, here at tab.html, that content could be static text or images or html input fields.

The html for the Tabbed navigation is a unordered list (could be an ordered list) and anchor href links for the target id’s and text:

<ul class="TabNav" >
<li id="defaultTab"><a href="#SectionAA">A Section</a></li>
<li><a href="#SectionAnother">another Section</a></li>
<li><a href="#Section3">Section 3</a></li>
<li><a href="#Section4">Section 4</a></li>
</ul>

where the target of the a href (i.e. “#Section3″ i) referees to the id of the content you wish to make visible if prefixed with a pound hash (#), otherwise it acts just like a regular anchor link. (and external page links works as normal.)

I’m also assuming that the all the static content is nested under a parent tag (in this case a “div”) like this

<div>
<div id="SectionAA" >SectionAA content</div>
<div id="SectionAnother" >SectionAnother content </div>
<div id="Section3">section content </div>
<div id="Section4" >section content</div>
<div id="Section5" >section content</div>
</div>

the only configuration is done in the JavaScript file tab.js:

var navTabClass = 'TabNav';
var navTabSelectedClass = 'selectedTab';
var defaultTabId = 'defaultTab';

where 2 CSS style names are set and the default selected tab’s id is indicated.

Using the defaultTabId is optional, and if not used then the item (<li>) under the navTabClass list is used. no default demonstrates this, the JavaScript was nasty to figure out - get the element with the class and get it’s first child:

$$('.'+navTabClass).first().firstDescendant()

Notice that the url on the page is not being updated with the anchor name (i.e. http://www.falsepositives.com/web/tab/tab.html#Section3), since you are navigation within a page.  The default behavior can be restored by setting the variable preventDefaultEventonTabSelect to zero.  (and yes I could parse the starting url to see if a valid anchor name is supplied and use that to set the default tab, on startup.)

the trickiest part of the JavaScript is handling whether the Li is selected or “just” the text of the A link

if (elm.tagName == 'A' ) {
liElm = elm.parentNode;
aElm = elm ;
} else {
liElm = elm;
aElm = elm.firstDescendant();
}

The CSS styling of the page tab.css I’ve also left minimalist, but workable.

Also note that if javascript is disabled, then all content is visible, and the anchor links in the tags navigate you to that location as a proper default behavior.

enjoy…

JavaScript for a single element radio button list, revisited with Prototype

Thursday, October 2nd, 2008

Last year I posted JavaScript for a single element radio button list, referring to a issue I had with getting the value of generated radio button list. (All the standard solutions / samples that i found assumed the there are 2 or more choices.  And I had a case were an optional field might only have one value.  So I had to detect / trap and report on the value of this boundary case.)

I recently had reason to revisit my solution  and have since corrected two things.

In my original posting I had hard coded the name attribute of the radio button array.   Very bad,very lazy!That’s been rectified by passing the value of the name attribute into the function and using the forms element collection like this:

var ne = document.forms[0].elements[name];

Much better!

I also had cause to see if I could do better using the Prototype javascript framework? How about reducing 12 lines to 1 line like this :

selected = $$(’input:checked[name=”‘+name+’”]’).pluck(’value’);

You gotta like that!  (I’m also using the Google AJAX Libraries API to load the latest 1.6.0.3 release.)

As I mentioned in last years post all this also works for Check Box lists as well a Radio button lists.

I have a demo of this in serbl.html, showing the js running on a single radio button list, as well as a multi value radio button list and (because I don’t expect one to take my word) single check box button list, as well as a multi value check box button list.  The javascript functions used (getSelectedOW for OldWay, and getSelectedPW for Prototype Way) are in sebl.js

Enjoy.

The Amazon Web Services (AWS) StartUp event in Toronto

Tuesday, September 16th, 2008

The team from came to Toronto (at the MaRS Building)to show us their stuff, and demo’s from some local folks showing the “what”, “where”, and “how” to their use of  AWS in real life. (no admission cost for the event. Yea!)
AWS the Start-up Project

Tracy Laxdal did a great job on all the the logistics and organizing.

Prashant Sridharan and Mike Culver, the Director and Evangelist for Amazon Web Services (respectively) kicked off things with comments and a presentation giving some background to the history of AWS, where things are too today and where you can expect this to go.
Prashant Sridharan, Director, Amazon Web Services

The overall focus was on the Infrastructure Services : in particular things like S3 Storage and Elastic Compute Cloud (EC2), but it did touch on the other parts (which is good because it did clarify some of them for me).
AWS the services side
Liitle Fish, Big Pond or Sushi?
Updated Sept 18th : Amazon CTO Werner Vogels has announced that Amazon is releasing a Content Delivery Network (CDN) in Expanding The Cloud, and on the AWS blog.

AWS future Directions

The meat of the afternoon was in  Customer Presentations :

Carlos Barrettara is from , a solution for publishers and adversiters on mobile platforms which -for example -would allow BlackBerry users to receive the latest headlines, news articles, feature columns, and editorials directly from Maclean’s and Canadian Business. As a very new startup they have been able to embrace AWS from the start.
Carlos Barrettara Polar Mobile

Carlos’s presentation is now on SlideShare.

Ilya Grigorik is from , which is a site and add-on and web service which acts as an intelligent RSS assistant to allow you to focus on the most information content of the Websites and Blogs you follow in your News Readers.
Ilya Grigorik AideRSS

Ilya talked about how they moved (in great detail, with numbers of servers : 14 for infrastructure and 70 (!) for web crawlers) the various parts onto the AWS cloud (including using Simple Queue Service ) as they gained comfort with it. Ilya’s presentation is now on Slide Share. (also their presentation from last year)

Chris Thiessen is from , which is bringing online the real bookstore experience of browsing bookshelves and making it an vivid experiance (SeaDragon meets Matrix meets Amazon?).
Chris Thiessen Zoomii.

He also showed off the custom scripting he uses. We should get Chris out to a Demo Camp! Chris’s presentation is now on Slide Share.

Farhan Thawar is from whom enable corporate incentive programs.
Farhan Thawar I Love Rewards
They moved from a traditional self hosting infrastructure to the amazon cloud for all but some legacy application. Given they are a Software as a Service and integrate with SalesForce (another SaaS) it made sense to embrace this style of hosting. Farhan’s presenation is now on Slide Share.

Paul Bloore from talked about their newest product , (I promise I will stop call it TinyEye some day, Paul!) their image search engine that tells you where and how that image appears all over the web—even if it has been modified.
Paul Bloore Idee tinEye

Paul talked about how they used EC2 to build a spider army to scan the web for new images, (and process the imaging matching secret sauce?) (currently at  900 million, soon to be 1Giga+! images indexed, he said in this best Doctor Evil voice.) Then he showed of a unreleased iphone app that takes a book or cd cover and uses a similar algorithm as TinEye to identify it and fetches reviews. Which caused my brain melted down ….

(Update : see TinEye Mobile : iPhone visual search for stuff )

Okay, they they also did a Group Q&A
aws q&a

The is well worth your time, and is still to come to New York City, Boston/Cambridge, London, Amsterdam and Seattle.

Some of the Presentation from last year went up on SlideShare (which uses AWS), so I hope this years will too!

Update :  34 on the Toronto presentations are now on SlideShare the startup project, plus those for other locations.

(and Hello to Mugur Marculescu of WeGif who has new take on doing animated gifs, and more, online, and is moving to AWS.  I hope the visit to Toronto was a good one!)

Now excuse me will I do some Cloud Hacking…

minor updates :

other posts about the amazon web services start up tour in Toronto :

and thinking about “use cases which are different form the usual uses” :

  • batch processing, either semi temporary or semi permanent (how often do temporary - or short temp - system and applications last for years and years? often), when you need 1 or more (or 100) computers to process a set of data needed by other processes.
  • those semi temporary or semi permanent applications that are needed until the real solution comes along
  • Transitioning from one version of the infrastructure to the next, one customer at a time, and still roll back to the previous version.
  • Real testing infrastructure that actually look like the production infrastructure.
  • thinking about some side discussions I had with Chris Nolan who has a Comic Books application on the FaceBook platform (see the about for more info), I though of anther scenario : if you know you have big spikes in the traffic or processing demands : one day of the week -new comics come out on Tuesday- or year -election day-, or Month - Xmas-, then add servers only for that known period (and only pay for them during on that period).  You could also monitor loads and start adding servers auto-magically when you exceed a threshold and remove them when you go before certian thresholds.

Any other suggestions come to mind?

CCS & Ajax Links for March 24th

Wednesday, March 26th, 2008

My 2008 extisp.icio.us

Sunday, February 3rd, 2008

extisp.icio.us 2008


extisp.icio.us 2008

generated by based on my bookmarks, and added to the flickr pool

This is the 4th year I’ve done this.

Links for December 5th

Thursday, December 6th, 2007
  • 9 CSS Ethics Every Designer Should Have - Writing a CSS Stylesheet That is Easy to Maintain is really easy, just by following these 9 “ethics”: Indent descendant ;Grouping and commenting;Break into sheets; Reset;color scheme refrence; Keep a library of helpful CSS classes.    just do it.
  • - css

JavaScript for a single element radio button list

Tuesday, October 16th, 2007

The Problem here is if your list of data generated radio button html yields only one value. All the standard solutions / samples that a google yields assume the there are 2 or more choices.

This is not unreasonable for radio buttons, but if your list of choices is not hand built then you may not have control over that.

Code is not reasonable and neither is Life.

And in that unreasonable use case those solutions fail, because if you have one one element in the radio button list then “f.choiceview.length = undefined” (assuming the html input tag name=”choiceview” ). Then the real fun begins…

How to fix this? The solution is simple if not obvious : the single element becomes a ordinary input tag type of element and you use the .checked and .value methods, as below….


function getSelected () {
var Selected = "";
var f = document.forms[0];
if(f.choiceview.checked) { // one element to fetch
Selected = f.view.value;
}
else {
for (var i = 0; i < f.choiceview.length; i ++) { //loop thur array
if (f.view[i].checked) { // test to see if checked
Selected = f.view[i].value;
}
}
}
if (Selected == "") {
alert("Nothing selected");
}
else {
alert(Selected + ' Selected'); // report back
}
}

Where would you use this? Mostly for form validation, or to grab user choices to drive other processing.

The same issue and solution applies to html CheckBox elements.

Update Oct 2008:  I’ve revised the code and removed the hard coding of the html elements “name” attribute, and linked to a demo form of it action of radio buttons and check boxes. Plus, if your interested, I also rewrote the whole thing down to 1 line using the Prototype javascript framework!   All here in JavaScript for a single element radio button list, revisited with Prototype

Facebook roundup for Sept 8th

Saturday, September 8th, 2007

The juggernaut continues although not without its critics.

Recent Code and the Culture of Code Links for Sept 5th

Thursday, September 6th, 2007

Recent Links for August 10th : the ProtoType Way; Superflat Panda; Nefertiti

Friday, August 10th, 2007

Close
  • Social Web
  • E-mail
E-mail It