SlideShare a Scribd company logo
1 of 31
Download to read offline
INFORMATION ORGANIZATION LAB                                                                     SEPTEMBER 8, 2009




                LAST WEEK ON IO LAB
            If you haven’t done these things already, please do them before we begin today’s lecture



                                   Install Firebug and Greasemonkey.


                                   Complete the online skills assessment.


                                   Join the iolab@ischool mailing list.


                       You can find links to help with all of these on the course website at
                                 http://courses.ischool.berkeley.edu/i290-4/f09/
INFORMATION ORGANIZATION LAB                                                           SEPTEMBER 8, 2009




             INFORMATION ORGANIZATION LAB
                                Faculty: Bob Glushko
                 Student Instructors: Nick Doty & Ryan Greenberg

A warning: Today is going to be a full-on crash course in the web client technologies we'll be
using for much of this class (HTML/CSS and Javascript/JQuery) followed by actually building
on that with web browser extensions like Greasemonkey. This should begin to explain the
basics behind the tutorial you worked on this past week and the demo that Ryan did last
week, but it may still be a lot to take in and we'll be talking a lot today. We promise that you'll
have time to learn this stuff beyond just today and that we won't be talking as much every
class.
INFORMATION ORGANIZATION LAB                                      SEPTEMBER 8, 2009




                               OFFICE HOURS
                                   Room 210


                   Nick                             Ryan
            Friday                            Wednesday
          1:00-2:00                           1:00–2:00

                            And by appointment.
              Email ryan@ischool or npdoty@ischool to schedule.
INFORMATION ORGANIZATION LAB                                                           SEPTEMBER 8, 2009




                           WHAT WE KNOW




                       HTML                   CSS                         Javascript


Based on the results of the unscientific survey you completed last week.
INFORMATION ORGANIZATION LAB                                                                SEPTEMBER 8, 2009




   DOCUMENT OBJECT MODEL
    <html>                                                             body
    <body>
    <div id="header">
        <h1>Document Object Model</h1>
    </div>                                                 div                       div
                                                          header                    content
    <div id="content">
        <p>This is my first paragraph</p>
        <p>My second paragraph has a list:
             <ul>                                           h1                p       p           p
                  <li>Item One</li>
                  <li>Item Two</li>
                  <li>Item Three</li>
             </ul>
                                                                                      ul
        </p>
        <p>This is the third paragraph</p>
    </div>
    </body>
    </html>                                                                    li      li         li




Here on the right side is a short HTML document. When your web browser loads this
document, it generates a representation called the Document Object Model.
If your code is properly indented, your can see that the hierarchy of the DOM corresponds to
the indentation level.

The big idea here is that the left is just a bunch of text. On the right there is a collection of
objects that you can manipulate and change.

See http://en.wikipedia.org/wiki/Document_Object_Model for more information.
INFORMATION ORGANIZATION LAB                                                    SEPTEMBER 8, 2009




       CASCADING STYLE SHEETS
Separate presentation from structure and content.
If you want to be impressed by what’s possible with CSS, see http://csszengarden.com.
INFORMATION ORGANIZATION LAB                                                                   SEPTEMBER 8, 2009




                          RULE STRUCTURE




                                                                     From CSS: The Definitive Guide




A stylesheet consists of a series of rules. Here you see the structure of a style rule. You start
with a selector, which specifies what elements in the DOM you want this rule to apply to.
Then you write one or more declarations to apply styles to that selection. Declarations are
separated by semi-colons.
INFORMATION ORGANIZATION LAB                                                          SEPTEMBER 8, 2009




                               SELECTORS
                                             CSS                         HTML

               Type (Tag)                      p                          <p>

                       Id                 #header                    id="header"

                    Class                  .author                 class="author"

              Descendent                     div p                   <div><p>

                Grouping                    h1, h2               <h1> and <h2>

Who can explain the difference between IDs and classes? IDs are unique, only occur once on
the page. Classes are recurring elements.
Both can add semantic meaning to the page.
For a complete list of selectors in CSS2, see http://www.w3.org/TR/CSS2/selector.html.
For a list of all the selectors that jQuery can use (which are a lot more than CSS2), see http://
docs.jquery.com/Selectors.
INFORMATION ORGANIZATION LAB                                                                        SEPTEMBER 8, 2009




               COMMON PROPERTIES
         font-family                  color                  border                  display



             margin                font-size                  width                  padding



        background                  position               text-align                  float


              See http://htmldog.com/reference/cssproperties/ for a good list of CSS2 properties.
Let’s do some examples.
(1) I want to make the blog
(2) Align the text in the header: #header { text-align: center; }
(3) Make every author’s name’s much bigger. .author
(4) I want to make the titles of the blog entries blue Papyrus.
INFORMATION ORGANIZATION LAB                                                     SEPTEMBER 8, 2009




                           THE BOX MODEL
                                        Margin
                                        Border
                                        Padding

                                          Width
                               Height




Every object on the page consists of a rectangular box. The content area, plus padding,
border, margin. When you set the width of an element using CSS, that is the width of the
content area, not the entire box. If you set {width: 500px; padding: 20px; border: 1px solid
black}, the box will be 542px wide: 500, plus 20 padding on each side, plus 1 border on each
side.
INFORMATION ORGANIZATION LAB                                                                 SEPTEMBER 8, 2009




                               CSS RESOURCES




                     Available free for students at http://proquest.safaribooksonline.com.

CSS Definitive Guide: http://proquest.safaribooksonline.com/0596527330
CSS Missing Manual:

Heads-First XHTML & CSS: http://proquest.safaribooksonline.com/059610197X/hfhtmlcss-
CHP-8?imagepage=285
“Expanding your vocabulary” http://proquest.safaribooksonline.com/059610197X/
hfhtmlcss-CHP-8?imagepage=285
INFORMATION ORGANIZATION LAB                                                       SEPTEMBER 8, 2009




      JAVASCRIPT CRASH COURSE
Everyone open up a copy of Firefox and Firebug. If you would like, you can also use Safari’s
web inspector. Some things in Safari are much better, but I’ll be using Firebug. Cross-
platform, has a few more developed features.
INFORMATION ORGANIZATION LAB                                                    SEPTEMBER 8, 2009




                       FIRST THINGS FIRST

       JavaScript is a high-level, object-oriented language used most
                            often in web browsers.

              You can write comments in your code with // or /* */

                 A semi-colon goes at the end of every statement.




It’s a dynamic, scripting language. Prototype-based inheritance, not class-based. See
Douglas Crockford’s explanation for more information: http://javascript.crockford.com/
prototypal.html
INFORMATION ORGANIZATION LAB                                                        SEPTEMBER 8, 2009




                               VARIABLES
               29                        'Bob'                              true
          Numbers                          Strings                         Boolean


              ['Bob', 'John', 'Coye', 'Deirdre']
                                           Arrays


            {'name': 'Arnold', 'weight': 240}
                                          Objects
Variables can be of different types. We’re going to cover these basic data types.
INFORMATION ORGANIZATION LAB                                                         SEPTEMBER 8, 2009




                               VARIABLES


                 var stateName = 'California';




You use the word ‘var’ to declare a variable. You don’t have to say what type of variable it
is--variables in JavaScript are untyped. Convention is to use camelCase.
INFORMATION ORGANIZATION LAB                                    SEPTEMBER 8, 2009




                                 STRINGS
                         A sequence of characters.
             Use single- or double-quotes to indicate a string.

                                      Examples
                                    var myName = "Larry";
                                       myName → "Larry"
                                      myName.length → 5
                               myName.toUpperCase() → "LARRY"
                                   myName.indexOf('a') → 1
INFORMATION ORGANIZATION LAB                                                 SEPTEMBER 8, 2009




                                   ARRAYS
                        An ordered collection of elements.
                      Use square brackets to indicate an array.

                                       Examples
                             var myArray = ['dog', 'fish', 'cat'];
                                       myArray.length → 3
                                      myArray[0] → ['dog']
              myArray.push('horse') → myArray == ['dog', 'fish', 'cat', 'horse']
                                  myArray.indexOf('fish') → 1
                           myArray.sort() → ['cat', 'dog', 'fish'];
INFORMATION ORGANIZATION LAB                                                           SEPTEMBER 8, 2009




                                   OBJECTS
          A collection of key-value pairs or named properties.
                    Use braces to indicate an object.

                                          Examples
                 var person = {'name': 'Arnold', 'weight': 240, 'height': 6.2 }
                                     person.name → "Arnold"
                                       person.height → 6.2
                                     person.wife = 'Maria';
                                      person.wife → 'Maria'
                                    person['wife'] → 'Maria'




The most confusing thing about objects in JavaScript is that they’re used for so many
different things. First, they fill the role of the data structure: hashes/dictionaries (in Python)/
associative arrays. Second, objects are naturally used for JavaScript’s object-oriented
programming. Third, JavaScript objects are also the basis for JSON.

You can access the properties of an object using the dot notation or bracket notation.
INFORMATION ORGANIZATION LAB                                                     SEPTEMBER 8, 2009




                               FUNCTIONS

                       function add(x, y) {
                           return x + y;
                       }
                       add(2,4) → 6

                       var add = function(x, y) {
                           return x + y;
                       }

JavaScript functions are defined with the keyword function and they return a value. Functions
can have names, as in the top example, or they can be anonymous.
INFORMATION ORGANIZATION LAB                                                         SEPTEMBER 8, 2009




                BROWSER FUNCTIONS
                          alert('…')
                        confirm('…')
                         prompt('…')
                       console.log('…')
console.log is better to use when debugging because alert (1) doesn’t give you any history,
(2) you have to click each button. That said, there are times when alert(‘Testing!’) is simply
more convenient.
INFORMATION ORGANIZATION LAB                                                       SEPTEMBER 8, 2009




             CONTROL STRUCTURES

                         if (3 > 2) {
                             alert('3 is greater than 2');
                         }


                         for (var i=0; i < myArray.length; i++) {
                             myArray[i];
                         }




The for loop in JavaScript is a standard C-style for loop. The first statement (here var i=0)
sets the starting condition. The second statement (i < myArray.length) sets how long the loop
will run--until this condition is false. The third statement (i++) says what will happen at the
end of each loop.
INFORMATION ORGANIZATION LAB                                                        SEPTEMBER 8, 2009




                                   +


                                    JQUERY
                                 CSS meets JavaScript


jQuery is a JavaScript library (intro. 2006) written by John Resig. When learning: great when
you can apply something you know to something else. A lot of JS in browser has to do with
selecting objects from the DOM. And we already have something to do that...CSS!
INFORMATION ORGANIZATION LAB                                                         SEPTEMBER 8, 2009




                         NEW HOTNESS VS.
                         OLD AND BUSTED




                           (But with JavaScript instead of computers)
Javascript has been around for awhile. Tutorials on the internet are old. Used to put your
Javascript inline with your HTML. onclick...onload...document.writeln(). Like CSS, the current
best practice is to separate your Javascript from the HTML. We don’t use onevent anymore.

Also, using JavaScript in browsers has often been onerous. To change all the elements with a
certain class, you used to write document.getElementsByTagName(‘*’) ... and a bunch of
other stuff. But new libraries like jQuery let you do this more efficiently: $(‘.name-of-class’)
INFORMATION ORGANIZATION LAB                                      SEPTEMBER 8, 2009




                                       JQUERY

                               Using jQuery involves two steps:

  • Selects        objects from the DOM using CSS selectors.
  • Do      something with the selected elements.
INFORMATION ORGANIZATION LAB                                                       SEPTEMBER 8, 2009




       MAIN JQUERY OPERATIONS


  • Attributes:                Changing existing elements.
  • Traversing:                Moving from selected elements in the DOM to
     others.
  • Manipulating:                 Inserting or removing elements.
  • Events:           Attaching functions to events in the browser.



The jQuery Documentation (http://docs.jquery.com), which is well organized and written,
uses these names as well. Examples:
- Attributes: $(‘h1’).text() gives you the text from the selected elements. $(‘h1’).text(‘New
Text Here’) sets the text in the selected elements.
- Traversing: Moves from selected elements elsewhere in the DOM.
- Manipulating: $(‘p’).after(‘This text will be added after every paragraph’); $
(‘body’).prepend(‘This will appear at the top of the page’)
- Events: You select the elements you want to attach an event to and provide an anonymous
function: $(‘h2’).click( function() { alert(‘You clicked on an h2’); });
INFORMATION ORGANIZATION LAB                                                         SEPTEMBER 8, 2009




                       WEB BROWSER EXTENSIONS
                    Greasemonkey and Jetpack and bears, oh my!


A general overview: we’ll be looking at a class of tools that extend the functionality of a web
browser, either to change the browser chrome (like the status bar or the menu options) or
modify an existing webpage.
INFORMATION ORGANIZATION LAB                                                    SEPTEMBER 8, 2009




                               EXTEND WHAT?

                        Browser chrome
                        Page content
                        Page style
                        Page behavior
Chrome: an image in the status bar that lets you know when you have new email
Content: removing an advertisement or adding a map
Style: giving Craiglist any kind of style at all
Behavior: make a button
INFORMATION ORGANIZATION LAB                                                      SEPTEMBER 8, 2009




                  Greasemonkey                             Mozilla Jetpack




                Firefox Extensions                        Chrome Extensions

Relative advantages and disadvantages. The left-hand column is fairly mature compared to
the right. The top row is fairly light-weight (for development and installation) than the
bottom row. Firefox Extensions have the best performance but are the hardest to develop.
We’ll use Greasemonkey here -- it’s easy to develop, easy to install, and fairly widespread.
But these others have their advantages -- Jetpack makes it particularly easy to add to the
browser’s chrome and Firefox gives you a lot of power that Greasemonkey doesn’t have -- if
you want to use one, go for it! But Greasemonkey is a good start for us and development is
just like modifying an existing webpage.

Anyone know of others? (Safari Saft, IE Activities....)
INFORMATION ORGANIZATION LAB                                                      SEPTEMBER 8, 2009




      GOOD FOR THE BROWSERS

                               GOOD FOR US


For the browsers:
Let users customize and extend the browser, but keep the core small.

For us:
Let us prototype website and browser features without building either from scratch.
INFORMATION ORGANIZATION LAB                                   SEPTEMBER 8, 2009




                               LET’S TRY IT
                               To the browser / text editor!
INFORMATION ORGANIZATION LAB                                                                  SEPTEMBER 8, 2009




                               FOR NEXT WEEK
                         For practice, make sure you can build the Delicious
                         Trailmaker all by yourself. Add a feature to it.


                         Write your first Greasemonkey script. Come with
                         questions next class.


                         Decide on an idea for Project 1.

                       You can find links to help with all of these on the course website at
                                 http://courses.ischool.berkeley.edu/i290-4/f09/

More Related Content

Viewers also liked

Viewers also liked (20)

Introduction To Weconomics
Introduction To WeconomicsIntroduction To Weconomics
Introduction To Weconomics
 
Idaily
IdailyIdaily
Idaily
 
My friend past simple
My friend past simpleMy friend past simple
My friend past simple
 
Griffiths ethnography
Griffiths ethnographyGriffiths ethnography
Griffiths ethnography
 
0perating
0perating 0perating
0perating
 
Teaching presentation rubric
Teaching presentation rubricTeaching presentation rubric
Teaching presentation rubric
 
Narration test
Narration testNarration test
Narration test
 
University of iowa libraries chinese collection new acquisitions ...
University of iowa libraries chinese collection new acquisitions ...University of iowa libraries chinese collection new acquisitions ...
University of iowa libraries chinese collection new acquisitions ...
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
2014 PV Performance Modeling Workshop: SolarAnywhere: WebWeb-Accessible Irrad...
2014 PV Performance Modeling Workshop: SolarAnywhere: WebWeb-Accessible Irrad...2014 PV Performance Modeling Workshop: SolarAnywhere: WebWeb-Accessible Irrad...
2014 PV Performance Modeling Workshop: SolarAnywhere: WebWeb-Accessible Irrad...
 
The Voicemail Script Part 2
The Voicemail Script Part 2The Voicemail Script Part 2
The Voicemail Script Part 2
 
QIA #9 - References
QIA #9 - ReferencesQIA #9 - References
QIA #9 - References
 
Tp ingles
Tp inglesTp ingles
Tp ingles
 
Auxiliary equipment
Auxiliary equipmentAuxiliary equipment
Auxiliary equipment
 
Taxonomy of Teachniques
Taxonomy of TeachniquesTaxonomy of Teachniques
Taxonomy of Teachniques
 
Pc54
Pc54Pc54
Pc54
 
Tu dien tranh tau thuy
Tu dien tranh tau thuyTu dien tranh tau thuy
Tu dien tranh tau thuy
 
Silsilah wayang purwa mawa carita jilid 2 2
Silsilah wayang purwa mawa carita jilid 2 2Silsilah wayang purwa mawa carita jilid 2 2
Silsilah wayang purwa mawa carita jilid 2 2
 
美团业务系统通用Ui方案
美团业务系统通用Ui方案美团业务系统通用Ui方案
美团业务系统通用Ui方案
 
Doc280
Doc280Doc280
Doc280
 

Similar to lecture2_public

GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1Heather Rock
 
Document Object Model
Document Object ModelDocument Object Model
Document Object ModelMayur Mudgal
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)Ivy Rueb
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingAshok Modi
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)Ivy Rueb
 
Web development resources brackets
Web development resources bracketsWeb development resources brackets
Web development resources bracketsLaurence Svekis ✔
 
Drupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityDrupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityAshok Modi
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Chapter15-Presentation.pptx
Chapter15-Presentation.pptxChapter15-Presentation.pptx
Chapter15-Presentation.pptxGFRomano
 
Sass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LASass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LAJake Johnson
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQueryDanWooster1
 
Lesson 3
Lesson 3Lesson 3
Lesson 3hstryk
 
Web Development Training Report.docx
Web Development Training Report.docxWeb Development Training Report.docx
Web Development Training Report.docxCuriosityKlinic
 

Similar to lecture2_public (20)

GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizing
 
Instagram filters (8 24)
Instagram filters (8 24)Instagram filters (8 24)
Instagram filters (8 24)
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
 
Web technologies part-2
Web technologies part-2Web technologies part-2
Web technologies part-2
 
Web development resources brackets
Web development resources bracketsWeb development resources brackets
Web development resources brackets
 
Drupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityDrupal Frontend Performance and Scalability
Drupal Frontend Performance and Scalability
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Chapter15-Presentation.pptx
Chapter15-Presentation.pptxChapter15-Presentation.pptx
Chapter15-Presentation.pptx
 
Sass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LASass Essentials at Mobile Camp LA
Sass Essentials at Mobile Camp LA
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQuery
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Web Development Training Report.docx
Web Development Training Report.docxWeb Development Training Report.docx
Web Development Training Report.docx
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

lecture2_public

  • 1. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 LAST WEEK ON IO LAB If you haven’t done these things already, please do them before we begin today’s lecture Install Firebug and Greasemonkey. Complete the online skills assessment. Join the iolab@ischool mailing list. You can find links to help with all of these on the course website at http://courses.ischool.berkeley.edu/i290-4/f09/
  • 2. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 INFORMATION ORGANIZATION LAB Faculty: Bob Glushko Student Instructors: Nick Doty & Ryan Greenberg A warning: Today is going to be a full-on crash course in the web client technologies we'll be using for much of this class (HTML/CSS and Javascript/JQuery) followed by actually building on that with web browser extensions like Greasemonkey. This should begin to explain the basics behind the tutorial you worked on this past week and the demo that Ryan did last week, but it may still be a lot to take in and we'll be talking a lot today. We promise that you'll have time to learn this stuff beyond just today and that we won't be talking as much every class.
  • 3. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 OFFICE HOURS Room 210 Nick Ryan Friday Wednesday 1:00-2:00 1:00–2:00 And by appointment. Email ryan@ischool or npdoty@ischool to schedule.
  • 4. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 WHAT WE KNOW HTML CSS Javascript Based on the results of the unscientific survey you completed last week.
  • 5. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 DOCUMENT OBJECT MODEL <html> body <body> <div id="header"> <h1>Document Object Model</h1> </div> div div header content <div id="content"> <p>This is my first paragraph</p> <p>My second paragraph has a list: <ul> h1 p p p <li>Item One</li> <li>Item Two</li> <li>Item Three</li> </ul> ul </p> <p>This is the third paragraph</p> </div> </body> </html> li li li Here on the right side is a short HTML document. When your web browser loads this document, it generates a representation called the Document Object Model. If your code is properly indented, your can see that the hierarchy of the DOM corresponds to the indentation level. The big idea here is that the left is just a bunch of text. On the right there is a collection of objects that you can manipulate and change. See http://en.wikipedia.org/wiki/Document_Object_Model for more information.
  • 6. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 CASCADING STYLE SHEETS Separate presentation from structure and content. If you want to be impressed by what’s possible with CSS, see http://csszengarden.com.
  • 7. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 RULE STRUCTURE From CSS: The Definitive Guide A stylesheet consists of a series of rules. Here you see the structure of a style rule. You start with a selector, which specifies what elements in the DOM you want this rule to apply to. Then you write one or more declarations to apply styles to that selection. Declarations are separated by semi-colons.
  • 8. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 SELECTORS CSS HTML Type (Tag) p <p> Id #header id="header" Class .author class="author" Descendent div p <div><p> Grouping h1, h2 <h1> and <h2> Who can explain the difference between IDs and classes? IDs are unique, only occur once on the page. Classes are recurring elements. Both can add semantic meaning to the page. For a complete list of selectors in CSS2, see http://www.w3.org/TR/CSS2/selector.html. For a list of all the selectors that jQuery can use (which are a lot more than CSS2), see http:// docs.jquery.com/Selectors.
  • 9. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 COMMON PROPERTIES font-family color border display margin font-size width padding background position text-align float See http://htmldog.com/reference/cssproperties/ for a good list of CSS2 properties. Let’s do some examples. (1) I want to make the blog (2) Align the text in the header: #header { text-align: center; } (3) Make every author’s name’s much bigger. .author (4) I want to make the titles of the blog entries blue Papyrus.
  • 10. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 THE BOX MODEL Margin Border Padding Width Height Every object on the page consists of a rectangular box. The content area, plus padding, border, margin. When you set the width of an element using CSS, that is the width of the content area, not the entire box. If you set {width: 500px; padding: 20px; border: 1px solid black}, the box will be 542px wide: 500, plus 20 padding on each side, plus 1 border on each side.
  • 11. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 CSS RESOURCES Available free for students at http://proquest.safaribooksonline.com. CSS Definitive Guide: http://proquest.safaribooksonline.com/0596527330 CSS Missing Manual: Heads-First XHTML & CSS: http://proquest.safaribooksonline.com/059610197X/hfhtmlcss- CHP-8?imagepage=285 “Expanding your vocabulary” http://proquest.safaribooksonline.com/059610197X/ hfhtmlcss-CHP-8?imagepage=285
  • 12. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 JAVASCRIPT CRASH COURSE Everyone open up a copy of Firefox and Firebug. If you would like, you can also use Safari’s web inspector. Some things in Safari are much better, but I’ll be using Firebug. Cross- platform, has a few more developed features.
  • 13. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 FIRST THINGS FIRST JavaScript is a high-level, object-oriented language used most often in web browsers. You can write comments in your code with // or /* */ A semi-colon goes at the end of every statement. It’s a dynamic, scripting language. Prototype-based inheritance, not class-based. See Douglas Crockford’s explanation for more information: http://javascript.crockford.com/ prototypal.html
  • 14. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 VARIABLES 29 'Bob' true Numbers Strings Boolean ['Bob', 'John', 'Coye', 'Deirdre'] Arrays {'name': 'Arnold', 'weight': 240} Objects Variables can be of different types. We’re going to cover these basic data types.
  • 15. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 VARIABLES var stateName = 'California'; You use the word ‘var’ to declare a variable. You don’t have to say what type of variable it is--variables in JavaScript are untyped. Convention is to use camelCase.
  • 16. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 STRINGS A sequence of characters. Use single- or double-quotes to indicate a string. Examples var myName = "Larry"; myName → "Larry" myName.length → 5 myName.toUpperCase() → "LARRY" myName.indexOf('a') → 1
  • 17. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 ARRAYS An ordered collection of elements. Use square brackets to indicate an array. Examples var myArray = ['dog', 'fish', 'cat']; myArray.length → 3 myArray[0] → ['dog'] myArray.push('horse') → myArray == ['dog', 'fish', 'cat', 'horse'] myArray.indexOf('fish') → 1 myArray.sort() → ['cat', 'dog', 'fish'];
  • 18. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 OBJECTS A collection of key-value pairs or named properties. Use braces to indicate an object. Examples var person = {'name': 'Arnold', 'weight': 240, 'height': 6.2 } person.name → "Arnold" person.height → 6.2 person.wife = 'Maria'; person.wife → 'Maria' person['wife'] → 'Maria' The most confusing thing about objects in JavaScript is that they’re used for so many different things. First, they fill the role of the data structure: hashes/dictionaries (in Python)/ associative arrays. Second, objects are naturally used for JavaScript’s object-oriented programming. Third, JavaScript objects are also the basis for JSON. You can access the properties of an object using the dot notation or bracket notation.
  • 19. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 FUNCTIONS function add(x, y) { return x + y; } add(2,4) → 6 var add = function(x, y) { return x + y; } JavaScript functions are defined with the keyword function and they return a value. Functions can have names, as in the top example, or they can be anonymous.
  • 20. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 BROWSER FUNCTIONS alert('…') confirm('…') prompt('…') console.log('…') console.log is better to use when debugging because alert (1) doesn’t give you any history, (2) you have to click each button. That said, there are times when alert(‘Testing!’) is simply more convenient.
  • 21. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 CONTROL STRUCTURES if (3 > 2) { alert('3 is greater than 2'); } for (var i=0; i < myArray.length; i++) { myArray[i]; } The for loop in JavaScript is a standard C-style for loop. The first statement (here var i=0) sets the starting condition. The second statement (i < myArray.length) sets how long the loop will run--until this condition is false. The third statement (i++) says what will happen at the end of each loop.
  • 22. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 + JQUERY CSS meets JavaScript jQuery is a JavaScript library (intro. 2006) written by John Resig. When learning: great when you can apply something you know to something else. A lot of JS in browser has to do with selecting objects from the DOM. And we already have something to do that...CSS!
  • 23. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 NEW HOTNESS VS. OLD AND BUSTED (But with JavaScript instead of computers) Javascript has been around for awhile. Tutorials on the internet are old. Used to put your Javascript inline with your HTML. onclick...onload...document.writeln(). Like CSS, the current best practice is to separate your Javascript from the HTML. We don’t use onevent anymore. Also, using JavaScript in browsers has often been onerous. To change all the elements with a certain class, you used to write document.getElementsByTagName(‘*’) ... and a bunch of other stuff. But new libraries like jQuery let you do this more efficiently: $(‘.name-of-class’)
  • 24. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 JQUERY Using jQuery involves two steps: • Selects objects from the DOM using CSS selectors. • Do something with the selected elements.
  • 25. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 MAIN JQUERY OPERATIONS • Attributes: Changing existing elements. • Traversing: Moving from selected elements in the DOM to others. • Manipulating: Inserting or removing elements. • Events: Attaching functions to events in the browser. The jQuery Documentation (http://docs.jquery.com), which is well organized and written, uses these names as well. Examples: - Attributes: $(‘h1’).text() gives you the text from the selected elements. $(‘h1’).text(‘New Text Here’) sets the text in the selected elements. - Traversing: Moves from selected elements elsewhere in the DOM. - Manipulating: $(‘p’).after(‘This text will be added after every paragraph’); $ (‘body’).prepend(‘This will appear at the top of the page’) - Events: You select the elements you want to attach an event to and provide an anonymous function: $(‘h2’).click( function() { alert(‘You clicked on an h2’); });
  • 26. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 WEB BROWSER EXTENSIONS Greasemonkey and Jetpack and bears, oh my! A general overview: we’ll be looking at a class of tools that extend the functionality of a web browser, either to change the browser chrome (like the status bar or the menu options) or modify an existing webpage.
  • 27. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 EXTEND WHAT? Browser chrome Page content Page style Page behavior Chrome: an image in the status bar that lets you know when you have new email Content: removing an advertisement or adding a map Style: giving Craiglist any kind of style at all Behavior: make a button
  • 28. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 Greasemonkey Mozilla Jetpack Firefox Extensions Chrome Extensions Relative advantages and disadvantages. The left-hand column is fairly mature compared to the right. The top row is fairly light-weight (for development and installation) than the bottom row. Firefox Extensions have the best performance but are the hardest to develop. We’ll use Greasemonkey here -- it’s easy to develop, easy to install, and fairly widespread. But these others have their advantages -- Jetpack makes it particularly easy to add to the browser’s chrome and Firefox gives you a lot of power that Greasemonkey doesn’t have -- if you want to use one, go for it! But Greasemonkey is a good start for us and development is just like modifying an existing webpage. Anyone know of others? (Safari Saft, IE Activities....)
  • 29. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 GOOD FOR THE BROWSERS GOOD FOR US For the browsers: Let users customize and extend the browser, but keep the core small. For us: Let us prototype website and browser features without building either from scratch.
  • 30. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 LET’S TRY IT To the browser / text editor!
  • 31. INFORMATION ORGANIZATION LAB SEPTEMBER 8, 2009 FOR NEXT WEEK For practice, make sure you can build the Delicious Trailmaker all by yourself. Add a feature to it. Write your first Greasemonkey script. Come with questions next class. Decide on an idea for Project 1. You can find links to help with all of these on the course website at http://courses.ischool.berkeley.edu/i290-4/f09/