Skip to content

Commit

Permalink
Updated to latest jquery-ujs, delegate and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JangoSteve committed Nov 26, 2011
1 parent 546029a commit 859e374
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/jquery/rails/version.rb
Expand Up @@ -3,6 +3,6 @@ module Rails
VERSION = "1.0.18"
JQUERY_VERSION = "1.7.0"
JQUERY_UI_VERSION = "1.8.16"
JQUERY_UJS_VERSION = "4fe37537cb2d8e71005303d3acb469e6205d26db"
JQUERY_UJS_VERSION = "82292010fb1743f038ab72b1f1e994e91be3eda3"
end
end
27 changes: 16 additions & 11 deletions vendor/assets/javascripts/jquery_ujs.js
Expand Up @@ -52,8 +52,8 @@
// Link elements bound by jquery-ujs
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',

// Select elements bound by jquery-ujs
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
// Select elements bound by jquery-ujs
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',

// Form elements bound by jquery-ujs
formSubmitSelector: 'form',
Expand Down Expand Up @@ -151,7 +151,9 @@
// Only pass url to `ajax` options if not blank
if (url) { options.url = url; }

rails.ajax(options);
return rails.ajax(options);
} else {
return false;
}
},

Expand Down Expand Up @@ -287,35 +289,37 @@

$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});

$(rails.linkDisableSelector).live('ajax:complete', function() {
$(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
rails.enableElement($(this));
});

$(rails.linkClickSelector).live('click.rails', function(e) {
$(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
var link = $(this), method = link.data('method'), data = link.data('params');
if (!rails.allowAction(link)) return rails.stopEverything(e);

if (link.is(rails.linkDisableSelector)) rails.disableElement(link);

if (link.data('remote') !== undefined) {
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
rails.handleRemote(link);

if (rails.handleRemote(link) === false) { rails.enableElement(link); }
return false;

} else if (link.data('method')) {
rails.handleMethod(link);
return false;
}
});

$(rails.inputChangeSelector).live('change.rails', function(e) {
$(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
var link = $(this);
if (!rails.allowAction(link)) return rails.stopEverything(e);

rails.handleRemote(link);
return false;
});

$(rails.formSubmitSelector).live('submit.rails', function(e) {
$(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
var form = $(this),
remote = form.data('remote') !== undefined,
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
Expand All @@ -339,13 +343,14 @@

rails.handleRemote(form);
return false;

} else {
// slight timeout so that the submit button gets properly serialized
setTimeout(function(){ rails.disableFormElements(form); }, 13);
}
});

$(rails.formInputClickSelector).live('click.rails', function(event) {
$(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
var button = $(this);

if (!rails.allowAction(button)) return rails.stopEverything(event);
Expand All @@ -357,11 +362,11 @@
button.closest('form').data('ujs:submit-button', data);
});

$(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
$(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
if (this == event.target) rails.disableFormElements($(this));
});

$(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
$(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
if (this == event.target) rails.enableFormElements($(this));
});

Expand Down

0 comments on commit 859e374

Please sign in to comment.