SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 267 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

openWith(this.href);
return false;
}
});
Here you??™re using an attribute selector to select all the elements with a rel attribute of
help and triggering Help.openWith(), passing the link??™s href when it is clicked. As with normal
event handlers, returning false will stop the default action of the link so you don??™t get taken
off to the help page.
You??™re now ready to test it, so let??™s include application.js in the page by updating the
application layout:
<%= javascript_include_tag 'prototype', 'lowpro', 'moofx', 'application' %>
When clicking any of the help links, you should now get the help content in the sidebar??”
but you aren??™t quite there yet. At the moment, the help content comes with a whole HTML page
wrapped around it, but you just want to inject the inner content. To implement this you need to
return to the Rails help controller (app/controllers/help_controller.rb) and adjust it so that if
the page is requested via Ajax, you return the content with a different layout:
class HelpController < ApplicationController
def show
template = '/help/' + params[:path].join('/')
if request.xhr?
render :template => template, :layout => 'help_sidebar'
else
render :template => template, :layout => 'help'
end
end
end
CHAPTER 9 n A DYNAMIC HELP SYSTEM 199
You??™ve added a condition to test whether the request does come from XMLHttpRequest (a.k.a.
Ajax) and then send the same template, but with the help_sidebar layout instead.


Pages:
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6