Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rewrite for Version 2.0

  • Loading branch information...
commit 1b36da397e29a2a3b0bf0bb1dfa61c4ae033202c 1 parent f0a0029
@spangenberg authored
View
20 .gitignore
@@ -1,5 +1,17 @@
-spec/support/*/Gemfile.lock
-spec/support/*/public/javascripts
-.rvmrc
+*.gem
+*.rbc
.bundle
-imports/*kg/*
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
View
7 Gemfile
@@ -1,9 +1,4 @@
-source :gemcutter
+source 'https://rubygems.org'
# Specify your gem's dependencies in mootools-rails.gemspec
gemspec
-# Rails is already being pulled in through gemspec
-# gem "rails", :git => "git://github.com/rails/rails.git"
-gem "rack", :git => "git://github.com/rack/rack.git"
-gem "sprockets", :git => "git://github.com/sstephenson/sprockets.git"
-gem "i18n", "0.6.0beta1"
View
100 Gemfile.lock
@@ -1,100 +0,0 @@
-GIT
- remote: git://github.com/rack/rack.git
- revision: a9beb476b27914794743d0677b327d5bafb5e8a3
- specs:
- rack (1.2.1)
-
-GIT
- remote: git://github.com/sstephenson/sprockets.git
- revision: c4800417792744c11eb1fb888bbe9a3a82859952
- specs:
- sprockets (2.0.0.beta.2)
- hike (~> 1.0)
- rack (~> 1.0)
- tilt (~> 1.0)
-
-PATH
- remote: .
- specs:
- mootools-rails (1.0.1)
- railties (~> 3.0)
- thor (~> 0.14)
-
-GEM
- remote: http://rubygems.org/
- specs:
- abstract (1.0.0)
- actionmailer (3.0.5)
- actionpack (= 3.0.5)
- mail (~> 2.2.15)
- actionpack (3.0.5)
- activemodel (= 3.0.5)
- activesupport (= 3.0.5)
- builder (~> 2.1.2)
- erubis (~> 2.6.6)
- i18n (~> 0.4)
- rack (~> 1.2.1)
- rack-mount (~> 0.6.13)
- rack-test (~> 0.5.7)
- tzinfo (~> 0.3.23)
- activemodel (3.0.5)
- activesupport (= 3.0.5)
- builder (~> 2.1.2)
- i18n (~> 0.4)
- activerecord (3.0.5)
- activemodel (= 3.0.5)
- activesupport (= 3.0.5)
- arel (~> 2.0.2)
- tzinfo (~> 0.3.23)
- activeresource (3.0.5)
- activemodel (= 3.0.5)
- activesupport (= 3.0.5)
- activesupport (3.0.5)
- arel (2.0.10)
- builder (2.1.2)
- erubis (2.6.6)
- abstract (>= 1.0.0)
- hike (1.0.0)
- i18n (0.6.0beta1)
- mail (2.2.19)
- activesupport (>= 2.3.6)
- i18n (>= 0.4.0)
- mime-types (~> 1.16)
- treetop (~> 1.4.8)
- mime-types (1.17.2)
- polyglot (0.3.3)
- rack-mount (0.6.14)
- rack (>= 1.0.0)
- rack-test (0.5.7)
- rack (>= 1.0)
- rails (3.0.5)
- actionmailer (= 3.0.5)
- actionpack (= 3.0.5)
- activerecord (= 3.0.5)
- activeresource (= 3.0.5)
- activesupport (= 3.0.5)
- bundler (~> 1.0)
- railties (= 3.0.5)
- railties (3.0.5)
- actionpack (= 3.0.5)
- activesupport (= 3.0.5)
- rake (>= 0.8.7)
- thor (~> 0.14.4)
- rake (0.9.2.2)
- thor (0.14.6)
- tilt (1.3)
- treetop (1.4.10)
- polyglot
- polyglot (>= 0.3.1)
- tzinfo (0.3.30)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- bundler (~> 1.0.0)
- i18n (= 0.6.0beta1)
- mootools-rails!
- rack!
- rails (~> 3.0)
- sprockets!
View
22 LICENSE.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Daniel Spangenberg <danielsp@parcydo.com>
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
86 README.md
@@ -4,44 +4,84 @@ MooTools! For Rails! So great.
This gem provides:
-* MooTools 1.4.1
-* MooTools More 1.4.0.1
-* the latest MooTools UJS adapter
-* modified version of Sam Ruby's assert_select_jquery function for MooTools, which is automatically included for use in tests
+ * MooTools 1.4.5
+ * MooTools More 1.4.0.1
+ * the MooTools UJS adapter
+ * assert_select_mootools to test MooTools responses in Ruby tests
-## Rails 3.1
+## Installation
-For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use. These two lines will be added to the file `app/assets/javascripts/application.js` by default:
+Apps generated with Rails 3.1 or later include jquery-rails in the
+Gemfile by default. To use MooTools instead, you have to pass the `-j
+mootools` option. So just make a new app:
- //= require mootools
- //= require mootools_ujs
+```sh
+rails new myapp -j mootools
+```
-If you wish to use MooTools More as well, you can add this line to `application.js`:
+If upgrading from an older version of rails, or for rails 3.0 apps,
+add the mootools-rails gem to your Gemfile.
- //= require mootools-more
+```ruby
+gem 'mootools-rails'
+```
-### Installation
+And run `bundle install`. The rest of the installation depends on
+whether the asset pipeline is being used.
-When you generate a new Rails 3.1 app, pass the `-j mootools` option, like this:
+### Rails 3.1 or greater (with asset pipeline *enabled*)
- rails new myapp -j mootools
+The mootools and mootools-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:
-You're done!
-
-## Rails 3.0
+```js
+//= require mootools
+//= require mootools_ujs
+```
-This gem adds a single generator to Rails 3, mootools:install. Running the generator will remove any Prototype JS files you may happen to have, fetch MooTools and the MooTools-ujs driver for Rails, and (optionally) fetch MooTools More.
+If you wish to use MooTools More as well, you can add this line to
+`app/assets/javascripts/application.js`:
-The gem will also hook into the Rails configuration process, removing Prototype and adding MooTools to the javascript files included by the `javascript_include_tag(:defaults)` call. While the plugin downloads minified and un-minified versions of MooTools and MooTools More, only the minified versions are included in :default.
+```js
+//= require mootools-more
+```
-### Installation
+### Rails 3.0 (or greater with asset pipeline *disabled*)
-In your Gemfile, add this line:
+This gem adds a single generator: `mootools:install`. Running the
+generator will remove any Prototype JS files you may happen to have, and
+copy MooTools and the MooTools-ujs driver for Rails (and optionally,
+MooTools More) to the `public/javascripts` directory.
- gem "mootools-rails"
+This gem will also hook into the Rails configuration process, removing
+Prototype and adding MooTools to the javascript files included by the
+`javascript_include_tag(:defaults)` call. While this gem contains the
+minified and un-minified versions of MooTools and MooTools More, only the minified versions will be included in the `:defaults` when Rails is run in `production` or `test` mode (un-minified versions will be included when Rails is run in `development` mode).
-Then, run `bundle install`. To invoke the generator, run:
+To invoke the generator, run:
- rails generate mootools:install #--more to enable MooTools More
+```sh
+rails generate mootools:install #--more to enable MooTools More
+```
You're done!
+
+## Contributing
+
+Feel free to open an issue ticket if you find something that could be improved. A couple notes:
+
+* If it's an issue pertaining to the mootools-ujs javascript, please
+ report it to the [mootools-ujs
+project](https://github.com/kevinvaldek/mootools-ujs).
+
+* If the mootools or mootools-more scripts are outdated (i.e. maybe a
+ new version of MooTools was released yesterday), feel free to open an
+issue and prod me to get that thing updated. However, for security
+reasons, I won't be accepting pull requests with updated mootools or
+mootools-more scripts.
+
+## Acknowledgements
+
+Many thanks to the [jquery-rails](https://github.com/rails/jquery-rails)
+guys.
+
+Copyright [Daniel Spangenberg](http://neonlex.com), released under the MIT License.
View
11 Rakefile
@@ -1,10 +1 @@
-require 'bundler'
-Bundler::GemHelper.install_tasks
-
-# require "spec/rake/spectask"
-# desc "Run all examples"
-# Spec::Rake::SpecTask.new(:spec) do |t|
-# t.ruby_opts = ['-r test/unit']
-# t.spec_opts = %w[--color]
-# end
-task :default => :spec
+require 'bundler/gem_tasks'
View
59 lib/generators/mootools/install/install_generator.rb
@@ -1,59 +0,0 @@
-require 'rails'
-
-# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
-if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
- module Mootools
- module Generators
- class InstallGenerator < ::Rails::Generators::Base
-
- desc "This generator installs MooTools #{Mootools::Rails::MOOTOOLS_VERSION}, MooTools-ujs, and (optionally) MooTools More #{Mootools::Rails::MOOTOOLS_MORE_VERSION}"
- class_option :more, :type => :boolean, :default => false, :desc => "Include MooTools More"
- source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
-
- def remove_prototype
- Rails::PROTOTYPE_JS.each do |name|
- remove_file "public/javascripts/#{name}.js"
- end
- end
-
- def copy_mootools
- say_status("copying", "MooTools (#{Mootools::Rails::MOOTOOLS_VERSION})", :green)
- copy_file "mootools.js", "public/javascripts/mootools.js"
- copy_file "mootools.min.js", "public/javascripts/mootools.min.js"
- end
-
- def copy_mootools_more
- if options.ui?
- say_status("copying", "MooTools More (#{Mootools::Rails::MOOTOOLS_MORE_VERSION})", :green)
- copy_file "mootools-more.js", "public/javascripts/mootools-more.js"
- copy_file "mootools-mootools.min.js", "public/javascripts/mootools-more.min.js"
- end
- end
-
- def copy_ujs_driver
- say_status("copying", "MooTools UJS adapter (#{Mootools::Rails::MOOTOOLS_UJS_VERSION[0..5]})", :green)
- remove_file "public/javascripts/rails.js"
- copy_file "mootools_ujs.js", "public/javascripts/mootools_ujs.js"
- end
-
- end
- end
- end
-else
- module Mootools
- module Generators
- class InstallGenerator < ::Rails::Generators::Base
- desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
-
- def do_nothing
- say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
- say_status("", "The necessary files are already in your asset pipeline.")
- say_status("", "Just add `//= require mootools` and `//= require mootools_ujs` to your app/assets/javascripts/application.js")
- say_status("", "If you upgraded your app from Rails 3.0 and still have mootools.js, rails.js, or mootools_ujs.js in your javascripts, be sure to remove them.")
- say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
- # ok, nothing
- end
- end
- end
- end
-end
View
59 lib/generators/mootools/install_generator.rb
@@ -0,0 +1,59 @@
+require 'rails'
+
+# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
+if ::Rails.version < '3.1' || !::Rails.application.config.assets.enabled
+ module Mootools
+ module Generators
+ class InstallGenerator < ::Rails::Generators::Base
+
+ desc "This generator installs MooTools #{Mootools::Rails::MOOTOOLS_VERSION}, MooTools-ujs, and (optionally) MooTools More #{Mootools::Rails::MOOTOOLS_MORE_VERSION}"
+ class_option :more, :type => :boolean, :default => false, :desc => 'Include MooTools More'
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
+
+ def remove_prototype
+ Rails::PROTOTYPE_JS.each do |name|
+ remove_file "public/javascripts/#{name}.js"
+ end
+ end
+
+ def copy_mootools
+ say_status('copying', "MooTools (#{Mootools::Rails::MOOTOOLS_VERSION})", :green)
+ copy_file 'mootools.js', 'public/javascripts/mootools.js'
+ copy_file 'mootools.min.js', 'public/javascripts/mootools.min.js'
+ end
+
+ def copy_mootools_more
+ if options.more?
+ say_status('copying', "MooTools More (#{Mootools::Rails::MOOTOOLS_MORE_VERSION})", :green)
+ copy_file 'mootools-more.js', 'public/javascripts/mootools-more.js'
+ copy_file 'mootools-more.min.js', 'public/javascripts/mootools-more.min.js'
+ end
+ end
+
+ def copy_ujs_driver
+ say_status('copying', "MooTools UJS adapter (#{Mootools::Rails::MOOTOOLS_UJS_VERSION[0..5]})", :green)
+ remove_file 'public/javascripts/rails.js'
+ copy_file 'mootools_ujs.js', 'public/javascripts/mootools_ujs.js'
+ end
+
+ end
+ end
+ end
+else
+ module Mootools
+ module Generators
+ class InstallGenerator < ::Rails::Generators::Base
+ desc 'Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps'
+
+ def do_nothing
+ say_status('deprecated', 'You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.')
+ say_status('', 'The necessary files are already in your asset pipeline.')
+ say_status('', 'Just add `//= require mootools` and `//= require mootools_ujs` to your app/assets/javascripts/application.js')
+ say_status('', 'If you upgraded your app from Rails 3.0 and still have mootools.js, rails.js, or mootools_ujs.js in your javascripts, be sure to remove them.')
+ say_status('', 'If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.')
+ # ok, nothing
+ end
+ end
+ end
+ end
+end
View
12 lib/mootools/rails.rb
@@ -1,12 +1,10 @@
+require 'mootools/assert_select' if ::Rails.env.test?
+require 'mootools/rails/engine' if ::Rails.version >= '3.1'
+require 'mootools/rails/railtie'
+require 'mootools/rails/version'
+
module Mootools
module Rails
PROTOTYPE_JS = %w{prototype effects dragdrop controls}
-
- if ::Rails.version < "3.1"
- require 'mootools/rails/railtie'
- else
- require 'mootools/rails/engine'
- end
- require 'mootools/rails/version'
end
end
View
11 lib/mootools/rails/engine.rb
@@ -1,12 +1,5 @@
-# Configure Rails 3.1 to have assert_select_mootools() in tests
-module Mootools
+module Jquery
module Rails
-
- class Engine < ::Rails::Engine
- config.before_configuration do
- require "mootools/assert_select" if ::Rails.env.test?
- end
- end
-
+ Engine = Class.new(::Rails::Engine)
end
end
View
28 lib/mootools/rails/railtie.rb
@@ -1,25 +1,23 @@
-# Configure Rails 3.0 to use public/javascripts/mootools et al
+# Used to ensure that Rails 3.0.x, as well as Rails >= 3.1 with asset pipeline disabled
+# get the minified version of the scripts included into the layout in production.
module Mootools
module Rails
-
class Railtie < ::Rails::Railtie
config.before_configuration do
- require "mootools/assert_select" if ::Rails.env.test?
+ if config.action_view.javascript_expansions
+ if ::Rails.root.join('public/javascripts/mootools-more.min.js').exist?
+ jq_defaults = %w(mootools mootools-more)
+ jq_defaults.map! { |name| "#{name}.min" } if ::Rails.env.production? || ::Rails.env.test?
+ else
+ jq_defaults = ::Rails.env.production? || ::Rails.env.test? ? %w(mootools.min.min) : %w(mootools)
+ end
- if ::Rails.root.join("public/javascripts/mootools-more.min.js").exist?
- jq_defaults = %w(mootools mootools-more)
- jq_defaults.map!{|a| a + ".min" } if ::Rails.env.production?
- else
- jq_defaults = ::Rails.env.production? ? %w(mootools.min) : %w(mootools)
+ # Merge the MooTools scripts, remove the Prototype defaults and finally add 'mootools_ujs'
+ # at the end, because load order is important
+ config.action_view.javascript_expansions[:defaults] -= PROTOTYPE_JS + ['rails']
+ config.action_view.javascript_expansions[:defaults] |= jq_defaults + ['mootools_ujs']
end
-
- # Merge the MooTools scripts, remove the Prototype defaults and finally add 'mootools_ujs'
- # at the end, because load order is important
- config.action_view.javascript_expansions[:defaults] -= PROTOTYPE_JS + ['rails']
- config.action_view.javascript_expansions[:defaults] |= jq_defaults
- config.action_view.javascript_expansions[:defaults] << 'mootools_ujs'
end
end
-
end
end
View
8 lib/mootools/rails/version.rb
@@ -1,8 +1,8 @@
module Mootools
module Rails
- VERSION = "1.0.1"
- MOOTOOLS_VERSION = "1.4.1"
- MOOTOOLS_MORE_VERSION = "1.4.0.1"
- MOOTOOLS_UJS_VERSION = "2c1e98715bc0fc74afa3c79e5d125e55450ba74a"
+ VERSION = '2.0.0'
+ MOOTOOLS_VERSION = '1.4.5'
+ MOOTOOLS_MORE_VERSION = '1.4.0.1'
+ MOOTOOLS_UJS_VERSION = '44c5b14455b2104e79306e6d05cd478777a68c1a'
end
end
View
40 mootools-rails.gemspec
@@ -1,26 +1,24 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/mootools/rails/version', __FILE__)
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'mootools/rails/version'
-Gem::Specification.new do |s|
- s.name = "mootools-rails"
- s.version = Mootools::Rails::VERSION
- s.platform = Gem::Platform::RUBY
- s.authors = ["Daniel Spangenberg"]
- s.email = ["daniel.spangenberg@parcydo.com"]
- s.homepage = "http://rubygems.org/gems/mootools-rails"
- s.summary = "Use MooTools with Rails 3"
- s.description = "This gem provides MooTools and the MooTools-ujs driver for your Rails 3 application."
+Gem::Specification.new do |spec|
+ spec.name = 'mootools-rails'
+ spec.version = Mootools::Rails::VERSION
+ spec.authors = 'Daniel Spangenberg'
+ spec.email = 'danielsp@parcydo.com'
+ spec.description = 'Use MooTools with Rails 3'
+ spec.summary = 'This gem provides MooTools and the MooTools-ujs driver for your Rails 3 application.'
+ spec.homepage = 'http://github.com/neonlex/mootools-rails'
+ spec.license = 'MIT'
- s.required_rubygems_version = ">= 1.3.6"
- s.rubyforge_project = "mootools-rails"
+ spec.files = `git ls-files`.split($/)
+ spec.require_paths = 'lib'
- s.add_dependency "railties", ">= 3.2.0", "< 5.0"
- s.add_dependency "thor", "~> 0.14"
-
- s.add_development_dependency "bundler", "~> 1.0.0"
- s.add_development_dependency "rails", "~> 3.0"
+ spec.add_dependency 'railties', '>= 3.0', '< 5.0'
+ spec.add_dependency 'thor', '>= 0.14', '< 2.0'
- s.files = `git ls-files`.split("\n")
- s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
- s.require_path = 'lib'
+ spec.add_development_dependency 'bundler'
+ spec.add_development_dependency 'rake'
end
View
BIN  pkg/mootools-rails-1.0.0.gem
Binary file not shown
View
3  spec/lib/mootools-rails_spec.rb
@@ -1,3 +0,0 @@
-require 'spec_helper'
-
-it "should probably test something, but I'm damned if I know what"
View
27 spec/spec_helper.rb
@@ -1,27 +0,0 @@
-# Set up RSpec
-require 'webmock/rspec'
-
-Spec::Runner.configure do |config|
- config.include WebMock::API
-end
-
-# Set up generator tests
-require 'rails/all'
-require 'rails/generators'
-require 'rails/generators/test_case'
-
-class TestApp < Rails::Application
- config.root = File.dirname(__FILE__)
-end
-Rails.application = TestApp
-
-module Rails
- def self.root
- @root ||= File.expand_path("../../tmp/rails", __FILE__)
- end
-end
-Rails.application.config.root = Rails.root
-
-# Call configure to load the settings from
-# Rails.application.config.generators to Rails::Generators
-Rails::Generators.configure!
View
6,447 vendor/assets/javascripts/mootools-compat.js
0 additions, 6,447 deletions not shown
View
13,463 vendor/assets/javascripts/mootools-more-compat.js
0 additions, 13,463 deletions not shown
View
1  vendor/assets/javascripts/mootools-more.js
@@ -13370,3 +13370,4 @@ Form.Validator.add('validate-currency-yuan', {
}
});
+
View
14,272 vendor/assets/javascripts/mootools-more.min.js
815 additions, 13,457 deletions not shown
View
15 vendor/assets/javascripts/mootools.js
@@ -37,7 +37,7 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
this.MooTools = {
version: '1.4.5',
- build: '74e34796f5f76640cdb98853004650aea1499d69'
+ build: 'ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0'
};
// typeOf, instanceOf
@@ -174,7 +174,7 @@ var Type = this.Type = function(name, object){
object.prototype.$family = (function(){
return lower;
}).hide();
-
+
}
}
@@ -1410,7 +1410,7 @@ this.Events = new Class({
addEvent: function(type, fn, internal){
type = removeOn(type);
-
+
this.$events[type] = (this.$events[type] || []).include(fn);
if (internal) fn.internal = true;
@@ -3796,16 +3796,17 @@ Element.implement({
var color = result.match(/rgba?\([\d\s,]+\)/);
if (color) result = result.replace(color[0], color[0].rgbToHex());
}
- if (Browser.ie && isNaN(parseFloat(result))){
- if ((/^(height|width)$/).test(property)){
+ if (Browser.opera || Browser.ie){
+ if ((/^(height|width)$/).test(property) && !(/px$/.test(result))){
var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0;
values.each(function(value){
size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt();
}, this);
return this['offset' + property.capitalize()] - size + 'px';
}
- if (Browser.opera && String(result).indexOf('px') != -1) return result;
- if ((/^border(.+)Width|margin|padding/).test(property)) return '0px';
+ if (Browser.ie && (/^border(.+)Width|margin|padding/).test(property) && isNaN(parseFloat(result))){
+ return '0px';
+ }
}
return result;
},
View
6,909 vendor/assets/javascripts/mootools.min.js
477 additions, 6,432 deletions not shown
View
113 vendor/assets/javascripts/mootools_ujs.js
@@ -6,9 +6,10 @@ license: MIT-style
authors:
- Kevin Valdek
+- Oskar Krawczyk
requires:
- core/1.3: '*'
+ core/1.4: '*'
provides:
- Rails 3 MooTools driver
@@ -16,37 +17,49 @@ provides:
...
*/
-(function($) {
+window.addEvent('domready', function(){
+
+ rails.csrf = {
+ token: rails.getCsrf('token'),
+ param: rails.getCsrf('param')
+ };
+
+ rails.applyEvents();
+});
+(function($){
+
window.rails = {
/**
* If el is passed as argument, events will only be applied to
* elements within el. Otherwise applied to document body.
*/
- applyEvents: function(el) {
+ applyEvents: function(el){
el = $(el || document.body);
- var apply = function(selector, action, callback) {
- el.getElements(selector).addEvent(action, callback);
+ var apply = function(selector, action, callback){
+ el.addEvent(action + ':relay(' + selector + ')', callback);
};
-
+
apply('form[data-remote="true"]', 'submit', rails.handleRemote);
apply('a[data-remote="true"], input[data-remote="true"]', 'click', rails.handleRemote);
- apply('a[data-method][data-remote!=true]', 'click', function(e) {
- e.preventDefault();
- if(rails.confirmed(this)) {
- var form = new Element('form', {
+ apply('a[data-method][data-remote!=true]', 'click', function(event){
+ event.preventDefault();
+ if (rails.confirmed(this)){
+ var form = Element('form', {
method: 'post',
action: this.get('href'),
- styles: { display: 'none' }
+ styles: {
+ display: 'none'
+ }
}).inject(this, 'after');
- var methodInput = new Element('input', {
+ var methodInput = Element('input', {
type: 'hidden',
name: '_method',
value: this.get('data-method')
});
- var csrfInput = new Element('input', {
+ var csrfInput = Element('input', {
type: 'hidden',
name: rails.csrf.param,
value: rails.csrf.token
@@ -56,30 +69,29 @@ provides:
}
});
var noMethodNorRemoteConfirm = ':not([data-method]):not([data-remote=true])[data-confirm]';
- apply('a' + noMethodNorRemoteConfirm + ',' + 'input' + noMethodNorRemoteConfirm, 'click', function() {
+ apply('a' + noMethodNorRemoteConfirm + ',' + 'input' + noMethodNorRemoteConfirm, 'click', function(){
return rails.confirmed(this);
});
},
-
- getCsrf: function(name) {
+
+ getCsrf: function(name){
var meta = document.getElement('meta[name=csrf-' + name + ']');
return (meta ? meta.get('content') : null);
},
-
- confirmed: function(el) {
+
+ confirmed: function(el){
var confirmMessage = el.get('data-confirm');
- if(confirmMessage && !confirm(confirmMessage)) {
+ if(confirmMessage && !confirm(confirmMessage)){
return false;
}
return true;
},
-
- disable: function(el) {
+
+ disable: function(el){
var button = el.get('data-disable-with') ? el : el.getElement('[data-disable-with]');
-
- if(button) {
+ if (button){
var enableWith = button.get('value');
- el.addEvent('ajax:complete', function() {
+ el.addEvent('ajax:complete', function(){
button.set({
value: enableWith,
disabled: false
@@ -91,70 +103,59 @@ provides:
});
}
},
-
- handleRemote: function(e) {
- e.preventDefault();
-
- if(rails.confirmed(this)) {
+
+ handleRemote: function(event){
+ event.preventDefault();
+ if(rails.confirmed(this)){
this.request = new Request.Rails(this);
rails.disable(this);
this.request.send();
}
}
};
-
+
Request.Rails = new Class({
-
+
Extends: Request,
-
- initialize: function(element, options) {
+
+ initialize: function(element, options){
this.el = element;
this.parent(Object.merge({
method: this.el.get('method') || this.el.get('data-method') || 'get',
url: this.el.get('action') || this.el.get('href')
}, options));
-
this.addRailsEvents();
},
-
+
send: function(options) {
this.el.fireEvent('ajax:before');
- if(this.el.get('tag') == 'form') {
+ if (this.el.get('tag') === 'form'){
this.options.data = this.el;
}
this.parent(options);
this.el.fireEvent('ajax:after', this.xhr);
},
-
- addRailsEvents: function() {
- this.addEvent('request', function() {
+
+ addRailsEvents: function(){
+ this.addEvent('request', function(){
this.el.fireEvent('ajax:loading', this.xhr);
});
-
- this.addEvent('success', function() {
+
+ this.addEvent('success', function(){
this.el.fireEvent('ajax:success', this.xhr);
});
-
- this.addEvent('complete', function() {
+
+ this.addEvent('complete', function(){
this.el.fireEvent('ajax:complete', this.xhr);
this.el.fireEvent('ajax:loaded', this.xhr);
});
-
- this.addEvent('failure', function() {
+
+ this.addEvent('failure', function(){
this.el.fireEvent('ajax:failure', this.xhr);
});
}
-
+
});
-
+
})(document.id);
-window.addEvent('domready', function() {
-
- rails.csrf = {
- token: rails.getCsrf('token'),
- param: rails.getCsrf('param')
- };
-
- rails.applyEvents();
-});
Please sign in to comment.
Something went wrong with that request. Please try again.