SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
JavaScript
What can I use it for?
• Add/remove/modify content
• Set CSS styles, add/remove classes
• Show/hide/animate parts of the page
• React to events (clicks, typing, etc.)
• And much, much more!
Basic Concept -
Comments
// this line doesn't do anything!
/* These series of lines
is a bit longer but it
also doesn't do anything! */
$('a').hide(); // hide 'a'
$('a').hide(); // hide all links
$('a').hide(); // hide links while we validate them
Basic Concept -
Variables
var classes = 'products rocks monkeys';
var num = 2;
classes = classes + ' another';
// now: products rocks monkeys another
num = num * 2;
// now: 4
Basic Concept -
Functions
// assigning a function to a variable
// so we can call it several times
var test = function(message, count) {
count = count * 2;
console.log(message, count);
};
test('hello!', 1);
test('hello again!', 2);
// using a function to delay work
$(document).ready(
function() {
alert('document is ready!');
}
);
Basic Concept - Scope
var test = function(message, count) {
poorForm = 'probably a mistake';
var test = 1;
console.log(message, count, test, poorForm);
};
test('hello!', 1);
Basic Concept - jQuery
// locate zero or more things on the page:
$('css selector');
// do something with them
$('css selector').method();
e.g.
$('a') // gets all links
$('a.prods') // gets all links with prods class
$('a').hide(); // hide all links
$('a.prods').hide(); // hide links with prods class
$('a.misses').hide(); // no matches? no worries!
Getting setup to run JS
• Include jQuery on the page
<script src="http://ajax.googleapis.com/ajax/libs/
jquery/1.9.0/jquery.min.js" type="text/javascript"></
script>
Getting setup to run JS
• Add a script block to your page
<script type="text/javascript">
$(document).ready(function() {
/* my fancy JS code goes here! */
});
</script>
Simple JS Example
• Lets turn all links on the page green
<script type="text/javascript">
$(document).ready(function() {
$('a').css('color', 'green');
});
</script>
Interactive JS Example
• Lets hide links when they are clicked
<script type="text/javascript">
$(document).ready(function() {
$('a').css('color', 'green');
$('a').click(function() {
$(this).fadeOut();
return false;
});
});
</script>
Do I need to use
jQuery?
• No! But a JavaScript framework sure helps.
• Cross-Browser Issues
• More compact code
Example Fade Out
• Plain JS
<script type="text/javascript">
document.addEventListener(
'DOMContentLoaded',
function(){
var s = document.getElementById('thing').style;
s.opacity = 1;
var fade = function(){
s.opacity = s.opacity - 0.1;
if (s.opacity < 0) {
s.display = "none";
} else {
setTimeout(fade, 40);
}
};
fade();
}
);
</script>
Example Fade Out
• jQuery
<script src="http://ajax.googleapis.com/ajax/libs/
jquery/1.9.0/jquery.min.js" type="text/javascript"></
script>
<script type="text/javascript">
$(document).ready(function() {
$('#thing').fadeOut();
});
</script>
Further Reading &
Plugins
• AJAX/JSON
• WebRTC
• Offline Storage
• Phonegap
• http://www.unheap.com/
• http://jqueryui.com/

Mais conteúdo relacionado

Mais procurados

Javascript
JavascriptJavascript
Javascript
timsplin
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
Gonzalo Parra
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 
jQuery presentation
jQuery presentationjQuery presentation
jQuery presentation
Mahesh Reddy
 

Mais procurados (20)

Yuihacku iitd-sumana
Yuihacku iitd-sumanaYuihacku iitd-sumana
Yuihacku iitd-sumana
 
webstudy jquery
webstudy jquerywebstudy jquery
webstudy jquery
 
OUTDATED (Encore)
OUTDATED (Encore)OUTDATED (Encore)
OUTDATED (Encore)
 
Front End Development - Beyond Javascript (Robin Cannon)
Front End Development - Beyond Javascript (Robin Cannon)Front End Development - Beyond Javascript (Robin Cannon)
Front End Development - Beyond Javascript (Robin Cannon)
 
Put a little Backbone in your WordPress
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
 
Casl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptxCasl. isomorphic permission management.pptx
Casl. isomorphic permission management.pptx
 
Owasp & php
Owasp & phpOwasp & php
Owasp & php
 
Intro to jquery
Intro to jqueryIntro to jquery
Intro to jquery
 
Javascript
JavascriptJavascript
Javascript
 
Jquery
JqueryJquery
Jquery
 
Jquery image slider
Jquery image slider Jquery image slider
Jquery image slider
 
Div id
Div idDiv id
Div id
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
 
Ember: Guts & Goals
Ember: Guts & GoalsEmber: Guts & Goals
Ember: Guts & Goals
 
Game jump: frontend introduction #1
Game jump: frontend introduction #1Game jump: frontend introduction #1
Game jump: frontend introduction #1
 
jQuery presentation
jQuery presentationjQuery presentation
jQuery presentation
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
 
Lightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with BrowserifyLightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with Browserify
 

Destaque

Methodes van plaagbestrijding
Methodes van plaagbestrijdingMethodes van plaagbestrijding
Methodes van plaagbestrijding
Yentl Loeckx
 
Visual Resume
Visual ResumeVisual Resume
Visual Resume
thaz202
 
Spenser's Visual Resume
Spenser's Visual ResumeSpenser's Visual Resume
Spenser's Visual Resume
SMWinters33
 
Methodes van plaagbestrijding
Methodes van plaagbestrijdingMethodes van plaagbestrijding
Methodes van plaagbestrijding
Yentl Loeckx
 
Railsbridge intro
Railsbridge introRailsbridge intro
Railsbridge intro
p4geoff
 
Visual Resume
Visual ResumeVisual Resume
Visual Resume
cepeak3
 

Destaque (17)

Methodes van plaagbestrijding
Methodes van plaagbestrijdingMethodes van plaagbestrijding
Methodes van plaagbestrijding
 
Develop Your CMS In Your CMS
Develop Your CMS In Your CMSDevelop Your CMS In Your CMS
Develop Your CMS In Your CMS
 
Richsmanroom
RichsmanroomRichsmanroom
Richsmanroom
 
Eenjarige 4 Tt
Eenjarige 4 TtEenjarige 4 Tt
Eenjarige 4 Tt
 
Visual Resume
Visual ResumeVisual Resume
Visual Resume
 
How to start a business
How to start a businessHow to start a business
How to start a business
 
04 sorting
04 sorting04 sorting
04 sorting
 
Spenser's Visual Resume
Spenser's Visual ResumeSpenser's Visual Resume
Spenser's Visual Resume
 
Rich’s man room
Rich’s man roomRich’s man room
Rich’s man room
 
Groene week
Groene weekGroene week
Groene week
 
Methodes van plaagbestrijding
Methodes van plaagbestrijdingMethodes van plaagbestrijding
Methodes van plaagbestrijding
 
Eenjarige 3 tt
Eenjarige 3 ttEenjarige 3 tt
Eenjarige 3 tt
 
Socialarc - Our Manifesto
Socialarc - Our ManifestoSocialarc - Our Manifesto
Socialarc - Our Manifesto
 
Groenten 3 tt
Groenten 3 ttGroenten 3 tt
Groenten 3 tt
 
Socialarc - Is Your Facebook Content Getting Lost In The Wild?
Socialarc - Is Your Facebook Content Getting Lost In The Wild?Socialarc - Is Your Facebook Content Getting Lost In The Wild?
Socialarc - Is Your Facebook Content Getting Lost In The Wild?
 
Railsbridge intro
Railsbridge introRailsbridge intro
Railsbridge intro
 
Visual Resume
Visual ResumeVisual Resume
Visual Resume
 

Semelhante a Railsbridge javascript

Jquery in-15-minutes1421
Jquery in-15-minutes1421Jquery in-15-minutes1421
Jquery in-15-minutes1421
palsingh26
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 

Semelhante a Railsbridge javascript (20)

Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Jquery in-15-minutes1421
Jquery in-15-minutes1421Jquery in-15-minutes1421
Jquery in-15-minutes1421
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Webpack
Webpack Webpack
Webpack
 
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScript
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 

Railsbridge javascript

  • 2. What can I use it for? • Add/remove/modify content • Set CSS styles, add/remove classes • Show/hide/animate parts of the page • React to events (clicks, typing, etc.) • And much, much more!
  • 3. Basic Concept - Comments // this line doesn't do anything! /* These series of lines is a bit longer but it also doesn't do anything! */ $('a').hide(); // hide 'a' $('a').hide(); // hide all links $('a').hide(); // hide links while we validate them
  • 4. Basic Concept - Variables var classes = 'products rocks monkeys'; var num = 2; classes = classes + ' another'; // now: products rocks monkeys another num = num * 2; // now: 4
  • 5. Basic Concept - Functions // assigning a function to a variable // so we can call it several times var test = function(message, count) { count = count * 2; console.log(message, count); }; test('hello!', 1); test('hello again!', 2); // using a function to delay work $(document).ready( function() { alert('document is ready!'); } );
  • 6. Basic Concept - Scope var test = function(message, count) { poorForm = 'probably a mistake'; var test = 1; console.log(message, count, test, poorForm); }; test('hello!', 1);
  • 7. Basic Concept - jQuery // locate zero or more things on the page: $('css selector'); // do something with them $('css selector').method(); e.g. $('a') // gets all links $('a.prods') // gets all links with prods class $('a').hide(); // hide all links $('a.prods').hide(); // hide links with prods class $('a.misses').hide(); // no matches? no worries!
  • 8. Getting setup to run JS • Include jQuery on the page <script src="http://ajax.googleapis.com/ajax/libs/ jquery/1.9.0/jquery.min.js" type="text/javascript"></ script>
  • 9. Getting setup to run JS • Add a script block to your page <script type="text/javascript"> $(document).ready(function() { /* my fancy JS code goes here! */ }); </script>
  • 10. Simple JS Example • Lets turn all links on the page green <script type="text/javascript"> $(document).ready(function() { $('a').css('color', 'green'); }); </script>
  • 11. Interactive JS Example • Lets hide links when they are clicked <script type="text/javascript"> $(document).ready(function() { $('a').css('color', 'green'); $('a').click(function() { $(this).fadeOut(); return false; }); }); </script>
  • 12. Do I need to use jQuery? • No! But a JavaScript framework sure helps. • Cross-Browser Issues • More compact code
  • 13. Example Fade Out • Plain JS <script type="text/javascript"> document.addEventListener( 'DOMContentLoaded', function(){ var s = document.getElementById('thing').style; s.opacity = 1; var fade = function(){ s.opacity = s.opacity - 0.1; if (s.opacity < 0) { s.display = "none"; } else { setTimeout(fade, 40); } }; fade(); } ); </script>
  • 14. Example Fade Out • jQuery <script src="http://ajax.googleapis.com/ajax/libs/ jquery/1.9.0/jquery.min.js" type="text/javascript"></ script> <script type="text/javascript"> $(document).ready(function() { $('#thing').fadeOut(); }); </script>
  • 15. Further Reading & Plugins • AJAX/JSON • WebRTC • Offline Storage • Phonegap • http://www.unheap.com/ • http://jqueryui.com/