ajax 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +68 -25
- data/VERSION +1 -1
- data/public/javascripts/ajax.js +7 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -2,11 +2,73 @@
|
|
2
2
|
|
3
3
|
<b>Ajax augments a traditional Rails application with a completely AJAX frontend, while transparently handling issues important to both the enterprise and end users. Issues like SEO/Crawlability, browser history, deep-linking and testing.</b>
|
4
4
|
|
5
|
-
The Ajax philosophy is that
|
5
|
+
The Ajax philosophy is that you shouldn't have to develop for AJAX. Your code shouldn't change; your tests shouldn't change; and the way Google sees your site shouldn't change.
|
6
6
|
|
7
|
-
The beauty of Ajax is that your Rails application only ever sees traditional requests, so it does not have to be "Ajax aware".
|
7
|
+
The beauty of Ajax is that your Rails application only ever sees traditional requests, so it does not have to be "Ajax aware". The Ajax framework does not interfere with your existing AJAX requests. AJAX requests pass through the framework unmodified. If the request headers contain the special <i>Ajax-Info</i> header then we invoke some additional Ajax framework handling.
|
8
8
|
|
9
|
-
As of May 2010 Ajax is being used live in production on kazaa.com[http://www.kazaa.com]. Try it out and create
|
9
|
+
As of May 2010 Ajax is being used live in production on kazaa.com[http://www.kazaa.com]. Try it out and create some wicked playlists while you're at it!
|
10
|
+
|
11
|
+
== Getting Started
|
12
|
+
|
13
|
+
1. Ajax looks for a layout to use for an Ajax request in <tt>app/views/layouts/ajax/</tt>. It looks for a layout with the same name as the default Rails layout for that action. So copy your existing layouts into <tt>layouts/ajax/</tt> and get them ready for Ajax by removing any excess HTML, leaving just the content that will be inserted into the container.
|
14
|
+
|
15
|
+
Your main layout should contain a container element to receive page content. Typically this would be a container below your page header. If you don't have a static header, you can make the whole BODY element the container.
|
16
|
+
|
17
|
+
Here is an {example of converting our <tt>layouts/application.html.haml</tt> to <tt>layouts/ajax/application.html.haml</tt>}[http://gist.github.com/373133/5a80a63ef69a883ed3c5630b68330b1036ad01ec].
|
18
|
+
|
19
|
+
2. Instantiate an instance of the Ajax class in <tt>public/javascripts/application.js</tt>. For example:
|
20
|
+
|
21
|
+
// public/javascripts/application.js
|
22
|
+
if (typeof(Ajax) != 'undefined') {
|
23
|
+
window.ajax = new Ajax({
|
24
|
+
default_container: '#main', // jQuery selector of your container element
|
25
|
+
enabled: true, // Enable/disable the plugin
|
26
|
+
lazy_load_assets: false // YMMV
|
27
|
+
});
|
28
|
+
}
|
29
|
+
|
30
|
+
3. Add a <tt>data-deep-link</tt> attribute to links that you want to load using the Ajax framework. A jQuery live event automatically intercepts all clicks on links with this attribute and loads their content using the framework.
|
31
|
+
|
32
|
+
By default all links that use the Rails link helpers will include this attribute. When a link with this attribute is clicked, content is requested using AJAX and goes through the Ajax framework. Rails receives a request for content at the <tt>data-deep-link</tt> location. The content is rendered using the default layout for the action but from the <tt>app/views/layouts/ajax</tt> directory. The rendered content is received client-side and special Ajax headers are processed. The content is then inserted into the specified container, or the <tt>default_container</tt> defined in your Ajax JS class above.
|
33
|
+
|
34
|
+
4. To submit forms using the Ajax framework, or to manually request content using various request methods, you can call <tt>window.ajax.loadPage</tt>, passing in options like _url_, _method_ and _data_.
|
35
|
+
|
36
|
+
For example to handle form submissions with Ajax, you could use code like the following:
|
37
|
+
|
38
|
+
$('.radio-search form').live('submit', function(e) {
|
39
|
+
var form = $(e.target);
|
40
|
+
window.ajax.loadPage({
|
41
|
+
url: form.attr('action'),
|
42
|
+
method: 'POST',
|
43
|
+
data: form.serialize()
|
44
|
+
});
|
45
|
+
});
|
46
|
+
|
47
|
+
5. Specify a container to receive Ajax content on a per-action, per-controller, per-layout or dynamic basis using the <tt>ajax_header :container, '<jquery css selector>'</tt> helper method.
|
48
|
+
|
49
|
+
For example:
|
50
|
+
|
51
|
+
# app/views/layouts/ajax/two_column.html.haml
|
52
|
+
ajax_header :container, '#twocolumns'
|
53
|
+
|
54
|
+
6. Specify tabs that should be activated on a per-action, per-controller or dynamic basis using the <tt>ajax_header :tab, '<jquery css selector>'</tt> helper method. The element(s) that match the selector will have their _activate_ event triggered, so you will need to setup an event handler.
|
55
|
+
|
56
|
+
For example:
|
57
|
+
|
58
|
+
# app/controllers/pages_controller.rb
|
59
|
+
ajax_header :tab, '#header .nav li:contains(Tour)', :only => :tour
|
60
|
+
|
61
|
+
# public/javascripts/application.js
|
62
|
+
$('#header .nav li').live('activate', function() {
|
63
|
+
$(this).siblings().removeClass('active').end().addClass('active');
|
64
|
+
});
|
65
|
+
|
66
|
+
7. Specify paths that should bypass the Ajax framework. I.e. accessing these paths using a full URL (not a hashed URL), will render the page like in a traditional Rails app. If that path was not excepted the Ajax framework would have forced a redirect to the hashed version of the URL before rendering the page contents using Ajax. See <i>Excepted Links</i>.
|
67
|
+
|
68
|
+
For example:
|
69
|
+
|
70
|
+
# config/initializers/ajax.rb
|
71
|
+
Ajax.exclude_paths %w[ /login /logout /signup ]
|
10
72
|
|
11
73
|
== Install
|
12
74
|
|
@@ -60,25 +122,6 @@ As of May 2010 Ajax is being used live in production on kazaa.com[http://www.kaz
|
|
60
122
|
skipped: app/views/ajax/framework.html.erb exists!
|
61
123
|
...
|
62
124
|
|
63
|
-
== Getting Started
|
64
|
-
|
65
|
-
1. Ajax looks for an alternative layout to use with AJAX requests in <tt>app/views/layouts/ajax/</tt>. Copy existing layouts into this directory and get them ready for AJAX by removing any HTML HEAD elements, everything but the inner BODY content.
|
66
|
-
|
67
|
-
Your main layout should contain a container element that will receive page content. Typically this would be the container below the page header. If you don't have a static header, you can make the whole BODY element the container.
|
68
|
-
|
69
|
-
Here is an {example of converting our <tt>layouts/application.html.haml</tt> to <tt>layouts/ajax/application.html.haml</tt>}[http://gist.github.com/373133/5a80a63ef69a883ed3c5630b68330b1036ad01ec].
|
70
|
-
|
71
|
-
2. Instantiate an instance of the Ajax class in <tt>public/javascripts/application.js</tt>. For example:
|
72
|
-
|
73
|
-
// public/javascripts/application.js
|
74
|
-
if (typeof(Ajax) != 'undefined') {
|
75
|
-
window.ajax = new Ajax({
|
76
|
-
default_container: '#main', // jQuery selector of your container element
|
77
|
-
enabled: true, // Enable/disable the plugin
|
78
|
-
lazy_load_assets: false // YMMV
|
79
|
-
});
|
80
|
-
}
|
81
|
-
|
82
125
|
== Introduction
|
83
126
|
|
84
127
|
=== Features and Support
|
@@ -107,7 +150,7 @@ Where before you would have seen something like <tt>http://example.com/the-beatl
|
|
107
150
|
|
108
151
|
Ajax comprises Rack middleware, Rails integrations and some JavaScript libraries to handle everything from redirecting and rewriting incoming requests, to managing the response headers and content, to handling the browser URL, JavaScript callbacks and client-side events.
|
109
152
|
|
110
|
-
Browsers do not send the hashed part of the the URL with page requests, so to an
|
153
|
+
Browsers do not send the hashed part of the the URL with page requests, so to an Ajax-ed application, all requests look like they are for root.
|
111
154
|
|
112
155
|
In order to load the correct page we must first render a framework page with accompanying JavaScript. The JS examines the URL and then issues another request to the server for the hashed part (which may still be <tt>/</tt> if the user requested the home page).
|
113
156
|
|
@@ -232,9 +275,9 @@ Our layouts:
|
|
232
275
|
|
233
276
|
== Link Handling
|
234
277
|
|
235
|
-
<b>All links which are rendered using the <tt>link_to</tt> (or any other url) helper method automatically include a <tt>data-deep-link</tt> attribute</b> containing the path
|
278
|
+
<b>All links which are rendered using the <tt>link_to</tt> (or any other url) helper method automatically include a <tt>data-deep-link</tt> attribute</b> containing the path portion of the link's HREF URL.
|
236
279
|
|
237
|
-
The Ajax JavaScript class listens for clicks on any link with a <tt>data-deep-link</tt> attribute and loads the link's content using
|
280
|
+
The Ajax JavaScript class listens for clicks on any link with a <tt>data-deep-link</tt> attribute and loads the link's content using the Ajax framework.
|
238
281
|
|
239
282
|
Should you need to, you can set this attribute on a link by passing in HTML options to <tt>link_to</tt>:
|
240
283
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
data/public/javascripts/ajax.js
CHANGED
@@ -386,6 +386,11 @@ var Ajax = function(options) {
|
|
386
386
|
* [callback] Execute a callback after assets have loaded
|
387
387
|
*
|
388
388
|
* Cookies in the response are automatically set on the document.cookie.
|
389
|
+
*
|
390
|
+
* Options:
|
391
|
+
* url request url (required)
|
392
|
+
* method request method, default GET
|
393
|
+
* data request data
|
389
394
|
*/
|
390
395
|
self.loadPage = function(options) {
|
391
396
|
if (!self.enabled) {
|
@@ -415,7 +420,8 @@ var Ajax = function(options) {
|
|
415
420
|
self.current_request = jQuery.ajax({
|
416
421
|
cache: false,
|
417
422
|
url: safe_url,
|
418
|
-
|
423
|
+
data: options.data,
|
424
|
+
type: options.method ? options.method : 'GET',
|
419
425
|
beforeSend: self.setRequestHeaders,
|
420
426
|
success: self.responseHandler,
|
421
427
|
dataType: 'html',
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ajax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 5
|
10
|
+
version: 1.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Karl Varga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-06 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|