SlideShare una empresa de Scribd logo
1 de 104
NinjaScript
JavaScript so unobtrusive, you’ll never see it coming.




              Mizugumo
Make your Rails app walk on water with NinjaScript.
Evan Dorn
CEO and Lead Developer,
 Logical Reality Design
Credits
NinjaScript was invented and (almost) entirely
                  coded by

           Judson Lester
 Co-owner and Senior Developer
NinjaScript
GOAL 1:
Completely
Unobtrusive
No
<HTML>
 Markup
Required
GOAL 2:
Graceful Degradation
JavaScript
enriches
a fully functional
     website
Your site should
 work without
  JavaScript!
Why do I care?
•   Spiders & Automation
• Accessibility: screen
 readers
•   NoScript users
Graceful degradation
         is a
    ROYAL
     PAIN
(Unless you use
  NinjaScript)
GOAL 3:
Persistent Behavior
CSS: is_awesome

$(JavaScript){ SUCKS }
JS should be like CSS

•CSS styles always apply
• Even if the DOM changes
• Why aren’t JS behaviors the same?
DOM Reconstruction and
   Event Bindings
DOM Reconstruction and
   Event Bindings

                         div#content




             a.has_tooltip        a.has_tooltip
DOM Reconstruction and
     Event Bindings

• Bind a tooltip behavior               div#content
  to $(‘.has_tooltip’)


                            a.has_tooltip        a.has_tooltip
DOM Reconstruction and
     Event Bindings

• Bind a tooltip behavior               div#content
  to $(‘.has_tooltip’)

• Dynamically add a
  new .tooltip element      a.has_tooltip        a.has_tooltip



                            a.has_tooltip
DOM Reconstruction and
     Event Bindings

• Bind a tooltip behavior               div#content
  to $(‘.has_tooltip’)

• Dynamically add a
  new .tooltip element      a.has_tooltip        a.has_tooltip


• New element has no
  bound event handler!      a.has_tooltip
DOM Reconstruction and
     Event Bindings

• Bind a tooltip behavior               div#content
  to $(‘.has_tooltip’)

• Dynamically add a
  new .tooltip element      a.has_tooltip        a.has_tooltip


• New element has no
  bound event handler!      a.has_tooltip


• This is really lame ...
What we want
What we want

•   Specify JS behaviors via CSS
    selectors
What we want

•   Specify JS behaviors via CSS
    selectors
•   Behaviors should always apply
What we want

•   Specify JS behaviors via CSS
    selectors
•   Behaviors should always apply
• Easy for the developer
Solution 1:
Event Delegation
Solution 1:
        Event Delegation

• jQuery live() and similar
Solution 1:
       Event Delegation

• jQuery live() and similar
• Bind handlers to root element of the
 DOM
Solution 1:
       Event Delegation

• jQuery live() and similar
• Bind handlers to root element of the
 DOM
• Since browsers bubble unhandled events
 up the DOM, the root handles all events
Solution 1:
       Event Delegation

• jQuery live() and similar
• Bind handlers to root element of the
 DOM
• Since browsers bubble unhandled events
 up the DOM, the root handles all events
 This is pretty awesome.
The Problem with
Event Delegation
The Problem with
       Event Delegation
• live() can’t handle element transformations
The Problem with
       Event Delegation
• live() can’t handle element transformations
• ... like giving <div>s rounded corners ...
The Problem with
       Event Delegation
• live() can’t handle element transformations
• ... like giving <div>s rounded corners ...
• Because there’s no event to process when
 we insert new elements into the DOM
The Problem with
       Event Delegation
• live() can’t handle element transformations
• ... like giving <div>s rounded corners ...
• Because there’s no event to process when
  we insert new elements into the DOM
• DOM Level 2-compliant browsers are suppossed
  to send DOMSubtreeModified and
  DOMNodeInserted
The Problem with
       Event Delegation
• live() can’t handle element transformations
• ... like giving <div>s rounded corners ...
• Because there’s no event to process when
  we insert new elements into the DOM
• DOM Level 2-compliant browsers are suppossed
  to send DOMSubtreeModified and
  DOMNodeInserted
               ... bad IE. No Biscuit!
Solution 1I:
Automatic Rebinding
Solution 1I:
     Automatic Rebinding
• Bind to and/or transform the element,
 not the root.
Solution 1I:
     Automatic Rebinding
• Bind to and/or transform the element,
 not the root.
• NinjaScript examines new DOM
 elements to see if any known behaviors
 match.
Solution 1I:
     Automatic Rebinding
• Bind to and/or transform the element,
 not the root.
• NinjaScript examines new DOM
 elements to see if any known behaviors
 match.
• NinjaScript fires its own event when the
 DOM is reconstructed so it works in IE.
So how do I use it?
NinjaScript
“Behavior Sheet”
NinjaScript
       “Behavior Sheet”
Ninja.behavior({
  'form#product':      submitsAsAjax,

 ‘a.delete_product’:   submitsAsAjax,

 ‘#login_form input’: isWatermarked,

 ‘flash.error’:        decays,

 ‘li.has_tooltip’:     showsTooltip
})
Defining a Behavior
Ninja.behavior({
  '.awesome': {
   transform:   function(elem){... add to the DOM ...},

     events: {
       click:     function(event){... handle click ...},
       mouseover: function(event){... pop tooltip ...}
     }
 }
})


 All awesome elements will get the transform
    applied, no matter when they’re added.
Defining a Behavior
Shortcut: skip the ‘events:’ mapping if you’re
just handling an event.

Ninja.behavior({
   '.awesome': {
     click: function(event){ ... handle click ...},
 }
})
Reusable Behaviors
You can easily define and name behaviors for
reuse.
Reusable Behaviors
You can easily define and name behaviors for
reuse. singsAndDances(){
function
    return new ninja.does({
      transform: function(elem) { elem.addATutu() },
      click:     function(event)
      { this.element.pirouette() },
      mouseover: function(event)
      { this.element.singAnAria()}
     })
}
Reusable Behaviors
You can easily define and name behaviors for
reuse. singsAndDances(){
function
 return new ninja.does({
   transform: function(elem) { elem.addATutu() },
   click:     function(event)
   { this.element.pirouette() },
   mouseover: function(event)
   { this.element.singAnAria()}
  })
}
Ninja.behavior({
   ‘#dhh’:         Ninja.singsAndDances(),
   ‘#katz’:        Ninja.singsAndDances(),
  ‘.code_monkey’: Ninja.singsAndDances()
})
Pre-Defined Behaviors
These work today - built into NinjaScript


• submitsAsAjax    (for forms or links)
• becomesLink      (for forms)
• decays           (fades away after 10
 sec)
• isWatermarked    (for form inputs)
Planned Behaviors
            Coming Sometime!

• popsTooltip        • getsRoundCorners
• validatesLocal     • getsDropShadow
• validatesViaAjax   • replacedByImage
• autocompletes      • isSortable
• hasAjaxObserver    • isSortableViaAjax
• editableViaAjax
CAVEAT!
CAVEAT!
 NinjaScript 0.8.x depends on
         jQuery-1.4.2


DOES NOT SUPPORT
 jQuery-1.4.4 or jQuery-1.5
CAVEAT!
 NinjaScript 0.8.x depends on
         jQuery-1.4.2


DOES NOT SUPPORT
 jQuery-1.4.4 or jQuery-1.5
      (... fix is coming)
Future Plans for
  NinjaScript
Future Plans for
       NinjaScript
• Lots more prepackaged behaviors
Future Plans for
       NinjaScript
• Lots more prepackaged behaviors
• Decouple from jQuery - build NinjaScript
 behaviors in any framework
Future Plans for
       NinjaScript
• Lots more prepackaged behaviors
• Decouple from jQuery - build NinjaScript
 behaviors in any framework
• Handle JSON returns from AJAX calls,
 not just eval()
The internals are
 “complicated”.
The internals are
  “complicated”.
But Judson is a ninja
      rockstar,
The internals are
  “complicated”.
But Judson is a ninja
      rockstar,
     4th dan.
Mizugumo
Let your Rails app walk on water with
              NinjaScript
gem install mizugumo
rails generate
mizugumo:install
A Mizugumo app is:
A Mizugumo app is:

•   AJAX by default
A Mizugumo app is:

•AJAX by default
• Degrades gracefully by default
A Mizugumo app is:

•AJAX by default
• Degrades gracefully by default
• No extra work!
The Rails 3
 RESTfail
The Rails 3 RESTfail
The Rails 3 RESTfail
• Simulate PUT and DELETE methods!
The Rails 3 RESTfail
• Simulate PUT and DELETE methods!
• link_to(:method => ‘delete’)
The Rails 3 RESTfail
• Simulate PUT and DELETE methods!
• link_to(:method => ‘delete’)
• <a href=’/product/1’ data-
 method=‘delete‘>
The Rails 3 RESTfail
• Simulate PUT and DELETE methods!
• link_to(:method => ‘delete’)
• <a href=’/product/1’ data-
  method=‘delete‘>
• Without JS, it’s a show link!
The Rails 3 RESTfail
• Simulate PUT and DELETE methods!
• link_to(:method => ‘delete’)
• <a href=’/product/1’ data-
  method=‘delete‘>
• Without JS, it’s a show link!
• ... oops!
The Mizugumo Way
The Mizugumo Way
link_to with :method => ‘delete’

<%= link_to ‘click me’, ‘/foo’, :method => :delete %>
The Mizugumo Way
link_to with :method => ‘delete’

<%= link_to ‘click me’, ‘/foo’, :method => :delete %>


Generates a <form>!
<form action=’/foo’ method=‘post’
 class=‘mizugumo_graceful_form’>
 <input type=‘hidden’ name=‘_method’ value=‘delete’>
  <input type=‘submit’ value=’click me’>
</a>
The Mizugumo Way
But a default NinjaScript behavior:
Ninja.behavior({
   ‘.mizugumo_graceful_form’:   becomesLink
})
The Mizugumo Way
But a default NinjaScript behavior:
Ninja.behavior({
   ‘.mizugumo_graceful_form’:   becomesLink
})


Converts it back!
<a href=’/foo’>click me</a>
The Result
The Result
•   JavaScript users see a link
The Result
•JavaScript users see a link
• Non-JS users see a button
The Result
•JavaScript users see a link
• Non-JS users see a button
• DELETE action works for both
The Result
•JavaScript users see a link
• Non-JS users see a button
• DELETE action works for both
The Result
•JavaScript users see a link
• Non-JS users see a button
• DELETE action works for both

• ...Rails developer does nothing!
What about AJAX?
No need for markup:
No need for markup:
Not this.
<%= form_for(@product, :remote => true) do %>
No need for markup:
Not this.
<%= form_for(@product, :remote => true) do %>




Just this:
<%= form_for(@product) do %>
Use NinjaScript!

Ninja.behavior({
   ‘#my_form’: submitsAsAjax
})
Ninja.submitsAsAjax
Ninja.submitsAsAjax

• Same Data
• Same URL
• Same Method
• Just write a format.js block in your
  controller, and a js.erb view.
The Mizugumo
scaffold does this for
         you.
(demo)
Future Plans for
   Mizugumo
Future Plans for
         Mizugumo
•   Replace rails.js
Future Plans for
      Mizugumo
•Replace rails.js
• Improve generators
Future Plans for
      Mizugumo
•Replace rails.js
• Improve generators
• Degradable :confirm
Future Plans for
       Mizugumo
•Replace rails.js
• Improve generators
• Degradable :confirm
• Automatic JS validations!
Please Contribute!
http://bit.ly/hFzoAG
NinjaScript and Mizugumo 2011-02-05

Más contenido relacionado

La actualidad más candente

Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...Edureka!
 
Introduction.to.j query
Introduction.to.j queryIntroduction.to.j query
Introduction.to.j queryHunter Wu
 
JQUERY TUTORIALS
JQUERY TUTORIALSJQUERY TUTORIALS
JQUERY TUTORIALSMoize Roxas
 
Mvc - Model: the great forgotten
Mvc - Model: the great forgottenMvc - Model: the great forgotten
Mvc - Model: the great forgottenDavid Rodenas
 
Jquery at-webcamp
Jquery at-webcampJquery at-webcamp
Jquery at-webcampgaplabs
 
GDG presentation hollywood action bar (Leonardo,vingle.inc)
GDG presentation hollywood action bar (Leonardo,vingle.inc)GDG presentation hollywood action bar (Leonardo,vingle.inc)
GDG presentation hollywood action bar (Leonardo,vingle.inc)Leonardo Taehwan Kim
 
Knockout mvvm-m6-slides
Knockout mvvm-m6-slidesKnockout mvvm-m6-slides
Knockout mvvm-m6-slidesMasterCode.vn
 
WordCamp US: ARIA. Roles, States and Properties
WordCamp US: ARIA. Roles, States and PropertiesWordCamp US: ARIA. Roles, States and Properties
WordCamp US: ARIA. Roles, States and PropertiesJoseph Dolson
 
Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2thgreasi
 
Javascript REST with Jester
Javascript REST with JesterJavascript REST with Jester
Javascript REST with JesterMike Bailey
 
jQuery basics for Beginners
jQuery basics for BeginnersjQuery basics for Beginners
jQuery basics for BeginnersPooja Saxena
 
From polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchFrom polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchSergi González Pérez
 

La actualidad más candente (18)

Advanced Silverlight
Advanced SilverlightAdvanced Silverlight
Advanced Silverlight
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Embedded d2w
Embedded d2wEmbedded d2w
Embedded d2w
 
J Query Presentation of David
J Query Presentation of DavidJ Query Presentation of David
J Query Presentation of David
 
Introduction.to.j query
Introduction.to.j queryIntroduction.to.j query
Introduction.to.j query
 
JQUERY TUTORIALS
JQUERY TUTORIALSJQUERY TUTORIALS
JQUERY TUTORIALS
 
Mvc - Model: the great forgotten
Mvc - Model: the great forgottenMvc - Model: the great forgotten
Mvc - Model: the great forgotten
 
jQuery
jQueryjQuery
jQuery
 
Jquery at-webcamp
Jquery at-webcampJquery at-webcamp
Jquery at-webcamp
 
GDG presentation hollywood action bar (Leonardo,vingle.inc)
GDG presentation hollywood action bar (Leonardo,vingle.inc)GDG presentation hollywood action bar (Leonardo,vingle.inc)
GDG presentation hollywood action bar (Leonardo,vingle.inc)
 
Attribute
AttributeAttribute
Attribute
 
Knockout mvvm-m6-slides
Knockout mvvm-m6-slidesKnockout mvvm-m6-slides
Knockout mvvm-m6-slides
 
WordCamp US: ARIA. Roles, States and Properties
WordCamp US: ARIA. Roles, States and PropertiesWordCamp US: ARIA. Roles, States and Properties
WordCamp US: ARIA. Roles, States and Properties
 
Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2Migrating UI-Sortable to Angular 2
Migrating UI-Sortable to Angular 2
 
Javascript REST with Jester
Javascript REST with JesterJavascript REST with Jester
Javascript REST with Jester
 
jQuery basics for Beginners
jQuery basics for BeginnersjQuery basics for Beginners
jQuery basics for Beginners
 
From polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratchFrom polling to real time: Scala, Akka, and Websockets from scratch
From polling to real time: Scala, Akka, and Websockets from scratch
 

Destacado

Will the computer world collapse in 2038?
Will the computer world collapse in 2038?Will the computer world collapse in 2038?
Will the computer world collapse in 2038?Joris Berthelot
 
Junction Creative Solutions
Junction Creative SolutionsJunction Creative Solutions
Junction Creative SolutionsConner Galway
 
jQuery and AJAX with Rails
jQuery and AJAX with RailsjQuery and AJAX with Rails
jQuery and AJAX with RailsAlan Hecht
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

Destacado (10)

Will the computer world collapse in 2038?
Will the computer world collapse in 2038?Will the computer world collapse in 2038?
Will the computer world collapse in 2038?
 
Y2 k38.
Y2 k38.Y2 k38.
Y2 k38.
 
Y2k38
Y2k38Y2k38
Y2k38
 
Genetic Risk assesment
Genetic Risk assesmentGenetic Risk assesment
Genetic Risk assesment
 
Junction Creative Solutions
Junction Creative SolutionsJunction Creative Solutions
Junction Creative Solutions
 
jQuery and AJAX with Rails
jQuery and AJAX with RailsjQuery and AJAX with Rails
jQuery and AJAX with Rails
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar a NinjaScript and Mizugumo 2011-02-05

Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationSean Burgess
 
Flexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldFlexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldFITC
 
Flexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldFlexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldKevin Ball
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
 
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Thinkful
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jqueryKostas Mavridis
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIMarcin Grzywaczewski
 
Nestoria new design
Nestoria new designNestoria new design
Nestoria new designlokku
 
J query introduction
J query introductionJ query introduction
J query introductionSMS_VietNam
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application danceNicholas Valbusa
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuerycolinbdclark
 
angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01Teo E
 

Similar a NinjaScript and Mizugumo 2011-02-05 (20)

Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
Flexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldFlexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework World
 
Flexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldFlexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework World
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UI
 
jQuery besic
jQuery besicjQuery besic
jQuery besic
 
Nestoria new design
Nestoria new designNestoria new design
Nestoria new design
 
Jquery
JqueryJquery
Jquery
 
Jquery
JqueryJquery
Jquery
 
J query introduction
J query introductionJ query introduction
J query introduction
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application dance
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01angularjsmeetup-150303044616-conversion-gate01
angularjsmeetup-150303044616-conversion-gate01
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetup
 
Jquery
JqueryJquery
Jquery
 
Jquery
JqueryJquery
Jquery
 

Último

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

NinjaScript and Mizugumo 2011-02-05

  • 1. NinjaScript JavaScript so unobtrusive, you’ll never see it coming. Mizugumo Make your Rails app walk on water with NinjaScript.
  • 2. Evan Dorn CEO and Lead Developer, Logical Reality Design
  • 3. Credits NinjaScript was invented and (almost) entirely coded by Judson Lester Co-owner and Senior Developer
  • 9. Your site should work without JavaScript!
  • 10. Why do I care? • Spiders & Automation • Accessibility: screen readers • NoScript users
  • 11. Graceful degradation is a ROYAL PAIN
  • 12. (Unless you use NinjaScript)
  • 15. JS should be like CSS •CSS styles always apply • Even if the DOM changes • Why aren’t JS behaviors the same?
  • 16. DOM Reconstruction and Event Bindings
  • 17. DOM Reconstruction and Event Bindings div#content a.has_tooltip a.has_tooltip
  • 18. DOM Reconstruction and Event Bindings • Bind a tooltip behavior div#content to $(‘.has_tooltip’) a.has_tooltip a.has_tooltip
  • 19. DOM Reconstruction and Event Bindings • Bind a tooltip behavior div#content to $(‘.has_tooltip’) • Dynamically add a new .tooltip element a.has_tooltip a.has_tooltip a.has_tooltip
  • 20. DOM Reconstruction and Event Bindings • Bind a tooltip behavior div#content to $(‘.has_tooltip’) • Dynamically add a new .tooltip element a.has_tooltip a.has_tooltip • New element has no bound event handler! a.has_tooltip
  • 21. DOM Reconstruction and Event Bindings • Bind a tooltip behavior div#content to $(‘.has_tooltip’) • Dynamically add a new .tooltip element a.has_tooltip a.has_tooltip • New element has no bound event handler! a.has_tooltip • This is really lame ...
  • 23. What we want • Specify JS behaviors via CSS selectors
  • 24. What we want • Specify JS behaviors via CSS selectors • Behaviors should always apply
  • 25. What we want • Specify JS behaviors via CSS selectors • Behaviors should always apply • Easy for the developer
  • 27. Solution 1: Event Delegation • jQuery live() and similar
  • 28. Solution 1: Event Delegation • jQuery live() and similar • Bind handlers to root element of the DOM
  • 29. Solution 1: Event Delegation • jQuery live() and similar • Bind handlers to root element of the DOM • Since browsers bubble unhandled events up the DOM, the root handles all events
  • 30. Solution 1: Event Delegation • jQuery live() and similar • Bind handlers to root element of the DOM • Since browsers bubble unhandled events up the DOM, the root handles all events This is pretty awesome.
  • 32. The Problem with Event Delegation • live() can’t handle element transformations
  • 33. The Problem with Event Delegation • live() can’t handle element transformations • ... like giving <div>s rounded corners ...
  • 34. The Problem with Event Delegation • live() can’t handle element transformations • ... like giving <div>s rounded corners ... • Because there’s no event to process when we insert new elements into the DOM
  • 35. The Problem with Event Delegation • live() can’t handle element transformations • ... like giving <div>s rounded corners ... • Because there’s no event to process when we insert new elements into the DOM • DOM Level 2-compliant browsers are suppossed to send DOMSubtreeModified and DOMNodeInserted
  • 36. The Problem with Event Delegation • live() can’t handle element transformations • ... like giving <div>s rounded corners ... • Because there’s no event to process when we insert new elements into the DOM • DOM Level 2-compliant browsers are suppossed to send DOMSubtreeModified and DOMNodeInserted ... bad IE. No Biscuit!
  • 38. Solution 1I: Automatic Rebinding • Bind to and/or transform the element, not the root.
  • 39. Solution 1I: Automatic Rebinding • Bind to and/or transform the element, not the root. • NinjaScript examines new DOM elements to see if any known behaviors match.
  • 40. Solution 1I: Automatic Rebinding • Bind to and/or transform the element, not the root. • NinjaScript examines new DOM elements to see if any known behaviors match. • NinjaScript fires its own event when the DOM is reconstructed so it works in IE.
  • 41. So how do I use it?
  • 43. NinjaScript “Behavior Sheet” Ninja.behavior({ 'form#product': submitsAsAjax, ‘a.delete_product’: submitsAsAjax, ‘#login_form input’: isWatermarked, ‘flash.error’: decays, ‘li.has_tooltip’: showsTooltip })
  • 44. Defining a Behavior Ninja.behavior({ '.awesome': { transform: function(elem){... add to the DOM ...}, events: { click: function(event){... handle click ...}, mouseover: function(event){... pop tooltip ...} } } }) All awesome elements will get the transform applied, no matter when they’re added.
  • 45. Defining a Behavior Shortcut: skip the ‘events:’ mapping if you’re just handling an event. Ninja.behavior({ '.awesome': { click: function(event){ ... handle click ...}, } })
  • 46. Reusable Behaviors You can easily define and name behaviors for reuse.
  • 47. Reusable Behaviors You can easily define and name behaviors for reuse. singsAndDances(){ function return new ninja.does({ transform: function(elem) { elem.addATutu() }, click: function(event) { this.element.pirouette() }, mouseover: function(event) { this.element.singAnAria()} }) }
  • 48. Reusable Behaviors You can easily define and name behaviors for reuse. singsAndDances(){ function return new ninja.does({ transform: function(elem) { elem.addATutu() }, click: function(event) { this.element.pirouette() }, mouseover: function(event) { this.element.singAnAria()} }) } Ninja.behavior({ ‘#dhh’: Ninja.singsAndDances(), ‘#katz’: Ninja.singsAndDances(), ‘.code_monkey’: Ninja.singsAndDances() })
  • 49. Pre-Defined Behaviors These work today - built into NinjaScript • submitsAsAjax (for forms or links) • becomesLink (for forms) • decays (fades away after 10 sec) • isWatermarked (for form inputs)
  • 50. Planned Behaviors Coming Sometime! • popsTooltip • getsRoundCorners • validatesLocal • getsDropShadow • validatesViaAjax • replacedByImage • autocompletes • isSortable • hasAjaxObserver • isSortableViaAjax • editableViaAjax
  • 52. CAVEAT! NinjaScript 0.8.x depends on jQuery-1.4.2 DOES NOT SUPPORT jQuery-1.4.4 or jQuery-1.5
  • 53. CAVEAT! NinjaScript 0.8.x depends on jQuery-1.4.2 DOES NOT SUPPORT jQuery-1.4.4 or jQuery-1.5 (... fix is coming)
  • 54. Future Plans for NinjaScript
  • 55. Future Plans for NinjaScript • Lots more prepackaged behaviors
  • 56. Future Plans for NinjaScript • Lots more prepackaged behaviors • Decouple from jQuery - build NinjaScript behaviors in any framework
  • 57. Future Plans for NinjaScript • Lots more prepackaged behaviors • Decouple from jQuery - build NinjaScript behaviors in any framework • Handle JSON returns from AJAX calls, not just eval()
  • 58. The internals are “complicated”.
  • 59. The internals are “complicated”. But Judson is a ninja rockstar,
  • 60. The internals are “complicated”. But Judson is a ninja rockstar, 4th dan.
  • 61. Mizugumo Let your Rails app walk on water with NinjaScript
  • 65. A Mizugumo app is: • AJAX by default
  • 66. A Mizugumo app is: •AJAX by default • Degrades gracefully by default
  • 67. A Mizugumo app is: •AJAX by default • Degrades gracefully by default • No extra work!
  • 68. The Rails 3 RESTfail
  • 69. The Rails 3 RESTfail
  • 70. The Rails 3 RESTfail • Simulate PUT and DELETE methods!
  • 71. The Rails 3 RESTfail • Simulate PUT and DELETE methods! • link_to(:method => ‘delete’)
  • 72. The Rails 3 RESTfail • Simulate PUT and DELETE methods! • link_to(:method => ‘delete’) • <a href=’/product/1’ data- method=‘delete‘>
  • 73. The Rails 3 RESTfail • Simulate PUT and DELETE methods! • link_to(:method => ‘delete’) • <a href=’/product/1’ data- method=‘delete‘> • Without JS, it’s a show link!
  • 74. The Rails 3 RESTfail • Simulate PUT and DELETE methods! • link_to(:method => ‘delete’) • <a href=’/product/1’ data- method=‘delete‘> • Without JS, it’s a show link! • ... oops!
  • 76. The Mizugumo Way link_to with :method => ‘delete’ <%= link_to ‘click me’, ‘/foo’, :method => :delete %>
  • 77. The Mizugumo Way link_to with :method => ‘delete’ <%= link_to ‘click me’, ‘/foo’, :method => :delete %> Generates a <form>! <form action=’/foo’ method=‘post’ class=‘mizugumo_graceful_form’> <input type=‘hidden’ name=‘_method’ value=‘delete’> <input type=‘submit’ value=’click me’> </a>
  • 78.
  • 79. The Mizugumo Way But a default NinjaScript behavior: Ninja.behavior({ ‘.mizugumo_graceful_form’: becomesLink })
  • 80. The Mizugumo Way But a default NinjaScript behavior: Ninja.behavior({ ‘.mizugumo_graceful_form’: becomesLink }) Converts it back! <a href=’/foo’>click me</a>
  • 82. The Result • JavaScript users see a link
  • 83. The Result •JavaScript users see a link • Non-JS users see a button
  • 84. The Result •JavaScript users see a link • Non-JS users see a button • DELETE action works for both
  • 85. The Result •JavaScript users see a link • Non-JS users see a button • DELETE action works for both
  • 86. The Result •JavaScript users see a link • Non-JS users see a button • DELETE action works for both • ...Rails developer does nothing!
  • 88.
  • 89. No need for markup:
  • 90. No need for markup: Not this. <%= form_for(@product, :remote => true) do %>
  • 91. No need for markup: Not this. <%= form_for(@product, :remote => true) do %> Just this: <%= form_for(@product) do %>
  • 92. Use NinjaScript! Ninja.behavior({ ‘#my_form’: submitsAsAjax })
  • 94. Ninja.submitsAsAjax • Same Data • Same URL • Same Method • Just write a format.js block in your controller, and a js.erb view.
  • 95. The Mizugumo scaffold does this for you.
  • 97. Future Plans for Mizugumo
  • 98. Future Plans for Mizugumo • Replace rails.js
  • 99. Future Plans for Mizugumo •Replace rails.js • Improve generators
  • 100. Future Plans for Mizugumo •Replace rails.js • Improve generators • Degradable :confirm
  • 101. Future Plans for Mizugumo •Replace rails.js • Improve generators • Degradable :confirm • Automatic JS validations!

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n