$30 off During Our Annual Pro Sale. View Details »
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
68
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
72
Other Decks in Programming
See All in Programming
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
400
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
ゲームの物理 剛体編
fadis
0
360
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
2
370
AIコーディングエージェント(Manus)
kondai24
0
200
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
130
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
870
愛される翻訳の秘訣
kishikawakatsumi
3
330
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
170
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
130
AIコーディングエージェント(skywork)
kondai24
0
190
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.1k
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
400
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
1
200
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.3k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
68
For a Future-Friendly Web
brad_frost
180
10k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Design in an AI World
tapps
0
92
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
290
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
75
Information Architects: The Missing Link in Design Systems
soysaucechin
0
710
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?