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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Christos Zisopoulos
September 26, 2011
Programming
75
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
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
980
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
230
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
220
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
230
A2UI という光を覗いてみる
satohjohn
1
160
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
1
490
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
110
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
310
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
200
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
270
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.3k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Designing Experiences People Love
moore
143
24k
Claude Code のすすめ
schroneko
67
230k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
220
The Curious Case for Waylosing
cassininazir
1
410
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
160
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
HDC tutorial
michielstock
2
720
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Test your architecture with Archunit
thirion
1
2.3k
Facilitating Awesome Meetings
lara
57
7k
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?