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

PDF
Javascript MVC & Backbone Tips & Tricks
KEY
An in-depth look at jQuery UI
KEY
An in-depth look at jQuery
PDF
JavaScript for Flex Devs
PPT
Jquery ui
PDF
DOM Scripting Toolkit - jQuery
PDF
JQuery UI
PPT
A Short Introduction To jQuery
Javascript MVC & Backbone Tips & Tricks
An in-depth look at jQuery UI
An in-depth look at jQuery
JavaScript for Flex Devs
Jquery ui
DOM Scripting Toolkit - jQuery
JQuery UI
A Short Introduction To jQuery

What's hot (20)

TXT
Convidar para page !!
PDF
Stack Overflow Austin - jQuery for Developers
PDF
Dependency Management with RequireJS
PPTX
Jquery Complete Presentation along with Javascript Basics
PDF
jQuery UI and Plugins
TXT
Fcr 2
PPTX
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
PPTX
webstudy jquery
PDF
jQuery (BostonPHP)
PDF
Virtual Madness @ Etsy
PDF
Styling components with JavaScript
PPT
PDF
GDI Seattle - Intro to JavaScript Class 4
KEY
Django Admin: Widgetry & Witchery
PDF
jQuery (MeshU)
PPTX
CSS: A Slippery Slope to the Backend
KEY
jQuery: Tips, tricks and hints for better development and Performance
PDF
jQuery (DrupalCamp Toronto)
PDF
Yearning jQuery
PDF
Fundamental JQuery
Convidar para page !!
Stack Overflow Austin - jQuery for Developers
Dependency Management with RequireJS
Jquery Complete Presentation along with Javascript Basics
jQuery UI and Plugins
Fcr 2
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
webstudy jquery
jQuery (BostonPHP)
Virtual Madness @ Etsy
Styling components with JavaScript
GDI Seattle - Intro to JavaScript Class 4
Django Admin: Widgetry & Witchery
jQuery (MeshU)
CSS: A Slippery Slope to the Backend
jQuery: Tips, tricks and hints for better development and Performance
jQuery (DrupalCamp Toronto)
Yearning jQuery
Fundamental JQuery
Ad

Viewers also liked (7)

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

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

PDF
Building iPhone Web Apps using "classic" Domino
KEY
Jarv.us Showcase — SenchaCon 2011
PPTX
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
PDF
Awesome html with ujs, jQuery and coffeescript
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
PDF
DirectToWeb 2.0
KEY
[Coscup 2012] JavascriptMVC
PDF
Unobtrusive JavaScript
PDF
Using jQuery to Extend CSS
PPTX
Big Data for each one of us
PPT
J query
KEY
Evrone.ru / BEM for RoR
PDF
Jquery In Rails
PDF
建立前端開發團隊 - 2011 中華電信訓練所版
PDF
前端MVC之BackboneJS
KEY
CSS3 Takes on the World
PDF
Styling Components with JavaScript: MelbCSS Edition
KEY
Bcblackpool jquery tips
PDF
Django at the Disco
PDF
Html standards presentation
Building iPhone Web Apps using "classic" Domino
Jarv.us Showcase — SenchaCon 2011
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
Awesome html with ujs, jQuery and coffeescript
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
DirectToWeb 2.0
[Coscup 2012] JavascriptMVC
Unobtrusive JavaScript
Using jQuery to Extend CSS
Big Data for each one of us
J query
Evrone.ru / BEM for RoR
Jquery In Rails
建立前端開發團隊 - 2011 中華電信訓練所版
前端MVC之BackboneJS
CSS3 Takes on the World
Styling Components with JavaScript: MelbCSS Edition
Bcblackpool jquery tips
Django at the Disco
Html standards presentation

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
Digital-Transformation-Roadmap-for-Companies.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
A comparative analysis of optical character recognition models for extracting...
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding

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