SlideShare a Scribd company logo
DR. STRANGELOVE OR:
           HOW I LEARNED TO STOP
            WORRYING AND LOVE
          HTML, CSS, AND JAVASCRIPT
Friday, September 10, 2010
POP QUIZ!!!!


Friday, September 10, 2010
Friday, September 10, 2010
git clone git://github.com/BJClark/Dr.-Strangelove.git




Friday, September 10, 2010
A LOVE STORY IN 3 PARTS


    • Writing                Beautiful HTML

    • CSS           for fun and profit

    • Javascript              like you give a shit Professional Javascript




Friday, September 10, 2010
Why?




Friday, September 10, 2010
Friday, September 10, 2010
SEMANTIC = MEANINGFUL


    • Know   your HTML elements
        (<samp> <abbr> <cite> <ol>)

    • Tables             for tables, lists for lists.

    • HTML5




Friday, September 10, 2010
IDS AND CLASSES

                                              <% div_for photo, :class => "hmedia" do %>
                                                  ...
                                              <% end -%>

                                              <div class="photo hmedia" id="photo_1">
                                                  . . .
    • IDs         are for identification       </div>



    • Classes                are categories   <%= dom_id @photo %>

                                              "photo_1"




Friday, September 10, 2010
MICROFORMATS

    • microformats.org                  <% div_for photo, :class => "hmedia" do %>
                                            <%= content_tag :h2, photo.title, :class => "fn"
                                        %>
    • Sensible               Defaults       <a rel="enclosure" type="image/jpeg" href="<%=
                                        url_for photo -%>">
                                                 <%= image_tag "strangelove.jpg", :alt => "Dr.
                                        Strangelove", :class => "photo" %>
    • Specific   HTML with                   </a>
                                            <div class="attribution">
        specific classes                          by <span class="contributor vcard">
                                                     <%= link_to photo.user, "http://
                                        example.com", :class => "url fn" %>

    • mofo, xoxo                                 </span>
                                            </div>
                                        <% end -%>




Friday, September 10, 2010
MICROFORMATS
                     XOXO - Microformat for Navigation Outlines
                                  <ol class='xoxo'>
                                    <li>Subject 1
                                      <ol>
                                           <li>subpoint a</li>
                                           <li>subpoint b</li>
                                      </ol>
                                    </li>
                                    <li>Subject 2
                                      <ol compact="compact">
                                           <li>subpoint c</li>
                                           <li>subpoint d</li>
                                      </ol>
                                    </li>
                                    <li>Subject 3
                                      <ol>
                                           <li>subpoint e</li>
                                      </ol>
                                    </li>
                                  </ol>



Friday, September 10, 2010
RESOURCEFUL VIEWS


    • Self-contained

    • Microformatted*

    • Matching               our domain
        objects



Friday, September 10, 2010
Cascading Style Sheets




Friday, September 10, 2010
WEBKIT




Friday, September 10, 2010
WEBKIT




Friday, September 10, 2010
WEBKIT



                      http://www.quirksmode.org/compatibility.html




Friday, September 10, 2010
CAN I USE. . .




Friday, September 10, 2010
CSS FRAMEWORKS

                                    • Sensible
                                            defaults! DRY!
                                     Convention over creativity.

                                    • Resets

                                    • Clearfix

                                    • Josef   Muller Brockman


Friday, September 10, 2010
GRACEFUL DEGRADATION




Friday, September 10, 2010
IT’S A SECRET




                             IE7              Webkit

Friday, September 10, 2010
GRACEFUL DEGRADATION
                     .editable_tag {
                       padding: 5px 10px;
                       margin: 5px 10px 0 0;
                       background: #bfbfbf; /* lowest common denominator */
                       float: left;
                       background: -webkit-gradient(linear, left top, left
                     bottom, from(#bfbfbf), to(#e4e4e4));
                       background: -moz-linear-gradient(top, #bfbfbf, #e4e4e4);
                       -webkit-border-radius: 4px; /* Safari 4 */
                       -moz-border-radius: 4px; /* Firefox */
                       border-radius: 4px; /* Safari 5 & Chrome */
                       box-shadow: rgba(0,0,0,1) 0 1px 0;
                     }




Friday, September 10, 2010
OBJECT ORIENTED CSS

    • CSS isn’t that different than
        OOP in other languages             .photo_navigation div.empty_photo{
                                             width: 60px;
                                             height: 60px;
                                             padding: 10px;
    • IDs         are singletons             background: silver;
                                             color: white;
                                             font-size: .8em;
    • Classes                are Objects   }
                                           .photo_navigation
                                           img, .photo_navigation
    • Inheritance and                      div.empty_photo {

        Composition                          float: left;
                                             padding-right: 10px;
                                           }

    • Namespacing

Friday, September 10, 2010
OBJECT ORIENTED CSS

   .photo_navigation div.empty_photo{
     width: 60px;                             class PhotoNavigation::EmptyPhoto
     height: 60px;                                width "60px"
                                                  height "60px"
     padding: 10px;
                                                  padding "10px"
     background: silver;                      end
     color: white;
     font-size: .8em;                         class PhotoNavigation::OtherOptions
   }                                            float "left"
                                                padding_right "10px"
   .photo_navigation img, .photo_navigation
                                              end
   div.empty_photo {
     float: left;                             empty_photo = PhotoNavigation::EmptyPhoto.new
     margin-right: 10px;                      empty_photo.extend(PhotoNavigation::OtherOptions)
   }




Friday, September 10, 2010
PROFESSIONAL JAVASCRIPT


    • Build           page to work without Javascript?

    • Inline           JS = Legacy code

    • Writing                reusable Javascript




Friday, September 10, 2010
WITHOUT JAVASCRIPT?




Friday, September 10, 2010
WITHOUT JAVASCRIPT?



    • Do    your users turn off
        javascript?




Friday, September 10, 2010
WITHOUT JAVASCRIPT?



    • Do    your users turn off
        javascript?

    • Do          you like testing?




Friday, September 10, 2010
WITHOUT JAVASCRIPT?



    • Do    your users turn off
        javascript?

    • Do          you like testing?




Friday, September 10, 2010
THE CASE FOR UJS

                                        <a href="#" onclick="new
                                        Ajax.Updater('foo', 'http://
    • Very            painful to test   strangelove.local/tags/1',
                                        {asynchronous:true,
                                        evalScripts:true,
    • Impossible             to reuse   parameters:'authenticity_token=' +
                                        encodeURIComponent('xXnuBemPMRAar/
    • Hard             to debug         EUBB9GbcXD/
                                        +HUhOaUxoAnkm5KSy8=')}); return
                                        false;">Zip</a>




Friday, September 10, 2010
WRITING REUSABLE
                                JAVASCRIPT
     var Photor = {};

     Photor.Tags = (function($){

        return {
          init: function(){
                                     • Namespaced
            }
        }

     })(jQuery);
                                     • Public   vs Private Methods
     $(document).ready(function(){
       Photor.Tags.init();

     });




Friday, September 10, 2010
INIT METHOD
     return {
         init: function(){
           $('.edit_tags').live('click', function(event){
              event.preventDefault();
              editTags(event.target);
           });

                 $('.destroy_tag').live('click', function(event){
                   event.preventDefault();
                   removeTag(event.target);
                 });

                 $('.add_tags').live('submit', function(event){
                   event.preventDefault();
                   addTags(event.target);
                 });

             }
         }



Friday, September 10, 2010
REMOVING A TAG

        var removeTag = function(tag){
          var editable_tag = $(tag).closest('.editable_tag');
          $(editable_tag).hide(); //instant user feedback
          $.ajax({url: $(tag).attr('href'),
                type: "POST",
                data: {"_method": 'delete'},
                success: function(data){
                   $(editable_tag).remove();
                   hideErrors(editable_tag);
                },
                error: function(data){
                   $(editable_tag).show();
                   handleError(data, editable_tag);
                }
          });
        }




Friday, September 10, 2010
SHOWING ADD TAGS
     //INCORRECT (and how every jQuery tutorial out there tells you how to do it)
     $('.edit_tags').click(function(event){
       event.preventDefault();
       $('.add_tags').show();
       $(event.target).hide();
     });




        var editTags = function(target){
          var parent_div = $(target).closest('.tags');
          $('.add_tags', parent_div).show();
          $(target).hide();
        }




Friday, September 10, 2010
ADDING TAGS

        var addTags = function(form) {
          $.ajax({url: $(form).attr('action') + ".js",
                type: "POST",
                data: $(form).serialize(),
                dataType: "html",
                success: function(data){
                   var tags_div = $(form).closest('.tags');
                   $('.editable_tag', tags_div).remove();
                   $('.error_messages', tags_div).after(data);
                   hideErrors();
                   $(form).find('input[type=text]').val("");
                },
                error: function(data){
                   handleError(data, form);
                }
          });




Friday, September 10, 2010
THINGS TO NOTE


    • No          use of “this”

    • Not           using IDs

    • Closures  allow for multiples of the same elements to act
        independently



Friday, September 10, 2010
BJ CLARK
                             UX Developer @ http://goldstar.com


                                    @RobotDeathSquad
                                   http://github.com/BJClark
                                       http://bjclark.me



Friday, September 10, 2010
Ad

More Related Content

Similar to Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript (20)

HTML5 - getting started
HTML5 - getting startedHTML5 - getting started
HTML5 - getting started
Ted Drake
 
lecture2_public
lecture2_publiclecture2_public
lecture2_public
tutorialsruby
 
lecture2_public
lecture2_publiclecture2_public
lecture2_public
tutorialsruby
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End Optimizations
Scott Taylor
 
Getting Started with Dojo Toolkit
Getting Started with Dojo ToolkitGetting Started with Dojo Toolkit
Getting Started with Dojo Toolkit
Thomas Koch
 
CSS Bloat!
CSS Bloat!CSS Bloat!
CSS Bloat!
Nicole Sullivan
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Adrian Olaru
 
A Primer on HTML 5 - By Nick Armstrong
A Primer on HTML 5 - By Nick ArmstrongA Primer on HTML 5 - By Nick Armstrong
A Primer on HTML 5 - By Nick Armstrong
Nick Armstrong
 
Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010
Zi Bin Cheah
 
Topsy Turvy Design
Topsy Turvy DesignTopsy Turvy Design
Topsy Turvy Design
Rich Quick
 
BDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZBDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZ
leondu
 
HTML5: Building for a Faster Web
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster Web
Eric Bidelman
 
Look ma! No images!
Look ma! No images!Look ma! No images!
Look ma! No images!
Lennart Schoors
 
Hardcore CSS
Hardcore CSSHardcore CSS
Hardcore CSS
PDX Web & Design
 
Http _css-tricks
Http  _css-tricksHttp  _css-tricks
Http _css-tricks
Daniel Downs
 
HTML5 & CSS3 Flag
HTML5 & CSS3 FlagHTML5 & CSS3 Flag
HTML5 & CSS3 Flag
Christopher Schmitt
 
Html5 coredevsummit
Html5 coredevsummitHtml5 coredevsummit
Html5 coredevsummit
Jen Simmons
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~
Sho Ito
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
Tim Wright
 
RWD in the Wild
RWD in the WildRWD in the Wild
RWD in the Wild
Rich Quick
 
HTML5 - getting started
HTML5 - getting startedHTML5 - getting started
HTML5 - getting started
Ted Drake
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End Optimizations
Scott Taylor
 
Getting Started with Dojo Toolkit
Getting Started with Dojo ToolkitGetting Started with Dojo Toolkit
Getting Started with Dojo Toolkit
Thomas Koch
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Adrian Olaru
 
A Primer on HTML 5 - By Nick Armstrong
A Primer on HTML 5 - By Nick ArmstrongA Primer on HTML 5 - By Nick Armstrong
A Primer on HTML 5 - By Nick Armstrong
Nick Armstrong
 
Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010
Zi Bin Cheah
 
Topsy Turvy Design
Topsy Turvy DesignTopsy Turvy Design
Topsy Turvy Design
Rich Quick
 
BDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZBDD and Cucumber at barcampGZ
BDD and Cucumber at barcampGZ
leondu
 
HTML5: Building for a Faster Web
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster Web
Eric Bidelman
 
Html5 coredevsummit
Html5 coredevsummitHtml5 coredevsummit
Html5 coredevsummit
Jen Simmons
 
Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~Attractive HTML5~開発者の視点から~
Attractive HTML5~開発者の視点から~
Sho Ito
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
Tim Wright
 
RWD in the Wild
RWD in the WildRWD in the Wild
RWD in the Wild
Rich Quick
 

Recently uploaded (20)

HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Ad

Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript

  • 1. DR. STRANGELOVE OR: HOW I LEARNED TO STOP WORRYING AND LOVE HTML, CSS, AND JAVASCRIPT Friday, September 10, 2010
  • 5. A LOVE STORY IN 3 PARTS • Writing Beautiful HTML • CSS for fun and profit • Javascript like you give a shit Professional Javascript Friday, September 10, 2010
  • 8. SEMANTIC = MEANINGFUL • Know your HTML elements (<samp> <abbr> <cite> <ol>) • Tables for tables, lists for lists. • HTML5 Friday, September 10, 2010
  • 9. IDS AND CLASSES <% div_for photo, :class => "hmedia" do %> ... <% end -%> <div class="photo hmedia" id="photo_1"> . . . • IDs are for identification </div> • Classes are categories <%= dom_id @photo %> "photo_1" Friday, September 10, 2010
  • 10. MICROFORMATS • microformats.org <% div_for photo, :class => "hmedia" do %> <%= content_tag :h2, photo.title, :class => "fn" %> • Sensible Defaults <a rel="enclosure" type="image/jpeg" href="<%= url_for photo -%>"> <%= image_tag "strangelove.jpg", :alt => "Dr. Strangelove", :class => "photo" %> • Specific HTML with </a> <div class="attribution"> specific classes by <span class="contributor vcard"> <%= link_to photo.user, "http:// example.com", :class => "url fn" %> • mofo, xoxo </span> </div> <% end -%> Friday, September 10, 2010
  • 11. MICROFORMATS XOXO - Microformat for Navigation Outlines <ol class='xoxo'> <li>Subject 1 <ol> <li>subpoint a</li> <li>subpoint b</li> </ol> </li> <li>Subject 2 <ol compact="compact"> <li>subpoint c</li> <li>subpoint d</li> </ol> </li> <li>Subject 3 <ol> <li>subpoint e</li> </ol> </li> </ol> Friday, September 10, 2010
  • 12. RESOURCEFUL VIEWS • Self-contained • Microformatted* • Matching our domain objects Friday, September 10, 2010
  • 13. Cascading Style Sheets Friday, September 10, 2010
  • 16. WEBKIT http://www.quirksmode.org/compatibility.html Friday, September 10, 2010
  • 17. CAN I USE. . . Friday, September 10, 2010
  • 18. CSS FRAMEWORKS • Sensible defaults! DRY! Convention over creativity. • Resets • Clearfix • Josef Muller Brockman Friday, September 10, 2010
  • 20. IT’S A SECRET IE7 Webkit Friday, September 10, 2010
  • 21. GRACEFUL DEGRADATION .editable_tag { padding: 5px 10px; margin: 5px 10px 0 0; background: #bfbfbf; /* lowest common denominator */ float: left; background: -webkit-gradient(linear, left top, left bottom, from(#bfbfbf), to(#e4e4e4)); background: -moz-linear-gradient(top, #bfbfbf, #e4e4e4); -webkit-border-radius: 4px; /* Safari 4 */ -moz-border-radius: 4px; /* Firefox */ border-radius: 4px; /* Safari 5 & Chrome */ box-shadow: rgba(0,0,0,1) 0 1px 0; } Friday, September 10, 2010
  • 22. OBJECT ORIENTED CSS • CSS isn’t that different than OOP in other languages .photo_navigation div.empty_photo{ width: 60px; height: 60px; padding: 10px; • IDs are singletons background: silver; color: white; font-size: .8em; • Classes are Objects } .photo_navigation img, .photo_navigation • Inheritance and div.empty_photo { Composition float: left; padding-right: 10px; } • Namespacing Friday, September 10, 2010
  • 23. OBJECT ORIENTED CSS .photo_navigation div.empty_photo{ width: 60px; class PhotoNavigation::EmptyPhoto height: 60px; width "60px" height "60px" padding: 10px; padding "10px" background: silver; end color: white; font-size: .8em; class PhotoNavigation::OtherOptions } float "left" padding_right "10px" .photo_navigation img, .photo_navigation end div.empty_photo { float: left; empty_photo = PhotoNavigation::EmptyPhoto.new margin-right: 10px; empty_photo.extend(PhotoNavigation::OtherOptions) } Friday, September 10, 2010
  • 24. PROFESSIONAL JAVASCRIPT • Build page to work without Javascript? • Inline JS = Legacy code • Writing reusable Javascript Friday, September 10, 2010
  • 26. WITHOUT JAVASCRIPT? • Do your users turn off javascript? Friday, September 10, 2010
  • 27. WITHOUT JAVASCRIPT? • Do your users turn off javascript? • Do you like testing? Friday, September 10, 2010
  • 28. WITHOUT JAVASCRIPT? • Do your users turn off javascript? • Do you like testing? Friday, September 10, 2010
  • 29. THE CASE FOR UJS <a href="#" onclick="new Ajax.Updater('foo', 'http:// • Very painful to test strangelove.local/tags/1', {asynchronous:true, evalScripts:true, • Impossible to reuse parameters:'authenticity_token=' + encodeURIComponent('xXnuBemPMRAar/ • Hard to debug EUBB9GbcXD/ +HUhOaUxoAnkm5KSy8=')}); return false;">Zip</a> Friday, September 10, 2010
  • 30. WRITING REUSABLE JAVASCRIPT var Photor = {}; Photor.Tags = (function($){ return { init: function(){ • Namespaced } } })(jQuery); • Public vs Private Methods $(document).ready(function(){ Photor.Tags.init(); }); Friday, September 10, 2010
  • 31. INIT METHOD return { init: function(){ $('.edit_tags').live('click', function(event){ event.preventDefault(); editTags(event.target); }); $('.destroy_tag').live('click', function(event){ event.preventDefault(); removeTag(event.target); }); $('.add_tags').live('submit', function(event){ event.preventDefault(); addTags(event.target); }); } } Friday, September 10, 2010
  • 32. REMOVING A TAG var removeTag = function(tag){ var editable_tag = $(tag).closest('.editable_tag'); $(editable_tag).hide(); //instant user feedback $.ajax({url: $(tag).attr('href'), type: "POST", data: {"_method": 'delete'}, success: function(data){ $(editable_tag).remove(); hideErrors(editable_tag); }, error: function(data){ $(editable_tag).show(); handleError(data, editable_tag); } }); } Friday, September 10, 2010
  • 33. SHOWING ADD TAGS //INCORRECT (and how every jQuery tutorial out there tells you how to do it) $('.edit_tags').click(function(event){ event.preventDefault(); $('.add_tags').show(); $(event.target).hide(); }); var editTags = function(target){ var parent_div = $(target).closest('.tags'); $('.add_tags', parent_div).show(); $(target).hide(); } Friday, September 10, 2010
  • 34. ADDING TAGS var addTags = function(form) { $.ajax({url: $(form).attr('action') + ".js", type: "POST", data: $(form).serialize(), dataType: "html", success: function(data){ var tags_div = $(form).closest('.tags'); $('.editable_tag', tags_div).remove(); $('.error_messages', tags_div).after(data); hideErrors(); $(form).find('input[type=text]').val(""); }, error: function(data){ handleError(data, form); } }); Friday, September 10, 2010
  • 35. THINGS TO NOTE • No use of “this” • Not using IDs • Closures allow for multiples of the same elements to act independently Friday, September 10, 2010
  • 36. BJ CLARK UX Developer @ http://goldstar.com @RobotDeathSquad http://github.com/BJClark http://bjclark.me Friday, September 10, 2010