slug-engine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +35 -0
- data/Rakefile +39 -0
- data/app/controllers/permalinks_controller.rb +45 -0
- data/app/helpers/permalinks_helper.rb +2 -0
- data/app/models/permalink.rb +28 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20111108194929_create_permalinks.rb +11 -0
- data/lib/slug-engine.rb +1 -0
- data/lib/slug.rb +80 -0
- data/lib/slug/engine.rb +8 -0
- data/lib/slug/filter.rb +31 -0
- data/lib/slug/version.rb +3 -0
- data/lib/tasks/slug_tasks.rake +4 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/javascripts/posts.js +2 -0
- data/test/dummy/app/assets/javascripts/users.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/assets/stylesheets/posts.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/assets/stylesheets/users.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/posts_controller.rb +83 -0
- data/test/dummy/app/controllers/users_controller.rb +83 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/posts_helper.rb +2 -0
- data/test/dummy/app/helpers/users_helper.rb +2 -0
- data/test/dummy/app/models/post.rb +10 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/app/views/layouts/_application.html.erb +14 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/posts/_form.html.erb +29 -0
- data/test/dummy/app/views/posts/_post.html.erb +22 -0
- data/test/dummy/app/views/posts/edit.html.erb +6 -0
- data/test/dummy/app/views/posts/index.html.erb +27 -0
- data/test/dummy/app/views/posts/new.html.erb +5 -0
- data/test/dummy/app/views/posts/show.html.erb +1 -0
- data/test/dummy/app/views/users/_form.html.erb +25 -0
- data/test/dummy/app/views/users/edit.html.erb +6 -0
- data/test/dummy/app/views/users/index.html.erb +25 -0
- data/test/dummy/app/views/users/new.html.erb +5 -0
- data/test/dummy/app/views/users/show.html.erb +15 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20111108195813_create_posts.rb +10 -0
- data/test/dummy/db/migrate/20111108195947_create_users.rb +10 -0
- data/test/dummy/db/schema.rb +37 -0
- data/test/dummy/log/development.log +4475 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/posts.yml +9 -0
- data/test/dummy/test/fixtures/users.yml +9 -0
- data/test/dummy/test/functional/posts_controller_test.rb +49 -0
- data/test/dummy/test/functional/users_controller_test.rb +49 -0
- data/test/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/dummy/test/unit/post_test.rb +7 -0
- data/test/dummy/test/unit/user_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/C06/A00/sprockets%2Fe8698635e3a42938c23078559237f054 +0 -0
- data/test/dummy/tmp/cache/assets/CAA/620/sprockets%2F87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/test/dummy/tmp/cache/assets/CC7/5F0/sprockets%2F8bf37168fb70e08b9e4578e72739a543 +0 -0
- data/test/dummy/tmp/cache/assets/CDA/250/sprockets%2F9f6ba51c401a4b1885146d692f56dd20 +9051 -0
- data/test/dummy/tmp/cache/assets/CDF/070/sprockets%2F70e3c8a3916622c17858d520dcee0d92 +0 -0
- data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/D03/AF0/sprockets%2F79009b48c13f7b213134c8ac51caf65b +9051 -0
- data/test/dummy/tmp/cache/assets/D11/D20/sprockets%2Fcac21eac42152981882bf9e489316af4 +0 -0
- data/test/dummy/tmp/cache/assets/D1A/310/sprockets%2F5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/test/dummy/tmp/cache/assets/D23/E70/sprockets%2F8de174e8fa8a6828ee7fa348335900f4 +369 -0
- data/test/dummy/tmp/cache/assets/D2E/090/sprockets%2Fc54283e81ce52bf9d542ab12492a01ad +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D36/030/sprockets%2F63bdbca18172eaab4b20628e4399d663 +9048 -0
- data/test/dummy/tmp/cache/assets/D3E/B20/sprockets%2F1f79ee84bd6d74d100c5cb018b662b67 +0 -0
- data/test/dummy/tmp/cache/assets/D46/650/sprockets%2Ff56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
- data/test/dummy/tmp/cache/assets/D73/220/sprockets%2F3dbc0a37f98fb43ec819b85a64d32c55 +0 -0
- data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +9429 -0
- data/test/dummy/tmp/cache/assets/D9B/9C0/sprockets%2F4e197c078b17aea1ec1df9746ddf2a30 +372 -0
- data/test/dummy/tmp/cache/assets/D9C/CD0/sprockets%2Fc85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/test/dummy/tmp/cache/assets/DA1/4A0/sprockets%2Fb398851b563c62cf3bf4cbbad8c57d25 +369 -0
- data/test/dummy/tmp/cache/assets/DBA/AB0/sprockets%2F8be4208fd77cb5ef9b6f77e5fcf18670 +0 -0
- data/test/dummy/tmp/cache/assets/DC0/870/sprockets%2F289d3a70441ad26d24edcd25fd0dca6c +372 -0
- data/test/dummy/tmp/cache/assets/E03/E80/sprockets%2F4a6c93824e15c2d5fdfbbbf7cfdc3646 +9048 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E06/920/sprockets%2F6baa37d1c26468aef4fe5fe4bf982fa3 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/slug_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +291 -0
@@ -0,0 +1,372 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@expires_in0:@value{"asset_paths["|/Users/jcarlson/.rvm/gems/ruby-1.8.7-p72@has_permalink/gems/jquery-rails-1.0.16/vendor/assets/javascripts/jquery_ujs.js" body";/**
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.6.0 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
|
7
|
+
* Uploading file using rails.js
|
8
|
+
* =============================
|
9
|
+
*
|
10
|
+
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
|
11
|
+
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
|
12
|
+
*
|
13
|
+
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
|
14
|
+
*
|
15
|
+
* Ex:
|
16
|
+
* $('form').live('ajax:aborted:file', function(event, elements){
|
17
|
+
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
|
18
|
+
* // Returning false in this handler tells rails.js to disallow standard form submission
|
19
|
+
* return false;
|
20
|
+
* });
|
21
|
+
*
|
22
|
+
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
|
23
|
+
*
|
24
|
+
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
|
25
|
+
* techniques like the iframe method to upload the file instead.
|
26
|
+
*
|
27
|
+
* Required fields in rails.js
|
28
|
+
* ===========================
|
29
|
+
*
|
30
|
+
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
|
31
|
+
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
|
32
|
+
*
|
33
|
+
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
|
34
|
+
*
|
35
|
+
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
|
36
|
+
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
|
37
|
+
*
|
38
|
+
* Ex:
|
39
|
+
* $('form').live('ajax:aborted:required', function(event, elements){
|
40
|
+
* // Returning false in this handler tells rails.js to submit the form anyway.
|
41
|
+
* // The blank required inputs are passed to this function in `elements`.
|
42
|
+
* return ! confirm("Would you like to submit the form with missing info?");
|
43
|
+
* });
|
44
|
+
*/
|
45
|
+
|
46
|
+
|
47
|
+
(function($, undefined) {
|
48
|
+
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
49
|
+
var rails;
|
50
|
+
|
51
|
+
$.rails = rails = {
|
52
|
+
// Link elements bound by jquery-ujs
|
53
|
+
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
|
54
|
+
|
55
|
+
// Select elements bound by jquery-ujs
|
56
|
+
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
57
|
+
|
58
|
+
// Form elements bound by jquery-ujs
|
59
|
+
formSubmitSelector: 'form',
|
60
|
+
|
61
|
+
// Form input elements bound by jquery-ujs
|
62
|
+
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])',
|
63
|
+
|
64
|
+
// Form input elements disabled during form submission
|
65
|
+
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
|
66
|
+
|
67
|
+
// Form input elements re-enabled after form submission
|
68
|
+
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
|
69
|
+
|
70
|
+
// Form required input elements
|
71
|
+
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
|
72
|
+
|
73
|
+
// Form file input elements
|
74
|
+
fileInputSelector: 'input:file',
|
75
|
+
|
76
|
+
// Link onClick disable selector with possible reenable after remote submission
|
77
|
+
linkDisableSelector: 'a[data-disable-with]',
|
78
|
+
|
79
|
+
// Make sure that every Ajax request sends the CSRF token
|
80
|
+
CSRFProtection: function(xhr) {
|
81
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
82
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
83
|
+
},
|
84
|
+
|
85
|
+
// Triggers an event on an element and returns false if the event result is false
|
86
|
+
fire: function(obj, name, data) {
|
87
|
+
var event = $.Event(name);
|
88
|
+
obj.trigger(event, data);
|
89
|
+
return event.result !== false;
|
90
|
+
},
|
91
|
+
|
92
|
+
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
93
|
+
confirm: function(message) {
|
94
|
+
return confirm(message);
|
95
|
+
},
|
96
|
+
|
97
|
+
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
98
|
+
ajax: function(options) {
|
99
|
+
return $.ajax(options);
|
100
|
+
},
|
101
|
+
|
102
|
+
// Submits "remote" forms and links with ajax
|
103
|
+
handleRemote: function(element) {
|
104
|
+
var method, url, data,
|
105
|
+
crossDomain = element.data('cross-domain') || null,
|
106
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
|
107
|
+
options;
|
108
|
+
|
109
|
+
if (rails.fire(element, 'ajax:before')) {
|
110
|
+
|
111
|
+
if (element.is('form')) {
|
112
|
+
method = element.attr('method');
|
113
|
+
url = element.attr('action');
|
114
|
+
data = element.serializeArray();
|
115
|
+
// memoized value from clicked submit button
|
116
|
+
var button = element.data('ujs:submit-button');
|
117
|
+
if (button) {
|
118
|
+
data.push(button);
|
119
|
+
element.data('ujs:submit-button', null);
|
120
|
+
}
|
121
|
+
} else if (element.is(rails.inputChangeSelector)) {
|
122
|
+
method = element.data('method');
|
123
|
+
url = element.data('url');
|
124
|
+
data = element.serialize();
|
125
|
+
if (element.data('params')) data = data + "&" + element.data('params');
|
126
|
+
} else {
|
127
|
+
method = element.data('method');
|
128
|
+
url = element.attr('href');
|
129
|
+
data = element.data('params') || null;
|
130
|
+
}
|
131
|
+
|
132
|
+
options = {
|
133
|
+
type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
|
134
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
135
|
+
beforeSend: function(xhr, settings) {
|
136
|
+
if (settings.dataType === undefined) {
|
137
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
138
|
+
}
|
139
|
+
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
|
140
|
+
},
|
141
|
+
success: function(data, status, xhr) {
|
142
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
143
|
+
},
|
144
|
+
complete: function(xhr, status) {
|
145
|
+
element.trigger('ajax:complete', [xhr, status]);
|
146
|
+
},
|
147
|
+
error: function(xhr, status, error) {
|
148
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
149
|
+
}
|
150
|
+
};
|
151
|
+
// Only pass url to `ajax` options if not blank
|
152
|
+
if (url) { options.url = url; }
|
153
|
+
|
154
|
+
rails.ajax(options);
|
155
|
+
}
|
156
|
+
},
|
157
|
+
|
158
|
+
// Handles "data-method" on links such as:
|
159
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
160
|
+
handleMethod: function(link) {
|
161
|
+
var href = link.attr('href'),
|
162
|
+
method = link.data('method'),
|
163
|
+
target = link.attr('target'),
|
164
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
165
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
166
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
167
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
168
|
+
|
169
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
170
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
171
|
+
}
|
172
|
+
|
173
|
+
if (target) { form.attr('target', target); }
|
174
|
+
|
175
|
+
form.hide().append(metadata_input).appendTo('body');
|
176
|
+
form.submit();
|
177
|
+
},
|
178
|
+
|
179
|
+
/* Disables form elements:
|
180
|
+
- Caches element value in 'ujs:enable-with' data store
|
181
|
+
- Replaces element text with value of 'data-disable-with' attribute
|
182
|
+
- Sets disabled property to true
|
183
|
+
*/
|
184
|
+
disableFormElements: function(form) {
|
185
|
+
form.find(rails.disableSelector).each(function() {
|
186
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
187
|
+
element.data('ujs:enable-with', element[method]());
|
188
|
+
element[method](element.data('disable-with'));
|
189
|
+
element.prop('disabled', true);
|
190
|
+
});
|
191
|
+
},
|
192
|
+
|
193
|
+
/* Re-enables disabled form elements:
|
194
|
+
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
195
|
+
- Sets disabled property to false
|
196
|
+
*/
|
197
|
+
enableFormElements: function(form) {
|
198
|
+
form.find(rails.enableSelector).each(function() {
|
199
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
200
|
+
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
201
|
+
element.prop('disabled', false);
|
202
|
+
});
|
203
|
+
},
|
204
|
+
|
205
|
+
/* For 'data-confirm' attribute:
|
206
|
+
- Fires `confirm` event
|
207
|
+
- Shows the confirmation dialog
|
208
|
+
- Fires the `confirm:complete` event
|
209
|
+
|
210
|
+
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
211
|
+
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
212
|
+
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
213
|
+
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
214
|
+
*/
|
215
|
+
allowAction: function(element) {
|
216
|
+
var message = element.data('confirm'),
|
217
|
+
answer = false, callback;
|
218
|
+
if (!message) { return true; }
|
219
|
+
|
220
|
+
if (rails.fire(element, 'confirm')) {
|
221
|
+
answer = rails.confirm(message);
|
222
|
+
callback = rails.fire(element, 'confirm:complete', [answer]);
|
223
|
+
}
|
224
|
+
return answer && callback;
|
225
|
+
},
|
226
|
+
|
227
|
+
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
228
|
+
blankInputs: function(form, specifiedSelector, nonBlank) {
|
229
|
+
var inputs = $(), input,
|
230
|
+
selector = specifiedSelector || 'input,textarea';
|
231
|
+
form.find(selector).each(function() {
|
232
|
+
input = $(this);
|
233
|
+
// Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
|
234
|
+
if (nonBlank ? input.val() : !input.val()) {
|
235
|
+
inputs = inputs.add(input);
|
236
|
+
}
|
237
|
+
});
|
238
|
+
return inputs.length ? inputs : false;
|
239
|
+
},
|
240
|
+
|
241
|
+
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
242
|
+
nonBlankInputs: function(form, specifiedSelector) {
|
243
|
+
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
244
|
+
},
|
245
|
+
|
246
|
+
// Helper function, needed to provide consistent behavior in IE
|
247
|
+
stopEverything: function(e) {
|
248
|
+
$(e.target).trigger('ujs:everythingStopped');
|
249
|
+
e.stopImmediatePropagation();
|
250
|
+
return false;
|
251
|
+
},
|
252
|
+
|
253
|
+
// find all the submit events directly bound to the form and
|
254
|
+
// manually invoke them. If anyone returns false then stop the loop
|
255
|
+
callFormSubmitBindings: function(form) {
|
256
|
+
var events = form.data('events'), continuePropagation = true;
|
257
|
+
if (events !== undefined && events['submit'] !== undefined) {
|
258
|
+
$.each(events['submit'], function(i, obj){
|
259
|
+
if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
|
260
|
+
});
|
261
|
+
}
|
262
|
+
return continuePropagation;
|
263
|
+
},
|
264
|
+
|
265
|
+
// replace element's html with the 'data-disable-with' after storing original html
|
266
|
+
// and prevent clicking on it
|
267
|
+
disableElement: function(element) {
|
268
|
+
element.data('ujs:enable-with', element.html()); // store enabled state
|
269
|
+
element.html(element.data('disable-with')); // set to disabled state
|
270
|
+
element.bind('click.railsDisable', function(e) { // prevent further clicking
|
271
|
+
return rails.stopEverything(e)
|
272
|
+
});
|
273
|
+
},
|
274
|
+
|
275
|
+
// restore element to its original state which was disabled by 'disableElement' above
|
276
|
+
enableElement: function(element) {
|
277
|
+
if (element.data('ujs:enable-with') !== undefined) {
|
278
|
+
element.html(element.data('ujs:enable-with')); // set to old enabled state
|
279
|
+
// this should be element.removeData('ujs:enable-with')
|
280
|
+
// but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
|
281
|
+
element.data('ujs:enable-with', false); // clean up cache
|
282
|
+
}
|
283
|
+
element.unbind('click.railsDisable'); // enable element
|
284
|
+
}
|
285
|
+
|
286
|
+
};
|
287
|
+
|
288
|
+
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
289
|
+
|
290
|
+
$(rails.linkDisableSelector).live('ajax:complete', function() {
|
291
|
+
rails.enableElement($(this));
|
292
|
+
});
|
293
|
+
|
294
|
+
$(rails.linkClickSelector).live('click.rails', function(e) {
|
295
|
+
var link = $(this), method = link.data('method'), data = link.data('params');
|
296
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
297
|
+
|
298
|
+
if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
|
299
|
+
|
300
|
+
if (link.data('remote') !== undefined) {
|
301
|
+
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
|
302
|
+
rails.handleRemote(link);
|
303
|
+
return false;
|
304
|
+
} else if (link.data('method')) {
|
305
|
+
rails.handleMethod(link);
|
306
|
+
return false;
|
307
|
+
}
|
308
|
+
});
|
309
|
+
|
310
|
+
$(rails.inputChangeSelector).live('change.rails', function(e) {
|
311
|
+
var link = $(this);
|
312
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
313
|
+
|
314
|
+
rails.handleRemote(link);
|
315
|
+
return false;
|
316
|
+
});
|
317
|
+
|
318
|
+
$(rails.formSubmitSelector).live('submit.rails', function(e) {
|
319
|
+
var form = $(this),
|
320
|
+
remote = form.data('remote') !== undefined,
|
321
|
+
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
|
322
|
+
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
|
323
|
+
|
324
|
+
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
325
|
+
|
326
|
+
// skip other logic when required values are missing or file upload is present
|
327
|
+
if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
328
|
+
return rails.stopEverything(e);
|
329
|
+
}
|
330
|
+
|
331
|
+
if (remote) {
|
332
|
+
if (nonBlankFileInputs) {
|
333
|
+
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
|
334
|
+
}
|
335
|
+
|
336
|
+
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
337
|
+
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
338
|
+
if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
|
339
|
+
|
340
|
+
rails.handleRemote(form);
|
341
|
+
return false;
|
342
|
+
} else {
|
343
|
+
// slight timeout so that the submit button gets properly serialized
|
344
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
345
|
+
}
|
346
|
+
});
|
347
|
+
|
348
|
+
$(rails.formInputClickSelector).live('click.rails', function(event) {
|
349
|
+
var button = $(this);
|
350
|
+
|
351
|
+
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
352
|
+
|
353
|
+
// register the pressed submit button
|
354
|
+
var name = button.attr('name'),
|
355
|
+
data = name ? {name:name, value:button.val()} : null;
|
356
|
+
|
357
|
+
button.closest('form').data('ujs:submit-button', data);
|
358
|
+
});
|
359
|
+
|
360
|
+
$(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
|
361
|
+
if (this == event.target) rails.disableFormElements($(this));
|
362
|
+
});
|
363
|
+
|
364
|
+
$(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
|
365
|
+
if (this == event.target) rails.enableFormElements($(this));
|
366
|
+
});
|
367
|
+
|
368
|
+
})( jQuery );
|
369
|
+
"content_type"application/javascript"
|
370
|
+
class"BundledAsset"
|
371
|
+
mtime"2011-11-08T14:46:19-05:00"
|
372
|
+
mtimeIu: Time
|
Binary file
|
@@ -0,0 +1,369 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry :@expires_in0:@value{ "
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.6.0 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
|
7
|
+
* Uploading file using rails.js
|
8
|
+
* =============================
|
9
|
+
*
|
10
|
+
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
|
11
|
+
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
|
12
|
+
*
|
13
|
+
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
|
14
|
+
*
|
15
|
+
* Ex:
|
16
|
+
* $('form').live('ajax:aborted:file', function(event, elements){
|
17
|
+
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
|
18
|
+
* // Returning false in this handler tells rails.js to disallow standard form submission
|
19
|
+
* return false;
|
20
|
+
* });
|
21
|
+
*
|
22
|
+
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
|
23
|
+
*
|
24
|
+
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
|
25
|
+
* techniques like the iframe method to upload the file instead.
|
26
|
+
*
|
27
|
+
* Required fields in rails.js
|
28
|
+
* ===========================
|
29
|
+
*
|
30
|
+
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
|
31
|
+
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
|
32
|
+
*
|
33
|
+
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
|
34
|
+
*
|
35
|
+
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
|
36
|
+
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
|
37
|
+
*
|
38
|
+
* Ex:
|
39
|
+
* $('form').live('ajax:aborted:required', function(event, elements){
|
40
|
+
* // Returning false in this handler tells rails.js to submit the form anyway.
|
41
|
+
* // The blank required inputs are passed to this function in `elements`.
|
42
|
+
* return ! confirm("Would you like to submit the form with missing info?");
|
43
|
+
* });
|
44
|
+
*/
|
45
|
+
|
46
|
+
|
47
|
+
(function($, undefined) {
|
48
|
+
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
49
|
+
var rails;
|
50
|
+
|
51
|
+
$.rails = rails = {
|
52
|
+
// Link elements bound by jquery-ujs
|
53
|
+
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
|
54
|
+
|
55
|
+
// Select elements bound by jquery-ujs
|
56
|
+
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
57
|
+
|
58
|
+
// Form elements bound by jquery-ujs
|
59
|
+
formSubmitSelector: 'form',
|
60
|
+
|
61
|
+
// Form input elements bound by jquery-ujs
|
62
|
+
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])',
|
63
|
+
|
64
|
+
// Form input elements disabled during form submission
|
65
|
+
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
|
66
|
+
|
67
|
+
// Form input elements re-enabled after form submission
|
68
|
+
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
|
69
|
+
|
70
|
+
// Form required input elements
|
71
|
+
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
|
72
|
+
|
73
|
+
// Form file input elements
|
74
|
+
fileInputSelector: 'input:file',
|
75
|
+
|
76
|
+
// Link onClick disable selector with possible reenable after remote submission
|
77
|
+
linkDisableSelector: 'a[data-disable-with]',
|
78
|
+
|
79
|
+
// Make sure that every Ajax request sends the CSRF token
|
80
|
+
CSRFProtection: function(xhr) {
|
81
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
82
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
83
|
+
},
|
84
|
+
|
85
|
+
// Triggers an event on an element and returns false if the event result is false
|
86
|
+
fire: function(obj, name, data) {
|
87
|
+
var event = $.Event(name);
|
88
|
+
obj.trigger(event, data);
|
89
|
+
return event.result !== false;
|
90
|
+
},
|
91
|
+
|
92
|
+
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
93
|
+
confirm: function(message) {
|
94
|
+
return confirm(message);
|
95
|
+
},
|
96
|
+
|
97
|
+
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
98
|
+
ajax: function(options) {
|
99
|
+
return $.ajax(options);
|
100
|
+
},
|
101
|
+
|
102
|
+
// Submits "remote" forms and links with ajax
|
103
|
+
handleRemote: function(element) {
|
104
|
+
var method, url, data,
|
105
|
+
crossDomain = element.data('cross-domain') || null,
|
106
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
|
107
|
+
options;
|
108
|
+
|
109
|
+
if (rails.fire(element, 'ajax:before')) {
|
110
|
+
|
111
|
+
if (element.is('form')) {
|
112
|
+
method = element.attr('method');
|
113
|
+
url = element.attr('action');
|
114
|
+
data = element.serializeArray();
|
115
|
+
// memoized value from clicked submit button
|
116
|
+
var button = element.data('ujs:submit-button');
|
117
|
+
if (button) {
|
118
|
+
data.push(button);
|
119
|
+
element.data('ujs:submit-button', null);
|
120
|
+
}
|
121
|
+
} else if (element.is(rails.inputChangeSelector)) {
|
122
|
+
method = element.data('method');
|
123
|
+
url = element.data('url');
|
124
|
+
data = element.serialize();
|
125
|
+
if (element.data('params')) data = data + "&" + element.data('params');
|
126
|
+
} else {
|
127
|
+
method = element.data('method');
|
128
|
+
url = element.attr('href');
|
129
|
+
data = element.data('params') || null;
|
130
|
+
}
|
131
|
+
|
132
|
+
options = {
|
133
|
+
type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
|
134
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
135
|
+
beforeSend: function(xhr, settings) {
|
136
|
+
if (settings.dataType === undefined) {
|
137
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
138
|
+
}
|
139
|
+
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
|
140
|
+
},
|
141
|
+
success: function(data, status, xhr) {
|
142
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
143
|
+
},
|
144
|
+
complete: function(xhr, status) {
|
145
|
+
element.trigger('ajax:complete', [xhr, status]);
|
146
|
+
},
|
147
|
+
error: function(xhr, status, error) {
|
148
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
149
|
+
}
|
150
|
+
};
|
151
|
+
// Only pass url to `ajax` options if not blank
|
152
|
+
if (url) { options.url = url; }
|
153
|
+
|
154
|
+
rails.ajax(options);
|
155
|
+
}
|
156
|
+
},
|
157
|
+
|
158
|
+
// Handles "data-method" on links such as:
|
159
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
160
|
+
handleMethod: function(link) {
|
161
|
+
var href = link.attr('href'),
|
162
|
+
method = link.data('method'),
|
163
|
+
target = link.attr('target'),
|
164
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
165
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
166
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
167
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
168
|
+
|
169
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
170
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
171
|
+
}
|
172
|
+
|
173
|
+
if (target) { form.attr('target', target); }
|
174
|
+
|
175
|
+
form.hide().append(metadata_input).appendTo('body');
|
176
|
+
form.submit();
|
177
|
+
},
|
178
|
+
|
179
|
+
/* Disables form elements:
|
180
|
+
- Caches element value in 'ujs:enable-with' data store
|
181
|
+
- Replaces element text with value of 'data-disable-with' attribute
|
182
|
+
- Sets disabled property to true
|
183
|
+
*/
|
184
|
+
disableFormElements: function(form) {
|
185
|
+
form.find(rails.disableSelector).each(function() {
|
186
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
187
|
+
element.data('ujs:enable-with', element[method]());
|
188
|
+
element[method](element.data('disable-with'));
|
189
|
+
element.prop('disabled', true);
|
190
|
+
});
|
191
|
+
},
|
192
|
+
|
193
|
+
/* Re-enables disabled form elements:
|
194
|
+
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
195
|
+
- Sets disabled property to false
|
196
|
+
*/
|
197
|
+
enableFormElements: function(form) {
|
198
|
+
form.find(rails.enableSelector).each(function() {
|
199
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
200
|
+
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
201
|
+
element.prop('disabled', false);
|
202
|
+
});
|
203
|
+
},
|
204
|
+
|
205
|
+
/* For 'data-confirm' attribute:
|
206
|
+
- Fires `confirm` event
|
207
|
+
- Shows the confirmation dialog
|
208
|
+
- Fires the `confirm:complete` event
|
209
|
+
|
210
|
+
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
211
|
+
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
212
|
+
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
213
|
+
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
214
|
+
*/
|
215
|
+
allowAction: function(element) {
|
216
|
+
var message = element.data('confirm'),
|
217
|
+
answer = false, callback;
|
218
|
+
if (!message) { return true; }
|
219
|
+
|
220
|
+
if (rails.fire(element, 'confirm')) {
|
221
|
+
answer = rails.confirm(message);
|
222
|
+
callback = rails.fire(element, 'confirm:complete', [answer]);
|
223
|
+
}
|
224
|
+
return answer && callback;
|
225
|
+
},
|
226
|
+
|
227
|
+
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
228
|
+
blankInputs: function(form, specifiedSelector, nonBlank) {
|
229
|
+
var inputs = $(), input,
|
230
|
+
selector = specifiedSelector || 'input,textarea';
|
231
|
+
form.find(selector).each(function() {
|
232
|
+
input = $(this);
|
233
|
+
// Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
|
234
|
+
if (nonBlank ? input.val() : !input.val()) {
|
235
|
+
inputs = inputs.add(input);
|
236
|
+
}
|
237
|
+
});
|
238
|
+
return inputs.length ? inputs : false;
|
239
|
+
},
|
240
|
+
|
241
|
+
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
242
|
+
nonBlankInputs: function(form, specifiedSelector) {
|
243
|
+
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
244
|
+
},
|
245
|
+
|
246
|
+
// Helper function, needed to provide consistent behavior in IE
|
247
|
+
stopEverything: function(e) {
|
248
|
+
$(e.target).trigger('ujs:everythingStopped');
|
249
|
+
e.stopImmediatePropagation();
|
250
|
+
return false;
|
251
|
+
},
|
252
|
+
|
253
|
+
// find all the submit events directly bound to the form and
|
254
|
+
// manually invoke them. If anyone returns false then stop the loop
|
255
|
+
callFormSubmitBindings: function(form) {
|
256
|
+
var events = form.data('events'), continuePropagation = true;
|
257
|
+
if (events !== undefined && events['submit'] !== undefined) {
|
258
|
+
$.each(events['submit'], function(i, obj){
|
259
|
+
if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
|
260
|
+
});
|
261
|
+
}
|
262
|
+
return continuePropagation;
|
263
|
+
},
|
264
|
+
|
265
|
+
// replace element's html with the 'data-disable-with' after storing original html
|
266
|
+
// and prevent clicking on it
|
267
|
+
disableElement: function(element) {
|
268
|
+
element.data('ujs:enable-with', element.html()); // store enabled state
|
269
|
+
element.html(element.data('disable-with')); // set to disabled state
|
270
|
+
element.bind('click.railsDisable', function(e) { // prevent further clicking
|
271
|
+
return rails.stopEverything(e)
|
272
|
+
});
|
273
|
+
},
|
274
|
+
|
275
|
+
// restore element to its original state which was disabled by 'disableElement' above
|
276
|
+
enableElement: function(element) {
|
277
|
+
if (element.data('ujs:enable-with') !== undefined) {
|
278
|
+
element.html(element.data('ujs:enable-with')); // set to old enabled state
|
279
|
+
// this should be element.removeData('ujs:enable-with')
|
280
|
+
// but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
|
281
|
+
element.data('ujs:enable-with', false); // clean up cache
|
282
|
+
}
|
283
|
+
element.unbind('click.railsDisable'); // enable element
|
284
|
+
}
|
285
|
+
|
286
|
+
};
|
287
|
+
|
288
|
+
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
289
|
+
|
290
|
+
$(rails.linkDisableSelector).live('ajax:complete', function() {
|
291
|
+
rails.enableElement($(this));
|
292
|
+
});
|
293
|
+
|
294
|
+
$(rails.linkClickSelector).live('click.rails', function(e) {
|
295
|
+
var link = $(this), method = link.data('method'), data = link.data('params');
|
296
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
297
|
+
|
298
|
+
if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
|
299
|
+
|
300
|
+
if (link.data('remote') !== undefined) {
|
301
|
+
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
|
302
|
+
rails.handleRemote(link);
|
303
|
+
return false;
|
304
|
+
} else if (link.data('method')) {
|
305
|
+
rails.handleMethod(link);
|
306
|
+
return false;
|
307
|
+
}
|
308
|
+
});
|
309
|
+
|
310
|
+
$(rails.inputChangeSelector).live('change.rails', function(e) {
|
311
|
+
var link = $(this);
|
312
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
313
|
+
|
314
|
+
rails.handleRemote(link);
|
315
|
+
return false;
|
316
|
+
});
|
317
|
+
|
318
|
+
$(rails.formSubmitSelector).live('submit.rails', function(e) {
|
319
|
+
var form = $(this),
|
320
|
+
remote = form.data('remote') !== undefined,
|
321
|
+
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
|
322
|
+
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
|
323
|
+
|
324
|
+
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
325
|
+
|
326
|
+
// skip other logic when required values are missing or file upload is present
|
327
|
+
if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
328
|
+
return rails.stopEverything(e);
|
329
|
+
}
|
330
|
+
|
331
|
+
if (remote) {
|
332
|
+
if (nonBlankFileInputs) {
|
333
|
+
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
|
334
|
+
}
|
335
|
+
|
336
|
+
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
337
|
+
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
338
|
+
if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
|
339
|
+
|
340
|
+
rails.handleRemote(form);
|
341
|
+
return false;
|
342
|
+
} else {
|
343
|
+
// slight timeout so that the submit button gets properly serialized
|
344
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
345
|
+
}
|
346
|
+
});
|
347
|
+
|
348
|
+
$(rails.formInputClickSelector).live('click.rails', function(event) {
|
349
|
+
var button = $(this);
|
350
|
+
|
351
|
+
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
352
|
+
|
353
|
+
// register the pressed submit button
|
354
|
+
var name = button.attr('name'),
|
355
|
+
data = name ? {name:name, value:button.val()} : null;
|
356
|
+
|
357
|
+
button.closest('form').data('ujs:submit-button', data);
|
358
|
+
});
|
359
|
+
|
360
|
+
$(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
|
361
|
+
if (this == event.target) rails.disableFormElements($(this));
|
362
|
+
});
|
363
|
+
|
364
|
+
$(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
|
365
|
+
if (this == event.target) rails.enableFormElements($(this));
|
366
|
+
});
|
367
|
+
|
368
|
+
})( jQuery );
|
369
|
+
:@compressedF:@created_atf1320783175.514503�
|