SlideShare a Scribd company logo
AMIR BARYLKO

AWESOME HTML5
      WITH
 UJS, JQUERY &
 COFFEESCRIPT
ABOUT ME
•   Architect
•   Developer
•   Mentor
•   Great cook
•   Software Quality Expert at mavenTHOUGHT Inc.
CONTACT INFO
•   Email: amir@barylko.com

•   Twitter: @abarylko

•   Slides: http://orthocoders.com/presentations.html

•   Company: http://maventhought.com
HTML5
SEMANTIC HTML

•   Communication is key
•   Being expressive
•   Show intent
•   Cleaner
STRUCTURE WITH
   MEANING
•   Section   •   Nav
•   Header    •   Article
•   Footer
•   Aside
ARE YOU SURE?

•   Which comes first, the section or the article?
•   I have a section with multiple articles...
•   Or is it an article with multiple sections?
•   What should I do?
IS IT COMPATIBLE?

•   Well.... (not for IE)
•   Modernizr will fix it for you!
•   And generate the code to let those tags behave as
    blocks, etc....
DATA ATTRIBUTES

•   Add custom values to tags
•   The attribute has to start with data-*
•   The value could be any string, for example:
    <span data-id='309'
          data-title='someTitle' data-time='10:00:30'> ...
USAGES

•   Store information related to your model or view
    model
•   Common usages like confirmation with data-
    confirm
JQUERY
WHAT IS IT?
•   Javascript library/framework to provide easy access
•   to operations that manipulate the DOM
•   to interact with the contents of the page
•   to a repository of plugins for common functionality
•   much more....
QUERYING WITH
     CSS SELECTOR
•   Elements in the page can be selected using css
    selection syntax
    •   $('#movies')

    •   $('#movies a.movie')

    •   $('#movies > li')
MANIPULATE
          DOM
•   Modify the element classes
    •   $('.movie').addClass('new-release')

    •   $('.movie').toggleClass('selected')

•   Add elements or remove elements
    •   $('.movie').append(....)
EVENTS

•   Bind functions/handlers to events
      •   $(document).ready(function() { ... });

      •   $('#movies').on('click', function(e) { .... })
UNOBSTRUSIVE
 JAVASCRIPT
WIKIPEDIA SAYS
Unobtrusive JavaScript is a general approach to the use of
JavaScript in web pages. Though the term is not formally defined, its basic
principles are generally understood to include:

■ Separation of functionality (the "behavior layer") from a Web page's
  structure/content and presentation[1]
■ Best practices to avoid the problems of traditional JavaScript
  programming (such as browser inconsistencies and lack ofscalability)
■ Progressive enhancement to support user agents that may not support
  advanced JavaScript functionality
VS CONFIG
<appSettings>

  <add key="webpages:Version" value="1.0.0.0" />

  <add key="ClientValidationEnabled" value="true" />

  <add key="UnobtrusiveJavaScriptEnabled" value="true"/>

</appSettings>
CLIENT SIDE
     VALIDATION
@Html.Script("jquery.validate.min.js")

@Html.Script("jquery.validate.unobtrusive.min.js")
MODEL
       ATTRIBUTES
•   System.ComponentModel.DataAnnotations
•   Helpers will generate extra code
•   jQuery adds the functionality out of the box!
GIVEN THE
      MODEL
public interface IMovie
{
    [Required]
    string Title { get; }

    DateTime ReleaseDate { get; set; }
}
ACTUAL HTML
<label for="Title">Title</label>

<input id="Title"
       class="text-box single-line input-validation-error"
       type="text" value=""
       name="Title"
       data-val-required="The Title field is required."
       data-val="true">
...
WHY
     UNOBTRUSIVE?
•   Stay out of the way!
•   Separate behavior from markup
•   Use a different file for the Javascript code
•   Use jQuery to handle events, etc...
NO MORE
HANDLERS INLINE
•   Instead of
    <a class="btn" href="#" onclick="addMovie()">

•   Use jQuery to bind the event
    <a class="btn" href="#" id="add-movie">
    $('#add-movie').on('click', addMovie);
COFFEESCRIPT
ANOTHER
    ENERGY DRINK?
•   From coffeescript.org:
    •   CoffeeScript is a little language that compiles into
        JavaScript. Underneath all those awkward braces and
        semicolons, JavaScript has always had a gorgeous object
        model at its heart. CoffeeScript is an attempt to expose
        the good parts of JavaScript in a simple way.


•   The website has a great tutorial showing side by
    side comparison with Javascript
STRING
    INTERPOLATION
•   You can concatenate inside a double quote string
    using the “#” and “{ }”
    •   "The result is #{3}" == "The result is 3"

•   Or use any expression
    •   "/movies/#{id}"
FUNCTIONS

•   The arrow/lambda is used to define functions
    •   square = (x) -> x * x

•   Parenthesis are optional when passing parameters
    •   storageDelete movieId, true
FUNCTIONS II

•   Return implicit (the last expression is the return
    value)

•Multiple lines, indentation is important
    deleteMovie = (e) ->
      movieId = $(e.target)....
      storageDelete(movieId)
OBJECTS

•   Objects are declared using indentation
    config =
      local:
        user:   'dev'
        pwd:    'dev123'
      remote:
        user:   'superdev'
        pwd:    "impossibleToGuess"
MAPS & ARRAYS

•   Arrays are declared with “[ ]”
    •   deploy = ['local', 'remote', 'uat']

•   And maps using “{ }”
    •   testing = {v1: true, v2: false, v3: true}
CONDITIONALS

•   Classic if does not need parenthesis or brackets
    if isJson
      callIndex()
      display()
    else
      dont()

•   Or use unless for the negated form
CONDITIONALS
      POSTFIX
•   The conditionals can be use as modifiers
    •   callIndex() if isJson

    •   exit() unless validated and inContext
LIST
COMPREHENSION
•   Iterate and call a function over each element
    •   deploy env for env in ['local', 'uat', 'prod']

•   Or filter over a collection
    •   allSelected = (n for n in nodes when n.selected)
CLASSES
class MovieRepository

  newMovie: ->
    $.ajax
      url: someUrl
      success: (data) -> $(id).append data
TESTING

•   Is just Javascript
•   so use Jasmine
•   or Qunit
•   any other....
DEBUGGING

•   Same variable names
•   Just set a breakpoint in the code
•   and add watches, etc....
CONTACT INFO
•   Email: amir@barylko.com

•   Twitter: @abarylko

•   Slides: http://orthocoders.com/presentations.html

•   Company: http://maventhought.com

More Related Content

PDF
Beutiful javascript with coffeescript
PDF
DevTeach12-betterspecs
PDF
SDEC12 Beautiful javascript with coffeescript
PDF
DevTeach12-Capybara
PDF
Beutiful javascript with coffeescript
PDF
PRDC12 advanced design patterns
PDF
Code camp 2012-advanced-design-patterns
KEY
Aae jv presentation
Beutiful javascript with coffeescript
DevTeach12-betterspecs
SDEC12 Beautiful javascript with coffeescript
DevTeach12-Capybara
Beutiful javascript with coffeescript
PRDC12 advanced design patterns
Code camp 2012-advanced-design-patterns
Aae jv presentation

What's hot (12)

PDF
Jina bolton - Refactoring Web Interfaces
PPTX
Fastest css3 animations
PPTX
Advanced Custom Fields Lightning Talk WordCamp Miami 2018
PDF
Famo.us introduction
PDF
Lose Your Head! Re-imagining WordPress's Role in Content Presentation
PDF
Outside-in Development with Cucumber and Rspec
PPTX
Testing Alexa Skill
PDF
Choosing your animation adventure - Generate NYC 2018
PPTX
Intro to EmberJS
PPTX
PG Day Us: Animations for Web & Hybrid
PDF
Arva JS Developer Introduction
PDF
Cucumber Ru09 Web
Jina bolton - Refactoring Web Interfaces
Fastest css3 animations
Advanced Custom Fields Lightning Talk WordCamp Miami 2018
Famo.us introduction
Lose Your Head! Re-imagining WordPress's Role in Content Presentation
Outside-in Development with Cucumber and Rspec
Testing Alexa Skill
Choosing your animation adventure - Generate NYC 2018
Intro to EmberJS
PG Day Us: Animations for Web & Hybrid
Arva JS Developer Introduction
Cucumber Ru09 Web
Ad

Similar to Awesome html with ujs, jQuery and coffeescript (20)

PPTX
Jquery fundamentals
PDF
Rich UI with Knockout.js &amp; Coffeescript
PDF
jQuery for beginners
PPT
J query b_dotnet_ug_meet_12_may_2012
PDF
JavaScript
PDF
J query fundamentals
PPTX
UNIT 1 (7).pptx
PPTX
jQuery
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
KEY
Week 4 - jQuery + Ajax
KEY
User Interface Development with jQuery
PDF
Remy Sharp The DOM scripting toolkit jQuery
PPTX
Java scriptforjavadev part2a
PPTX
Rohit&kunjan
PDF
PDF
What's this jQuery? Where it came from, and how it will drive innovation
PPTX
A Rich Web experience with jQuery, Ajax and .NET
PPTX
Modern JavaScript Talk
PDF
jQuery Features to Avoid
KEY
Learning How To Use Jquery #3
Jquery fundamentals
Rich UI with Knockout.js &amp; Coffeescript
jQuery for beginners
J query b_dotnet_ug_meet_12_may_2012
JavaScript
J query fundamentals
UNIT 1 (7).pptx
jQuery
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Week 4 - jQuery + Ajax
User Interface Development with jQuery
Remy Sharp The DOM scripting toolkit jQuery
Java scriptforjavadev part2a
Rohit&kunjan
What's this jQuery? Where it came from, and how it will drive innovation
A Rich Web experience with jQuery, Ajax and .NET
Modern JavaScript Talk
jQuery Features to Avoid
Learning How To Use Jquery #3
Ad

More from Amir Barylko (20)

PDF
Functional converter project
PDF
Elm: delightful web development
PDF
Dot Net Core
PDF
No estimates
PDF
User stories deep dive
PDF
Coderetreat hosting training
PDF
There's no charge for (functional) awesomeness
PDF
What's new in c# 6
PDF
Productive teams
PDF
Who killed object oriented design?
PDF
From coach to owner - What I learned from the other side
PDF
Communication is the Key to Teamwork and productivity
PDF
Acceptance Test Driven Development
PDF
Refactoring
PDF
Agile requirements
PDF
Agile teams and responsibilities
PDF
Refactoring
PDF
Sass & bootstrap
PDF
Agile requirements
PDF
Cpl12 continuous integration
Functional converter project
Elm: delightful web development
Dot Net Core
No estimates
User stories deep dive
Coderetreat hosting training
There's no charge for (functional) awesomeness
What's new in c# 6
Productive teams
Who killed object oriented design?
From coach to owner - What I learned from the other side
Communication is the Key to Teamwork and productivity
Acceptance Test Driven Development
Refactoring
Agile requirements
Agile teams and responsibilities
Refactoring
Sass & bootstrap
Agile requirements
Cpl12 continuous integration

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars

Awesome html with ujs, jQuery and coffeescript

  • 1. AMIR BARYLKO AWESOME HTML5 WITH UJS, JQUERY & COFFEESCRIPT
  • 2. ABOUT ME • Architect • Developer • Mentor • Great cook • Software Quality Expert at mavenTHOUGHT Inc.
  • 3. CONTACT INFO • Email: amir@barylko.com • Twitter: @abarylko • Slides: http://orthocoders.com/presentations.html • Company: http://maventhought.com
  • 5. SEMANTIC HTML • Communication is key • Being expressive • Show intent • Cleaner
  • 6. STRUCTURE WITH MEANING • Section • Nav • Header • Article • Footer • Aside
  • 7. ARE YOU SURE? • Which comes first, the section or the article? • I have a section with multiple articles... • Or is it an article with multiple sections? • What should I do?
  • 8. IS IT COMPATIBLE? • Well.... (not for IE) • Modernizr will fix it for you! • And generate the code to let those tags behave as blocks, etc....
  • 9. DATA ATTRIBUTES • Add custom values to tags • The attribute has to start with data-* • The value could be any string, for example: <span data-id='309' data-title='someTitle' data-time='10:00:30'> ...
  • 10. USAGES • Store information related to your model or view model • Common usages like confirmation with data- confirm
  • 12. WHAT IS IT? • Javascript library/framework to provide easy access • to operations that manipulate the DOM • to interact with the contents of the page • to a repository of plugins for common functionality • much more....
  • 13. QUERYING WITH CSS SELECTOR • Elements in the page can be selected using css selection syntax • $('#movies') • $('#movies a.movie') • $('#movies > li')
  • 14. MANIPULATE DOM • Modify the element classes • $('.movie').addClass('new-release') • $('.movie').toggleClass('selected') • Add elements or remove elements • $('.movie').append(....)
  • 15. EVENTS • Bind functions/handlers to events • $(document).ready(function() { ... }); • $('#movies').on('click', function(e) { .... })
  • 17. WIKIPEDIA SAYS Unobtrusive JavaScript is a general approach to the use of JavaScript in web pages. Though the term is not formally defined, its basic principles are generally understood to include: ■ Separation of functionality (the "behavior layer") from a Web page's structure/content and presentation[1] ■ Best practices to avoid the problems of traditional JavaScript programming (such as browser inconsistencies and lack ofscalability) ■ Progressive enhancement to support user agents that may not support advanced JavaScript functionality
  • 18. VS CONFIG <appSettings> <add key="webpages:Version" value="1.0.0.0" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings>
  • 19. CLIENT SIDE VALIDATION @Html.Script("jquery.validate.min.js") @Html.Script("jquery.validate.unobtrusive.min.js")
  • 20. MODEL ATTRIBUTES • System.ComponentModel.DataAnnotations • Helpers will generate extra code • jQuery adds the functionality out of the box!
  • 21. GIVEN THE MODEL public interface IMovie { [Required] string Title { get; } DateTime ReleaseDate { get; set; } }
  • 22. ACTUAL HTML <label for="Title">Title</label> <input id="Title" class="text-box single-line input-validation-error" type="text" value="" name="Title" data-val-required="The Title field is required." data-val="true"> ...
  • 23. WHY UNOBTRUSIVE? • Stay out of the way! • Separate behavior from markup • Use a different file for the Javascript code • Use jQuery to handle events, etc...
  • 24. NO MORE HANDLERS INLINE • Instead of <a class="btn" href="#" onclick="addMovie()"> • Use jQuery to bind the event <a class="btn" href="#" id="add-movie"> $('#add-movie').on('click', addMovie);
  • 26. ANOTHER ENERGY DRINK? • From coffeescript.org: • CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. • The website has a great tutorial showing side by side comparison with Javascript
  • 27. STRING INTERPOLATION • You can concatenate inside a double quote string using the “#” and “{ }” • "The result is #{3}" == "The result is 3" • Or use any expression • "/movies/#{id}"
  • 28. FUNCTIONS • The arrow/lambda is used to define functions • square = (x) -> x * x • Parenthesis are optional when passing parameters • storageDelete movieId, true
  • 29. FUNCTIONS II • Return implicit (the last expression is the return value) •Multiple lines, indentation is important deleteMovie = (e) -> movieId = $(e.target).... storageDelete(movieId)
  • 30. OBJECTS • Objects are declared using indentation config = local: user: 'dev' pwd: 'dev123' remote: user: 'superdev' pwd: "impossibleToGuess"
  • 31. MAPS & ARRAYS • Arrays are declared with “[ ]” • deploy = ['local', 'remote', 'uat'] • And maps using “{ }” • testing = {v1: true, v2: false, v3: true}
  • 32. CONDITIONALS • Classic if does not need parenthesis or brackets if isJson callIndex() display() else dont() • Or use unless for the negated form
  • 33. CONDITIONALS POSTFIX • The conditionals can be use as modifiers • callIndex() if isJson • exit() unless validated and inContext
  • 34. LIST COMPREHENSION • Iterate and call a function over each element • deploy env for env in ['local', 'uat', 'prod'] • Or filter over a collection • allSelected = (n for n in nodes when n.selected)
  • 35. CLASSES class MovieRepository newMovie: -> $.ajax url: someUrl success: (data) -> $(id).append data
  • 36. TESTING • Is just Javascript • so use Jasmine • or Qunit • any other....
  • 37. DEBUGGING • Same variable names • Just set a breakpoint in the code • and add watches, etc....
  • 38. CONTACT INFO • Email: amir@barylko.com • Twitter: @abarylko • Slides: http://orthocoders.com/presentations.html • Company: http://maventhought.com