SlideShare a Scribd company logo
DR. STRANGELOVE OR:
 HOW I LEARNED TO STOP
  WORRYING AND LOVE
HTML, CSS, AND JAVASCRIPT
BJ CLARK
UX Developer @ http://goldstar.com


       @RobotDeathSquad
      http://github.com/BJClark
          http://bjclark.me
POP QUIZ!!!!
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Javascript
git clone git://github.com/BJClark/Dr.-Strangelove.git
A LOVE STORY IN 3 PARTS


• Writing   Beautiful HTML

• CSS   for fun and profit

• Javascript   like you give a shit Professional Javascript
BEAUTIFUL HTML

• Why?

• Valid

• Semantic

• IDs   vs Classes

• Microformats
Why?
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Javascript
SEMANTIC = MEANINGFUL


• HTML     Elements

• CSS   Classnames and IDs

• Tables   for tables, lists for lists.

• HTML5
IDS AND CLASSES


                                <% div_for photo, :class => "hmedia" do %>
                                    ...
• IDs   are for identification   <% end -%>

                                <div class="photo hmedia" id="photo_1">
• Classes   are categories          . . .
                                </div>
MICROFORMATS


                        <% div_for photo, :class => "hmedia" do %>
• microformats.org      %>
                            <%= content_tag :h2, photo.title, :class => "fn"

                            <a rel="enclosure" type="image/jpeg" href="<%=
                        url_for photo -%>">
• Sensible   Defaults           <%= image_tag "strangelove.jpg", :alt => "Dr.
                        Strangelove", :class => "photo" %>
                            </a>
                            <div class="attribution">
• SpecificHTML with              by <span class="contributor vcard">
                                     <%= link_to photo.user, "http://
 specific classes        example.com", :class => "url fn" %>
                                 </span>
                            </div>
                        <% end -%>
RESOURCEFUL VIEWS


• Self-contained

• Microformatted*

• Matching   our domain
 objects
Cascading Style Sheets
CSS FOR FUN AND PROFIT


• Webkit

• CSS   Frameworks

• Graceful   Degradation/Progressive Enhancement

• CSS   is close enough to OOP
WEBKIT
WEBKIT
WEBKIT



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

       • Sensible
               defaults! DRY!
        Convention over creativity.

       • Resets

       • Clearfix

       • Josef   Muller Brockman
GRACEFUL DEGRADATION
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;
 }
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
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)
}
PROFESSIONAL JAVASCRIPT


• Build    page to work without Javascript?

• Inline   JS = Legacy code

• Writing    reusable Javascript
WITHOUT JAVASCRIPT?
WITHOUT JAVASCRIPT?



• Do your users turn off
 javascript?
WITHOUT JAVASCRIPT?



• Do your users turn off
 javascript?

• Do   you like testing?
WITHOUT JAVASCRIPT?



• Do your users turn off
 javascript?

• Do   you like testing?
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>
WRITING REUSABLE
                  JAVASCRIPT
var Photor = {};

Photor.Tags = (function($){

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

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

});
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);
         });

     }
 }
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);
        }
  });
}
SHOWING ADD TAGS

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




//INCORRECT
$('.edit_tags').click(function(event){
  event.preventDefault();
  $('.add_tags').show();
  $(event.target).hide();
});
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);
        }
  });
THINGS TO NOTE


• No   use of “this”

• Not   using IDs

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


bjclark@scidept.com • http://bjclark.me

More Related Content

What's hot (20)

TXT
Convidar para page !!
Jhonny Batista
 
PDF
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
PDF
Dependency Management with RequireJS
Aaronius
 
PPTX
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
PDF
jQuery UI and Plugins
Marc Grabanski
 
TXT
Fcr 2
Ravi Peter
 
PPTX
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui
 
PPTX
webstudy jquery
Seungho Han
 
PDF
jQuery (BostonPHP)
jeresig
 
PDF
Virtual Madness @ Etsy
Nishan Subedi
 
PDF
Styling components with JavaScript
bensmithett
 
PPT
Jquery 5
Manish Kumar Singh
 
PDF
GDI Seattle - Intro to JavaScript Class 4
Heather Rock
 
KEY
Django Admin: Widgetry & Witchery
Pamela Fox
 
PDF
jQuery (MeshU)
jeresig
 
PPTX
CSS: A Slippery Slope to the Backend
FITC
 
KEY
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
PDF
jQuery (DrupalCamp Toronto)
jeresig
 
PDF
Yearning jQuery
Remy Sharp
 
PDF
Fundamental JQuery
Achmad Solichin
 
Convidar para page !!
Jhonny Batista
 
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
 
Dependency Management with RequireJS
Aaronius
 
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
jQuery UI and Plugins
Marc Grabanski
 
Fcr 2
Ravi Peter
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui
 
webstudy jquery
Seungho Han
 
jQuery (BostonPHP)
jeresig
 
Virtual Madness @ Etsy
Nishan Subedi
 
Styling components with JavaScript
bensmithett
 
GDI Seattle - Intro to JavaScript Class 4
Heather Rock
 
Django Admin: Widgetry & Witchery
Pamela Fox
 
jQuery (MeshU)
jeresig
 
CSS: A Slippery Slope to the Backend
FITC
 
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
jQuery (DrupalCamp Toronto)
jeresig
 
Yearning jQuery
Remy Sharp
 
Fundamental JQuery
Achmad Solichin
 

Viewers also liked (7)

PPTX
2012-03 Search Congress Community Management Workshop
Gillian Muessig
 
PDF
Felixlau
guestc352eb
 
PPTX
2011 06 OMS Denver Gillian Muessig - Topic Modeling; Writing for Search Bots ...
Gillian Muessig
 
PPT
Vocabulary and Cycles
Pinkham Elementary
 
KEY
OOP CSS Presenation
RobotDeathSquad
 
KEY
ActiveRecord
RobotDeathSquad
 
PDF
Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript
RobotDeathSquad
 
2012-03 Search Congress Community Management Workshop
Gillian Muessig
 
Felixlau
guestc352eb
 
2011 06 OMS Denver Gillian Muessig - Topic Modeling; Writing for Search Bots ...
Gillian Muessig
 
Vocabulary and Cycles
Pinkham Elementary
 
OOP CSS Presenation
RobotDeathSquad
 
ActiveRecord
RobotDeathSquad
 
Dr. Strangelove: or How I learned to love HTML, CSS, and Javascript
RobotDeathSquad
 
Ad

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

KEY
Ease into HTML5 and CSS3
Brian Moon
 
PDF
Accelerated Stylesheets
Wynn Netherland
 
PDF
Web Standards: Fueling Innovation [Web Builder 2.0 - 2008]
Aaron Gustafson
 
PDF
Intro to CSS3
Denise Jacobs
 
KEY
What is Object Oriented CSS?
Nicole Sullivan
 
PDF
Web Standards: Fueling Innovation [Web Design World Boston '08]
Aaron Gustafson
 
KEY
HTML5, CSS3, and other fancy buzzwords
Mo Jangda
 
PDF
Front End on Rails
Justin Halsall
 
PDF
Web Development for UX Designers
Ashlimarie
 
PPTX
HTML5 on Mobile(For Designer)
Adam Lu
 
KEY
The Fast And The Fabulous
Nicole Sullivan
 
PDF
SilverStripe CMS JavaScript Refactoring
Ingo Schommer
 
KEY
CSS Wish List @JSConf
Nicole Sullivan
 
PDF
The YUI Library (Yahoo! Course @NCU)
Joseph Chiang
 
PPTX
Course Tech 2013, Sasha Vodnik, A Crash Course in HTML5
Cengage Learning
 
DOCX
SIVASOFT - BEST ONLINE WEB DEVELOPMENT TRAINING COURSE
sivasoft12
 
PDF
CSS3 Talk (PDF version)
Robyn Overstreet
 
PDF
CSS3 Talk at SF HTML5 Meetup
Robyn Overstreet
 
PDF
Html5, css3 y js
Facundo Ferrero
 
PDF
Sachin Foujdar , BCA Third Year
Dezyneecole
 
Ease into HTML5 and CSS3
Brian Moon
 
Accelerated Stylesheets
Wynn Netherland
 
Web Standards: Fueling Innovation [Web Builder 2.0 - 2008]
Aaron Gustafson
 
Intro to CSS3
Denise Jacobs
 
What is Object Oriented CSS?
Nicole Sullivan
 
Web Standards: Fueling Innovation [Web Design World Boston '08]
Aaron Gustafson
 
HTML5, CSS3, and other fancy buzzwords
Mo Jangda
 
Front End on Rails
Justin Halsall
 
Web Development for UX Designers
Ashlimarie
 
HTML5 on Mobile(For Designer)
Adam Lu
 
The Fast And The Fabulous
Nicole Sullivan
 
SilverStripe CMS JavaScript Refactoring
Ingo Schommer
 
CSS Wish List @JSConf
Nicole Sullivan
 
The YUI Library (Yahoo! Course @NCU)
Joseph Chiang
 
Course Tech 2013, Sasha Vodnik, A Crash Course in HTML5
Cengage Learning
 
SIVASOFT - BEST ONLINE WEB DEVELOPMENT TRAINING COURSE
sivasoft12
 
CSS3 Talk (PDF version)
Robyn Overstreet
 
CSS3 Talk at SF HTML5 Meetup
Robyn Overstreet
 
Html5, css3 y js
Facundo Ferrero
 
Sachin Foujdar , BCA Third Year
Dezyneecole
 
Ad

Recently uploaded (20)

PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Digital Circuits, important subject in CS
contactparinay1
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 

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

  • 1. DR. STRANGELOVE OR: HOW I LEARNED TO STOP WORRYING AND LOVE HTML, CSS, AND JAVASCRIPT
  • 2. BJ CLARK UX Developer @ http://goldstar.com @RobotDeathSquad http://github.com/BJClark http://bjclark.me
  • 6. A LOVE STORY IN 3 PARTS • Writing Beautiful HTML • CSS for fun and profit • Javascript like you give a shit Professional Javascript
  • 7. BEAUTIFUL HTML • Why? • Valid • Semantic • IDs vs Classes • Microformats
  • 10. SEMANTIC = MEANINGFUL • HTML Elements • CSS Classnames and IDs • Tables for tables, lists for lists. • HTML5
  • 11. IDS AND CLASSES <% div_for photo, :class => "hmedia" do %> ... • IDs are for identification <% end -%> <div class="photo hmedia" id="photo_1"> • Classes are categories . . . </div>
  • 12. MICROFORMATS <% div_for photo, :class => "hmedia" do %> • microformats.org %> <%= content_tag :h2, photo.title, :class => "fn" <a rel="enclosure" type="image/jpeg" href="<%= url_for photo -%>"> • Sensible Defaults <%= image_tag "strangelove.jpg", :alt => "Dr. Strangelove", :class => "photo" %> </a> <div class="attribution"> • SpecificHTML with by <span class="contributor vcard"> <%= link_to photo.user, "http:// specific classes example.com", :class => "url fn" %> </span> </div> <% end -%>
  • 13. RESOURCEFUL VIEWS • Self-contained • Microformatted* • Matching our domain objects
  • 15. CSS FOR FUN AND PROFIT • Webkit • CSS Frameworks • Graceful Degradation/Progressive Enhancement • CSS is close enough to OOP
  • 19. CSS FRAMEWORKS • Sensible defaults! DRY! Convention over creativity. • Resets • Clearfix • Josef Muller Brockman
  • 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; }
  • 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
  • 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) }
  • 24. PROFESSIONAL JAVASCRIPT • Build page to work without Javascript? • Inline JS = Legacy code • Writing reusable Javascript
  • 26. WITHOUT JAVASCRIPT? • Do your users turn off javascript?
  • 27. WITHOUT JAVASCRIPT? • Do your users turn off javascript? • Do you like testing?
  • 28. WITHOUT JAVASCRIPT? • Do your users turn off javascript? • Do you like testing?
  • 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>
  • 30. WRITING REUSABLE JAVASCRIPT var Photor = {}; Photor.Tags = (function($){ return { init: function(){ • Namespaced } } })(jQuery); • Public vs Private Methods $(document).ready(function(){ Photor.Tags.init(); });
  • 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); }); } }
  • 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); } }); }
  • 33. SHOWING ADD TAGS var editTags = function(target){ var parent_div = $(target).closest('.tags'); $('.add_tags', parent_div).show(); $(target).hide(); } //INCORRECT $('.edit_tags').click(function(event){ event.preventDefault(); $('.add_tags').show(); $(event.target).hide(); });
  • 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); } });
  • 35. THINGS TO NOTE • No use of “this” • Not using IDs • Closures allow for multiples of the same elements to act independently