Академический Документы
Профессиональный Документы
Культура Документы
De JavaScript jQuery
La naissance de JavaScript
1995 : Brendan Eich dveloppe pour Netscape
Communications Corporation, un langage de script, appel
Mocha, puis LiveScript et finalement JavaScript
Javascript est intgr dans le navigateur Netscape 2.
Succs immdiat.
Mootools - mootools.net
DoJo Toolkit - www.dojotoolkit.org
Yahoo UI - developer.yahoo.com/yui/
ExtJS - www.extjs.com
UIZE - www.uize.com
Cours applications web M1 Miage 2011
JQuery
Une bibliothque javascript open-source et crossbrowser
Elle permet de traverser et manipuler trs facilement
l'arbre DOM des pages web l'aide d'une syntaxe
fortement similaire celle d'XPath.
JQuery permet par exemple de changer/ajouter une
classe CSS, crer des animations, modifier des
attributs, etc.
Grer les vnements javascript
Faire des requtes AJAX simplement
Cours applications web M1 Miage 2011
John Resig
John Resig est un dveloppeur doutils
JavaScript pour Mozilla Corporation et auteur
du livre Pro JavaScript Techniques. Il est
galement le crateur et dveloppeur principal
de la jQuery JavaScript library.
Il vit Boston, MA. Il a publi son second livre
: Secrets of the JavaScript Ninja, en 2009.
Il a port le langage processing en javascript
lanne dernire (http://processingjs.org/),
Il a cr galement jQuery Mobile
(http://jquerymobile.com/)
Microsoft et Nokia incluent jQuery sur leurs
plateformes,[1] Microsoft dansVisual Studio[2]
pour lutiliser avec les frameworks ASP.NET
AJAX et ASP.NET MVC Framework alors que
Nokia la intgr dans sa plateformeWeb RunTime.
La fonction jQuery()
jQuery repose sur une seule fonction :
jQuery() ou $().
Cest une fonction JavaScript
Elle accepte des paramtres
Elle retourne un objet
10
11
$(anything)
$ accepte des slecteurs spcifiques :
$(':radio'), $(':header'), $(':first-child')
des attributs
$('a[href]'), $('a[href^=http://'), $('img[src$=.png]'
12
14
jQuery: un objet
les mthodes s'appliquent gnralement tous les lments
slectionns
$('.classe').hide();
$('.classe').show();
15
16
<ul>
<li>
<span>Changed</span>
First item
</li>
<li>
Second item
</li>
<li>
<span>Changed</span>
Third item
</li>
</ul>
<ul>
<li style=background:red;>
<span>Changed</span>
First item
</li>
<li>
Second item
</li>
<li style=background:red;>
<span>Changed</span>
Third item
</li>
</ul>
<div>
<span class=foo>
Some text
</span>
</div>
<div style=display:none>
<span>
More text
</span>
<span class=foo>
Goodbye cruel world.
</span>
</div>
<div>
<span class=foo>
Some text
</span>
</div>
<div style=display:none>
<span>
More text
</span>
<span class=foo>
</span>
</div>
<div>
<span class=foo>
Some text
</span>
</div>
<div style=display:none>
<span>
More text
</span>
<span class=foo>
Changed
</span>
</div>
<div>
<span class=foo>
Some text
</span>
</div>
<div style=display:none>
<span>
More text
</span>
<span class=foo>
Changed
</span>
</div>
<div>
<span class=foo>
Some text
</span>
</div>
<div style=display:block>
<span>
More text
</span>
<span class=foo>
Changed
</span>
</div>
<div>
<span class=all>Select All</span>
or
$(span).click(
function(){
if($(this).text()==Select All))
$(this).siblings(:checkbox).attr(checked,checked);
else if ($(this).attr(class)==none)
$(this).siblings(:checkbox).removeAttr(checked);
}
);
Ajax
JQuery possde toute une panoplie de fonctions
permettant de simplifier les requtes Ajax
La plus simple :
$('#maDiv').load('page.html');
Plus complexe :
$.get('test.html',
function(data) {faire quelque chose);
Gnrale :
$.ajax({
url: 'document.xml',
type: 'GET',
dataType: 'xml',
timeout: 1000,
error: function(){alert('Erreur chargement'); },
success: function(xml){faire quelque chose}
});
24
25
<?php
$output = ;
switch($_REQUEST[in]) {
case hello:
$output = Hello back.;
break;
case foo:
$output = Foo you, too.;
break;
case bar:
$output = Where Andy Capp can be found.;
break;
case foobar:
$output = This is German, right?;
break;
default:
$output = Unrecognized string.;
}
$count = $_REQUEST[count]+1;
echo json_encode(
array(
out => $output,
cnt => $count
)
);
exit;
?>
$.get
$.getJSON
$.getIfModified
$.getScript
$.post
ajaxComplete
ajaxError
ajaxSend
ajaxStart
ajaxStop
ajaxSuccess
async
beforeSend
complete
contentType
data
dataType
error
global
ifModified
processData
success
timeout
type
url
28
Voir : http://www.jsonpexamples.com/
Cours applications web M1 Miage 2011
29
} }
Cours applications web M1 Miage 2011
30
31
32
jQuery et JSON
jQuery.getJSON( url, [ data ],
[ callback(data, textStatus) ] )
Exemple :
<html><head>
<script src="jquery.min.js"></script>
</head>
<body>
<div id="images" style="height: 300px"></div>
<script>
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tag
s=besancon&tagmode=any&format=json&jsoncallback=?",
function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#images");
if ( i == 3 ) return false;
});
});
</script>
</body></html>
33
jQuery UI
http://jqueryui.com/
Un ensemble de composants graphiques tlchargeable
l'adresse http://jqueryui.com/download.
un noyau (Core)
des comportements (interactions)
draggable : pour glisser-dplacer un lment
http://jqueryui.com/demos/draggable/
droppable : pour dposer un lment
http://jqueryui.com/demos/droppable/
resizable : pour redimensionner un lment
http://jqueryui.com/demos/resizable/
selectable : pour slectionner des lments la souris
http://jqueryui.com/demos/selectable/
sortable : pour trier des lments
http://jqueryui.com/demos/selectable/
Cours applications web M1 Miage 2011
34
jQuery UI
des widgets
accordon http://jqueryui.com/demos/accordion/
calendrier http://jqueryui.com/demos/datepicker/
bote de dialogue http://jqueryui.com/demos/dialog/
barre de progression http://jqueryui.com/demos/progressbar/
curseur http://jqueryui.com/demos/slider/
onglets http://jqueryui.com/demos/tabs/
des effets
http://jqueryui.com/demos/effect/
Clignotement, disparition, apparition, clatement, transition
35
jQuery Plugins
On peut tendre facilement jQuery en utilisant des plugins
Les mthodes ajoutes sont au mme niveau que les mthodes
natives
Ils conservent les mmes smantiques que les mthodes
natives: retourner l'objet jQuery, appliquer la mthode tous
les lments reprsents
Des centaines plugins existent d'ores et dj, de qualit
variable; certains mis en avant par l'quipe de dveloppement
http://plugins.jquery.com/
des menus
http://apycom.com/
http://www.wizzud.com/jqDock/
Galerie photo : VisualLightbox
http://visuallightbox.com
36
Conclusion
37
http://www.jquery.com
Learning Center
http://docs.jquery.com/Tutorials
http://www.learningjquery.com/
http://15daysofjquery.com/
http://www.roseindia.net/ajax/jquery/
Support
http://docs.jquery.com/Discussion
http://www.nabble.com/JQuery-f15494.html mailing list archive
irc.freenode.net irc room: #jquery
Documentation
http://docs.jquery.com/Main_Page
http://www.visualjquery.com
http://jquery.bassistance.de/api-browser/
http://docs.jquery.com/Sites_Using_jQuery