Giter Site home page Giter Site logo

jquery-ujs's Introduction

Unobtrusive scripting adapter for jQuery

This unobtrusive scripting support file is developed for the Ruby on Rails framework, but is not strictly tied to any specific backend. You can drop this into any application to:

  • force confirmation dialogs for various actions;
  • make non-GET requests from hyperlinks;
  • make forms or hyperlinks submit data asynchronously with Ajax;
  • have submit buttons become automatically disabled on form submit to prevent double-clicking.

These features are achieved by adding certain "data" attributes to your HTML markup. In Rails, they are added by the framework's template helpers.

Full documentation is on the wiki, including the list of published Ajax events.

Requirements

If you don't use HTML5, adding "data" attributes to your HTML4 or XHTML pages might make them fail W3C markup validation. However, this shouldn't create any issues for web browsers or other user agents.

Installation using the jquery-rails gem

For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile:

gem 'jquery-rails'

And run:

$ bundle install

Require both jquery and jquery_ujs into your application.js manifest.

//= require jquery
//= require jquery_ujs

Installation using npm.

Run npm install --save jquery-ujs to install the jquery-ujs package.

Installation using Rails and Webpacker

If you're using webpacker (introduced in Rails 5.1) to manage JavaScript assets, then you can add the jquery-ujs npm package to your project using the yarn CLI.

$ yarn add jquery-ujs

Then, from any of your included files (e.g. app/javascript/packs/application.js, or from a JavaScript file imported by such a pack), you need only import the package for jquery-ujs to be initialized:

import {} from 'jquery-ujs'

Installation using Bower

Run bower install jquery-ujs --save to install the jquery-ujs package.

Usage

Require both jquery and jquery-ujs into your application.js manifest.

//= require jquery
//= require jquery-ujs

How to run tests

Follow this wiki to run tests.

Contributing to jquery-ujs

jquery-ujs is work of many contributors. You're encouraged to submit pull requests, propose features and discuss issues.

See CONTRIBUTING.

License

jquery-ujs is released under the MIT License.

jquery-ujs's People

Contributors

8bitdesigner avatar aianus avatar aki77 avatar akzhan avatar alexcrichton avatar asilano avatar brianmario avatar carlosantoniodasilva avatar dhh avatar escobera avatar foca avatar jangosteve avatar javierjulio avatar josevalim avatar justin808 avatar lucasmazza avatar lucasuyezu avatar marnen avatar mislav avatar monkbroc avatar pier-oliviert avatar qhoxie avatar rafaelfranca avatar rstankov avatar scottgonzalez avatar simsalabim avatar sskirby avatar stefanpenner avatar stevestmartin avatar twalpole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-ujs's Issues

Namespace

I added a "rails" namespace to all of the live click and submit bindings, making them .live('click.rails') and .live('submit.rails'), so that you can easily unbind all of the live events created specifically by Rails.

This is handy for instances where you may want to disable the Rails data-remote goodness without needing to exclude the rails.js file from that page (which may be combined and minified with all your other js files), by simply calling $(selector).die('rails').

For example, I may want to add my own .live('click') bindings on a given page, and then want to turn off the Rails bindings so that they don't also get called.

Perhaps this circumstance is rare, but namespacing the events is cleaner, more maintainable, adds basically no extra code, and is completely backwards compatible with everything people are already doing.

For more information about jQuery namespacing, see http://docs.jquery.com/Namespaced_Events

disable-with handlers crashes in IE 8.0.x

I have an application that does not have any data-disable-with elements. On one particular page it crashes in IE. If i disable these lines in rails.js. things go back to normal.

I will investigate more later and add any additional information I can.

form_for with data-method 'delete' will be sent with method 'post'

In the rails.js function 'callRemote' (line 26), the order to get the 'method'
is firstly the attribute 'method' and then the attribute 'data-method'.
Is there a reason for? Can it not be changed to?
method = el.attr('data-method') || el.attr('method') || 'GET'

In my app (Rails: 2.3.8), the form will be sent with 'post', but I excepted the method 'delete'
<% form_for(@foo, :html => {'data-remote' => true, 'data-method' => :delete}) do |f| %>

github https upgrade breaks jquery:install

rails g jquery:install causes the error:

lib/ruby/1.9.1/open-uri.rb:216:in `open_loop': redirection forbidden: http://github.com/rails/jquery-ujs/raw/master/src/rails.js -> https://github.com/rails/jquery-ujs/raw/master/src/rails.js (RuntimeError)

data-confirm with remote send

When the link does send an ajax request, but it has :confirm option. It sends the request even if the users presses 'No' in the confirmation box.

I suggest this solution:

 /**
  • confirmation handler
    */
    • $('a[data-confirm],input[data-confirm]').live('click', function () {

    • $('a[data-confirm],input[data-confirm]').live('click', function (event) {
      var el = $(this);
      if (el.triggerAndReturn('confirm')) {
      if (!confirm(el.attr('data-confirm'))) {

    •            event.confirmFalse = true;
           return false;
       }
      

      }
      @@ -79,6 +81,9 @@ jQuery(function ($) {
      });

      $('a[data-remote],input[data-remote]').live('click', function (e) {

    •    if (e.confirmFalse){
      
    •      return;
      
    •    }
      

      $(this).callRemote();
      e.preventDefault();
      });

`open_loop': redirection forbidden: http://github.com/rails/jquery-ujs/raw/master/src/rails.js -> https://github.com/rails/jquery-ujs/raw/master/src/rails.js (RuntimeError)

today,i came cross this issue:

/home/dxiao/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:216:in open_loop': redirection forbidden: http://github.com/rails/jquery-ujs/raw/master/src/rails.js -> https://github.com/rails/jquery-ujs/raw/master/src/rails.js (RuntimeError) from /home/dxiao/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:146:inopen_uri'
from /home/dxiao/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:671:in open' from /home/dxiao/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:33:inopen'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/actions/file_manipulation.rb:55:in get' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/jquery-rails-0.2.4/lib/generators/jquery/install/install_generator.rb:34:indownload_ujs_driver'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/task.rb:22:in run' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/invocation.rb:118:ininvoke_task'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/invocation.rb:124:in block in invoke_all' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/invocation.rb:124:ineach'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/invocation.rb:124:in map' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/invocation.rb:124:ininvoke_all'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/group.rb:226:in dispatch' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.3/lib/thor/base.rb:389:instart'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/generators.rb:163:in invoke' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/generate.rb:10:in<top (required)>'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in require' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:inblock in require'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in block in load_dependency' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:innew_constants_in'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in load_dependency' from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:inrequire'
from /home/dxiao/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:17:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `

'

$('a').die('rails') not working

This is a problem described in #29: I need to override the handlers bound by rails.js with my own functions in my application's application.js. The comments in that pull request indicate a

$('a').die('rails')

should do the trick. Only it doesn't. I've also tried it from the firebug console, and no luck. $('a').undelegate() and $('a').undelegate('rails') also don't work. Am I doing something wrong? Using jquery-ujs from head and jquery 1.4.4. Basically every link with a "data-confirm" attribute keeps bringing up the rails.js confirmation dialog (which is the one I want to override).

jquery:install fails when behind a proxy

Automatic installation failed when being behind a proxy:

> rails generate jquery:install
      remove  public/javascripts/controls.js
      remove  public/javascripts/dragdrop.js
      remove  public/javascripts/effects.js
      remove  public/javascripts/prototype.js
    fetching  jQuery (1.4.4)
     warning  could not find jQuery (1.4.4)
    fetching  jQuery (1.4.4)

C:/Ruby192/lib/ruby/1.9.1/open-uri.rb:346:in `open_http':
  407 Proxy Authentication Required (OpenURI::HTTPError)

OS: Windows XP x64 bits
Ruby: 1.9.2.
Rails: 3.0.3

bug: rails generate

rails generate jquery:install
remove public/javascripts/controls.js
remove public/javascripts/dragdrop.js
remove public/javascripts/effects.js
remove public/javascripts/prototype.js
fetching jQuery (1.4.3)
identical public/javascripts/jquery.js
identical public/javascripts/jquery.min.js
fetching jQuery UJS adapter (github HEAD)
/usr/local/lib/ruby/1.9.1/open-uri.rb:216:in `open_loop': redirection forbidden: http://github.com/rails/jquery-ujs/raw/master/src/rails.js -> https://github.com/rails/jquery-ujs/raw/master/src/rails.js (RuntimeError)

rails 3.0.0^ ruby 1.9.2

IE + jQuery 1.4.2 + live('submit', ...

Not work in IE with jQuery 1.4.2
http://forum.jquery.com/topic/ie-specific-issues-with-live-submit
$('form[data-remote]').live('submit', function (e) {

    $(this).callRemote();
    if(e.preventDefault) e.preventDefault();

});

Path for IE

if (jQuery.browser.msie){
  $("form[data-remote]").find("input[type='submit'],button[type='submit'],input[name='commit']").live('click',function(e) {
      $(this).parents("form[data-remote]").callRemote();
      if(e.preventDefault) e.preventDefault();
  });
}

Incompatibility with jquery 1.4.3

Only with jquery 1.4.3, each ajax request is duplicates. (in ":remote => true" helpers)
Avec jquery 1.4.3, chaque requête ajax est doublonnée. (dans les helpers ":remote => true")

Default Data-type with Accepts Header

This is in response to the comment threads here and here.

The issue is that if the data-type of the remote request, set with the dataType parameter in jQuery's .ajax(), is not set, we would like the default behavior to request JavaScript from the server. The problem is that, if the controller does not have respond_to :js set as one of the acceptable formats, we don't want our preference to cause the application to error out.

For this reason, rails.js has been modified to no longer set the default data-type to 'script'. As a result, if the data-type is not set explicitly, remote requests are sent with an Accepts header of '*/*', which causes the controller to respond with the first format listed in the Responder.

So, if the controller has:

respond_to :html, :js

or:

respond_with(@object) do |format|
    format.html { }
    format.js { }
end

It will respond with HTML as the default AJAX response, which is counter-intuitive. To fix this, we must reverse the order of the JS and HTML format declarations such that the JS is first. This is confusing and not immediately apparent.

What if we could tell the server that we'd prefer JS, but if it's not an acceptable data-type (i.e. the JS format is not defined in the Responder), then to just return whatever it's got? Actually, we can, with the following code in the beforeSend callback in our $.ajax() method:

beforeSend: function(xhr, settings) {
    if ( settings.dataType == undefined ) {
        xhr.setRequestHeader("Accept", "text/javascript, */*; q=0.5");
    }
    return fire(element, 'ajax:beforeSend', xhr);
},

According to the Accepts header and q-parameter definitions, this tells the server precisely, "I'd prefer javascript, but if you don't have it, I'll take whatever you've got."

I tested this in my own rails.js file, and sure enough it works as expected. Whether I have respond_to :js, :html or respond_to :html, :js, it always responds with JS. If I take out the :js and just have respond_to :html, then it responds with the HTML.

I can submit a pull request with this if everyone's on board.

:method => :delete don't work

I'm testing Rails 3 with the jquery driver and :method => :delete don't work, i got redirected to the show page every time i try to delete a record.
:remote => true with method => :delete work fine, the normal version no.

Fix for disable_with handlers

In the disable_with handlers

$(this).children('input[data-disable-with]')

should be

$(this).find('input[data-disable-with]')

Otherwise, the script won't find the button if it's nested within any type of markup

"Certificate verify failed" when trying to run "rails g jquery:install --ui"

~/code/rails/app(feature_branch) $ rails g jquery:install --ui
remove public/javascripts/controls.js
remove public/javascripts/dragdrop.js
remove public/javascripts/effects.js
remove public/javascripts/prototype.js
fetching jQuery (1.4.4)
create public/javascripts/jquery.js
create public/javascripts/jquery.min.js
fetching jQuery UI (latest 1.x release)
create public/javascripts/jquery-ui.js
create public/javascripts/jquery-ui.min.js
fetching jQuery UJS adapter (github HEAD)
/home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:677:in connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError) from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:677:inconnect'
from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:637:in do_start' from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:626:instart'
from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:306:in open_http' from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:769:inbuffer_open'
from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:203:in block in open_loop' from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:201:incatch'
from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:201:in open_loop' from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:146:inopen_uri'
from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:671:in open' from /home/user/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:33:inopen'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/actions/file_manipulation.rb:55:in get' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/jquery-rails-0.2.6/lib/generators/jquery/install/install_generator.rb:34:indownload_ujs_driver'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/task.rb:22:in run' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/invocation.rb:118:ininvoke_task'
from /home/jmeridth/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/invocation.rb:124:in block in invoke_all' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/invocation.rb:124:ineach'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/invocation.rb:124:in map' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/invocation.rb:124:ininvoke_all'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/group.rb:226:in dispatch' from /home/jmeridth/.rvm/gems/ruby-1.9.2-p0@app/gems/thor-0.14.4/lib/thor/base.rb:389:instart'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/railties-3.0.1/lib/rails/generators.rb:163:in invoke' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/railties-3.0.1/lib/rails/commands/generate.rb:10:in<top (required)>'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in require' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:inblock in require'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in block in load_dependency' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:innew_constants_in'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in load_dependency' from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:inrequire'
from /home/user/.rvm/gems/ruby-1.9.2-p0@app/gems/railties-3.0.1/lib/rails/commands.rb:17:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `

'

OS: Ubuntu 10.10
Using RVM with Rails 1.9.2 and Rails 3.0.3

I see Github mentioned, a possible cert error on their side?

Any help is appreciated. Thank you.

The problem of :disable_with

My code is below:

<%= f.submit "submit", :class => "submit", :disable_with => "waiting..." %>

In IE8 Using jquery1.4.1, when i clicked the button to submit,it really was disabled, but the http request wasn't posted, so the "create" action isn't called. Using jquery1.4.2,http request is posted,but the button isn't disabled.This works fine in firefox.I don't know why...

Example Initializer is deprecated

The example in which you overwrite the javascript_include_tag :defaults included files is now deprecated. The way to achieve the same effect is to add:

config.action_view.javascript_expansions[:defaults] = %w(jquery-1.4.2.min rails)

To application.rb !

Thanks for the code :)

confirm not working on google chrome

The confirm dialog comes up, but no matter whether you click OK or Cancel, it always submits (the Cancel is never respected).

Debugging it now, as I think it has something to do with event propagation, but if anyone has idea of what might be wrong, I'd appreciate it.

The problem is somewhere here:

$('a[data-confirm],input[data-confirm]').live('click', function (e) {
    var el = $(this);
    if (el.triggerAndReturn('confirm')) {
      if (!confirm(el.attr('data-confirm'))) {

// the return false is not preventing default event handling in chrome. I tried
// e.preventDefault() and
// e.stopPropagation()
// but to no avail (as of now)
return false;
}
}
});

Namespacing is wrong

I'm not sure whether you'll want to keep it inline with the prototype API, but your event namspacing isn't very jqueryish. For example, the ajax:complete event should be complete.ajax
This has the added advantage that I can bind to all the events in a namespace.

http://api.jquery.com/bind/

Why is the dataType attribute set to 'script' in the ajax call?

In the callRemotefunction, the $.ajax is configured with dataType: 'script'

JQuery docs says that:
The type of data that you're expecting back from the server. If none is specified, jQuery will intelligently try to get the results, based on the MIME type of the response

Wouldn't it be better to remove this attribute and let jquery to decide the type?.

With the current implementation, I am having this problem using Chrome: it throws an Uncaught SyntaxError: Unexpected token : (my controller is returning json data). When I remove the dataType: 'script' line it works fine (but instead of returning the json text, jquery parses it automatically and instantiates the object directly, as expected according to jquery api doc). I can't reproduce this problem with firefox.

Support for data-action and data-href in callRemote

Make callRemote() more universal by supporting "data-action" and "data-href" in addition to the "href" and "action" attributes.

Reason for this:

  1. use different links based on javascript support in browser
  2. make it possible to trigger callRemote() from elements not supporting "action" or "href" attributes

A possible implementation is in this commit: 3119c79a9b515f17356542e8bc56779ac5580141

Automatic install fails when fetching rails.js

Automatic install is failing when getting the rails.js file. It's trying to access http and not https and github redirection will make it fail.

fetching  jQuery UJS adapter (github HEAD)
/Users/tesla/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:216:in `open_loop': redirection forbidden: http://github.com/rails/jquery-ujs/raw/master/src/rails.js -> https://github.com/rails/jquery-ujs/raw/master/src/rails.js (RuntimeError)
from /Users/tesla/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
from /Users/tesla/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:671:in `open'
from /Users/tesla/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/open-uri.rb:33:in `open'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/actions/file_manipulation.rb:55:in `get'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/jquery-rails-0.2.4/lib/generators/jquery/install/install_generator.rb:34:in `download_ujs_driver'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/task.rb:22:in `run'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/invocation.rb:118:in `invoke_task'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/invocation.rb:124:in `block in invoke_all'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/invocation.rb:124:in `each'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/invocation.rb:124:in `map'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/invocation.rb:124:in `invoke_all'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/group.rb:226:in `dispatch'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/thor-0.14.2/lib/thor/base.rb:389:in `start'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/generators.rb:163:in `invoke'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/generate.rb:10:in `<top (required)>'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
from /Users/tesla/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

no license provided

There's no indication of what the license is for this project.

Could you please provide a LICENSE file or add a license to the source?

Default dataType value issue

wouldn't it be better to leave the dataType value blank if a data-type is not specified for the form or a tag? This way jQuery uses its "Intelligent Guess" feature by default allowing for different content types to be returned under different scenarios.

line 35: dataType = el.attr('data-type') || '';

dataType overwritten from ajaxSetup()

Is it possible to go with the default dataType chosen by jQuery instead of defaulting to 'script', thus allowing ajaxSetup() to work as expected?

It's a bit of a doubletake to explicitly set the default, then see it completely ignored.

jQuery & jQuery UI get included twice when using all instead of default

I used the automated installation.

In application.html.erb if I use

<%= javascript_include_tag :all %>

Instead of :default, it results in jQuery and jQuery UI getting pulled in twice.

<script src="/javascripts/jquery.js?1286100693" type="text/javascript"></script> 
<script src="/javascripts/jquery-ui.js?1286100699" type="text/javascript"></script> 
<script src="/javascripts/rails.js?1286100708" type="text/javascript"></script> 
<script src="/javascripts/application.js?1285891614" type="text/javascript"></script> 
<script src="/javascripts/jquery-ui.min.js?1286100696" type="text/javascript"></script> 
<script src="/javascripts/jquery.min.js?1286100691" type="text/javascript"></script> 

Automated installation error (GitHub certificate)

Hello,

I was trying to install jquery-rails via

rails generate jquery:install

and got this:

fetching  jQuery UJS adapter (github HEAD) /usr/local/lib/ruby/1.9/net/http.rb:677:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
    from /usr/local/lib/ruby/1.9/net/http.rb:677:in `connect'
    from /usr/local/lib/ruby/1.9/net/http.rb:637:in `do_start'
    from /usr/local/lib/ruby/1.9/net/http.rb:626:in `start'
    from /usr/local/lib/ruby/1.9/open-uri.rb:306:in `open_http'
    from /usr/local/lib/ruby/1.9/open-uri.rb:769:in `buffer_open'
    from /usr/local/lib/ruby/1.9/open-uri.rb:203:in `block in open_loop'
    from /usr/local/lib/ruby/1.9/open-uri.rb:201:in `catch'
    from /usr/local/lib/ruby/1.9/open-uri.rb:201:in `open_loop'
    from /usr/local/lib/ruby/1.9/open-uri.rb:146:in `open_uri'
    from /usr/local/lib/ruby/1.9/open-uri.rb:671:in `open'
    from /usr/local/lib/ruby/1.9/open-uri.rb:33:in `open'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:77:in `get'
    from /usr/local/lib/ruby/gems/1.9/gems/jquery-rails-0.2.5/lib/generators/jquery/install/install_generator.rb:34:in `download_ujs_driver'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from /usr/local/lib/ruby/gems/1.9/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
    from /usr/local/lib/ruby/gems/1.9/gems/railties-3.0.3/lib/rails/generators.rb:163:in `invoke'
    from /usr/local/lib/ruby/gems/1.9/gems/railties-3.0.3/lib/rails/commands/generate.rb:10:in `'
    from /usr/local/lib/ruby/gems/1.9/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
    from /usr/local/lib/ruby/gems/1.9/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
    from /usr/local/lib/ruby/gems/1.9/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /usr/local/lib/ruby/gems/1.9/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /usr/local/lib/ruby/gems/1.9/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /usr/local/lib/ruby/gems/1.9/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
    from /usr/local/lib/ruby/gems/1.9/gems/railties-3.0.3/lib/rails/commands.rb:17:in `'
    from script/rails:6:in `require'
    from script/rails:6:in `'

Any suggestions?

confirm issue of the latest version

No matter what I choose, the cancle or ok button of the confirmation dialog, the "destroy" action is always called.My env : the latest version of jquery-ujs , jquery 1.4.3, IE8

Rails needs xhr.setRequestHeader("Accept", "text/javascript");

So I made a form the rails way, with:
form_tag, :remote=>true`

The controller it submitted to had the standard:

respond_to do |format|
    format.html 
    format.js
end

When I submitted the form, it did submit as an xhr request, but rails responded by rendering the .html.erb instead of the .js.rjs

This is because the Request Header: Accept is set to / (discovered via Chrome's resources tab).

To fix this, I had to edit your rails.js at line 56-59 the following way:

beforeSend: function (xhr) {
  xhr.setRequestHeader("Accept", "text/javascript");
  el.trigger('ajax:loading', xhr);
},

I'm not submitting this as a patch, as I suspect this needs to be added in other places, but I'm not nearly smart enough to know where.

Firefox specific bug: Setting Accept to "text/javascript" causes 406.

Hi,

What is the reason for setting the "Accept" header field to "text/javascript" before sending the ajax request? The problem is that if you want the server to return anything else than javascript in response to the ajax call then you will get a "406 Not Acceptable" in Firefox. I think the correct solution is to accept "/" or not set it at all.
(The bug is Firefox specific because setting the "Accept" header field will override the existing value - which is "/". Other browsers e.g. Chrome will append the new value.)
I'm happy to do a fork and submit a pull request if you agree.

Kind regards,
Nicholas

remote form_for and params

Dears,

in my form i'm using :remote => true, and i add a parameter :name to a submit button as :
<%= f.submit "Back", :name => "back_button" %>
when the user submit the form with UJS as :remote => true, i didn't receive the params[:back_button] as this parameter is not there.

but with disabling UJS as remove ":remote => true" , i receive the params[:back_button] normally.

please, advice.

Caching in IE

I ran into this issue when I created a poller. I created an anchor tag with the ujs stuff setup on it. the my timeout would just fire the click() event to run the ajax. In ie I noticed nothing was getting to the server after the first click. I discovered that the ajax was caching the request.

I add this code to allow me to set the cache param in callRemote.

var cache = dataType == 'jsonp' || dataType == 'script' ? false : true;
if ( el.attr('data-cache') ){
if ( el.attr('data-cache') == 'false'){
cache = false;
}else{
cache = true;
}
}

Some methods don't exist

Here is very simple rails application with only two pages.
When i click "test ajax" I get an error

TypeError: Object function Element() { [native code] } has no method 'update'

It seems that methods from original dragdrop/controls/effects/<base such as prototype/ are not implemented. Are jquery implementation of them planned?

This driver should support $.load with post out-of-the-box

When we call some code like $.load(url, {data: 'sample'}) it would be great if this driver sent the CSRF token automatically for seamless integration with jQuery.

Before Rails 3 I used to do something like http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery, setting also the request header as in http://railscasts.com/episodes/136-jquery.

I don't see any reasons why this shouldn't be integrated in this plugin. Any thoughts?

The options :submit, :with doesnt exist anymore !

Hi,

i try to use the :submit, :with with <%= link_to %> html tag, but it doesnt work anymore. It was working in rails 2.3 with link_to_remote

With the new refactor off the javascript module it doesnt seems to exist anymore.
i found a solution, but it only works with the ajax GET request, i dont know how to make it work for the POST request.

https://gist.github.com/752805 can we find a way to integrate back this features with the new way ???

More informations:
http://railspikes.com/2007/4/17/partial_dom_submit_with_link_to_remote

http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/link_to_remote

data-disable-with doesn't work anymore

I've downloaded the latest version today and its not working now. It was before, though I don't have the old file to do a diff.

<form accept-charset="UTF-8" action="/login" class="sd_form bold_label big" data-disable-with="Please wait...">
<input name="commit" type="submit" value="Submit" /> 
</form> 

Do I need a special ID on my submit button?

Where are all the callback (link_to_remote - rails 2.3.x)

It should be great to get back all the callback in link_to define in the old link_to_remote (rails 2.3.x)

read this http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/link_to_remote

The callbacks that may be specified are (in order):

:loading: Called when the remote document is being loaded with data by the browser.

:loaded: Called when the browser has finished loading the remote document.

:interactive: Called when the user can interact with the remote document, even though it has not finished loading.

:success: Called when the XMLHttpRequest is completed, and the HTTP status code is in the 2XX range.

:failure: Called when the XMLHttpRequest is completed, and the HTTP status code is not in the 2XX range.

:complete: Called when the XMLHttpRequest is complete (fires after success/failure if they are present).

and useful callback

:confirm: Adds confirmation dialog.

:condition: Perform remote request conditionally by this expression. Use this to describe browser-side conditions when request should not be initiated.

:before: Called before request is initiated.

:after: Called immediately after request was initiated and before :loading.

:submit: Specifies the DOM element ID that’s used as the parent of the form elements. By default this is the current form, but it could just as well be the ID of a table row or any other DOM element.

:with: A JavaScript expression specifying the parameters for the XMLHttpRequest. Any expressions should return a valid URL query string.

PS: i already implements in another issue (:with and :submit) for my need.

thanks. i could provide this functions in the jquery-ujs... but the others team (prototype and mootols should also provide this functions)

thanks

empty xhr response in failure callback

I'm seeing some strange behaviour with my Rails3 app. Note that I'm using the jQuery version of rails.js

From rails.js starting at line :49

error: function (xhr, status, error) {
el.trigger('ajax:failure', [xhr, status, error]);
alert('error in: ' + xhr.responseText );
}
From my jQuery code to execute after the form.

.bind('ajax:failure', function(xhr, status, error) {
alert('error in: ' + xhr.responseText );
})
In the alert in rails.js shows the expected return text, but the alert my callback shows:

error in: undefined
So it doesn't appear that xhr is being sent to the callback correctly. Am I doing something wrong, or is this an issue with rails.js?

(see http://stackoverflow.com/questions/3739606/rails3-ajax-callback-has-empty-xhr for nicer formatting)

disable-with handler triggers too soon

The disable-with handler triggers a revert to the original before the ajax call has been completed.

$('form[data-remote="true"]').live('ajax:after', function () {

should be

$('form[data-remote="true"]').live('ajax:complete', function () {

Is any of the ajax stuff working right now?

None of my listeners are firing. There's no docs, just the code? It changed listener names in previous releases, but I'm using the new "ajax:beforeSend" and nothing is still getting called.

$('#myform').live("ajax:beforeSend", function() {
console.log('ajax:loading')
}

Ditto with 'ajax:success'. Any tips for debugging? I am using data-disable-with on my submit button..

Need add button[data-confirm] to rails.js

diff --git a/public/javascripts/rails.js b/public/javascripts/rails.js
index 4e9a8ae..566fd2a 100644
--- a/public/javascripts/rails.js
+++ b/public/javascripts/rails.js
@@ -60,7 +60,7 @@ jQuery(function ($) {
     /**
      *  confirmation handler
      */
-    $('a[data-confirm],input[data-confirm]').live('click', function () {
+    $('a[data-confirm],input[data-confirm], button[data-confirm]').live('click', function 

data-confirm not working for button tags

data-confirm issue with .delegate()

In case anyone else runs into this. Some other plugins out there (like the validate one) will override the delegate function. If you go searching around like crazy looking for why your confirmation box isn't showing, make sure you have the latest version of these plugins....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.