Giter VIP home page Giter VIP logo

jquery-rails's Introduction

jquery-rails

jQuery! For Rails! So great.

This gem provides:

  • jQuery 1, 2 and 3
  • the jQuery UJS adapter
  • assert_select_jquery to test jQuery responses in Ruby tests

Versions

Starting with v2.1, the jquery-rails gem follows these version guidelines to provide more control over your app's jQuery version from your Gemfile:

patch version bump = updates to jquery-ujs, jquery-rails, and patch-level updates to jQuery
minor version bump = minor-level updates to jQuery
major version bump = major-level updates to jQuery and updates to Rails which may be backwards-incompatible

See VERSIONS.md to see which versions of jquery-rails bundle which versions of jQuery.

Installation

Add

gem 'jquery-rails'

to your Gemfile.

The jquery and jquery-ujs files will be added to the asset pipeline and available for you to use. If they're not already in app/assets/javascripts/application.js by default, add these lines:

//= require jquery
//= require jquery_ujs

If you are running Rails 5.1 and up, and if you have included //= require rails-ujs, then jquery_ujs is not needed anymore. You can just add:

//= require jquery

If you want to use jQuery 2, you can require jquery2 instead:

//= require jquery2
//= require jquery_ujs

And if you want to use jQuery 3, you can require jquery3:

//= require jquery3
//= require jquery_ujs

For jQuery UI, we recommend the jquery-ui-rails gem, as it includes the jquery-ui css and allows easier customization.

As of v3.0, jquery-rails no longer includes jQuery UI. Use the jquery-ui-rails gem above.

Contributing to jquery-rails

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

  • If it's an issue pertaining to the jquery-ujs javascript, please report it to the jquery-ujs project.

  • If the jQuery scripts are outdated (i.e. maybe a new version of jquery was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated jQuery scripts.

See CONTRIBUTING.

License

jquery-rails is released under the MIT License.

Acknowledgements

Many thanks are due to all of the jquery-rails contributors. Special thanks to JangoSteve for tirelessly answering questions and accepting patches, and the Rails Core Team for making jquery-rails an official part of Rails 3.1.

jquery-rails's People

Contributors

ai avatar amatsuda avatar andrewhaines avatar benpickles avatar bquorning avatar cannikin avatar carlosantoniodasilva avatar chancancode avatar csommerauer avatar digitalpardoe avatar dy-dx avatar francocatena avatar fudoshiki avatar georgeclaghorn avatar gtd avatar guilleiguaran avatar indirect avatar jangosteve avatar jeremy avatar joliss avatar josevalim avatar juank-pa avatar kaspth avatar lucasmazza avatar mrhead avatar rafaelfranca avatar robertd avatar robertomiranda avatar snowyote avatar thegcat 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

jquery-rails's Issues

jQuery 1.6.3 & 1.6.4 support

jQuery 1.6.3 broke some stuff on jquery-ujs. Until it's fixed, I'm hesitant to make it the default for jquery-rails. I opened a ticket in the jquery bug tracker here: http://bugs.jquery.com/ticket/10202

In the meantime, I'll open this ticket to keep track and let people know why jquery-rails is staying at 1.6.2 for the time being.

Support for CDN

Hi,

Do you plan to add support for any jQuery CDN? It could be great to have option to include local copy of jQuery in development envirement and point the user's browser to any CDN in production (for example, google).

It also solves the problem of distributing minified versions.

Thanks.

assert_select_jquery without a block returns "No JQuery call matches #{opts.inspect}" even though it did find a match

Rails 3.0.6, jquery-rails 1.0.9, ruby 1.9.2-p180 and p136

below usage does not work even though a match is found

assert_select_jquery "#userInfo"
assert_select_jquery :replaceWith
assert_select_jquery :replaceWith, "#userInfo"

But this one does

assert_select_jquery :replaceWith,"#userInfo" do
    assert_select "input#user_first_name"
end

This is the js file that answers for the edit action

#edit.js.erb
$('#userInfo').replaceWith("<%=escape_javascript(render :partial=>"edit_user", :locals=>{:user => @user} )%>");

and this is the partial that is rendered

#_edit_user.html.erb
<div class="profile twoPixRadius cocoBorder user lightGrayFade" id="userInfo">
    <%= form_for(@user, :remote => true, :id=>"edit_user_info" ) do |f| %>
        <h2> My Information</h2>
        <div>
           <label for="user_first_name">Name</label>
           <%= f.text_field :first_name, :size=>"60", :class=>"text-input" %>
           <%= f.text_field :last_name, :size=>"60", :class=>"text-input" %>
           <br/> 
       </div>
       <div>
           <%= f.submit "Update", :class =>"vportant" %>
          <input type="button" value="Cancel" name="cancel" id="user_cancel"/>
       </div>
    <% end %>
</div>

Solution Some preliminary testing shows that it works even for the previous cases when adding the PATTERN_HTML to the regex pattern even when no block was given (on line 55 of assert_select.rb). I have not tested for jquery_opt.

 #assert_select.rb
      53   pattern = "\\.#{jquery_method || '\\w+'}\\("
      54   pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
    ->55   pattern = "#{pattern}#{PATTERN_HTML}" #if block  removed to make this work
      56   pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id

Ctrl click should work

Hello,

As many of you I guess, I like to Ctrl+Click to open pages in another tab. Because of the click handler on remote link this does not work.

For now, I'm trying to edit the live("click.rails") function with this one :

$(rails.linkClickSelector).live('click.rails', function(e) {
var link = $(this);
if (!rails.allowAction(link)) return rails.stopEverything(e);

if (link.data('remote') !== undefined) {
  if (e.which == 2 || e.metaKey || e.ctrlKey){
    return true
  } else {
    rails.handleRemote(link);
    return false;
  }
} else if (link.data('method')) {
  rails.handleMethod(link);
  return false;
}

});

But I haven't tested it properly yet.
Any thoughts ?

Request for spec removal

Given there are no real tests for this gem I suggest to remove them. It's not adapted to RSpec2 and outdated since Rails::Generators.configure! now takes one argument.

Also, I think it makes sense since this gem only provides jquery through the asset pipeline and has not logic to test.

The reason is because if a project dynamically runs all tests over all engines that are loaded, it has to skip jquery-rails explicitly to make tests pass.

Update Invalid gemspec date

Invalid gemspec in [/var/lib/gems/1.8/specifications/jquery-rails-2.0.1.gemspec]: invalid date format in specification: "2012-02-28 00:00:00.000000000Z"

This message is printed anytime rails commands are executed.

Use Google's CDN to host jQuery

Here's a gem that already provides this behaviour: https://github.com/kenn/jquery-rails-cdn

I think this should be the default behaviour of the jquery-rails gem.
It seems like a waste of resources if we are all compiling our own copies of jQuery and jquery-ui into our application.js.

Sites like Twitter, Stack Overflow, Posterous, and Foursquare are ensuring that your users will already have a cached copy of jQuery ready for you to use, because they all reference Google's CDN. This provides cross-site caching.

You may find it helpful to read the following articles:

In order to implement this, we would need to provide an install generator (rails g jquery:install), since we'll need to make some changes to the Rails application:

  • Remove //= require jquery from application.js
  • Add = jquery_include_tag :google_schemeless to your layout
  • Add config.assets.precompile += ['jquery.js'] to application.rb (provides a fallback in case Google's CDN goes down, is blocked, you're offline, etc.)

disable_with doesn't work with link in IE

link_to "do it", :data => {:disable_with => 'Please wait...'}
Please note that this is not a remote link.

It works as expected in latest Chrome and latest Firefox.
It never shows "Please wait..." in the latest Safari (feels like a cosmetic rendering bug in Safari, v6 just seems generally buggy, earlier versions worked fine)
In IE8 and IE9 it shows "Please wait..." but doesn't make the request. It just hangs. So the link is essentially broken.

I tested this with 2.0.2 and with 2.1.3.

Radio with required=true preventing form submission on 2.0.3 - 2.1.1

Since upgrading, any form that has more than one radio with required=true on it will not submit. It appears they are failing some kind of validation.

Excuse the crude example, but if you fill out the form at http://jsfiddle.net/Rumpp/2/ & try to submit it, check the network tab and observe that no POST is ever made. Removing the required="required" on the radios fixes the issue.

edit: I think this line in UJS may be the culprit 463ace5#L1L240

I updated to jquery-rails 1.0.18, but still getting old jquery

Hi, I updated to the new version, and restarted my server, but it still serves the old jquery. I am just running in development mode.

I did rake assets:clean just to be sure, but it did make any difference.

I am running rails 3.1.0. Is there something else I need to do to remove the old jquery. Now it is still loading jquery 1.6.2.

If you need more info, just ask.

including jquery_ujs twice does not raise an error

I just included jquery_ujs twice (once in the head, once in the footer - merge accident) and did not get a warning like "jquery-ujs has already been loaded!", but instead all Rails-related events where fired twice: clicking an a[data-remote] triggered 2 ajax requests, forms are submitted twice.

Problems with 2.2.0 version

Hello. I have an app that is heavily relied on jquery. I just updated to 2.2.0 version and got the following error in the Firebug console:

TypeError: $(...).live is not a function

....get(0).nodeName.toUpperCase()=="LI"?(i.replaceWith(o),i=o):i.empty().append(n)

And part of my functionality was broken. When i reverted to 2.1.4 version everything was OK again.

Retain the generators for people not using the asset pipeline.

There are many good reasons that someone might not be using the asset pipeline, or might not be using it yet, even if they are using the rest of rails-3.1.

For people not using the asset pipeline, the generators remain useful and correct, and should be retained.

Asset digest issue

jquery ui functions dont work if

config.assets.digest = false

rails (3.2.3)
jquery-rails (2.0.2)

by default the digest is false except in the production environment. The js files are successfully included but the browser console shows errors like

autocomplete is not a function
dialog is not a function

railties 3.2.0 is out

but not supported....

ERROR: While executing gem ... (Gem::DependencyError)

Unable to resolve dependencies: jquery-rails requires railties (< 5.0, >= 3.2.0.beta)

Hope you continue your good job!
Serge

Update sprockets dependency

Unfortunately I'm trying to use sprockets >= 2.3, but because I am using jquery-rails v2.0 that depends on sprockets 2.1.2, I am unable to load up the correct version of sprockets.

Bundler could not find compatible versions for gem "sprockets":
  In Gemfile:
    sprockets (>= 2.3) ruby

    jquery-rails (>= 2.0) ruby depends on
      sprockets (2.1.2)```

jquery-rails broken in IE6

Since 2.0.3 (16 August 2012) and upwards, anything with :remote => true (eg. link with :remote => true) has stopped working on IE6. Unfortunately we still have a lot of users on IE6 which I cannot get rid of!

Downgrading back to jquery-rails 2.0.2 works fine.

I'm using rails 3.2.6 at present.

Is anyone else having this problem?

Could not override ajax() with Rails 3.1

With jQuery 1.4.2 and Rails 3.x (manual method), I could override and bind the ajax to invoke callbacks on ajax success. However, this doesn't work with jquery-ujs 1.0.12 and Rails 3.1 (git) that leads to two requests to be invoked instead of one. I suspect this is related to issue #10 Here is an example:

  1. Generate test app

    rails new test123
    cd test123
    rails g scaffold states name:string abbr:string
    rake db:migrate
    
  2. Make sure we're usin the latest 3-1-stable by modify Gemfile:

    gem 'rails', :git => 'git://github.com/rails/rails.git', :branch => '3-1-stable'
    
  3. bundle install
  4. Modify following files:

app/controllers/states_controller.rb:

  def new
    @state = State.new

    respond_to do |format|
      format.html # new.html.erb
      format.js { render :text => 'hello world' } # we add this 
    end
  end

app/views/states/index.html.erb:

<%= link_to 'New State', new_state_path, :remote => true %>

app/assets/javascripts/states.js:

$(function(){
    $('a[data-remote=true]').live('click', function(){
        $.get(this.href, function(data) {
          alert(data);
        });
        return false;
    });
});

With the help of Firebug, it is indicated that there are 2 requests invoked. This might explain that the binding is not successful.

break on install on rails 3.1

for 2 days, the gem update command give me :

ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]

Updating installed gems
Updating jquery-rails
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: jquery-rails requires railties (< 5.0, >= 3.2.0.beta)

So it break on my system without rails 3.2 beta....
I think a new release shoud no break the current production version
Any idea to correct it ?

Bump the minor version of jquery-rails for new minor versions of jQuery

Not an issue per se, but I wonder if it would be better to bump the minor version of jquery-rails when a new minor version of jquery is bundled?

For example, 1.0.17 of jquery-rails included jQuery 1.7. If it were tagged as 1.1.0 instead, we could more easily manage the version of jQuery we want in our Gemfile. It's not currently possible to bundle update and get the latest patch release of a particular jQuery version.

# We want jQuery to 1.6.x
gem 'jquery-rails', '~>1.0'

Of course, this is tricky to manage sensibly for jquery-rails because it essentially bundles up a bunch of different libraries.

What I'm wondering aloud is whether there is a more meaningful way to tag jquery-rails releases. What does everyone think?

Move jquery-ui.js into jquery-ui-rails gem

Hey guys,

I just packaged up jQuery UI for the asset pipeline: http://www.solitr.com/blog/2012/02/jquery-ui-rails-gem-for-the-asset-pipeline/

I was wondering what you thought about moving the jquery-ui.js that's currently shipping with jquery-rails into the jquery-ui-rails gem?

Right now we can't add a "jquery-ui.js" asset to jquery-ui-rails, because it would conflict with jquery-rails's version. (Which of the two gets picked up by Sprockets would be undefined, so that's asking for trouble.) So here's my suggestion:

  • In jquery-rails:
    1. Make one last 2.x release with jquery-ui.js 1.8.17
    2. Remove jquery-ui.js and jquery-ui.min.js from jquery-rails
    3. Bump the major version to 3.0.0-beta1 and release
    4. Put a note in the README that people might need to add the jquery-ui-rails gem with the 3.0.0 beta release if they want to use jquery-ui[1]
  • In jquery-ui-rails:
    1. Add jquery-ui.js (essentially the same as the one that ships with jquery-rails)
    2. Depend on jquery-rails >= 3.0.0-beta1 to avoid conflicts
    3. Bump the version to 1.0.0-beta1 and release

What do you think?

[1] I was thinking whether jquery-rails should depend on jquery-ui-rails so people get jquery-ui automatically. But since jquery-ui-rails adds a bunch of files (like "jquery.ui.datepicker.js") into the asset space that might conceivably conflict with user-supplied jQuery UI assets, I think it's best not to force it onto people, and instead require them to add jquery-ui-rails to their Gemfile if they want it.

Gem and Jquery versions

Would be nice if there was a list of what gem version corresponds to what version of jquery in an easy to find place. Might be even better if the version numbers moved in sync, since sometimes require a specific version for other software you're using.

No generator?

weirdly, rails g jquery isnt recognized in my app... is this happening just here?

I've turned asset pipeline off here because it was serving some files, but not others and tried to generate the driver but there's no jquery generators for the app..

rails g doesnt show nothing for jquery here also...

rails31/gems/jquery-rails-1.0.12

jQuery 1.8.0 released

Downloads

Additions

  • Sizzle re-architected: selector engine rewritten for speed
  • Animations re-imagined: large refactor of animation system, improvements to generality and extendability
  • Automatic CSS prefixing: browser-specific prefixes are automatically added when using CSS properties
  • More flexibility with $(html, props): ability to use any jQuery method or plugin in object passed to $(html, props)
  • More than 160 bugs closed
  • Smaller code size
  • Modularity: new grunt-based build system allows stripping jQuery down

Removed

  • $(element).data(“events”)
  • Deferred.isResolved() and Deferred.isRejected()
  • $(element).closest(Array) returning Array
  • $.curCSS
  • $.attrFn

jQuery 1.8.0 is compatible with with the latest versions of jQuery UI (1.8.22), and jQuery Mobile (1.1.1).

There are more details at the full blog post

Version 2.0.0 has added a bad dependency to Rails 3.2.8.rc

After being stable for months, jquery-rails 2.0.0 inexplicably added a dependency to the new Rails release candidate, 3.2.8.rc. This breaks the sample application for a bunch of Rails Tutorial readers, among others—anyone using 2.0.0 with Rails 3.2.x is probably affected. Version 2.0.2 works fine, and I've updated the tutorial's Gemfile accordingly, but this still seems worth fixing.

By the way, I'm genuinely curious to know how this happened. How could a previous version of a gem suddenly depend on an as-yet unreleased version of Rails?

Putting JQuery into application.js causes remote forms to submit twice

I ran into an interesting problem where I had a remote form:

#index.html.erb#quick_reply
<%= simple_form_for [@discussion, @post], :remote => true do |f| %>
  <%= f.input :body, :input_html => {:class => 'span12 short_text_area' } %>
  <%= f.submit 'Post Reply', :class => 'btn-primary' %>
<% end %>

And when the form submitted, it was processed twice. I ended up fixing by removing

//= require jquery
//= require jquery_ujs

from my application.js file. This is in exact opposition with what this gem's documentation says, but it seems that I'm getting the JQuery scripts without having them in the manifest file. Does the doc need updated or is there something else going on here?

Non-Remote Non-GET Links with Request Entities

Feature Suggestion: Support non-remote non-get links with request entities.

Given the following:

link_to title, resource, :method => :put, :data => { :params => { "a" => "x", "b" => "y" } }

This, when clicked, should send a PUT request with the params above as the request entity in either text/www-url-form-encoded or application/json. It looks like there's code to handle this scenario in a :remote => true link; handle this case even when it is not a :remote => true link.

javascript_include_tag :all causes duplicate jquery inclusion

I like the approach of having both a minified and regular version of jquery. The problem is that this results in javascript_include_tag :all always including whichever one was not specified in the bulk of the js files. I'm really not sure how to solve this...

In my case I could just put it in a subdirectory, but that breaks down if the :recursive option is set.

Ideas?

v.2.1.2 breaks IE8 performance

There seem to be an issue with performance using 2.1.2 of this gem in IE8. The selectors used in jquery_ujs are interpreted very slowly by jquery.

This is most likely not a problem of jquery-rails, but I wanted to report it here if more people experience this issue.

Don't tight up jquery-rails to a jquery version

require jquery should send me the latest jquery
require jquery-1.6 should send me the latest 1.6 release
etc.

same for jquery-ui and jquery_ujs

Use case: when jquery is a dependency of an engine, you (maintainer of the engine) don't want to freeze jquery-rails to the supported version of jquery-rails containing the supported version of the required library.

Gem dependencies are meant for lib compatibilities and should not get in the way transversally.

edit: just saw #2
.. Maybe reconsider?

Why does bundle install always take SOOOO long on jquery-rails?

I was curious as I'm learning Rails from scratch.

Whenever I run a bundle install command on any Rails application it always takes several minutes on "Installing jquey-rails" - why is that?

Every other gem in my Gemfile bundles quickly in 1 to 10 seconds, except this gem.

Any ideas?

Upgrade jQuery UI to 1.8.16

Is it possible to get this gem updated to the latest jqueryui (1.8.16) ?

There is a bug in 1.8.14 that has since been fixed, so I'm pretty keen to get the latest version

thanks,
-adam

Hello, I m Bender

aka47 oche chetki pacan!
it would help if you would also add each package of jquery-ui into the gem datepicker, timepicker, effects etc.. so one could decide to use all of them or just pick some of them

No AJAX callbacks are triggering

I'm on Rails 3.0.8 and jquery-rails 1.0.12. I ran the jquery generator to install the javascripts. Both jquery and jquery_ujs are included in my defaults and I can verify they are being included on the page.

Here's my javascript:

jQuery(function($) {
  $("#deactivate")
    .bind("ajax:success", function() {
      alert("HELLO");
    })
    .bind("ajax:error", function() {
      alert("GOODBYE");
    }
  );
});

The link:

= link_to 'Deactivate', activate_patient_path(patient), :id => 'deactivate', :class => "button button-red", :remote => true

The activate action:

def activate
    patient = Patient.find(params[:id])
    patient.do_not_call = !patient.do_not_call
    if patient.save
      render :json => :success
    else
      render :status => 500, :json => :success
    end
end

The ajax call seems to be working fine. The action is triggered and I can see the changes in the database. However, the ajax callbacks are not being triggered. I can't get any of them to work. I can get other events, such as click, to work perfectly.

If I debug rails_ujs in Firebug I see that the following code gets ran from the Rails ajax block:

success: function(data, status, xhr) {
  element.trigger('ajax:success', [data, status, xhr]);
}

If I execute

element = $("#deactivate");
element.trigger('ajax:success');

in the console I can get the callback to trigger.

Using Firebug, if I put a breakpoint at the element.trigger('ajax:success', [data, status, xhr]) line in rails_ujs and then bind $("#deactivate") to ajax:success when stopped the callback will trigger. The callback will continue to trigger correctly when I click the link until I refresh the page. It seems that $("#deactivate") is not the same reference to the element that the trigger is being executed upon.

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.