Created
October 20, 2010 16:41
-
-
Save mauricioszabo/636777 to your computer and use it in GitHub Desktop.
app/views/javascript/index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var applyToElements = function(bodies, selector, f) { | |
for(var i=0; i < bodies.length; i++) { | |
var elements = bodies[i].select(selector) | |
for(var i2=0; i2 < elements.length; i2++) { | |
f(elements[i2]) | |
} | |
} | |
} | |
document.on('ajax:complete', function(event) { | |
var bodies = document.getElementsByTagName('body') | |
var otherId = '[id=' + event.element().readAttribute('update') + ']' | |
applyToElements(bodies, '*[data-update=true]' + otherId, function(e) { | |
e.innerHTML = event.memo.responseText | |
}) | |
applyToElements(bodies, '*[data-update=top]' + otherId, function(e) { | |
e.innerHTML = event.memo.responseText + e.innerHTML | |
}) | |
applyToElements(bodies, '*[data-update=bottom]' + otherId, function(e) { | |
e.innerHTML = e.innerHTML + event.memo.responseText | |
}) | |
}) | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JavascriptController < ApplicationController | |
def index | |
end | |
def post | |
render :text => "#{rand(100000000)}<br />" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Javascript#index</h1> | |
<div data-update='bottom'> | |
Nada | |
</div> | |
<br /> | |
<div data-update='true'> | |
Zero | |
</div> | |
<%= link_to 'Randomizar', post_path, :remote => true, 'data-update-success' => 'wow' %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment