Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added jQuery Migrate #100

Closed
wants to merge 10 commits into from
23 changes: 23 additions & 0 deletions README.md
Expand Up @@ -5,6 +5,7 @@ jQuery! For Rails! So great.
This gem provides:

* jQuery 1.9.0
* jQuery Migrate 1.1.0
* jQuery UI 1.9.2 (javascript only)
* the jQuery UJS adapter
* assert_select_jquery to test jQuery responses in Ruby tests
Expand Down Expand Up @@ -69,6 +70,28 @@ rails generate jquery:install #--ui to enable jQuery UI

You're done!

### jQuery Migrate

jQuery 1.9 removed or modified several APIs. To avoid breaking your scripts, [jQuery Migrate](https://github.com/jquery/jquery-migrate) was introduced. It will bring back all of the behaviour of jQuery 1.8 and optionally log calls to those removed or modified APIs. For details, see the [jQuery Core 1.9 Upgrade Guide](http://jquery.com/upgrade-guide/1.9/).

If you would like to include jQuery Migrate, you can add it in your `application.js`

```js
//= require jquery-migrate.default-config
//= require jquery-migrate
```

`jquery-migrate.default-config` will disable logging of warning messages to the console for Rails' `test` and `production` environments. If you would like to customize this behaviour, omit the require directive and add your own configuration script, for example:

```js
(function() {
var rails_env = "#{Rails.env}"; //.js.str extension required for this
if(rails_env == 'test' || rails_env == 'production') {
jQuery.migrateMute = true;
}
})();
```

## Contributing

Feel free to open an issue ticket if you find something that could be improved. A couple notes:
Expand Down
9 changes: 9 additions & 0 deletions lib/generators/jquery/install/install_generator.rb
Expand Up @@ -8,6 +8,7 @@ class InstallGenerator < ::Rails::Generators::Base

desc "This generator installs jQuery #{Jquery::Rails::JQUERY_VERSION}, jQuery-ujs, and (optionally) jQuery UI #{Jquery::Rails::JQUERY_UI_VERSION}"
class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
class_option :migrate, :type => :boolean, :default => false, :desc => "Include jQuery Migrate"
source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)

def remove_prototype
Expand All @@ -21,6 +22,14 @@ def copy_jquery
copy_file "jquery.js", "public/javascripts/jquery.js"
copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
end

def copy_jquery_migrate
if options.migrate?
say_status("copying", "jQuery Migrate (#{Jquery::Rails::JQUERY_MIGRATE_VERSION})", :green)
copy_file "jquery-migrate.js", "public/javascripts/jquery-migrate.js"
copy_file "jquery-migrate.min.js", "public/javascripts/jquery-migrate.min.js"
end
end

def copy_jquery_ui
if options.ui?
Expand Down
1 change: 1 addition & 0 deletions lib/jquery/rails/version.rb
Expand Up @@ -2,6 +2,7 @@ module Jquery
module Rails
VERSION = "2.2.0"
JQUERY_VERSION = "1.9.0"
JQUERY_MIGRATE_VERSION = "1.1.0"
JQUERY_UI_VERSION = "1.9.2"
JQUERY_UJS_VERSION = "bddff6a677edc54f00e48bde740b0b22d68deef6"
end
Expand Down
@@ -0,0 +1,5 @@
(function() {
if("#{Rails.env}" !== 'development') {
jQuery.migrateMute = true;
}
})();