Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
jQuery y Rails - Take a walk on the wild side
Search
Christos Zisopoulos
September 26, 2011
Programming
2
69
jQuery y Rails - Take a walk on the wild side
Christos Zisopoulos
September 26, 2011
Tweet
Share
More Decks by Christos Zisopoulos
See All by Christos Zisopoulos
Building a Boring Pub Sub(madrid.rb Feb 2025)
christos
0
90
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
230
Claude Code、ちょっとした工夫で開発体験が変わる
tigertora7571
0
200
TipKitTips
ktcryomm
0
150
AIプロダクト時代のQAエンジニアに求められること
imtnd
2
710
CSC307 Lecture 12
javiergs
PRO
0
460
Codex の「自走力」を高める
yorifuji
0
560
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
220
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
1
530
CSC307 Lecture 14
javiergs
PRO
0
450
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
310
CopilotKit + AG-UIを学ぶ
nearme_tech
PRO
1
130
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
230
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
150
Being A Developer After 40
akosma
91
590k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
310
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
450
4 Signs Your Business is Dying
shpigford
187
22k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
980
Exploring anti-patterns in Rails
aemeredith
2
280
Agile that works and the tools we love
rasmusluckow
331
21k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Transcript
jQuery y Rails “Take a walk on the wild side”
Christos Zisopoulos jobandtalent.com
¿Quien soy?
¿Quien soy? Soy un desarrollador de Rails (como la mayoría
de vosotros, me imagino)
¿Quien soy? Pero a veces toca hacer Javascript (el síndrome
del “lone developer”)
¿Quien soy? Una confesión: Me gusta Javascript (pero odio a
los navegadores)
¿Que es? Es una librería Javascript para manipulación sofisticada del
DOM independiente del navegador.
La filosofía
Encontrar algo... (casi todo es un objeto jQuery)
Encontrar algo... $('div.info p:first') (casi todo es un objeto jQuery)
...y hacer algo con ello $('div.info p:first') .text('Todo bien!') .css('color',
'green') .fadeIn()
Encontrar algo <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('div'); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('div:first'); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('p:last'); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('p:gt(2)'); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('strong:contains(Hola)'); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
CSS selectors #id, tag, .class, * ancestor descendant parent >
child prev + next prev ~ siblings E[@attr] E[@attr=val] E[@attr^=val] E[@attr$=val] E[@attr*=val] E[@attr=val][@attr=val]
CSS selectors #id, tag, .class, * ancestor descendant parent >
child prev + next prev ~ siblings E[@attr] E[@attr=val] E[@attr^=val] E[@attr$=val] E[@attr*=val] E[@attr=val][@attr=val]
CSS selectors :first :last :not(selector) :even :odd :eq(index) :gt(index) :lt(index)
:contains(text) :empty :has(selector) :parent :nth-child(index) :first-child :last-child :only-child
CSS selectors :first :last :not(selector) :even :odd :eq(index) :gt(index) :lt(index)
:contains(text) :empty :has(selector) :parent :nth-child(index) :first-child :last-child :only-child
CSS selectors :input :text :password :radio :checkbox :submit :image :reset
:button :file :hidden :enabled :disabled :checked :selected :hidden :visible :header :animated
CSS selectors :input :text :password :radio :checkbox :submit :image :reset
:button :file :hidden :enabled :disabled :checked :selected :hidden :visible :header :animated
...y hacer algo. <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('div:first').slideDown(); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('p:last').css('color', 'red'); <div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div>
$('strong:contains(Hola)'). wrap('<em></em>'); <div> <p><span>...</span></p> <p><div><em><strong>Hola</strong><em></div></p> <p>...</p> <p>...</p> </div>
<div> <p><span>...</span></p> <p><div><strong>Hola</strong></div></p> <p>...</p> <p>...</p> </div> $('p:even'). css('background-color', 'grey');
¿Que se puede hacer? Atravesar Manipular Eventos Efectos AJAX
Atravesar .hasClass(class) .filter(expr) .is(expr) .map(callback) .not(expr) .slice(start, end) .add(e) .children(e)
.siblings(e) .contents() .find(e) .next(e), .nextAll(e) .prev(e), .prevAll(e) .each(callback) .size(), .length .get(), .get(index) .index(subject) .andSelf() .end()
Atravesar .hasClass(class) .filter(expr) .is(expr) .map(callback) .not(expr) .slice(start, end) .add(e) .children(e)
.siblings(e) .contents() .find(e) .next(e), .nextAll(e) .prev(e), .prevAll(e) .each(callback) .size(), .length .get(), .get(index) .index(subject) .andSelf() .end()
Manipular .append(c) .appendTo(elem) .prepend(c) .prependTo(elem) .wrap(html) .wrap(elem) .wrapAll(html) .wrapAll(elem) .wrapInner(html)
.wrapInner(elem) .after(c), .before(c) .insertAfter(c) .insertBefore(c) .replaceWith(c) .replaceAll(selector) .empty() .remove(expr) .clone(), clone(true)
Manipular .append(c) .appendTo(elem) .prepend(c) .prependTo(elem) .wrap(html) .wrap(elem) .wrapAll(html) .wrapAll(elem) .wrapInner(html)
.wrapInner(elem) .after(c), .before(c) .insertAfter(c) .insertBefore(c) .replaceWith(c) .replaceAll(selector) .empty() .remove(expr) .clone(), clone(true)
Manipular .css(name) .css(name, value) .css(properties) .html() .html(value) .text() .text(value) .val()
.val(value) .attr(name) .attr(name, value) .attr(name, function) .attr(properties) .removeAttr(name) .addClass(class) .removeClass(class) .toggleClass(class) .offset()
Manipular .css(name) .css(name, value) .css(properties) .html() .html(value) .text() .text(value) .val()
.val(value) .attr(name) .attr(name, value) .attr(name, function) .attr(properties) .removeAttr(name) .addClass(class) .removeClass(class) .toggleClass(class) .offset()
Eventos
$('a.remote').bind('click', function(e) {...}); $('p').one('dblclick', function(e) {...}); $('p > a.remote').bind('mouseover', function(e)
{...});
$('div') .bind('mySpecialEvent', function(e) {...}); $('div') .trigger('mySpecialEvent');
$("p").click(function () { $(this).slideUp(); }); $("p").hover(function () { $(this).addClass("hilite"); },
function () { $(this).removeClass("hilite"); });
Eventos .bind(type, data, fn) .one(type, data, fn) .trigger(type, data) .triggerHandler(type,
data) .unbind(type, data) .load(fn), .resize(fn) .scroll(fn) .ready(fn) .error(), .error(fn) .mousedown(fn) .mouseup(fn) .mouseout(fn) .mousover(fn) .mousemove(fn) .keydown() .keydown(fn) .keyup() .keyup(fn) .keypress() .keypress(fn)
Eventos .bind(type, data, fn) .one(type, data, fn) .trigger(type, data) .triggerHandler(type,
data) .unbind(type, data) .load(fn), .resize(fn) .scroll(fn) .ready(fn) .error(), .error(fn) .mousedown(fn) .mouseup(fn) .mouseout(fn) .mousover(fn) .mousemove(fn) .keydown() .keydown(fn) .keyup() .keyup(fn) .keypress() .keypress(fn)
Eventos .hover(fnEnter, fnLeave) .toggle(fnOn, fnOff) .blur() .blur(fn) .unblur() .unblur(fn) .click()
.click(fn) .dblclick() .dblclick(fn) .submit() .submit(fn) .focus() .focus(fn) .select() .select(fn) .unload() .unload(fn)
Eventos .hover(fnEnter, fnLeave) .toggle(fnOn, fnOff) .blur() .blur(fn) .unblur() .unblur(fn) .click()
.click(fn) .dblclick() .dblclick(fn) .submit() .submit(fn) .focus() .focus(fn) .select() .select(fn) .unload() .unload(fn)
Efectos
Efectos .show() .show(speed, callback) .hide() .hide(speed, callback) .toggle() .slideUp() .slideUp(speed,
callback) .slideDown() .slideDown(speed, callback) .fadeIn() .fadeIn(speed, callback) .fadeOut() .fadeOut(speed, callback) .fadeTo(speed, opacity, callback)
Efectos .show() .show(speed, callback) .hide() .hide(speed, callback) .toggle() .slideUp() .slideUp(speed,
callback) .slideDown() .slideDown(speed, callback) .fadeIn() .fadeIn(speed, callback) .fadeOut() .fadeOut(speed, callback) .fadeTo(speed, opacity, callback)
Efectos .animate(params, duration, easing, callback) .animate(params, options) .stop() .queue() .queue(callback)
.queue(queue) .dequeue()
$("#block").animate({ width: "70%", opacity: 0.4, marginLeft: "0.6in", fontSize: "3em", borderWidth:
"10px" }, 1500 );
AJAX
AJAX $.ajax(options) .load(url, data, callback) .loadIfModified (url, data, callback) $.get
(url, data, callback) $.post (url, data, callback) $.getJSON (url, data, callback) $.getScript (url, data, callback)
$.ajax({ url: "/contacts/search", {data: "q=choan"}, success: function(html){ $("#results").append(html); } });
$.get("/contacts/search", {data: "q=choan"}, function(html){ $("#results").append(html); } });
$("#results") .load("/contacts/search", data: "q=choan")
AJAX .ajaxComplete(callback) .ajaxSend(callback) .ajaxStart(callback) .ajaxStop(callback) .ajaxSuccess(callback) .ajaxError(callback)
AJAX .ajaxComplete(callback) .ajaxSend(callback) .ajaxStart(callback) .ajaxStop(callback) .ajaxSuccess(callback) .ajaxError(callback)
jRails - jQuery on Rails
Instalación ./script/plugin install \ http://ennerchi.googlecode.com/svn/trunk/plugins/jrails rake jrails:install:javascripts
Prototype form_remote_for form_remote_tag link_to_remote observe_field observe_form periodically_call_remote remote_form_for submit_to_remote Scriptaculous
draggable_element drop_receiving_element sortable_element visual_effect RJS hide insert_html remove replace replace_html show toggle Funcionalidad “Drop In”
$.ajaxSetup( { data: { authenticity_token : AUTH_TOKEN } }) $.post("/todo",
{_method:"put"}); $.post("/todo", _method:"put"); Caveat Emptor (#1)
jQuery $('#footerNav') Prototype $('footerNav') Caveat Emptor (#2)
Unobtrusive
¿Que es?
Ejemplo formulario <form class='remote' action="http://search.twitter.com/search"> <input type="text" value=""> <input type="submit"
value="Buscar"> </form> <div id='searchResults'> </div>
Ejemplo formulario $(function() { $('form.remote').each(function() { var url = $(this).attr('action');
$(this).find('input[@type=submit]:first').hide(); $(this).find('input[@type=text]:first') .keyup(function() { var query = $(this).val(); $('#searchResults').load( url + query + ' #results'); }); }); });
Plugins
Livequery $('a').livequery('click', function(event) { alert('clicked'); return false; });
Autocomplete var data = "blat mamuso denegro".split(" "); $("input.suggest").autocomplete(data); $("input.suggest").autocomplete("/contactos");
Autocomplete $("#imageSearch").autocomplete("/images", { width: 320, max: 4, highlight: false, scroll:
true, scrollHeight: 300, formatItem: function(data, i, n, value) { return "<img src='images/" + value + "'/> " + value.split(".")[0]; }, formatResult: function(data, value) { return value.split(".")[0]; } });
Tablesorter <table id="myTable"> <thead> <tr><th>Nombre</th><th>Apellido</th><th>Email</th></tr> </thead> <tbody> <tr><td>Smith</td><td>John</td><td>
[email protected]
</td></tr> <tr><td>Doe</td><td>John</td><td>
[email protected]
</td></tr> <tr><td>Jack</td><td>Ripper</td><td>
[email protected]
</td></tr>
<tbody> </table> $("#myTable").tablesorter();
jQuery form $('#myForm').ajaxForm(); $('#commentsForm').ajaxForm({ target: '#comments', url: '/comments', success: function()
{ alert('Hemos recibido tu comentario'); } });
jQuery UI Interaction Draggable Droppable Resizable Selectable Sortable Widgets Accordion
Autocomplete Colorpicker Dialog Slider Tabs Datepicker Magnifier Progressbar Spinner Effects "Blind" "Bounce" "Clip" "Drop" "Explode" "Fold" "Highlight" "Pulsate" "Scale" "Shake" "Slide" "Transfer"
¿El futuro? Sizzle + (V8, SpiderMonkey, SquirelFish)
¿Preguntas?