SlideShare a Scribd company logo
1 of 32
Download to read offline
JQuery [1]
 Matteo Magni
jQuery: The Write Less, Do More, JavaScript
                   Library
jQuery
Cos'è?
jQuery è una libreria di funzioni (framework)
javascript, cross-browser per le applicazioni
web, che si propone come obiettivo quello di
semplificare la programmazione lato client
delle pagine HTML. (wikipedia)
Cos'è:            Cosa fa:
• Framework       • Document
• Cross browser     traversing
                  • Event handling
                  • Animating
                  • Ajax interactions
Quindi?
Versioni

            http://jquery.com/
a)PRODUCTION (32KB, Minified and Gzipped)
b)DEVELOPMENT (252KB, Uncompressed Code)

                Differenze?
Production
Pesa solo 32 kb perché è minificata.
http://en.wikipedia.org/wiki/Minification_(programming)


“processo di rimozione di tutti i caratteri non necessari
dal codice sorgente, senza cambiarne la sua
funzionalità.”
Development
252 kb perché scritta in maniera leggibile al
programmatore.
Adatta per la fase di sviluppo, meno per la
produzione per via della banda che occupa.

Le funzionalità di tutte e due sono le stesse
Integrare jQuery
Per integrare jQuery nei nostri progetti basta
includere il file js come javascript esterno.

    <script src="jquery.js"></script>


A quel punto tutte le funzionalità di jQuery ci
saranno disponibili.
Content Delivery Network
E' possibile utilizzare jQuery anche da CDN.
• CDN:Content Delivery Network
  Rete per la consegna di contenuti, cioè
  sistema distribuito di grande estensione
  che attraverso un alto numero di server, il
  quale consente di fornire contenuti agli
  utenti con maggior affidabilità.
CDN
 Vantaggi
 • Far risparmiare banda al
   proprio server
 • L'utente avendola già
   utilizzata protrebbe quindi
   averla già in cache nel
   browser
Google
https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
Microsoft
http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js
jQuery
http://code.jquery.com/jquery-1.8.2.min.js

<script 
src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
Release
Da CDN possiamo vedere che jQuery è
arrivato alla versione 1.8.2 e che quando le
chiamiamo la libreria in quel modo
dobbiamo ricordaci quale vogliamo.
Come usiamo jQuery?
          Il framework jQuery
          definisce una
          variabile jQuery la
          quale contiene un
          oggetto che ha tutti i
          metodi e le proprietà
          implementate dalla
          libreria.
Alias $
jQuery.isNumeric(“­10”);

Ma abbiamo anche a disposizione un alias come
$ che rappresenta la variabile jQuery.

$.isNumeric(“­10”);
Aspettare il DOM
Fino ad ora dovevamo fare una cosa del genere per far partire lo script dopo
il caricamento del documento.
window.onload = function(){ 
  alert("welcome"); 
}


Con jQuery possiamo usare una sintassi di questo tipo
$(document).ready(function(){
   alert("welcome");
 });
Ready vs Load
il codice viene eseguito quando il DOM è pronto ma prima che le immagini
ed altri elementi grafici siano caricati
$(document).ready(function(){
   alert("welcome");
 });


Qui aspetto che tutti gli elementi siano caricati
$(window).load(function(){
   alert("welcome");
 });
Selettori
Attraverso jQuery
possiamo selezionare
tutti gli elementi
presenti nel DOM,
attraverso una sintassi
più semplice che con
Javascript, e poi
andare a manipolarli a
nostro piacimento.
Per elemento - tag
            http://api.jquery.com/element-selector/
<div>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>
<script>
divs = $("div");
alert(divs);
divs.each(function(index) {
alert(index + ': ' + $(this).text());
});
</script>
.each()
Il metodo each() è       Molto importante, la
pensato per eseguire     parola chiave this fa
cicli.                   riferimento ogni volta
Quando viene             ad un elemento
chiamato scandisce gli   diverso del “ciclo”
elementi DOM che
fanno parte
dell'oggetto jQuery.
Per ID
            http://api.jquery.com/id-selector/

<div id=”pippo”>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>
<script>
divs = $("#pippo");
alert(divs.text());
</script>
Per className
             http://api.jquery.com/class-selector/
<div class=”pippo”>DIV1</div>
<div>DIV2</div>
<span class=”pippo”>SPAN</span>
<script>
divs = $(".pippo");
alert(divs.text());
divs.each(function(index) {
alert(index + ': ' + $(this).text());
});
</script>
Per Attributo [name]
Has Attribute Selector [name]
Selects elements that have the specified attribute, with any value.
<div>no id</div>
  <div id="hey">with id</div>
  <div id="there">has an id</div>
  <div>nope</div>
<script>
    $('div[id]').each(function(index) {
       alert(index + ': ' + $(this).text());
    });
</script>
Per attributo [name|="value"]
Attribute Contains Prefix Selector [name|="value"]
Selects elements that have the specified attribute with a value either equal to a given
string or starting with that string followed by a hyphen (-).
<body>
  <a href="example.html" hreflang="en">Some text</a> 
  <a href="example.html" hreflang="en­UK">Some other text</a>
  <a href="example.html" hreflang="english">will not be 
outlined</a>
<script>
$('a[hreflang|="en"]').css('border','3px dotted green');
</script>
Per attributo [name*="value"]
Attribute Contains Selector [name*="value"]
Selects elements that have the specified attribute with a
value containing the a given substring.
<input name="man­news" />
<input name="milkman" />
<input name="letterman2" />
<input name="newmilk" />
<script>$('input[name*="man"]').val('has man 
in it!');</script>
Per attributo [name~="value"]
Attribute Contains Word Selector [name~="value"]
Selects elements that have the specified attribute with a value
containing a given word, delimited by spaces.


 <input name="man­news" />
  <input name="milk man" />
  <input name="letterman2" />
  <input name="newmilk" />
<script>$('input[name~="man"]').val('mr. man is in 
it!');</script>
Per Attributo [name$="value"]
Attribute Ends With Selector [name$="value"]
Selects elements that have the specified attribute with a
value ending exactly with a given string. The comparison is
case sensitive.
<input name="newsletter" />
  <input name="milkman" />
  <input name="jobletter" />
<script>$('input[name$="letter"]').val('a 
letter');</script>
Per Attributo [name="value"]
Attribute Equals Selector [name="value"]
Selects elements that have the specified attribute with a value exactly equal to a
certain value.
      <input type="radio" name="newsletter" value="Hot Fuzz" />
      <span>name?</span>
      <input type="radio" name="newsletter" value="Cold Fusion" 
/>
      <span>value?</span>
      <input type="radio" name="newsletter" value="Evil 
Plans" />
      <span>value?</span>
<script>$('input[value="Hot Fuzz"]').next().text(" Hot 
Fuzz");</script>
Per attributo [name!="value"]
Attribute Not Equal Selector [name!="value"]
Select elements that either don't have the specified attribute, or do have the
specified attribute but not with a certain value.
   <input type="radio" name="newsletter" value="Hot Fuzz" />
    <span>name is newsletter</span>
    <input type="radio" value="Cold Fusion" />
    <span>no name</span>
    <input type="radio" name="accept" value="Evil Plans" />
    <span>name is accept</span>
  </div>
<script>$('input[name!="newsletter"]').next().append('<b>; not 
newsletter</b>');</script>
Per Attributo [name^="value"]
Attribute Starts With Selector [name^="value"]
Selects elements that have the specified attribute with a
value beginning exactly with a given string.
  <input name="newsletter" />
  <input name="milkman" />
  <input name="newsboy" />
<script>$('input[name^="news"]').val('news 
here!');</script>
Domande?

               Slide:
http://www.slideshare.net/ilbonzo
               Code:
https://github.com/ilbonzo/Cypher
                mail:
        matteo@magni.me

More Related Content

What's hot

Progetto su iPhone - Seminario di Reti Wireless
Progetto su iPhone - Seminario di Reti WirelessProgetto su iPhone - Seminario di Reti Wireless
Progetto su iPhone - Seminario di Reti WirelessSilvio Daminato
 
ZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFXZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFXTiziano Lattisi
 
Ubuntu Touch: Sviluppo App e Convergenza
Ubuntu Touch: Sviluppo App e ConvergenzaUbuntu Touch: Sviluppo App e Convergenza
Ubuntu Touch: Sviluppo App e ConvergenzaGiulio Collura
 
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQueryXeDotNet
 
Javascript - 4 | WebMaster & WebDesigner
Javascript - 4 | WebMaster & WebDesignerJavascript - 4 | WebMaster & WebDesigner
Javascript - 4 | WebMaster & WebDesignerMatteo Magni
 
Entity Framework 4 vs NHibernate 3
Entity Framework 4 vs NHibernate 3Entity Framework 4 vs NHibernate 3
Entity Framework 4 vs NHibernate 3Martino Bordin
 
Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!Michael Denny
 
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8Wellnet srl
 
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8Eugenio Minardi
 
AngularJS: accessibility
AngularJS: accessibilityAngularJS: accessibility
AngularJS: accessibilityVittorio Conte
 

What's hot (20)

Progetto su iPhone - Seminario di Reti Wireless
Progetto su iPhone - Seminario di Reti WirelessProgetto su iPhone - Seminario di Reti Wireless
Progetto su iPhone - Seminario di Reti Wireless
 
Introduzione a node.js
Introduzione a node.jsIntroduzione a node.js
Introduzione a node.js
 
AngularJS-Intro
AngularJS-IntroAngularJS-Intro
AngularJS-Intro
 
ZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFXZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFX
 
Javascript
JavascriptJavascript
Javascript
 
Ubuntu Touch: Sviluppo App e Convergenza
Ubuntu Touch: Sviluppo App e ConvergenzaUbuntu Touch: Sviluppo App e Convergenza
Ubuntu Touch: Sviluppo App e Convergenza
 
Write less do more...with jQuery
Write less do more...with jQueryWrite less do more...with jQuery
Write less do more...with jQuery
 
m-v-vm @ UgiAlt.Net
m-v-vm @ UgiAlt.Netm-v-vm @ UgiAlt.Net
m-v-vm @ UgiAlt.Net
 
Angularjs
AngularjsAngularjs
Angularjs
 
Corso angular js componenti
Corso angular js componentiCorso angular js componenti
Corso angular js componenti
 
Ajax e jQuery
Ajax e jQueryAjax e jQuery
Ajax e jQuery
 
Javascript - 4 | WebMaster & WebDesigner
Javascript - 4 | WebMaster & WebDesignerJavascript - 4 | WebMaster & WebDesigner
Javascript - 4 | WebMaster & WebDesigner
 
Require js
Require jsRequire js
Require js
 
Entity Framework 4 vs NHibernate 3
Entity Framework 4 vs NHibernate 3Entity Framework 4 vs NHibernate 3
Entity Framework 4 vs NHibernate 3
 
Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!
 
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
 
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
 
Php mysql3
Php mysql3Php mysql3
Php mysql3
 
AngularJS: accessibility
AngularJS: accessibilityAngularJS: accessibility
AngularJS: accessibility
 
Usare Knockout JS
Usare Knockout JSUsare Knockout JS
Usare Knockout JS
 

Viewers also liked

Html e Css - 1 | WebMaster & WebDesigner
Html e Css - 1 | WebMaster & WebDesigner Html e Css - 1 | WebMaster & WebDesigner
Html e Css - 1 | WebMaster & WebDesigner Matteo Magni
 
Javascript - 1 | WebMaster & WebDesigner
Javascript - 1 | WebMaster & WebDesignerJavascript - 1 | WebMaster & WebDesigner
Javascript - 1 | WebMaster & WebDesignerMatteo Magni
 
follow-ap DAY 4: HTML5 e jQuery
follow-ap DAY 4: HTML5 e jQueryfollow-ap DAY 4: HTML5 e jQuery
follow-ap DAY 4: HTML5 e jQueryQIRIS
 
Francesco Inguscio - Avviare una start-up
Francesco Inguscio - Avviare una start-upFrancesco Inguscio - Avviare una start-up
Francesco Inguscio - Avviare una start-upQIRIS
 
Francesco Inguscio - Start-up financing from the side of the entrepreneur
Francesco Inguscio - Start-up financing from the side of the entrepreneurFrancesco Inguscio - Start-up financing from the side of the entrepreneur
Francesco Inguscio - Start-up financing from the side of the entrepreneurQIRIS
 
Web Usability - 1 | WebMaster & WebDesigner
Web Usability - 1 | WebMaster & WebDesignerWeb Usability - 1 | WebMaster & WebDesigner
Web Usability - 1 | WebMaster & WebDesignerMatteo Magni
 
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache luceneQIRIS
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerMatteo Magni
 
Gianfrasoft Corso Di Php Parte 1
Gianfrasoft   Corso Di Php   Parte 1Gianfrasoft   Corso Di Php   Parte 1
Gianfrasoft Corso Di Php Parte 1Gianfranco Fedele
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHPextrategy
 
PHP: programmi gestionali, introduzione
PHP: programmi gestionali, introduzionePHP: programmi gestionali, introduzione
PHP: programmi gestionali, introduzioneHigh Secondary School
 

Viewers also liked (11)

Html e Css - 1 | WebMaster & WebDesigner
Html e Css - 1 | WebMaster & WebDesigner Html e Css - 1 | WebMaster & WebDesigner
Html e Css - 1 | WebMaster & WebDesigner
 
Javascript - 1 | WebMaster & WebDesigner
Javascript - 1 | WebMaster & WebDesignerJavascript - 1 | WebMaster & WebDesigner
Javascript - 1 | WebMaster & WebDesigner
 
follow-ap DAY 4: HTML5 e jQuery
follow-ap DAY 4: HTML5 e jQueryfollow-ap DAY 4: HTML5 e jQuery
follow-ap DAY 4: HTML5 e jQuery
 
Francesco Inguscio - Avviare una start-up
Francesco Inguscio - Avviare una start-upFrancesco Inguscio - Avviare una start-up
Francesco Inguscio - Avviare una start-up
 
Francesco Inguscio - Start-up financing from the side of the entrepreneur
Francesco Inguscio - Start-up financing from the side of the entrepreneurFrancesco Inguscio - Start-up financing from the side of the entrepreneur
Francesco Inguscio - Start-up financing from the side of the entrepreneur
 
Web Usability - 1 | WebMaster & WebDesigner
Web Usability - 1 | WebMaster & WebDesignerWeb Usability - 1 | WebMaster & WebDesigner
Web Usability - 1 | WebMaster & WebDesigner
 
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesigner
 
Gianfrasoft Corso Di Php Parte 1
Gianfrasoft   Corso Di Php   Parte 1Gianfrasoft   Corso Di Php   Parte 1
Gianfrasoft Corso Di Php Parte 1
 
Introduzione al linguaggio PHP
Introduzione al linguaggio PHPIntroduzione al linguaggio PHP
Introduzione al linguaggio PHP
 
PHP: programmi gestionali, introduzione
PHP: programmi gestionali, introduzionePHP: programmi gestionali, introduzione
PHP: programmi gestionali, introduzione
 

Similar to jQuery - 1 | WebMaster & WebDesigner

Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Corso WebApp iOS - Lezione 06:   Web Development for iOS DevicesCorso WebApp iOS - Lezione 06:   Web Development for iOS Devices
Corso WebApp iOS - Lezione 06: Web Development for iOS DevicesAndrea Picchi
 
Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Pietro Polsinelli
 
AngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni webAngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni webLuca Milan
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - GateinJBug Italy
 
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuerySandro Marcon
 
MongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDBMongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDBStefano Dindo
 
Node.js - Server Side Javascript
Node.js - Server Side JavascriptNode.js - Server Side Javascript
Node.js - Server Side JavascriptMatteo Napolitano
 
Tech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non soloTech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non soloCodemotion
 
Le novita di visual studio 2012
Le novita di visual studio 2012Le novita di visual studio 2012
Le novita di visual studio 2012Crismer La Pignola
 
Sviluppo web con Ruby on Rails
Sviluppo web con Ruby on RailsSviluppo web con Ruby on Rails
Sviluppo web con Ruby on Railsjekil
 
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...Codemotion
 
Drupal Day 2012 - DRUPAL 8: I CAMBIAMENTI CHE CI ASPETTANO
Drupal Day 2012 - DRUPAL 8:  I CAMBIAMENTI CHE CI ASPETTANODrupal Day 2012 - DRUPAL 8:  I CAMBIAMENTI CHE CI ASPETTANO
Drupal Day 2012 - DRUPAL 8: I CAMBIAMENTI CHE CI ASPETTANODrupalDay
 
Luca Masini: Introduzione a GWT 2.0
Luca Masini: Introduzione a GWT 2.0Luca Masini: Introduzione a GWT 2.0
Luca Masini: Introduzione a GWT 2.0firenze-gtug
 

Similar to jQuery - 1 | WebMaster & WebDesigner (20)

Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Corso WebApp iOS - Lezione 06:   Web Development for iOS DevicesCorso WebApp iOS - Lezione 06:   Web Development for iOS Devices
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
 
Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5Matteo Bicocchi - Introducing HTML5
Matteo Bicocchi - Introducing HTML5
 
AngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni webAngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni web
 
Ddive Xpage852
Ddive Xpage852Ddive Xpage852
Ddive Xpage852
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - Gatein
 
#dd12 grillo daniele_xpages_tips_tricks_rev2
#dd12 grillo daniele_xpages_tips_tricks_rev2#dd12 grillo daniele_xpages_tips_tricks_rev2
#dd12 grillo daniele_xpages_tips_tricks_rev2
 
Introduzione a jQuery
Introduzione a jQueryIntroduzione a jQuery
Introduzione a jQuery
 
DDive - 8.5.2 Xpages - L'evoluzione continua
DDive - 8.5.2 Xpages - L'evoluzione continuaDDive - 8.5.2 Xpages - L'evoluzione continua
DDive - 8.5.2 Xpages - L'evoluzione continua
 
MongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDBMongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDB
 
XPages Tips & Tricks, #dd13
XPages Tips & Tricks, #dd13XPages Tips & Tricks, #dd13
XPages Tips & Tricks, #dd13
 
Node.js - Server Side Javascript
Node.js - Server Side JavascriptNode.js - Server Side Javascript
Node.js - Server Side Javascript
 
Tech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non soloTech Webinar: Test e2e per AngularJS e non solo
Tech Webinar: Test e2e per AngularJS e non solo
 
Le novita di visual studio 2012
Le novita di visual studio 2012Le novita di visual studio 2012
Le novita di visual studio 2012
 
Sviluppo web con Ruby on Rails
Sviluppo web con Ruby on RailsSviluppo web con Ruby on Rails
Sviluppo web con Ruby on Rails
 
Corso Javascript
Corso JavascriptCorso Javascript
Corso Javascript
 
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
 
react-it.pdf
react-it.pdfreact-it.pdf
react-it.pdf
 
Drupal Day 2012 - DRUPAL 8: I CAMBIAMENTI CHE CI ASPETTANO
Drupal Day 2012 - DRUPAL 8:  I CAMBIAMENTI CHE CI ASPETTANODrupal Day 2012 - DRUPAL 8:  I CAMBIAMENTI CHE CI ASPETTANO
Drupal Day 2012 - DRUPAL 8: I CAMBIAMENTI CHE CI ASPETTANO
 
Luca Masini: Introduzione a GWT 2.0
Luca Masini: Introduzione a GWT 2.0Luca Masini: Introduzione a GWT 2.0
Luca Masini: Introduzione a GWT 2.0
 
jQuery
jQueryjQuery
jQuery
 

More from Matteo Magni

Introduzione DevOps con Ansible
Introduzione DevOps con AnsibleIntroduzione DevOps con Ansible
Introduzione DevOps con AnsibleMatteo Magni
 
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerHTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerMatteo Magni
 
HTML5 e Css3 - 6 | WebMaster & WebDesigner
HTML5 e Css3 - 6 | WebMaster & WebDesignerHTML5 e Css3 - 6 | WebMaster & WebDesigner
HTML5 e Css3 - 6 | WebMaster & WebDesignerMatteo Magni
 
HTML5 e Css3 - 5 | WebMaster & WebDesigner
HTML5 e Css3 - 5 | WebMaster & WebDesignerHTML5 e Css3 - 5 | WebMaster & WebDesigner
HTML5 e Css3 - 5 | WebMaster & WebDesignerMatteo Magni
 
HTML5 e Css3 - 4 | WebMaster & WebDesigner
HTML5 e Css3 - 4 | WebMaster & WebDesignerHTML5 e Css3 - 4 | WebMaster & WebDesigner
HTML5 e Css3 - 4 | WebMaster & WebDesignerMatteo Magni
 
HTML5 e Css3 - 3 | WebMaster & WebDesigner
HTML5 e Css3 - 3 | WebMaster & WebDesignerHTML5 e Css3 - 3 | WebMaster & WebDesigner
HTML5 e Css3 - 3 | WebMaster & WebDesignerMatteo Magni
 
HTML5 e Css3 - 2 | WebMaster & WebDesigner
HTML5 e Css3 - 2 | WebMaster & WebDesignerHTML5 e Css3 - 2 | WebMaster & WebDesigner
HTML5 e Css3 - 2 | WebMaster & WebDesignerMatteo Magni
 
HTML5 e Css3 - 1 | WebMaster & WebDesigner
HTML5 e Css3 - 1 | WebMaster & WebDesigner HTML5 e Css3 - 1 | WebMaster & WebDesigner
HTML5 e Css3 - 1 | WebMaster & WebDesigner Matteo Magni
 
jQuery - 5 | WebMaster & WebDesigner
jQuery - 5 | WebMaster & WebDesignerjQuery - 5 | WebMaster & WebDesigner
jQuery - 5 | WebMaster & WebDesignerMatteo Magni
 
jQuery - 4 | WebMaster & WebDesigner
jQuery - 4 | WebMaster & WebDesignerjQuery - 4 | WebMaster & WebDesigner
jQuery - 4 | WebMaster & WebDesignerMatteo Magni
 
jQuery - 3 | WebMaster & WebDesigner
jQuery - 3 | WebMaster & WebDesignerjQuery - 3 | WebMaster & WebDesigner
jQuery - 3 | WebMaster & WebDesignerMatteo Magni
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerMatteo Magni
 
Javascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesignerJavascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesignerMatteo Magni
 
Javascript - 6 | WebMaster & WebDesigner
Javascript - 6 | WebMaster & WebDesignerJavascript - 6 | WebMaster & WebDesigner
Javascript - 6 | WebMaster & WebDesignerMatteo Magni
 
Javascript - 5 | WebMaster & WebDesigner
Javascript - 5 | WebMaster & WebDesignerJavascript - 5 | WebMaster & WebDesigner
Javascript - 5 | WebMaster & WebDesignerMatteo Magni
 
Javascript - 3 | WebMaster & WebDesigner
Javascript - 3 | WebMaster & WebDesignerJavascript - 3 | WebMaster & WebDesigner
Javascript - 3 | WebMaster & WebDesignerMatteo Magni
 
Javascript - 2 | WebMaster & WebDesigner
Javascript - 2 | WebMaster & WebDesignerJavascript - 2 | WebMaster & WebDesigner
Javascript - 2 | WebMaster & WebDesignerMatteo Magni
 
Web Usability - 3 | WebMaster & WebDesigner
 Web Usability - 3 | WebMaster & WebDesigner Web Usability - 3 | WebMaster & WebDesigner
Web Usability - 3 | WebMaster & WebDesignerMatteo Magni
 
Web Usability - 2 | WebMaster & WebDesigner
Web Usability - 2 | WebMaster & WebDesignerWeb Usability - 2 | WebMaster & WebDesigner
Web Usability - 2 | WebMaster & WebDesignerMatteo Magni
 
Seo e Web Marketing - 5 | WebMaster & WebDesigner
Seo e Web Marketing - 5 | WebMaster & WebDesignerSeo e Web Marketing - 5 | WebMaster & WebDesigner
Seo e Web Marketing - 5 | WebMaster & WebDesignerMatteo Magni
 

More from Matteo Magni (20)

Introduzione DevOps con Ansible
Introduzione DevOps con AnsibleIntroduzione DevOps con Ansible
Introduzione DevOps con Ansible
 
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerHTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesigner
 
HTML5 e Css3 - 6 | WebMaster & WebDesigner
HTML5 e Css3 - 6 | WebMaster & WebDesignerHTML5 e Css3 - 6 | WebMaster & WebDesigner
HTML5 e Css3 - 6 | WebMaster & WebDesigner
 
HTML5 e Css3 - 5 | WebMaster & WebDesigner
HTML5 e Css3 - 5 | WebMaster & WebDesignerHTML5 e Css3 - 5 | WebMaster & WebDesigner
HTML5 e Css3 - 5 | WebMaster & WebDesigner
 
HTML5 e Css3 - 4 | WebMaster & WebDesigner
HTML5 e Css3 - 4 | WebMaster & WebDesignerHTML5 e Css3 - 4 | WebMaster & WebDesigner
HTML5 e Css3 - 4 | WebMaster & WebDesigner
 
HTML5 e Css3 - 3 | WebMaster & WebDesigner
HTML5 e Css3 - 3 | WebMaster & WebDesignerHTML5 e Css3 - 3 | WebMaster & WebDesigner
HTML5 e Css3 - 3 | WebMaster & WebDesigner
 
HTML5 e Css3 - 2 | WebMaster & WebDesigner
HTML5 e Css3 - 2 | WebMaster & WebDesignerHTML5 e Css3 - 2 | WebMaster & WebDesigner
HTML5 e Css3 - 2 | WebMaster & WebDesigner
 
HTML5 e Css3 - 1 | WebMaster & WebDesigner
HTML5 e Css3 - 1 | WebMaster & WebDesigner HTML5 e Css3 - 1 | WebMaster & WebDesigner
HTML5 e Css3 - 1 | WebMaster & WebDesigner
 
jQuery - 5 | WebMaster & WebDesigner
jQuery - 5 | WebMaster & WebDesignerjQuery - 5 | WebMaster & WebDesigner
jQuery - 5 | WebMaster & WebDesigner
 
jQuery - 4 | WebMaster & WebDesigner
jQuery - 4 | WebMaster & WebDesignerjQuery - 4 | WebMaster & WebDesigner
jQuery - 4 | WebMaster & WebDesigner
 
jQuery - 3 | WebMaster & WebDesigner
jQuery - 3 | WebMaster & WebDesignerjQuery - 3 | WebMaster & WebDesigner
jQuery - 3 | WebMaster & WebDesigner
 
jQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesignerjQuery - 2 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesigner
 
Javascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesignerJavascript - 7 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesigner
 
Javascript - 6 | WebMaster & WebDesigner
Javascript - 6 | WebMaster & WebDesignerJavascript - 6 | WebMaster & WebDesigner
Javascript - 6 | WebMaster & WebDesigner
 
Javascript - 5 | WebMaster & WebDesigner
Javascript - 5 | WebMaster & WebDesignerJavascript - 5 | WebMaster & WebDesigner
Javascript - 5 | WebMaster & WebDesigner
 
Javascript - 3 | WebMaster & WebDesigner
Javascript - 3 | WebMaster & WebDesignerJavascript - 3 | WebMaster & WebDesigner
Javascript - 3 | WebMaster & WebDesigner
 
Javascript - 2 | WebMaster & WebDesigner
Javascript - 2 | WebMaster & WebDesignerJavascript - 2 | WebMaster & WebDesigner
Javascript - 2 | WebMaster & WebDesigner
 
Web Usability - 3 | WebMaster & WebDesigner
 Web Usability - 3 | WebMaster & WebDesigner Web Usability - 3 | WebMaster & WebDesigner
Web Usability - 3 | WebMaster & WebDesigner
 
Web Usability - 2 | WebMaster & WebDesigner
Web Usability - 2 | WebMaster & WebDesignerWeb Usability - 2 | WebMaster & WebDesigner
Web Usability - 2 | WebMaster & WebDesigner
 
Seo e Web Marketing - 5 | WebMaster & WebDesigner
Seo e Web Marketing - 5 | WebMaster & WebDesignerSeo e Web Marketing - 5 | WebMaster & WebDesigner
Seo e Web Marketing - 5 | WebMaster & WebDesigner
 

jQuery - 1 | WebMaster & WebDesigner

  • 2. jQuery: The Write Less, Do More, JavaScript Library
  • 4. Cos'è? jQuery è una libreria di funzioni (framework) javascript, cross-browser per le applicazioni web, che si propone come obiettivo quello di semplificare la programmazione lato client delle pagine HTML. (wikipedia)
  • 5. Cos'è: Cosa fa: • Framework • Document • Cross browser traversing • Event handling • Animating • Ajax interactions
  • 7. Versioni http://jquery.com/ a)PRODUCTION (32KB, Minified and Gzipped) b)DEVELOPMENT (252KB, Uncompressed Code) Differenze?
  • 8. Production Pesa solo 32 kb perché è minificata. http://en.wikipedia.org/wiki/Minification_(programming) “processo di rimozione di tutti i caratteri non necessari dal codice sorgente, senza cambiarne la sua funzionalità.”
  • 9. Development 252 kb perché scritta in maniera leggibile al programmatore. Adatta per la fase di sviluppo, meno per la produzione per via della banda che occupa. Le funzionalità di tutte e due sono le stesse
  • 10. Integrare jQuery Per integrare jQuery nei nostri progetti basta includere il file js come javascript esterno. <script src="jquery.js"></script> A quel punto tutte le funzionalità di jQuery ci saranno disponibili.
  • 11. Content Delivery Network E' possibile utilizzare jQuery anche da CDN. • CDN:Content Delivery Network Rete per la consegna di contenuti, cioè sistema distribuito di grande estensione che attraverso un alto numero di server, il quale consente di fornire contenuti agli utenti con maggior affidabilità.
  • 12. CDN Vantaggi • Far risparmiare banda al proprio server • L'utente avendola già utilizzata protrebbe quindi averla già in cache nel browser
  • 14. Release Da CDN possiamo vedere che jQuery è arrivato alla versione 1.8.2 e che quando le chiamiamo la libreria in quel modo dobbiamo ricordaci quale vogliamo.
  • 15. Come usiamo jQuery? Il framework jQuery definisce una variabile jQuery la quale contiene un oggetto che ha tutti i metodi e le proprietà implementate dalla libreria.
  • 16. Alias $ jQuery.isNumeric(“­10”); Ma abbiamo anche a disposizione un alias come $ che rappresenta la variabile jQuery. $.isNumeric(“­10”);
  • 17. Aspettare il DOM Fino ad ora dovevamo fare una cosa del genere per far partire lo script dopo il caricamento del documento. window.onload = function(){    alert("welcome");  } Con jQuery possiamo usare una sintassi di questo tipo $(document).ready(function(){    alert("welcome");  });
  • 18. Ready vs Load il codice viene eseguito quando il DOM è pronto ma prima che le immagini ed altri elementi grafici siano caricati $(document).ready(function(){    alert("welcome");  }); Qui aspetto che tutti gli elementi siano caricati $(window).load(function(){    alert("welcome");  });
  • 19. Selettori Attraverso jQuery possiamo selezionare tutti gli elementi presenti nel DOM, attraverso una sintassi più semplice che con Javascript, e poi andare a manipolarli a nostro piacimento.
  • 20. Per elemento - tag http://api.jquery.com/element-selector/ <div>DIV1</div> <div>DIV2</div> <span>SPAN</span> <script> divs = $("div"); alert(divs); divs.each(function(index) { alert(index + ': ' + $(this).text()); }); </script>
  • 21. .each() Il metodo each() è Molto importante, la pensato per eseguire parola chiave this fa cicli. riferimento ogni volta Quando viene ad un elemento chiamato scandisce gli diverso del “ciclo” elementi DOM che fanno parte dell'oggetto jQuery.
  • 22. Per ID http://api.jquery.com/id-selector/ <div id=”pippo”>DIV1</div> <div>DIV2</div> <span>SPAN</span> <script> divs = $("#pippo"); alert(divs.text()); </script>
  • 23. Per className http://api.jquery.com/class-selector/ <div class=”pippo”>DIV1</div> <div>DIV2</div> <span class=”pippo”>SPAN</span> <script> divs = $(".pippo"); alert(divs.text()); divs.each(function(index) { alert(index + ': ' + $(this).text()); }); </script>
  • 24. Per Attributo [name] Has Attribute Selector [name] Selects elements that have the specified attribute, with any value. <div>no id</div>   <div id="hey">with id</div>   <div id="there">has an id</div>   <div>nope</div> <script>     $('div[id]').each(function(index) {        alert(index + ': ' + $(this).text());     }); </script>
  • 25. Per attributo [name|="value"] Attribute Contains Prefix Selector [name|="value"] Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-). <body>   <a href="example.html" hreflang="en">Some text</a>    <a href="example.html" hreflang="en­UK">Some other text</a>   <a href="example.html" hreflang="english">will not be  outlined</a> <script> $('a[hreflang|="en"]').css('border','3px dotted green'); </script>
  • 26. Per attributo [name*="value"] Attribute Contains Selector [name*="value"] Selects elements that have the specified attribute with a value containing the a given substring. <input name="man­news" /> <input name="milkman" /> <input name="letterman2" /> <input name="newmilk" /> <script>$('input[name*="man"]').val('has man  in it!');</script>
  • 27. Per attributo [name~="value"] Attribute Contains Word Selector [name~="value"] Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.  <input name="man­news" />   <input name="milk man" />   <input name="letterman2" />   <input name="newmilk" /> <script>$('input[name~="man"]').val('mr. man is in  it!');</script>
  • 28. Per Attributo [name$="value"] Attribute Ends With Selector [name$="value"] Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive. <input name="newsletter" />   <input name="milkman" />   <input name="jobletter" /> <script>$('input[name$="letter"]').val('a  letter');</script>
  • 29. Per Attributo [name="value"] Attribute Equals Selector [name="value"] Selects elements that have the specified attribute with a value exactly equal to a certain value.       <input type="radio" name="newsletter" value="Hot Fuzz" />       <span>name?</span>       <input type="radio" name="newsletter" value="Cold Fusion"  />       <span>value?</span>       <input type="radio" name="newsletter" value="Evil  Plans" />       <span>value?</span> <script>$('input[value="Hot Fuzz"]').next().text(" Hot  Fuzz");</script>
  • 30. Per attributo [name!="value"] Attribute Not Equal Selector [name!="value"] Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.    <input type="radio" name="newsletter" value="Hot Fuzz" />     <span>name is newsletter</span>     <input type="radio" value="Cold Fusion" />     <span>no name</span>     <input type="radio" name="accept" value="Evil Plans" />     <span>name is accept</span>   </div> <script>$('input[name!="newsletter"]').next().append('<b>; not  newsletter</b>');</script>
  • 31. Per Attributo [name^="value"] Attribute Starts With Selector [name^="value"] Selects elements that have the specified attribute with a value beginning exactly with a given string.   <input name="newsletter" />   <input name="milkman" />   <input name="newsboy" /> <script>$('input[name^="news"]').val('news  here!');</script>
  • 32. Domande? Slide: http://www.slideshare.net/ilbonzo Code: https://github.com/ilbonzo/Cypher mail: matteo@magni.me