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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Christos Zisopoulos
September 26, 2011
Programming
74
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
jQuery y Rails - Take a walk on the wild side
Christos Zisopoulos
September 26, 2011
More Decks by Christos Zisopoulos
See All by Christos Zisopoulos
Building a Boring Pub Sub(madrid.rb Feb 2025)
christos
0
100
Other Decks in Programming
See All in Programming
GitHub Copilot CLIのいいところ
htkym
2
1.3k
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
540
AIとRubyの静的型付け
ukin0k0
0
540
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.5k
Webフレームワークの ベンチマークについて
yusukebe
0
130
さぁV100、メモリをお食べ・・・
nilpe
0
130
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
300
AI時代のUIはどこへ行く?その2!
yusukebe
19
6.6k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
970
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.1k
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
590
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
190
Featured
See All Featured
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
420
Into the Great Unknown - MozCon
thekraken
41
2.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
150
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
4 Signs Your Business is Dying
shpigford
187
22k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
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?