From c8ec804f925c0e2d1640492feb7b62ec563be11b Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Sat, 2 May 2015 12:57:15 -0700 Subject: [PATCH] Update jquery-ujs to 1.0.3 Previously there was not a tagged release, so this commit just brings us to the latest release. --- bower.json | 2 +- bower_components/jquery-ujs/.bower.json | 22 ++-- bower_components/jquery-ujs/CHANGELOG.md | 69 +++++------- bower_components/jquery-ujs/README.md | 31 +++--- bower_components/jquery-ujs/bower.json | 6 +- bower_components/jquery-ujs/src/rails.js | 131 +++++++++++++++++------ 6 files changed, 161 insertions(+), 100 deletions(-) diff --git a/bower.json b/bower.json index c9bea04..9fdf0ee 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "dependencies": { "replacejs": "~0.0.4", "jquery": "~2.1.0", - "jquery-ujs": "", + "jquery-ujs": "~1.0.3", "jquery.visible": "~1.1.0" }, "resolutions": { diff --git a/bower_components/jquery-ujs/.bower.json b/bower_components/jquery-ujs/.bower.json index 8dc40ad..fef671d 100644 --- a/bower_components/jquery-ujs/.bower.json +++ b/bower_components/jquery-ujs/.bower.json @@ -1,28 +1,32 @@ { "name": "jquery-ujs", "homepage": "https://github.com/rails/jquery-ujs", - "authors": [], + "authors": [ + "Stephen St. Martin", + "Steve Schwartz" + ], "description": "Ruby on Rails unobtrusive scripting adapter for jQuery", "main": "src/rails.js", "license": "MIT", + "version": "1.0.3", "dependencies": { - "jquery": ">1.7.* <2.0.0" + "jquery": ">1.8.*" }, "ignore": [ "**/.*", "Gemfile*", "Rakefile", "bower_components", + "script", "test" ], - "_release": "737273923b", + "_release": "1.0.3", "_resolution": { - "type": "branch", - "branch": "master", - "commit": "737273923b67a1895a74abcaaa94d4289b0340e3" + "type": "version", + "tag": "v1.0.3", + "commit": "519aad962496497870621e5b6afe2a727a28839d" }, "_source": "git://github.com/rails/jquery-ujs.git", - "_target": "*", - "_originalSource": "jquery-ujs", - "_direct": true + "_target": "~1.0.3", + "_originalSource": "jquery-ujs" } \ No newline at end of file diff --git a/bower_components/jquery-ujs/CHANGELOG.md b/bower_components/jquery-ujs/CHANGELOG.md index fe03033..8e4116f 100644 --- a/bower_components/jquery-ujs/CHANGELOG.md +++ b/bower_components/jquery-ujs/CHANGELOG.md @@ -1,45 +1,24 @@ -CHANGELOG -========= - -Here is a non-exhaustive list of notable changes to jquery-ujs (oldest -to newest): - -- [`085d910a5ec07b69`](https://github.com/rails/jquery-ujs/commit/085d910a5ec07b69f31beabce286141aa26f3005) last version before callback names updated -- [`72d875a8d57c6bb4`](https://github.com/rails/jquery-ujs/commit/72d875a8d57c6bb466170980a5142c66ac74e8f0) callback name updates completed -- [`e076121248913143`](https://github.com/rails/jquery-ujs/commit/e0761212489131437402a92fa8f548a78f685ae2) dropped support for jQuery 1.4, 1.4.1, 1.4.2 (separate [v1.4 branch](https://github.com/rails/jquery-ujs/commits/v1.4) created) -- [`498b35e24cdb14f2`](https://github.com/rails/jquery-ujs/commit/498b35e24cdb14f2d94486e8a1f4a1f661091426) last version before `.callRemote()` removed -- [`ec96408a746d3b06`](https://github.com/rails/jquery-ujs/commit/ec96408a746d3b0692da9249f218a3943fbffc28) `ACCEPTS` header data-type default changed to prefer `:js` but not require it -- [`fc639928d1e15c88`](https://github.com/rails/jquery-ujs/commit/fc639928d1e15c885b85de5b517346db7f963f44) default form method changed from `POST` to `GET` -- [`e9311550fdb3afeb`](https://github.com/rails/jquery-ujs/commit/e9311550fdb3afeb2917bcb1fef39767bf715003) added CSRF Protection to remote requests -- [`a284dd706e7d76e8`](https://github.com/rails/jquery-ujs/commit/a284dd706e7d76e85471ef39ab3efdf07feef374) CSRF fixed - changed to only add if token is present -- [`f9b21b3a3c7c4684`](https://github.com/rails/jquery-ujs/commit/f9b21b3a3c7c46840fed8127a90def26911fad3d) `ajax:before` added back -- [`7f2acc1811f62877`](https://github.com/rails/jquery-ujs/commit/7f2acc1811f62877611e16451530728b5e13dbe7) last version before file-upload aborting behavior added -- [`ca575e184e93b3ef`](https://github.com/rails/jquery-ujs/commit/ca575e184e93b3efe1a858cf598f8a37f0a760cc) added `ajax:aborted:required` and `ajax:aborted:file` event hooks -- [`d2abd6f9df4e4a42`](https://github.com/rails/jquery-ujs/commit/d2abd6f9df4e4a426c17c218b7d5e05004c768d0) fixed submit and bubbling behavior for IE -- [`d59144177d867908`](https://github.com/rails/jquery-ujs/commit/d59144177d86790891fdb99b0e3437312e04fda2) created external api via `$.rails` object -- [`cd357e492de14747`](https://github.com/rails/jquery-ujs/commit/cd357e492de147472a8a2524575acce5d923e640) added support for jQuery 1.6 and dropped support for jQuery 1.4.3 -- [`50c06dcc02c1b08c`](https://github.com/rails/jquery-ujs/commit/50c06dcc02c1b08cb7a9b4b8eced54ed685c1c93) added `confirm:complete` event hook which is passed result from confirm dialog -- [`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 -- [`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 -- [`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 -- [`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` -- [`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 +## v1.0.3 + +* Replace deprecated `deferred.error()` with `fail()`. + + *Carlos Antonio da Silva* +## v1.0.2 + +* Re-enables buttons and links after going back through the `pageshow` event. + + *Gabriel Sobrinho* + +## v1.0.1 + +* `confirm` is no longer called twice for `button` elements inside a `form`. + + *Lucas Mazza* + +* `button` or submit inputs using the `form` attribute are properly bound. + + *Marnen Laibow-Koser* + +## v1.0.0 + +* First tagged release. diff --git a/bower_components/jquery-ujs/README.md b/bower_components/jquery-ujs/README.md index bc488b7..29ea432 100644 --- a/bower_components/jquery-ujs/README.md +++ b/bower_components/jquery-ujs/README.md @@ -15,42 +15,47 @@ Full [documentation is on the wiki][wiki], including the [list of published Ajax Requirements ------------ -- [jQuery 1.7.x or higher][jquery]; +- [jQuery 1.8.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. -Installation +Installation using the jquery-rails gem ------------ For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile: ```ruby -gem 'jquery-rails', '~> 2.1' +gem 'jquery-rails' ``` And run: - $ bundle install - -This next step depends on your version of Rails. +```shell +$ bundle install +``` -a. For Rails 3.1, add these lines to the top of your app/assets/javascripts/application.js file: +Require both `jquery` and `jquery_ujs` into your application.js manifest. ```javascript //= require jquery //= require jquery_ujs ``` -b. For Rails 3.0, run this command: +Installation using Bower +------------ + +Run `bower install jquery-ujs --save` to install the jquery-ujs package. -*Be sure to get rid of the rails.js file if it exists, and instead use -the new jquery_ujs.js file that gets copied to the public directory. -Choose to overwrite jquery_ujs.js if prompted.* +Usage +------------ - $ rails generate jquery:install +Require both `jquery` and `jquery-ujs` into your application.js manifest. -c. For Rails 2.x and for manual installation follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Manual-installing-and-Rails-2) . +```javascript +//= require jquery +//= require jquery-ujs +``` How to run tests ------------ diff --git a/bower_components/jquery-ujs/bower.json b/bower_components/jquery-ujs/bower.json index ecbb138..9b5d5df 100644 --- a/bower_components/jquery-ujs/bower.json +++ b/bower_components/jquery-ujs/bower.json @@ -1,18 +1,20 @@ { "name": "jquery-ujs", "homepage": "https://github.com/rails/jquery-ujs", - "authors": [], + "authors": ["Stephen St. Martin", "Steve Schwartz"], "description": "Ruby on Rails unobtrusive scripting adapter for jQuery", "main": "src/rails.js", "license": "MIT", + "version": "1.0.3", "dependencies": { - "jquery": ">1.7.* <2.0.0" + "jquery": ">1.8.*" }, "ignore": [ "**/.*", "Gemfile*", "Rakefile", "bower_components", + "script", "test" ] } diff --git a/bower_components/jquery-ujs/src/rails.js b/bower_components/jquery-ujs/src/rails.js index 309d74d..a4fb0be 100644 --- a/bower_components/jquery-ujs/src/rails.js +++ b/bower_components/jquery-ujs/src/rails.js @@ -4,7 +4,7 @@ * Unobtrusive scripting adapter for jQuery * https://github.com/rails/jquery-ujs * - * Requires jQuery 1.7.0 or later. + * Requires jQuery 1.8.0 or later. * * Released under the MIT license * @@ -22,10 +22,10 @@ $.rails = rails = { // Link elements bound by jquery-ujs - linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]', + linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with], a[data-disable]', // Button elements bound by jquery-ujs - buttonClickSelector: 'button[data-remote]', + buttonClickSelector: 'button[data-remote]:not(form button), button[data-confirm]:not(form button)', // Select elements bound by jquery-ujs inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]', @@ -34,13 +34,13 @@ 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([type])', + formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])', // Form input elements disabled during form submission - disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]', + disableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled', // Form input elements re-enabled after form submission - enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled', + enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled', // Form required input elements requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])', @@ -49,7 +49,10 @@ fileInputSelector: 'input[type=file]', // Link onClick disable selector with possible reenable after remote submission - linkDisableSelector: 'a[data-disable-with]', + linkDisableSelector: 'a[data-disable-with], a[data-disable]', + + // Button onClick disable selector with possible reenable after remote submission + buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]', // Make sure that every Ajax request sends the CSRF token CSRFProtection: function(xhr) { @@ -129,7 +132,11 @@ if (settings.dataType === undefined) { xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script); } - return rails.fire(element, 'ajax:beforeSend', [xhr, settings]); + if (rails.fire(element, 'ajax:beforeSend', [xhr, settings])) { + element.trigger('ajax:send', xhr); + } else { + return false; + } }, success: function(data, status, xhr) { element.trigger('ajax:success', [data, status, xhr]); @@ -154,9 +161,7 @@ // Only pass url to `ajax` options if not blank if (url) { options.url = url; } - var jqxhr = rails.ajax(options); - element.trigger('ajax:send', jqxhr); - return jqxhr; + return rails.ajax(options); } else { return false; } @@ -183,32 +188,54 @@ form.submit(); }, + // Helper function that returns form elements that match the specified CSS selector + // If form is actually a "form" element this will return associated elements outside the from that have + // the html form attribute set + formElements: function(form, selector) { + return form.is('form') ? $(form[0].elements).filter(selector) : form.find(selector); + }, + /* Disables form elements: - Caches element value in 'ujs:enable-with' data store - Replaces element text with value of 'data-disable-with' attribute - Sets disabled property to true */ disableFormElements: function(form) { - form.find(rails.disableSelector).each(function() { - var element = $(this), method = element.is('button') ? 'html' : 'val'; - element.data('ujs:enable-with', element[method]()); - element[method](element.data('disable-with')); - element.prop('disabled', true); + rails.formElements(form, rails.disableSelector).each(function() { + rails.disableFormElement($(this)); }); }, + disableFormElement: function(element) { + var method, replacement; + + method = element.is('button') ? 'html' : 'val'; + replacement = element.data('disable-with'); + + element.data('ujs:enable-with', element[method]()); + if (replacement !== undefined) { + element[method](replacement); + } + + element.prop('disabled', true); + }, + /* Re-enables disabled form elements: - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) - Sets disabled property to false */ enableFormElements: function(form) { - form.find(rails.enableSelector).each(function() { - var element = $(this), method = element.is('button') ? 'html' : 'val'; - if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); - element.prop('disabled', false); + rails.formElements(form, rails.enableSelector).each(function() { + rails.enableFormElement($(this)); }); }, + enableFormElement: function(element) { + var method = element.is('button') ? 'html' : 'val'; + if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with')); + element.prop('disabled', false); + }, + /* For 'data-confirm' attribute: - Fires `confirm` event - Shows the confirmation dialog @@ -269,8 +296,13 @@ // replace element's html with the 'data-disable-with' after storing original html // and prevent clicking on it disableElement: function(element) { + var replacement = element.data('disable-with'); + element.data('ujs:enable-with', element.html()); // store enabled state - element.html(element.data('disable-with')); // set to disabled state + if (replacement !== undefined) { + element.html(replacement); + } + element.bind('click.railsDisable', function(e) { // prevent further clicking return rails.stopEverything(e); }); @@ -284,17 +316,43 @@ } element.unbind('click.railsDisable'); // enable element } - }; if (rails.fire($document, 'rails:attachBindings')) { $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }}); + // This event works the same as the load event, except that it fires every + // time the page is loaded. + // + // See https://github.com/rails/jquery-ujs/issues/357 + // See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching + $(window).on("pageshow.rails", function () { + $($.rails.enableSelector).each(function () { + var element = $(this); + + if (element.data("ujs:enable-with")) { + $.rails.enableFormElement(element); + } + }); + + $($.rails.linkDisableSelector).each(function () { + var element = $(this); + + if (element.data("ujs:enable-with")) { + $.rails.enableElement(element); + } + }); + }); + $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() { rails.enableElement($(this)); }); + $document.delegate(rails.buttonDisableSelector, 'ajax:complete', function() { + rails.enableFormElement($(this)); + }); + $document.delegate(rails.linkClickSelector, 'click.rails', function(e) { var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey; if (!rails.allowAction(link)) return rails.stopEverything(e); @@ -309,11 +367,11 @@ if (handleRemote === false) { rails.enableElement(link); } else { - handleRemote.error( function() { rails.enableElement(link); } ); + handleRemote.fail( function() { rails.enableElement(link); } ); } return false; - } else if (link.data('method')) { + } else if (method) { rails.handleMethod(link); return false; } @@ -321,9 +379,18 @@ $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) { var button = $(this); + if (!rails.allowAction(button)) return rails.stopEverything(e); - rails.handleRemote(button); + if (button.is(rails.buttonDisableSelector)) rails.disableFormElement(button); + + var handleRemote = rails.handleRemote(button); + // response from rails.handleRemote() will either be false or a deferred object promise. + if (handleRemote === false) { + rails.enableFormElement(button); + } else { + handleRemote.fail( function() { rails.enableFormElement(button); } ); + } return false; }); @@ -338,17 +405,21 @@ $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); + blankRequiredInputs, + nonBlankFileInputs; if (!rails.allowAction(form)) return rails.stopEverything(e); // 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 (form.attr('novalidate') == undefined) { + blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector); + if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) { + return rails.stopEverything(e); + } } if (remote) { + nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector); if (nonBlankFileInputs) { // slight timeout so that the submit button gets properly serialized // (make it easy for event handler to serialize form without disabled values) @@ -382,7 +453,7 @@ button.closest('form').data('ujs:submit-button', data); }); - $document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) { + $document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) { if (this == event.target) rails.disableFormElements($(this)); });