From a59f28f0a7e68214985c1fb591ea6766125d45c8 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Mon, 19 Nov 2012 15:30:18 -0500 Subject: [PATCH 001/148] Replace deprecated input:file with input[type=file] selector. --- src/rails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index df9dc862..ac4f7dc0 100644 --- a/src/rails.js +++ b/src/rails.js @@ -82,7 +82,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]', From 3014cd54a178c23fb2ecfe9c55ef258707988cb4 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Mon, 19 Nov 2012 15:40:50 -0500 Subject: [PATCH 002/148] Replace deprecated :checkbox and :radio with [type=checkbox] and [type=radio] selectors. --- src/rails.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index ac4f7dc0..ec8d5d95 100644 --- a/src/rails.js +++ b/src/rails.js @@ -257,12 +257,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 } From b1c482f55c8674168720c1f886af63799f7eb809 Mon Sep 17 00:00:00 2001 From: Edgars Beigarts Date: Thu, 3 Jan 2013 11:26:49 +0200 Subject: [PATCH 003/148] Avoid setting withCredentials to null. Fixes #295. Fixes #279. --- src/rails.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index df9dc862..05e369ac 100644 --- a/src/rails.js +++ b/src/rails.js @@ -164,11 +164,17 @@ error: function(xhr, status, error) { element.trigger('ajax:error', [xhr, status, error]); }, - xhrFields: { - withCredentials: withCredentials - }, 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; } From 6927b82cadf3146c2b9ae3028e9b197af64011ca Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 15:27:52 -0500 Subject: [PATCH 004/148] Added support for jquery 1.8.3 --- test/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/server.rb b/test/server.rb index afa1a19f..a9abe258 100644 --- a/test/server.rb +++ b/test/server.rb @@ -1,7 +1,7 @@ require 'sinatra' require 'json' -JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 ].freeze +JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 ].freeze use Rack::Static, :urls => ["/src"], :root => File.expand_path('..', settings.root) @@ -48,7 +48,7 @@ def jquery_versions end get '/' do - params[:version] ||= '1.8.2' + params[:version] ||= '1.8.3' params[:cdn] ||= 'jquery' erb :index end From f32a303d6baf8013320cba2f8b350c71266fdfc5 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 16:24:45 -0500 Subject: [PATCH 005/148] Added jquery 1.9.2 to test suite --- test/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/server.rb b/test/server.rb index a9abe258..0bf7052c 100644 --- a/test/server.rb +++ b/test/server.rb @@ -1,7 +1,7 @@ require 'sinatra' require 'json' -JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 ].freeze +JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 ].freeze use Rack::Static, :urls => ["/src"], :root => File.expand_path('..', settings.root) From 212e71ee3ae2d75b8a605565729e3fe2bb8b702c Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 16:25:29 -0500 Subject: [PATCH 006/148] Fixed issue with binding to 'iframe:loaded' event on form with jquery 1.9 --- test/public/test/data-disable.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/public/test/data-disable.js b/test/public/test/data-disable.js index d80a5102..29faa888 100644 --- a/test/public/test/data-disable.js +++ b/test/public/test/data-disable.js @@ -21,6 +21,9 @@ module('data-disable', { href: '/echo', 'data-disable-with': 'clicking...' })); + }, + teardown: function() { + $(document).unbind('iframe:loaded'); } }); @@ -82,14 +85,15 @@ asyncTest('form input[type=submit][data-disable-with] disables', 6, function(){ checkEnabledState(input, 'Submit'); // WEEIRDD: attaching this handler makes the test work in IE7 - form.bind('iframe:loading', function(e, form) {}); + $(document).bind('iframe:loading', function(e, form) {}); - form.bind('iframe:loaded', function(e, data) { + $(document).bind('iframe:loaded', function(e, data) { setTimeout(function() { checkDisabledState(input, 'submitting ...'); start(); }, 30); - }).trigger('submit'); + }); + form.trigger('submit'); setTimeout(function() { checkDisabledState(input, 'submitting ...'); From f22f74aae4fff766b321fc34244ff4acd61ddfa2 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 16:36:16 -0500 Subject: [PATCH 007/148] Removed all instances of .live() and .die() in docs and test suite --- src/rails.js | 4 +-- test/public/test/call-remote-callbacks.js | 32 +++++++++++------------ test/public/test/data-disable.js | 8 +++--- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/rails.js b/src/rails.js index df9dc862..087d5eb6 100644 --- a/src/rails.js +++ b/src/rails.js @@ -15,7 +15,7 @@ * The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish. * * Ex: - * $('form').live('ajax:aborted:file', function(event, elements){ + * $('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; @@ -38,7 +38,7 @@ * get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior. * * Ex: - * $('form').live('ajax:aborted:required', function(event, elements){ + * $('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?"); diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index ecba5013..7536487c 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -7,10 +7,10 @@ module('call-remote-callbacks', { })); }, teardown: function() { - $('form[data-remote]').die('ajax:beforeSend'); - $('form[data-remote]').die('ajax:before'); - $('form[data-remote]').die('ajax:complete'); - $('form[data-remote]').die('ajax:success'); + $(document).undelegate('form[data-remote]', 'ajax:beforeSend'); + $(document).undelegate('form[data-remote]', 'ajax:before'); + $(document).undelegate('form[data-remote]', 'ajax:complete'); + $(document).undelegate('form[data-remote]', 'ajax:success'); } }); @@ -29,7 +29,7 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque $('form[data-remote]') .append($('')) .append($('')) - .live('ajax:before', function() { + .bind('ajax:before', function() { var form = $(this); form .append($('',{name: 'other_user_name',value: 'jonathan'})) @@ -49,7 +49,7 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque asyncTest('modifying data("type") with "ajax:before" requests new dataType in request', 2, function(){ $('form[data-remote]').data('type','html') - .live('ajax:before', function() { + .bind('ajax:before', function() { var form = $(this); form.data('type','xml') }); @@ -63,7 +63,7 @@ asyncTest('modifying data("type") with "ajax:before" requests new dataType in re asyncTest('setting data("cross-domain",true) with "ajax:before" uses new setting in request', 2, function(){ $('form[data-remote]').data('cross-domain',false) - .live('ajax:before', function() { + .bind('ajax:before', function() { var form = $(this); form.data('cross-domain',true) }); @@ -77,7 +77,7 @@ asyncTest('setting data("cross-domain",true) with "ajax:before" uses new setting asyncTest('setting data("with-credentials",true) with "ajax:before" uses new setting in request', 2, function(){ $('form[data-remote]').data('with-credentials',false) - .live('ajax:before', function() { + .bind('ajax:before', function() { var form = $(this); form.data('with-credentials',true); }); @@ -304,7 +304,7 @@ function skipIt() { } asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation', 1, function() { - $('form[data-remote]').live('ajax:beforeSend', function() { + $(document).delegate('form[data-remote]', 'ajax:beforeSend', function() { ok(true, 'ajax:beforeSend observed with event delegation'); return false; }); @@ -353,18 +353,18 @@ asyncTest('"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on }); // IF THIS TEST IS FAILING, TRY INCREASING THE TIMEOUT AT THE BOTTOM TO > 100 -asyncTest('binding to ajax callbacks via .live() triggers handlers properly', 3, function() { - $('form[data-remote]') - .live('ajax:beforeSend', function() { +asyncTest('binding to ajax callbacks via .delegate() triggers handlers properly', 3, function() { + $(document) + .delegate('form[data-remote]', 'ajax:beforeSend', function() { ok(true, 'ajax:beforeSend handler is triggered'); }) - .live('ajax:complete', function() { + .delegate('form[data-remote]', 'ajax:complete', function() { ok(true, 'ajax:complete handler is triggered'); }) - .live('ajax:success', function() { + .delegate('form[data-remote]', 'ajax:success', function() { ok(true, 'ajax:success handler is triggered'); - }) - .trigger('submit'); + }); + $('form[data-remote]').trigger('submit'); setTimeout(function() { start(); diff --git a/test/public/test/data-disable.js b/test/public/test/data-disable.js index 29faa888..241c1583 100644 --- a/test/public/test/data-disable.js +++ b/test/public/test/data-disable.js @@ -162,9 +162,11 @@ asyncTest('a[data-remote][data-disable-with] disables and re-enables', 6, functi .bind('ajax:beforeSend', function() { checkDisabledState(link, 'clicking...'); }) - .live('ajax:complete', function() { - checkEnabledState(link, 'Click me'); - start(); + .bind('ajax:complete', function() { + setTimeout( function() { + checkEnabledState(link, 'Click me'); + start(); + }, 15); }) .trigger('click'); }); From 8409edbdc937abe297f0cb972ab73fe7a57fdcd1 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 17:12:35 -0500 Subject: [PATCH 008/148] Rebound instances of ajaxStop to document, where jquery 1.9 now only fires them --- test/public/test/call-remote-callbacks.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index 7536487c..3b0ecade 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -11,6 +11,7 @@ module('call-remote-callbacks', { $(document).undelegate('form[data-remote]', 'ajax:before'); $(document).undelegate('form[data-remote]', 'ajax:complete'); $(document).undelegate('form[data-remote]', 'ajax:success'); + $(document).unbind('ajaxStop'); } }); @@ -101,7 +102,7 @@ asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function form.bind('ajax:error', function(e, xhr, status, error) { ok(false, 'ajax:error should not run'); }); - form.bind('ajaxStop', function() { + $(document).bind('ajaxStop', function() { start(); }); }); @@ -313,7 +314,7 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation', form.unbind('ajax:complete').bind('ajax:complete', function() { ok(false, 'ajax:complete should not run'); }); - form.bind('ajaxStop', function() { + $(document).bind('ajaxStop', function() { start(); }); }); From a2caea88ec87e1cc0d064cc669d8f631954abe21 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 17:19:39 -0500 Subject: [PATCH 009/148] More iframe:loading fixes for jquery 1.9 --- test/public/test/call-remote-callbacks.js | 22 +++++++++++++--------- test/public/test/data-method.js | 14 +++++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index 3b0ecade..60bff422 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -12,6 +12,7 @@ module('call-remote-callbacks', { $(document).undelegate('form[data-remote]', 'ajax:complete'); $(document).undelegate('form[data-remote]', 'ajax:success'); $(document).unbind('ajaxStop'); + $(document).unbind('iframe:loading'); } }); @@ -109,15 +110,16 @@ asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function }); asyncTest('blank required form input field should abort request and trigger "ajax:aborted:required" event', 5, function() { + $(document).bind('iframe:loading', function() { + ok(false, 'form should not get submitted'); + }); + var form = $('form[data-remote]') .append($('')) .append($('')) .bind('ajax:beforeSend', function() { ok(false, 'ajax:beforeSend should not run'); }) - .bind('iframe:loading', function() { - ok(false, 'form should not get submitted'); - }) .bind('ajax:aborted:required', function(e,data){ ok(data.length == 2, 'ajax:aborted:required event is passed all blank required inputs (jQuery objects)'); ok(data.first().is('input[name="user_name"]') , 'ajax:aborted:required adds blank required input to data'); @@ -192,13 +194,14 @@ asyncTest('form should be submitted with blank required fields if it has the "no }); asyncTest('blank required form input for non-remote form with "novalidate" attribute should not abort normal submission', 1, function() { + $(document).bind('iframe:loading', function() { + ok(true, 'form should get submitted'); + }); + var form = $('form[data-remote]') .append($('')) .removeAttr('data-remote') .attr("novalidate","novalidate") - .bind('iframe:loading', function() { - ok(true, 'form should get submitted'); - }) .trigger('submit'); setTimeout(function() { @@ -236,13 +239,14 @@ asyncTest('unchecked required radio should abort form submission', 1, function() }); asyncTest('required radio should only require one to be checked', 1, function() { + $(document).bind('iframe:loading', function() { + ok(true, 'form should get submitted'); + }); + var form = $('form[data-remote]') .append($('')) .append($('')) .removeAttr('data-remote') - .bind('iframe:loading', function() { - ok(true, 'form should get submitted'); - }) .bind('ujs:everythingStopped', function() { ok(false, 'ujs:everythingStopped should not run'); }) diff --git a/test/public/test/data-method.js b/test/public/test/data-method.js index 40e99210..c4426624 100644 --- a/test/public/test/data-method.js +++ b/test/public/test/data-method.js @@ -5,16 +5,20 @@ module('data-method', { $('#qunit-fixture').append($('', { href: '/echo', 'data-method': 'delete', text: 'destroy!' })); + }, + teardown: function() { + $(document).unbind('iframe:loaded'); } }); function submit(fn, options) { + $(document).bind('iframe:loaded', function(e, data) { + fn(data); + start(); + }); + $('#qunit-fixture').find('a') - .bind('iframe:loaded', function(e, data) { - fn(data); - start(); - }) - .trigger('click'); + .trigger('click'); } asyncTest('link with "data-method" set to "delete"', 3, function() { From 22068f3913e3ca7e987c12a624f76dfce5ae7b96 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 19:03:07 -0500 Subject: [PATCH 010/148] Fixed click binding modifier test in IE --- test/public/test/override.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/public/test/override.js b/test/public/test/override.js index 92119ea2..6ce632d4 100644 --- a/test/public/test/override.js +++ b/test/public/test/override.js @@ -41,9 +41,11 @@ asyncTest("the getter for an element's href works normally if not overridden", 1 asyncTest("the event selector strings are overridable", 2, function() { var documentClickBindings = $._data(document, 'events').click, linkClickBinding = $.grep(documentClickBindings, function(a) { - return a.selector.indexOf('a[data-remote]') != -1; + return a.selector && a.selector.indexOf('a[data-remote]') != -1; })[0]; + //var documentClickBindings = "", linkClickBinding = {selector: ""}; + ok($.rails.linkClickSelector.indexOf(', a[data-custom-remote-link]') != -1, 'linkClickSelector contains custom selector'); ok(linkClickBinding.selector.indexOf(', a[data-custom-remote-link]') != -1, 'actual document binding contains custom selector'); From cc356656cc3edf1596fd685265187d2f75d1bc7c Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 18 Jan 2013 23:21:58 -0500 Subject: [PATCH 011/148] Official support for jquery 1.9.0 --- test/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/server.rb b/test/server.rb index 0bf7052c..8a2412c9 100644 --- a/test/server.rb +++ b/test/server.rb @@ -48,7 +48,7 @@ def jquery_versions end get '/' do - params[:version] ||= '1.8.3' + params[:version] ||= '1.9.0' params[:cdn] ||= 'jquery' erb :index end From fd9f043dae22c66e07cf9f470a77c3c458d40d31 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Sat, 19 Jan 2013 12:18:56 -0500 Subject: [PATCH 012/148] Removed debugging comment from test suite. --- test/public/test/override.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/public/test/override.js b/test/public/test/override.js index 6ce632d4..ba84b6dc 100644 --- a/test/public/test/override.js +++ b/test/public/test/override.js @@ -44,8 +44,6 @@ asyncTest("the event selector strings are overridable", 2, function() { return a.selector && a.selector.indexOf('a[data-remote]') != -1; })[0]; - //var documentClickBindings = "", linkClickBinding = {selector: ""}; - ok($.rails.linkClickSelector.indexOf(', a[data-custom-remote-link]') != -1, 'linkClickSelector contains custom selector'); ok(linkClickBinding.selector.indexOf(', a[data-custom-remote-link]') != -1, 'actual document binding contains custom selector'); From f681221504a760d73acfe8cf76e1606e6a1e3202 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 00:34:39 -0500 Subject: [PATCH 013/148] jquery 1.6 is not being supported --- src/rails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index fd9415d4..fc33c2a1 100644 --- a/src/rails.js +++ b/src/rails.js @@ -3,7 +3,7 @@ /** * Unobtrusive scripting adapter for jQuery * - * Requires jQuery 1.6.0 or later. + * Requires jQuery 1.7.0 or later. * https://github.com/rails/jquery-ujs * Uploading file using rails.js From dff02f903822859a3b5021fadfb4b02b34ba8c55 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 00:45:42 -0500 Subject: [PATCH 014/148] moved the repo info closer to the top --- src/rails.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index fc33c2a1..d9447713 100644 --- a/src/rails.js +++ b/src/rails.js @@ -2,10 +2,10 @@ /** * Unobtrusive scripting adapter for jQuery + * https://github.com/rails/jquery-ujs * * Requires jQuery 1.7.0 or later. - * https://github.com/rails/jquery-ujs - + * * Uploading file using rails.js * ============================= * From be8a59f60afc1c463bf9c13997d17c82fe123254 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 00:46:44 -0500 Subject: [PATCH 015/148] Added license information in the file. closes #292 --- src/rails.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rails.js b/src/rails.js index d9447713..17c2f539 100644 --- a/src/rails.js +++ b/src/rails.js @@ -6,6 +6,8 @@ * * Requires jQuery 1.7.0 or later. * + * Released under the MIT license + * * Uploading file using rails.js * ============================= * From 0f094f7330da9dba0d15040cd31cd0fa9c6c808b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 00:49:39 -0500 Subject: [PATCH 016/148] moved instructions to wiki https://github.com/rails/jquery-ujs/wiki/Uploading-file-using-rails.js --- src/rails.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/rails.js b/src/rails.js index 17c2f539..5e4b5126 100644 --- a/src/rails.js +++ b/src/rails.js @@ -8,26 +8,6 @@ * * Released under the MIT license * - * 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 * =========================== * From e96a1f6bc18561c31713742b4ab5418a184a854d Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 00:52:13 -0500 Subject: [PATCH 017/148] moved instructions to wiki https://github.com/rails/jquery-ujs/wiki/Required-fields-in-rails.js --- src/rails.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/rails.js b/src/rails.js index 5e4b5126..369ed9fe 100644 --- a/src/rails.js +++ b/src/rails.js @@ -8,23 +8,6 @@ * * Released under the MIT license * - * 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. - * - * !! 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. - * - * 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 From 827b85f8b11a838bb3035fd79274f3203955dc43 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 01:00:27 -0500 Subject: [PATCH 018/148] Added missing var. closes #298 --- src/rails.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index 369ed9fe..f63fe049 100644 --- a/src/rails.js +++ b/src/rails.js @@ -391,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); }); } From 1becac6b45762134835b33646e626b38a36b4df6 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 24 Jan 2013 01:30:32 -0500 Subject: [PATCH 019/148] jquery 1.9 is also being supported --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db3dff79..537eed7c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Full [documentation is on the wiki][wiki], including the [list of published Ajax Requirements ------------ -- [jQuery 1.7.x or 1.8.x][jquery]; +- [jQuery 1.7.x or higher][jquery]; - HTML5 doctype (optional). If you don't use HTML5, adding "data" attributes to your HTML4 or XHTML pages might make them fail [W3C markup validation][validator]. However, this shouldn't create any issues for web browsers or other user agents. From 2f8ccdf26eac199a11aa1a893a8909bb4650d0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= Date: Wed, 6 Feb 2013 00:48:54 +1100 Subject: [PATCH 020/148] Support jQuery 1.9.1 --- test/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/server.rb b/test/server.rb index 8a2412c9..5ed58ec3 100644 --- a/test/server.rb +++ b/test/server.rb @@ -1,7 +1,7 @@ require 'sinatra' require 'json' -JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 ].freeze +JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 ].freeze use Rack::Static, :urls => ["/src"], :root => File.expand_path('..', settings.root) @@ -48,7 +48,7 @@ def jquery_versions end get '/' do - params[:version] ||= '1.9.0' + params[:version] ||= '1.9.1' params[:cdn] ||= 'jquery' erb :index end From 35acdbd047c3069dffd6fa990fd7d61635a429f1 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 5 Feb 2013 19:14:53 -0500 Subject: [PATCH 021/148] putting README on diet --- README.md | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/README.md b/README.md index 537eed7c..f3b0d4f3 100644 --- a/README.md +++ b/README.md @@ -50,45 +50,7 @@ Choose to overwrite jquery_ujs.js if prompted.* $ rails generate jquery:install - -### Manual installation (including Rails 2) - -[Download jQuery][jquery] and ["rails.js"][adapter] and place them in your "javascripts" directory. - -Configure the following in your application startup file (for Rails 3): - -```ruby - config.action_view.javascript_expansions[:defaults] = %w(jquery rails) -``` - -Or create an initializer (for Rails 2): - -```ruby -module ActionView::Helpers::AssetTagHelper - remove_const :JAVASCRIPT_DEFAULT_SOURCES - JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js) - - reset_javascript_include_default -end -``` - -Now the template helper `javascript_include_tag :defaults` will generate SCRIPT tags to load jQuery and rails.js. - -For Rails 2, you will need to manually implement the `csrf_meta_tag` helper and include it inside the `` of your application layout. - -The `csrf_meta_tags` (Rails 3.1) and `csrf_meta_tag` (Rails 3.0) helpers generate two meta tags containing values necessary for the [cross-site request forgery protection][csrf] built into Rails. Here is how to implement that helper in Rails 2: - -```ruby - # app/helpers/application_helper.rb - def csrf_meta_tag - if protect_against_forgery? - out = %(\n) - out << %() - out % [ Rack::Utils.escape_html(request_forgery_protection_token), - Rack::Utils.escape_html(form_authenticity_token) ] - end - end -``` +c. For Rails 2.x and for manual installation follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Manual-installing-and-Rails-2) . [data]: http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes "Embedding custom non-visible data with the data-* attributes" [wiki]: https://github.com/rails/jquery-ujs/wiki From e576b90e22270a80cc26e2227a794767523a9812 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 5 Feb 2013 19:16:25 -0500 Subject: [PATCH 022/148] added instruction on README on how to run tests --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f3b0d4f3..5abfd10a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,12 @@ Choose to overwrite jquery_ujs.js if prompted.* c. For Rails 2.x and for manual installation follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Manual-installing-and-Rails-2) . +Requirements +------------ + +Follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Running-Tests-and-Contributing) to run tests . + + [data]: http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes "Embedding custom non-visible data with the data-* attributes" [wiki]: https://github.com/rails/jquery-ujs/wiki [events]: https://github.com/rails/jquery-ujs/wiki/ajax From 5fa4791cb97461eec1063ab6ec13c1e91300e89b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 5 Feb 2013 19:17:12 -0500 Subject: [PATCH 023/148] changed header to How to run tests --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5abfd10a..758a1a20 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Choose to overwrite jquery_ujs.js if prompted.* c. For Rails 2.x and for manual installation follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Manual-installing-and-Rails-2) . -Requirements +How to run tests ------------ Follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Running-Tests-and-Contributing) to run tests . From 1b861bb7032aac5621b60ac0620202a1780e0a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= Date: Thu, 7 Feb 2013 00:23:19 +1100 Subject: [PATCH 024/148] Update CHANGELOG.md --- CHANGELOG.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfff7571..fe03033a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,16 +22,16 @@ to newest): - [`8063d1d47ea6a08e`](https://github.com/rails/jquery-ujs/commit/8063d1d47ea6a08e545e9a6ba3e84af584200e41) made $.rails.confirm and $.rails.ajax functions available in $.rails object - [`a96c4e9b074998c6`](https://github.com/rails/jquery-ujs/commit/a96c4e9b074998c6b6d102e4573b81c8a76f07a7) added support for jQuery 1.6.1 - [`dad6982dc5926866`](https://github.com/rails/jquery-ujs/commit/dad6982dc592686677e6845e681233c40d2ead27) added support for `data-params` attribute on remote links -- [`5433841d01622345`](https://github.com/rails/jquery-ujs/commit/5433841d01622345f734f22f82394ac035c2f783) removed support for jquery 1.4.4 and 1.5.x, and added support for jquery 1.6.2 +- [`5433841d01622345`](https://github.com/rails/jquery-ujs/commit/5433841d01622345f734f22f82394ac035c2f783) removed support for jQuery 1.4.4 and 1.5.x, and added support for jQuery 1.6.2 - [`cd619df9f0daad33`](https://github.com/rails/jquery-ujs/commit/cd619df9f0daad3303aacd4f992fff19158b1e5d) added support for html5 `novalidate` attribute, so required fields validation is not enforced -- [`840ab6ac76b2d5ab`](https://github.com/rails/jquery-ujs/commit/840ab6ac76b2d5ab931841bc3d8567e5b57f183e) added support for jquery 1.6.3 +- [`840ab6ac76b2d5ab`](https://github.com/rails/jquery-ujs/commit/840ab6ac76b2d5ab931841bc3d8567e5b57f183e) added support for jQuery 1.6.3 - [`ba5808e73111fb65`](https://github.com/rails/jquery-ujs/commit/ba5808e73111fb65e91610b078577bb014d9b6d8) added `data-remote` support for checkboxes - [`6e9a06d45eaf2da1`](https://github.com/rails/jquery-ujs/commit/6e9a06d45eaf2da1036d4c2ead25ff57d0127d03) added `data-disable-with` support for links - [`89396108ce574080`](https://github.com/rails/jquery-ujs/commit/89396108ce574080f9b877cad74573c5d1ae9aa2) added `data-remote` support for all input types -- [`c01215c3d48ebb9f`](https://github.com/rails/jquery-ujs/commit/c01215c3d48ebb9f9f1059f26efa0c0c9092da2b) added support for jquery 1.6.4 -- [`17f4004310b6ece3`](https://github.com/rails/jquery-ujs/commit/17f4004310b6ece3cb240914932b4d6d46032c24) added support for jquery 1.7 -- [`cb54ae287f5c7320`](https://github.com/rails/jquery-ujs/commit/cb54ae287f5c73207aef2891cdf22212aea5fb86) added support for jquery 1.7.1 -- [`dbb1b5f72a62e59f`](https://github.com/rails/jquery-ujs/commit/dbb1b5f72a62e59f34f6b5be4bee291ee7f3318f) added support for jquery 1.7.2 +- [`c01215c3d48ebb9f`](https://github.com/rails/jquery-ujs/commit/c01215c3d48ebb9f9f1059f26efa0c0c9092da2b) added support for jQuery 1.6.4 +- [`17f4004310b6ece3`](https://github.com/rails/jquery-ujs/commit/17f4004310b6ece3cb240914932b4d6d46032c24) added support for jQuery 1.7 +- [`cb54ae287f5c7320`](https://github.com/rails/jquery-ujs/commit/cb54ae287f5c73207aef2891cdf22212aea5fb86) added support for jQuery 1.7.1 +- [`dbb1b5f72a62e59f`](https://github.com/rails/jquery-ujs/commit/dbb1b5f72a62e59f34f6b5be4bee291ee7f3318f) added support for jQuery 1.7.2 - [`8100cf3b2462f144`](https://github.com/rails/jquery-ujs/commit/8100cf3b2462f144e6a0bcef7cb78d05be41755d) created `rails:attachBindings` to allow for customization of $.rails object settings - [`e4ca2045b202cd7a`](https://github.com/rails/jquery-ujs/commit/e4ca2045b202cd7ade97d78c20caa2822c5c28da) created `ajax:send` event to provide access to jqXHR object from @@ -39,3 +39,7 @@ to newest): - [`4382f580766fcdd1`](https://github.com/rails/jquery-ujs/commit/4382f580766fcdd14201c204f43ca5aeb0928501) added support for `data-with-credentials` - [`12da9fc2f175c8e4`](https://github.com/rails/jquery-ujs/commit/12da9fc2f175c8e445413b15cf6b685deb271d6e) added support for jQuery 1.8.0, removed support for jquery 1.6.x - [`faeb0ad734ff6867`](https://github.com/rails/jquery-ujs/commit/faeb0ad734ff6867149b8522f9a29081734442e6) added support for jQuery 1.8.1 +- [`b6dae4ef4a2d031a`](https://github.com/rails/jquery-ujs/commit/b6dae4ef4a2d031a222627c7f6a4284602f99160) added support for jQuery 1.8.2 +- [`6927b82cadf3146c`](https://github.com/rails/jquery-ujs/commit/6927b82cadf3146c2b9ae3028e9b197af64011ca) added support for jQuery 1.8.3 +- [`cc356656cc3edf15`](https://github.com/rails/jquery-ujs/commit/cc356656cc3edf1596fd685265187d2f75d1bc7c) added support for jQuery 1.9.0 +- [`2f8ccdf26eac199a`](https://github.com/rails/jquery-ujs/commit/2f8ccdf26eac199a11aa1a893a8909bb4650d0fb) added support for jQuery 1.9.1 From 049d2039da7188783408a22294982f01330d1b38 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Fri, 8 Feb 2013 00:44:20 -0500 Subject: [PATCH 025/148] Much simpler method of checking if rails.js has already been loaded. --- src/rails.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/rails.js b/src/rails.js index f63fe049..69db1843 100644 --- a/src/rails.js +++ b/src/rails.js @@ -12,12 +12,7 @@ // Cut down on the number if issues from people inadvertently including jquery_ujs twice // by detecting and raising an error when it happens. - var alreadyInitialized = function() { - var events = $._data(document, 'events'); - return events && events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length; - } - - if ( alreadyInitialized() ) { + if ( $.rails !== undefined ) { $.error('jquery-ujs has already been loaded!'); } From 610dfb8881377598b7e63ab2c152d73aa1d3632f Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Tue, 19 Feb 2013 00:28:38 -0500 Subject: [PATCH 026/148] Fixed bug where a[disable-with] got set to blank html when ajax returned error, due to enableElement being triggered twice. --- src/rails.js | 4 +--- test/public/test/data-disable.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index 69db1843..a1661f31 100644 --- a/src/rails.js +++ b/src/rails.js @@ -276,9 +276,7 @@ enableElement: function(element) { if (element.data('ujs:enable-with') !== undefined) { element.html(element.data('ujs:enable-with')); // set to old enabled state - // this should be element.removeData('ujs:enable-with') - // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed - element.data('ujs:enable-with', false); // clean up cache + element.removeData('ujs:enable-with'); // clean up cache } element.unbind('click.railsDisable'); // enable element } diff --git a/test/public/test/data-disable.js b/test/public/test/data-disable.js index 241c1583..6c973dfd 100644 --- a/test/public/test/data-disable.js +++ b/test/public/test/data-disable.js @@ -207,6 +207,23 @@ asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` e }, 30); }); +asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', 6, function() { + var link = $('a[data-disable-with]').attr('data-remote', true).attr('href', '/error'); + + checkEnabledState(link, 'Click me'); + + link + .bind('ajax:beforeSend', function() { + checkDisabledState(link, 'clicking...'); + }) + .trigger('click'); + + setTimeout(function() { + checkEnabledState(link, 'Click me'); + start(); + }, 30); +}); + asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not disable when `ajax:beforeSend` event is cancelled', 8, function() { var form = $('form[data-remote]'), input = form.find('input:text'), From c30462003c41175acf7337536b036a47645cf742 Mon Sep 17 00:00:00 2001 From: ingeniarius Date: Wed, 20 Feb 2013 15:22:34 +0400 Subject: [PATCH 027/148] Supporting button[data-remote] as replacement of button_to helper --- src/rails.js | 16 ++++++++++++++++ test/public/test/data-remote.js | 31 +++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/rails.js b/src/rails.js index a1661f31..2cb26b53 100644 --- a/src/rails.js +++ b/src/rails.js @@ -23,6 +23,9 @@ // Link elements bound by jquery-ujs linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]', + // Button elements boud jquery-ujs + buttonClickSelector: 'button[data-remote]', + // Select elements bound by jquery-ujs inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]', @@ -100,6 +103,11 @@ url = element.data('url'); data = element.serialize(); if (element.data('params')) data = data + "&" + element.data('params'); + } else if (element.is(rails.buttonClickSelector)) { + method = element.data('method') || 'post'; + url = element.data('url'); + data = element.serialize(); + if (element.data('params')) data = data + "&" + element.data('params'); } else { method = element.data('method'); url = rails.href(element); @@ -315,6 +323,14 @@ } }); + $(document).delegate(rails.buttonClickSelector, 'click.rails', function(e) { + var button = $(this); + if (!rails.allowAction(button)) return rails.stopEverything(e); + + rails.handleRemote(button); + return false; + }); + $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) { var link = $(this); if (!rails.allowAction(link)) return rails.stopEverything(e); diff --git a/test/public/test/data-remote.js b/test/public/test/data-remote.js index d9c2f6d7..1ce113e9 100644 --- a/test/public/test/data-remote.js +++ b/test/public/test/data-remote.js @@ -7,6 +7,12 @@ module('data-remote', { 'data-params': 'data1=value1&data2=value2', text: 'my address' })) + .append($('