Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Writing a Prototype-enabled page

From: Prototype and script.aculo.us Essential Training

Video: Writing a Prototype-enabled page

Let's just jump right in and build our first Prototype enabled web page. So before we do that, a quick word about tools. For the remainder of this course, I'm going to be using a tool named Aptana Studio. And Aptana Studio is a really good cross-platform IDE for working with web content like HTML and JavaScript files. And it's freely available from aptana.org. The reason I chose to use it is because it's cross-platform, so if you're following me along on a Mac or Windows, it doesn't really matter.

Writing a Prototype-enabled page

Let's just jump right in and build our first Prototype enabled web page. So before we do that, a quick word about tools. For the remainder of this course, I'm going to be using a tool named Aptana Studio. And Aptana Studio is a really good cross-platform IDE for working with web content like HTML and JavaScript files. And it's freely available from aptana.org. The reason I chose to use it is because it's cross-platform, so if you're following me along on a Mac or Windows, it doesn't really matter.

You can just download it to your computer free of charge and follow along with me. Now, since Prototype and script.aculo.us are just JavaScript files and we'll be working with HTML, you can use whatever IDE you are happy and familiar with. I just want to let you know that I'm going to be using Aptana. So you can download it here from the aptana.org website. You just click Download Now. You can see that it's available for various different platforms, whether standalone, or if you already have Eclipse installed, and you can get it for Windows, Mac, or Linux.

So that's the tool that I'm going to be using. Now, I've already installed it, so I'm going to go ahead and switch over to it. So this is Aptana Studio. And this is the tool that I'm going to be using for the examples. So I'm going to go ahead and open up our example file. So I'm going to open up the file. Now, if you have the exercise files, you'll see that in the exercise_files folder, I have arranged all of the examples according to chapters. And here in the first chapter for the overview, I've got two examples, the FirstPrototype Start and Finished.

Now, the Finished file is the completed example. And you can go ahead and jump forward to that if you just want to see how everything works, or you can follow along with me and we can work together on the Start version. So I'm going to open up the Start. And you can see that this is a pretty plain HTML page. So to use Prototype in our web page, I just have to include it using a script tag. So I'm going to insert a script and let's say type equals text/javascript.

And now I need to point the source attribute to the location where the prototype.js file is kept. Now, I've put it at the root level of the exercise_files folder. That way it can be accessed by all of the examples using a relative URL format. So I'm just going to type "../". And you can see that there it is right there, the prototype.js file. So I'll double click that and close the tag. And that's pretty much all there's to it. Now our prototype is embedded in the page. And we can Save.

All right. So now let's just do a quick simple example to show how Prototype works. So I'm going to enter another script tag, type equals, once again, text/javascript. So I'll put our example code in here. What I'm going to do is show an example of how to fire off a script when the page loads. And ordinarily, you would do this by doing something like body and then you'd probably do something like onload equals function.

The problem with this approach is that the onload event on the body tag only fires once all of the body's content has finished downloading, and that includes images. So if you have a bunch of images in your page or a lot of content, then this event isn't going to fire until-- It could be sometime before all the content downloads, and in the meantime, your user is trying to interact with the page and nothing is happening. Well, prototype fixes that problem by making available a cross-browser event called dom:loaded, which fires much, much sooner than the body's onload event.

The way that works is you observe the document event for the dom:loaded. Now, I'm not going to expect that you understand everything that I'm about to type right away, but we will cover all of this in subsequent lessons. Just for the moment, follow along with me as I explain what's going on here. So what I need to do is write document. observe, and this is how in Prototype you register for event handlers. You type the name of the element, in this case document, and then the observe function is what observes events.

So the event I'm interested in observing is the dom:loaded event. And then I need to provide a function that's going to run when the dom gets loaded. So I'm just going to put in an anonymous function right here. And I'm going to write just a simple alert that says "The page has loaded! You're using Prototype!" So that's all there is to it.

That's our first Prototype-enabled page. So let's jump over to the browsers and see if it works. I'm going to go to the exercise_ files folder. Here's the folder. So I'm just going to double-click on this guy and that should bring up Firefox. And you can see that when Firefox loads, we get our alert. So let's make sure that this is running properly cross-browser. I'll bring up IE next. Okay. So here I am in the examples. I'm going to right-click. I'm going to choose Open with Internet Explorer.

And you can see I get the same result. So we have a cross-browser way now of detecting when the page has loaded. And that's our first example using Prototype.

Show transcript

This video is part of

Image for Prototype and script.aculo.us Essential Training
Prototype and script.aculo.us Essential Training

49 video lessons · 7001 viewers

Joe Marini
Author

 
Expand all | Collapse all
  1. 2m 26s
    1. Welcome
      1m 19s
    2. Using the exercise files
      1m 7s
  2. 18m 4s
    1. Introducing Prototype
      4m 59s
    2. Downloading and installing Prototype
      4m 53s
    3. Writing a Prototype-enabled page
      5m 44s
    4. Exploring Prototype's features
      2m 28s
  3. 38m 9s
    1. Overview of Prototype content functions
      4m 42s
    2. Looking up elements with $()
      5m 14s
    3. Using the $$() selector function
      12m 32s
    4. Retrieving form element values with $F()
      8m 38s
    5. Getting practical: Annotating page links
      7m 3s
  4. 1h 5m
    1. Introducing the extensions
      1m 47s
    2. Using objects
      10m 54s
    3. Using strings
      15m 32s
    4. Using numbers
      7m 17s
    5. Using arrays
      7m 19s
    6. Using Prototype templates
      8m 9s
    7. Performing periodic tasks with PeriodicalExecuter
      7m 41s
    8. Using JSON support
      6m 51s
  5. 48m 2s
    1. Understanding the collection features
      2m 55s
    2. Working with the Enumerable class
      24m 51s
    3. Creating arrays with $A()
      3m 58s
    4. Handling ranges with $R()
      2m 46s
    5. Making Hash objects with $H()
      13m 32s
  6. 1h 2m
    1. Understanding Prototype's element class
      9m 0s
    2. Manipulating content
      6m 21s
    3. Traversing the DOM
      14m 24s
    4. Changing CSS and element visibility
      5m 53s
    5. Setting element positioning
      12m 38s
    6. Using other DOM element functions
      2m 32s
    7. Getting practical: The automatic table of contents generator
      11m 26s
  7. 41m 2s
    1. Understanding the Prototype event class
      5m 6s
    2. Observing events
      11m 45s
    3. Getting information about events
      8m 28s
    4. Creating custom events
      8m 43s
    5. Getting practical: Table striping and highlighting
      7m 0s
  8. 25m 59s
    1. Creating and handling AJAX requests
      12m 25s
    2. Using the Ajax.Updater
      8m 40s
    3. Handling periodic updates
      4m 54s
  9. 25m 36s
    1. Introducing script.aculo.us
      4m 37s
    2. Using visual effects
      7m 7s
    3. Using drag and drop
      4m 47s
    4. Using autocomplete
      5m 23s
    5. Using sliders
      3m 42s
  10. 54m 10s
    1. Getting started
      4m 50s
    2. Displaying information dynamically
      14m 32s
    3. Filtering data
      19m 32s
    4. Building an image rotator
      15m 16s
  11. 19s
    1. Goodbye
      19s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Prototype and script.aculo.us Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.