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
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
atmaCup #23でAIコーディングを活用した話
ml_bear
4
740
Rubyと楽しいをつくる / Creating joy with Ruby
chobishiba
0
200
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
350
Geminiの機能を調べ尽くしてみた
naruyoshimi
0
200
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
1.6k
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
640
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
380
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
110
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
420
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
120
Fundamentals of Software Engineering In the Age of AI
therealdanvega
0
160
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
440
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
220
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
210
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Prompt Engineering for Job Search
mfonobong
0
180
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Rails Girls Zürich Keynote
gr2m
96
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
280
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
130
Information Architects: The Missing Link in Design Systems
soysaucechin
0
810
Speed Design
sergeychernyshev
33
1.6k
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?