Skip to content

Commit

Permalink
Updated to latest jquery_ujs.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JangoSteve committed Feb 8, 2013
1 parent 84d94df commit 9e1eb79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lib/jquery/rails/version.rb
Expand Up @@ -3,6 +3,6 @@ module Rails
VERSION = "2.2.0"
JQUERY_VERSION = "1.9.0"
JQUERY_UI_VERSION = "1.9.2"
JQUERY_UJS_VERSION = "bddff6a677edc54f00e48bde740b0b22d68deef6"
JQUERY_UJS_VERSION = "aab2251d90afbdfc808d8031312d063b1ccf8f6f"
end
end
66 changes: 17 additions & 49 deletions vendor/assets/javascripts/jquery_ujs.js
Expand Up @@ -2,47 +2,12 @@

/**
* Unobtrusive scripting adapter for jQuery
*
* Requires jQuery 1.6.0 or later.
* https://github.com/rails/jquery-ujs
* Uploading file using rails.js
* =============================
*
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
*
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
*
* Ex:
* $('form').bind('ajax:aborted:file', function(event, elements){
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
* // Returning false in this handler tells rails.js to disallow standard form submission
* return false;
* });
*
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
*
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
* techniques like the iframe method to upload the file instead.
*
* Required fields in rails.js
* ===========================
*
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
*
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
* Requires jQuery 1.7.0 or later.
*
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
* Released under the MIT license
*
* Ex:
* $('form').bind('ajax:aborted:required', function(event, elements){
* // Returning false in this handler tells rails.js to submit the form anyway.
* // The blank required inputs are passed to this function in `elements`.
* return ! confirm("Would you like to submit the form with missing info?");
* });
*/

// Cut down on the number if issues from people inadvertently including jquery_ujs twice
Expand Down Expand Up @@ -82,7 +47,7 @@
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',

// Form file input elements
fileInputSelector: 'input:file',
fileInputSelector: 'input[type=file]',

// Link onClick disable selector with possible reenable after remote submission
linkDisableSelector: 'a[data-disable-with]',
Expand Down Expand Up @@ -118,17 +83,12 @@
// Submits "remote" forms and links with ajax
handleRemote: function(element) {
var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options;
var xhrFields = {};

if (rails.fire(element, 'ajax:before')) {
elCrossDomain = element.data('cross-domain');
crossDomain = elCrossDomain === undefined ? null : elCrossDomain;
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
withCredentials = element.data('with-credentials') || null;

if (withCredentials) {
xhrFields["withCredentials"] = withCredentials;
}
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);

if (element.is('form')) {
method = element.attr('method');
Expand Down Expand Up @@ -169,9 +129,17 @@
error: function(xhr, status, error) {
element.trigger('ajax:error', [xhr, status, error]);
},
xhrFields: xhrFields,
crossDomain: crossDomain
};

// There is no withCredentials for IE6-8 when
// "Enable native XMLHTTP support" is disabled
if (withCredentials) {
options.xhrFields = {
withCredentials: withCredentials
};
}

// Only pass url to `ajax` options if not blank
if (url) { options.url = url; }

Expand Down Expand Up @@ -260,12 +228,12 @@

allInputs.each(function() {
input = $(this);
valueToCheck = input.is(':checkbox,:radio') ? input.is(':checked') : input.val();
valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
// If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
if (!valueToCheck === !nonBlank) {

// Don't count unchecked required radio if other radio with same name is checked
if (input.is(':radio') && allInputs.filter('input:radio:checked[name="' + input.attr('name') + '"]').length) {
if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
return true; // Skip to next input
}

Expand Down Expand Up @@ -423,8 +391,8 @@

$(function(){
// making sure that all forms have actual up-to-date token(cached forms contain old one)
csrf_token = $('meta[name=csrf-token]').attr('content');
csrf_param = $('meta[name=csrf-param]').attr('content');
var csrf_token = $('meta[name=csrf-token]').attr('content');
var csrf_param = $('meta[name=csrf-param]').attr('content');
$('form input[name="' + csrf_param + '"]').val(csrf_token);
});
}
Expand Down

0 comments on commit 9e1eb79

Please sign in to comment.