From 33ce990ebb45f00813d2bee9658ac244ba1bc879 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 13 Aug 2012 13:34:47 -0400 Subject: [PATCH 001/170] Modified form button click selector. Fixes #63. --- src/rails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index a8c3c59a..6ebcdb2b 100644 --- a/src/rails.js +++ b/src/rails.js @@ -59,7 +59,7 @@ formSubmitSelector: 'form', // Form input elements bound by jquery-ujs - formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])', + formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])', // Form input elements disabled during form submission disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]', From 8100cf3b2462f144e6a0bcef7cb78d05be41755d Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 13 Aug 2012 15:43:13 -0400 Subject: [PATCH 002/170] Added rails:attachBindings event to enable customization of binding selectors. Fixes #263. --- src/rails.js | 135 ++++++++++++++++++----------------- test/public/test/override.js | 23 +++++- test/views/layout.erb | 9 ++- 3 files changed, 97 insertions(+), 70 deletions(-) diff --git a/src/rails.js b/src/rails.js index 6ebcdb2b..2d53bf68 100644 --- a/src/rails.js +++ b/src/rails.js @@ -291,94 +291,97 @@ }; - $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); + if (rails.fire($(document), 'rails:attachBindings')) { - $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() { - rails.enableElement($(this)); - }); + $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); - $(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); + $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() { + rails.enableElement($(this)); + }); - if (link.is(rails.linkDisableSelector)) rails.disableElement(link); + $(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.data('remote') !== undefined) { - if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; } + if (link.is(rails.linkDisableSelector)) rails.disableElement(link); - if (rails.handleRemote(link) === false) { rails.enableElement(link); } - return false; + if (link.data('remote') !== undefined) { + if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; } - } else if (link.data('method')) { - rails.handleMethod(link); - return false; - } - }); + if (rails.handleRemote(link) === false) { rails.enableElement(link); } + return false; - $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) { - var link = $(this); - if (!rails.allowAction(link)) return rails.stopEverything(e); + } else if (link.data('method')) { + rails.handleMethod(link); + return false; + } + }); - rails.handleRemote(link); - return false; - }); + $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) { + var link = $(this); + if (!rails.allowAction(link)) return rails.stopEverything(e); - $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) { - var form = $(this), - remote = form.data('remote') !== undefined, - blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector), - nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector); + rails.handleRemote(link); + return false; + }); - if (!rails.allowAction(form)) return rails.stopEverything(e); + $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) { + var form = $(this), + remote = form.data('remote') !== undefined, + blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector), + nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector); - // skip other logic when required values are missing or file upload is present - if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) { - return rails.stopEverything(e); - } + if (!rails.allowAction(form)) return rails.stopEverything(e); - if (remote) { - if (nonBlankFileInputs) { - return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); + // skip other logic when required values are missing or file upload is present + if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) { + return rails.stopEverything(e); } - // If browser does not support submit bubbling, then this live-binding will be called before direct - // bindings. Therefore, we should directly call any direct bindings before remotely submitting form. - if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e); + if (remote) { + if (nonBlankFileInputs) { + return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); + } - rails.handleRemote(form); - return false; + // If browser does not support submit bubbling, then this live-binding will be called before direct + // bindings. Therefore, we should directly call any direct bindings before remotely submitting form. + if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e); - } else { - // slight timeout so that the submit button gets properly serialized - setTimeout(function(){ rails.disableFormElements(form); }, 13); - } - }); + rails.handleRemote(form); + return false; + + } else { + // slight timeout so that the submit button gets properly serialized + setTimeout(function(){ rails.disableFormElements(form); }, 13); + } + }); - $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) { - var button = $(this); + $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) { + var button = $(this); - if (!rails.allowAction(button)) return rails.stopEverything(event); + if (!rails.allowAction(button)) return rails.stopEverything(event); - // register the pressed submit button - var name = button.attr('name'), - data = name ? {name:name, value:button.val()} : null; + // register the pressed submit button + var name = button.attr('name'), + data = name ? {name:name, value:button.val()} : null; - button.closest('form').data('ujs:submit-button', data); - }); + button.closest('form').data('ujs:submit-button', data); + }); - $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) { - if (this == event.target) rails.disableFormElements($(this)); - }); + $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) { + if (this == event.target) rails.disableFormElements($(this)); + }); - $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) { - if (this == event.target) rails.enableFormElements($(this)); - }); + $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) { + if (this == event.target) rails.enableFormElements($(this)); + }); - $(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'); - $('form input[name="' + csrf_param + '"]').val(csrf_token); - }); + $(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'); + $('form input[name="' + csrf_param + '"]').val(csrf_token); + }); + } })( jQuery ); diff --git a/test/public/test/override.js b/test/public/test/override.js index a5dce2c6..471f2324 100644 --- a/test/public/test/override.js +++ b/test/public/test/override.js @@ -3,9 +3,13 @@ module('override', { setup: function() { window.realHref = $.rails.href; - $('#qunit-fixture').append($('', { - href: '/real/href', 'data-method': 'delete', 'data-href': '/data/href' - })); + $('#qunit-fixture') + .append($('', { + href: '/real/href', 'data-method': 'delete', 'data-href': '/data/href' + })) + .append($('', { + href: '/other/href', 'data-custom-remote-link': 'true' + })); }, teardown: function() { $.rails.href = window.realHref; @@ -34,4 +38,17 @@ asyncTest("the getter for an element's href works normally if not overridden", 1 start(); }); +asyncTest("the event selector strings are overridable", 2, function() { + var documentClickBindings = $(document).data('events').click, + linkClickBinding = $.grep(documentClickBindings, function(a) { + return a.selector.indexOf('a[data-remote]') != -1; + })[0]; + + 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'); + + start(); +}); + })(); diff --git a/test/views/layout.erb b/test/views/layout.erb index 53962f9d..fe2c5483 100644 --- a/test/views/layout.erb +++ b/test/views/layout.erb @@ -11,8 +11,15 @@ #jquery-cdn { margin-right: 550px; } #jquery-cdn a, #jquery-version a { color: white; text-decoration: underline; } - + <%= script_tag jquery_src %> + <%= script_tag "/src/rails.js" %> From e4ca2045b202cd7ade97d78c20caa2822c5c28da Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 13 Aug 2012 17:05:08 -0400 Subject: [PATCH 003/170] Added ajax:send event to provide access to jqXHR object for ajax requests. Fixes #254. --- src/rails.js | 4 +++- test/public/test/call-remote-callbacks.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 2d53bf68..bda84154 100644 --- a/src/rails.js +++ b/src/rails.js @@ -155,7 +155,9 @@ // Only pass url to `ajax` options if not blank if (url) { options.url = url; } - return rails.ajax(options); + var jqxhr = rails.ajax(options); + element.trigger('ajax:send', jqxhr); + return jqxhr; } else { return false; } diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index 32dfdfaf..af0232db 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -308,4 +308,16 @@ asyncTest('binding to ajax callbacks via .live() triggers handlers properly', 3, }, 63); }); +asyncTest('binding to ajax:send event to call jquery methods on ajax object', 2, function() { + $('form[data-remote]') + .bind('ajax:send', function(e, xhr) { + ok(true, 'event should fire'); + equal(typeof(xhr.abort), 'function', 'event should pass jqXHR object'); + xhr.abort(); + }) + .trigger('submit'); + + setTimeout(function() { start(); }, 35); +}); + })(); From 9790178579af06db7d8b9e507e14fff127dad9c3 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 13 Aug 2012 17:22:57 -0400 Subject: [PATCH 004/170] Make crossDomain respect data-cross-domain=false on element. Fixes #232. --- src/rails.js | 5 +++-- test/public/test/call-remote.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index bda84154..b3c564f6 100644 --- a/src/rails.js +++ b/src/rails.js @@ -106,10 +106,11 @@ // Submits "remote" forms and links with ajax handleRemote: function(element) { - var method, url, data, crossDomain, dataType, options; + var method, url, data, elCrossDomain, crossDomain, dataType, options; if (rails.fire(element, 'ajax:before')) { - crossDomain = element.data('cross-domain') || null; + elCrossDomain = element.data('cross-domain'); + crossDomain = elCrossDomain === undefined ? null : elCrossDomain; dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType); if (element.is('form')) { diff --git a/test/public/test/call-remote.js b/test/public/test/call-remote.js index 5d48b00c..ef998a8b 100644 --- a/test/public/test/call-remote.js +++ b/test/public/test/call-remote.js @@ -157,4 +157,19 @@ asyncTest('intelligently guesses crossDomain behavior when target URL is a diffe setTimeout(function() { start(); }, 13); }); +asyncTest('does not set crossDomain if explicitly set to false on element', 1, function() { + build_form({ action: 'http://www.alfajango.com', 'data-cross-domain': false }); + $('#qunit-fixture').append(''); + + $('#qunit-fixture').find('form') + .bind('ajax:beforeSend', function(e, xhr, settings) { + equal(settings.crossDomain, false, 'crossDomain should be set to false'); + // prevent request from actually getting sent off-domain + return false; + }) + .trigger('submit'); + + setTimeout(function() { start(); }, 13); +}); + })(); From 43bfec1da658145ce0af764256929a8439d1d56f Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 13 Aug 2012 18:01:20 -0400 Subject: [PATCH 005/170] Detect and throw error when jquery-ujs is included in document more than once. --- src/rails.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/rails.js b/src/rails.js index b3c564f6..ccdaa449 100644 --- a/src/rails.js +++ b/src/rails.js @@ -45,6 +45,17 @@ * }); */ + // 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 = $(document).data('events'); + return events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length; + } + + if ( alreadyInitialized() ) { + $.error('jquery-ujs has already been loaded!'); + } + // Shorthand to make it a little easier to call public rails functions from within rails.js var rails; From 1e184328c69b76cd7c1bb66cacc3439f737b56ab Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Tue, 14 Aug 2012 12:43:24 -0400 Subject: [PATCH 006/170] Use :checked for required checkbox and radio inputs. Fixes #236. --- src/rails.js | 7 +++--- test/public/test/call-remote-callbacks.js | 29 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index ccdaa449..fa6ce1f7 100644 --- a/src/rails.js +++ b/src/rails.js @@ -246,12 +246,13 @@ // Helper function which checks for blank inputs in a form that match the specified CSS selector blankInputs: function(form, specifiedSelector, nonBlank) { - var inputs = $(), input, + var inputs = $(), input, valueToCheck, selector = specifiedSelector || 'input,textarea'; form.find(selector).each(function() { input = $(this); - // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs - if (nonBlank ? input.val() : !input.val()) { + valueToCheck = input.is(':checkbox,:radio') ? input.is(':checked') : input.val(); + // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey + if (valueToCheck == !!nonBlank) { inputs = inputs.add(input); } }); diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index af0232db..4808c974 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -191,6 +191,35 @@ asyncTest('blank required form input for non-remote form with "novalidate" attri }, 13); }); +asyncTest('unchecked required checkbox should abort form submission', 1, function() { + var form = $('form[data-remote]') + .append($('')) + .removeAttr('data-remote') + .bind('ujs:everythingStopped', function() { + ok(true, 'ujs:everythingStopped should run'); + }) + .trigger('submit'); + + setTimeout(function() { + start(); + }, 13); +}); + +asyncTest('unchecked required radio should abort form submission', 1, function() { + var form = $('form[data-remote]') + .append($('')) + .append($('')) + .removeAttr('data-remote') + .bind('ujs:everythingStopped', function() { + ok(true, 'ujs:everythingStopped should run'); + }) + .trigger('submit'); + + setTimeout(function() { + start(); + }, 13); +}); + function skipIt() { // This test cannot work due to the security feature in browsers which makes the value // attribute of file input fields readonly, so it cannot be set with default value. From cde5d979a22bb15aefc1a9b23f1cda3bcd6a141c Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Tue, 14 Aug 2012 12:58:02 -0400 Subject: [PATCH 007/170] Disable form elements when form falls back to regular submit for file-fields. Fixes #231. --- src/rails.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rails.js b/src/rails.js index fa6ce1f7..61384498 100644 --- a/src/rails.js +++ b/src/rails.js @@ -355,6 +355,7 @@ if (remote) { if (nonBlankFileInputs) { + setTimeout(function(){ rails.disableFormElements(form); }, 13); return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); } From 2f6447cb59ed38110f4cb16b14141722d540af7f Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Wed, 15 Aug 2012 10:44:40 -0400 Subject: [PATCH 008/170] Fixed multiple-inclusion detection for when no event handlers bound to document. --- src/rails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 61384498..9f18fb33 100644 --- a/src/rails.js +++ b/src/rails.js @@ -49,7 +49,7 @@ // by detecting and raising an error when it happens. var alreadyInitialized = function() { var events = $(document).data('events'); - return events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length; + return events && events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length; } if ( alreadyInitialized() ) { From b19fae1f379bb4b8949206c4089fbb6cca24d1be Mon Sep 17 00:00:00 2001 From: Brad Philips Date: Wed, 15 Aug 2012 19:18:04 -0400 Subject: [PATCH 009/170] Committing only the xhr changes. --- src/rails.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/rails.js b/src/rails.js index a8c3c59a..f7095dfc 100644 --- a/src/rails.js +++ b/src/rails.js @@ -106,10 +106,11 @@ // Submits "remote" forms and links with ajax handleRemote: function(element) { - var method, url, data, crossDomain, dataType, options; + var method, url, data, crossDomain, withCredentials, dataType, options; if (rails.fire(element, 'ajax:before')) { crossDomain = element.data('cross-domain') || null; + withCredentials = element.data('with-credentials') || null; dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType); if (element.is('form')) { @@ -134,7 +135,7 @@ } options = { - type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain, + type: method || 'GET', data: data, dataType: dataType, // stopping the "ajax:beforeSend" event will cancel the ajax request beforeSend: function(xhr, settings) { if (settings.dataType === undefined) { @@ -150,7 +151,11 @@ }, error: function(xhr, status, error) { element.trigger('ajax:error', [xhr, status, error]); - } + }, + xhrFields: { + withCredentials: withCredentials + }, + crossDomain: crossDomain }; // Only pass url to `ajax` options if not blank if (url) { options.url = url; } @@ -274,7 +279,7 @@ element.data('ujs:enable-with', element.html()); // store enabled state element.html(element.data('disable-with')); // set to disabled state element.bind('click.railsDisable', function(e) { // prevent further clicking - return rails.stopEverything(e) + return rails.stopEverything(e); }); }, From 4382f580766fcdd14201c204f43ca5aeb0928501 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 16 Aug 2012 11:21:53 -0400 Subject: [PATCH 010/170] Added test back from bradphilips-master, slightly modified --- test/public/test/call-remote-callbacks.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index 4808c974..adb5a86c 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -75,6 +75,20 @@ 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() { + var form = $(this); + form.data('with-credentials',true); + }); + + submit(function(form) { + form.bind('ajax:beforeSend', function(e, xhr, settings) { + equal(settings.xhrFields && settings.xhrFields.withCredentials, true, 'setting modified in ajax:before should have forced withCredentials request'); + }); + }); +}); + asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function() { submit(function(form) { form.bind('ajax:beforeSend', function() { From 8674fb14552d8c6e394da39dd352c68b25b78142 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 16 Aug 2012 11:44:41 -0400 Subject: [PATCH 011/170] Updated changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5ffeae..d7cc1deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,3 +32,8 @@ to newest): - [`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 + ajax requests +- [`4382f580766fcdd1`](https://github.com/rails/jquery-ujs/commit/4382f580766fcdd14201c204f43ca5aeb0928501) added support for `data-with-credentials` From 8a642e45c752d9485ddefc2122a40d3d8647d4fe Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 16 Aug 2012 14:39:41 -0400 Subject: [PATCH 012/170] Added jquery 1.8.0 to test suite. Removed jquery 1.6.x support. --- test/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/server.rb b/test/server.rb index e1067bc2..b76864f6 100644 --- a/test/server.rb +++ b/test/server.rb @@ -1,7 +1,7 @@ require 'sinatra' require 'json' -JQUERY_VERSIONS = %w[ 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 1.7.2 ].freeze +JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 ].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.7.2' + params[:version] ||= '1.8.0' params[:cdn] ||= 'jquery' erb :index end From 3d5c7ce1cb27d1323f7df7d1970352d428b405df Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 16 Aug 2012 14:40:08 -0400 Subject: [PATCH 013/170] Fixed multiple-inclusion check for compatibility with jquery 1.8. --- src/rails.js | 2 +- test/public/test/override.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index ecc315b2..9fb22d65 100644 --- a/src/rails.js +++ b/src/rails.js @@ -48,7 +48,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 = $(document).data('events'); + var events = $._data(document, 'events'); return events && events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length; } diff --git a/test/public/test/override.js b/test/public/test/override.js index 471f2324..92119ea2 100644 --- a/test/public/test/override.js +++ b/test/public/test/override.js @@ -39,7 +39,7 @@ 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 = $(document).data('events').click, + var documentClickBindings = $._data(document, 'events').click, linkClickBinding = $.grep(documentClickBindings, function(a) { return a.selector.indexOf('a[data-remote]') != -1; })[0]; @@ -51,4 +51,18 @@ asyncTest("the event selector strings are overridable", 2, function() { start(); }); +// Not sure why this test isn't working in jquery 1.7, +// or why the error message doesn't show in the console in 1.8 +// when the test is run. +// +//asyncTest("including jquery-ujs multiple times throws error", 1, function() { +// var script = document.createElement( 'script' ); +// script.type = 'text/javascript'; +// script.src = '/src/rails.js'; +// raises(function() { +// $("#qunit-fixture").append( script ); +// }, 'appending rails.js again throws error'); +// setTimeout(function() { start(); }, 50); +//}); + })(); From 12da9fc2f175c8e445413b15cf6b685deb271d6e Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 16 Aug 2012 15:42:32 -0400 Subject: [PATCH 014/170] Fixed re-enabling elements when ajax:beforeSend returns false. This worked in jQuery 1.6 and 1.7 due to what was considered a bug, according to this ticket, which has been fixed in jQuery 1.8: http://bugs.jquery.com/ticket/10944 --- src/rails.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 9fb22d65..baac8b9a 100644 --- a/src/rails.js +++ b/src/rails.js @@ -328,7 +328,13 @@ if (link.data('remote') !== undefined) { if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; } - if (rails.handleRemote(link) === false) { rails.enableElement(link); } + var handleRemote = rails.handleRemote(link); + // response from rails.handleRemote() will either be false or a deferred object promise. + if (handleRemote === false) { + rails.enableElement(link); + } else { + handleRemote.error( function() { rails.enableElement(link); } ); + } return false; } else if (link.data('method')) { From a5c2df333e8e51afd1a8911f14e674c4de9db7b9 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 16 Aug 2012 15:53:10 -0400 Subject: [PATCH 015/170] Updated changelog and readme --- CHANGELOG.md | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7cc1deb..9a46db32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,3 +37,4 @@ to newest): - [`e4ca2045b202cd7a`](https://github.com/rails/jquery-ujs/commit/e4ca2045b202cd7ade97d78c20caa2822c5c28da) created `ajax:send` event to provide access to jqXHR object from ajax requests - [`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 diff --git a/README.md b/README.md index 028bf27d..62426ffe 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.6][jquery] or later; +- [jQuery 1.7.x or 1.8.0][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. @@ -26,7 +26,7 @@ Installation For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile: ```ruby -gem 'jquery-rails', '>= 1.0.12' +gem 'jquery-rails', '~> 2.0' ``` And run: From 9c8fc791a1e6b370ac53c5071ae5008432734968 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Sat, 18 Aug 2012 02:36:25 -0400 Subject: [PATCH 016/170] Compare boolean values for non-blank file field to fire ajax:aborted:file. Fixes #271. --- src/rails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index baac8b9a..af4bf18b 100644 --- a/src/rails.js +++ b/src/rails.js @@ -257,7 +257,7 @@ input = $(this); valueToCheck = input.is(':checkbox,:radio') ? input.is(':checked') : input.val(); // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey - if (valueToCheck == !!nonBlank) { + if (!valueToCheck === !nonBlank) { inputs = inputs.add(input); } }); From 8b147fb023f0d13deebea750e7e9827b6d3bc8ba Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Sat, 18 Aug 2012 02:36:56 -0400 Subject: [PATCH 017/170] Re-enable form fields if ajax:aborted:file handler returns false. --- src/rails.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index af4bf18b..8de1faaa 100644 --- a/src/rails.js +++ b/src/rails.js @@ -366,8 +366,15 @@ if (remote) { if (nonBlankFileInputs) { + // slight timeout so that the submit button gets properly serialized + // (make it easy for event handler to serialize form without disabled values) setTimeout(function(){ rails.disableFormElements(form); }, 13); - return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); + var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]); + + // re-enable form elements if event bindings return false (canceling normal form submission) + if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); } + + return aborted; } // If browser does not support submit bubbling, then this live-binding will be called before direct From 688ffdceef5308396b9555492b0f3667ec3507d5 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 6 Sep 2012 19:30:37 -0400 Subject: [PATCH 018/170] Only require one required radio input in set to be checked. --- src/rails.js | 11 +++++++++-- test/public/test/call-remote-callbacks.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index 8de1faaa..0a7cf58c 100644 --- a/src/rails.js +++ b/src/rails.js @@ -252,12 +252,19 @@ // Helper function which checks for blank inputs in a form that match the specified CSS selector blankInputs: function(form, specifiedSelector, nonBlank) { var inputs = $(), input, valueToCheck, - selector = specifiedSelector || 'input,textarea'; - form.find(selector).each(function() { + selector = specifiedSelector || 'input,textarea', + $allInputs = form.find(selector); + $allInputs.each(function() { input = $(this); valueToCheck = input.is(':checkbox,: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) { + return true; // Skip to next input + } + inputs = inputs.add(input); } }); diff --git a/test/public/test/call-remote-callbacks.js b/test/public/test/call-remote-callbacks.js index adb5a86c..ecba5013 100644 --- a/test/public/test/call-remote-callbacks.js +++ b/test/public/test/call-remote-callbacks.js @@ -234,6 +234,26 @@ asyncTest('unchecked required radio should abort form submission', 1, function() }, 13); }); +asyncTest('required radio should only require one to be checked', 1, function() { + 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'); + }) + .find('#checkme').prop('checked', true) + .end() + .trigger('submit'); + + setTimeout(function() { + start(); + }, 13); +}); + function skipIt() { // This test cannot work due to the security feature in browsers which makes the value // attribute of file input fields readonly, so it cannot be set with default value. From faeb0ad734ff6867149b8522f9a29081734442e6 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 6 Sep 2012 19:32:20 -0400 Subject: [PATCH 019/170] Added support for jquery 1.8.1 --- test/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/server.rb b/test/server.rb index b76864f6..fb129c14 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 ].freeze +JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.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.8.0' + params[:version] ||= '1.8.1' params[:cdn] ||= 'jquery' erb :index end From 015061adccb2bfff9232b902e2a15b37868213bf Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 6 Sep 2012 19:34:53 -0400 Subject: [PATCH 020/170] Updated changelog and readme --- CHANGELOG.md | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a46db32..cfff7571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,3 +38,4 @@ to newest): ajax requests - [`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 diff --git a/README.md b/README.md index 62426ffe..db3dff79 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.0][jquery]; +- [jQuery 1.7.x or 1.8.x][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. @@ -26,7 +26,7 @@ Installation For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile: ```ruby -gem 'jquery-rails', '~> 2.0' +gem 'jquery-rails', '~> 2.1' ``` And run: From bddff6a677edc54f00e48bde740b0b22d68deef6 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Thu, 6 Sep 2012 19:36:49 -0400 Subject: [PATCH 021/170] Change var naming convention for consistency --- src/rails.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rails.js b/src/rails.js index 0a7cf58c..df9dc862 100644 --- a/src/rails.js +++ b/src/rails.js @@ -253,15 +253,16 @@ blankInputs: function(form, specifiedSelector, nonBlank) { var inputs = $(), input, valueToCheck, selector = specifiedSelector || 'input,textarea', - $allInputs = form.find(selector); - $allInputs.each(function() { + allInputs = form.find(selector); + + allInputs.each(function() { input = $(this); valueToCheck = input.is(':checkbox,: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(':radio') && allInputs.filter('input:radio:checked[name="' + input.attr('name') + '"]').length) { return true; // Skip to next input } From b6dae4ef4a2d031a222627c7f6a4284602f99160 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 24 Sep 2012 11:02:09 -0400 Subject: [PATCH 022/170] Added support for jquery 1.8.2 --- test/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/server.rb b/test/server.rb index fb129c14..afa1a19f 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 ].freeze +JQUERY_VERSIONS = %w[ 1.7 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 ].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.1' + params[:version] ||= '1.8.2' params[:cdn] ||= 'jquery' erb :index end From a59f28f0a7e68214985c1fb591ea6766125d45c8 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Mon, 19 Nov 2012 15:30:18 -0500 Subject: [PATCH 023/170] 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 024/170] 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 025/170] 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 026/170] 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 027/170] 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 028/170] 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 029/170] 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 030/170] 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 031/170] 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 032/170] 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 033/170] 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 034/170] 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 035/170] 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 036/170] 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 037/170] 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 038/170] 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 039/170] 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 040/170] 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 041/170] 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 042/170] 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 043/170] 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 044/170] 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 045/170] 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 046/170] 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 047/170] 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 048/170] 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 049/170] 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($('