Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add test app.

  • Loading branch information...
commit 1a0a2a50f6c21df853a6fcedbec26550ae8a3b59 1 parent 1910700
@huacnlee authored
Showing with 2,384 additions and 167 deletions.
  1. +2 −0  .gitignore
  2. +1 −0  .rspec
  3. +12 −27 Gemfile
  4. +67 −140 Gemfile.lock
  5. +7 −0 spec/dummy/Rakefile
  6. +2 −0  spec/dummy/app/assets/javascripts/app.coffee
  7. +8 −0 spec/dummy/app/assets/stylesheets/app.scss
  8. +12 −0 spec/dummy/app/controllers/application_controller.rb
  9. +7 −0 spec/dummy/app/controllers/users_controller.rb
  10. +2 −0  spec/dummy/app/helpers/application_helper.rb
  11. +20 −0 spec/dummy/app/models/user.rb
  12. +26 −0 spec/dummy/app/views/layouts/application.html.erb
  13. +1 −0  spec/dummy/app/views/users/index.html.erb
  14. +4 −0 spec/dummy/config.ru
  15. +52 −0 spec/dummy/config/application.rb
  16. +10 −0 spec/dummy/config/boot.rb
  17. +5 −0 spec/dummy/config/environment.rb
  18. +39 −0 spec/dummy/config/environments/development.rb
  19. +49 −0 spec/dummy/config/environments/production.rb
  20. +37 −0 spec/dummy/config/environments/test.rb
  21. +7 −0 spec/dummy/config/initializers/backtrace_silencers.rb
  22. +223 −0 spec/dummy/config/initializers/devise.rb
  23. +7 −0 spec/dummy/config/initializers/homeland.rb
  24. +10 −0 spec/dummy/config/initializers/inflections.rb
  25. +5 −0 spec/dummy/config/initializers/mime_types.rb
  26. +7 −0 spec/dummy/config/initializers/secret_token.rb
  27. +8 −0 spec/dummy/config/initializers/session_store.rb
  28. +57 −0 spec/dummy/config/locales/devise.en.yml
  29. +5 −0 spec/dummy/config/locales/en.yml
  30. +14 −0 spec/dummy/config/locales/homeland.zh-CN.yml
  31. +19 −0 spec/dummy/config/mongoid.yml
  32. +8 −0 spec/dummy/config/routes.rb
  33. +7 −0 spec/dummy/db/seeds.rb
  34. +26 −0 spec/dummy/public/404.html
  35. +26 −0 spec/dummy/public/422.html
  36. +26 −0 spec/dummy/public/500.html
  37. 0  spec/dummy/public/favicon.ico
  38. +6 −0 spec/dummy/script/rails
  39. BIN  spec/dummy/vendor/assets/images/jquery.chosen.png
  40. +898 −0 spec/dummy/vendor/assets/javascripts/jquery.chosen.js
  41. +99 −0 spec/dummy/vendor/assets/javascripts/jquery.hotkeys.js
  42. +147 −0 spec/dummy/vendor/assets/javascripts/jquery.timeago.js
  43. +367 −0 spec/dummy/vendor/assets/stylesheets/jquery.chosen.scss
  44. +7 −0 spec/homeland_spec.rb
  45. +9 −0 spec/integration/navigation_spec.rb
  46. +33 −0 spec/spec_helper.rb
View
2  .gitignore
@@ -11,6 +11,8 @@ config/config.yml
config/mongoid.yml
config/mailer_daemon.yml
public/uploads/**/*
+spec/dummy/tmp
+spec/dummy/log
public/t
public/t/**/*
.redcar
View
1  .rspec
@@ -0,0 +1 @@
+--colour
View
39 Gemfile
@@ -1,33 +1,18 @@
source 'http://ruby.taobao.org'
gem "rails", "3.1.1"
-gem "bson_ext", "1.4.1"
-gem "mongoid", "2.2.0"
-gem 'carrierwave', '0.5.6'
-gem 'carrierwave-mongoid', '0.1.2', :require => 'carrierwave/mongoid'
-gem 'mini_magick','3.3'
-gem 'mongo-rails-instrumentation','0.2.4'
-gem "mongoid-eager-loading",'0.3.1'
-gem 'mongoid_auto_increment_id', "0.2"
-gem "devise", "1.4.5"
+gem "mongoid", "2.4.8"
+gem "bson_ext", "1.6.2"
+gem "devise"
gem 'will_paginate', '3.0.pre2'
-gem 'omniauth', '0.3.0'
-gem "oa-openid", '0.3.0'
-gem 'redis-store', '1.0.0.1'
-gem 'chinese_pinyin', '0.4.1'
-gem "rmmseg-cpp-huacnlee", "0.2.8"
-gem 'redis-search', '0.6.3'
-gem "rails-i18n","0.1.8"
-gem 'redis-namespace','~> 1.0.2'
-gem "redis-objects", "0.5.2"
gem "bluecloth","2.1.0"
-gem "nokogiri", "1.5.0"
-gem "jquery-rails", "1.0.16"
-gem "rails_autolink", ">= 1.0.4"
-gem "settingslogic", "~> 2.0.6"
+gem "jquery-atwho-rails"
+gem 'anjlab-bootstrap-rails', '>= 2.0', :require => 'bootstrap-rails'
+gem "jquery-rails"
+gem "rails_autolink"
+
+gem "sass-rails"
+gem 'coffee-rails'
+gem 'rspec-rails'
+gem 'capybara'
-group :assets do
- gem 'sass-rails', " ~> 3.1.4"
- gem 'coffee-rails', "~> 3.1.1"
- gem 'uglifier'
-end
View
207 Gemfile.lock
@@ -1,8 +1,6 @@
GEM
- remote: http://rubygems.org/
+ remote: http://ruby.taobao.org/
specs:
- XMLCanonicalizer (1.0.1)
- log4r (>= 1.0.4)
actionmailer (3.1.1)
actionpack (= 3.1.1)
mail (~> 2.3.0)
@@ -31,118 +29,69 @@ GEM
activesupport (= 3.1.1)
activesupport (3.1.1)
multi_json (~> 1.0)
- addressable (2.2.6)
+ anjlab-bootstrap-rails (2.0.2.1)
+ railties (>= 3.0)
+ sass
arel (2.2.1)
bcrypt-ruby (3.0.1)
bluecloth (2.1.0)
- bson (1.4.1)
- bson_ext (1.4.1)
+ bson (1.6.2)
+ bson_ext (1.6.2)
+ bson (~> 1.6.2)
builder (3.0.0)
- carrierwave (0.5.6)
- activesupport (~> 3.0)
- carrierwave-mongoid (0.1.2)
- carrierwave (>= 0.5.6)
- mongoid (~> 2.1)
- chinese_pinyin (0.4.1)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (~> 3.1.0)
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.1.2)
- devise (1.4.5)
+ coffee-script-source (1.3.1)
+ devise (2.0.4)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
- warden (~> 1.0.3)
+ railties (~> 3.1)
+ warden (~> 1.1.1)
+ diff-lcs (1.1.3)
erubis (2.7.0)
- execjs (1.2.9)
+ execjs (1.3.0)
multi_json (~> 1.0)
- faraday (0.7.5)
- addressable (~> 2.2.6)
- multipart-post (~> 1.1.3)
- rack (>= 1.1.0, < 2)
+ ffi (1.0.11)
hike (1.2.1)
i18n (0.6.0)
- jquery-rails (1.0.16)
+ jquery-atwho-rails (0.1.5)
+ jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)
- log4r (1.1.9)
- macaddr (1.4.0)
- systemu (~> 2.2.0)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
- mini_magick (3.3)
- subexec (~> 0.1.0)
- mongo (1.4.1)
- bson (= 1.4.1)
- mongo-rails-instrumentation (0.2.4)
- mongoid (2.2.0)
- activemodel (~> 3.0)
+ mongo (1.6.2)
+ bson (~> 1.6.2)
+ mongoid (2.4.8)
+ activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
- mongoid-eager-loading (0.3.1)
- mongoid_auto_increment_id (0.2)
- mongoid (~> 2.2.0)
multi_json (1.0.3)
- multi_xml (0.4.1)
- multipart-post (1.1.3)
- net-ldap (0.2.2)
- nokogiri (1.5.0)
- oa-basic (0.3.0)
- oa-core (= 0.3.0)
- rest-client (~> 1.6.0)
- oa-core (0.3.0)
- oa-enterprise (0.3.0)
- XMLCanonicalizer (~> 1.0.1)
- addressable (~> 2.2.6)
- net-ldap (~> 0.2.2)
- nokogiri (~> 1.5.0)
- oa-core (= 0.3.0)
- pyu-ruby-sasl (~> 0.0.3.1)
- rubyntlm (~> 0.1.1)
- uuid
- oa-more (0.3.0)
- multi_json (~> 1.0.0)
- oa-core (= 0.3.0)
- rest-client (~> 1.6.0)
- oa-oauth (0.3.0)
- faraday (~> 0.7.3)
- multi_json (~> 1.0.0)
- multi_xml (~> 0.4.0)
- oa-core (= 0.3.0)
- oauth (~> 0.4.0)
- oauth2 (~> 0.5.0)
- oa-openid (0.3.0)
- oa-core (= 0.3.0)
- rack-openid (~> 1.3.1)
- ruby-openid-apps-discovery (~> 1.2.0)
- oauth (0.4.5)
- oauth2 (0.5.1)
- faraday (~> 0.7.4)
- multi_json (~> 1.0.3)
- omniauth (0.3.0)
- oa-basic (= 0.3.0)
- oa-core (= 0.3.0)
- oa-enterprise (= 0.3.0)
- oa-more (= 0.3.0)
- oa-oauth (= 0.3.0)
- oa-openid (= 0.3.0)
- orm_adapter (0.0.5)
+ nokogiri (1.5.2)
+ orm_adapter (0.0.6)
polyglot (0.3.2)
- pyu-ruby-sasl (0.0.3.3)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
- rack-openid (1.3.1)
- rack (>= 1.1.0)
- ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
@@ -155,10 +104,8 @@ GEM
activesupport (= 3.1.1)
bundler (~> 1.0)
railties (= 3.1.1)
- rails-i18n (0.1.8)
- i18n (~> 0.5)
- rails_autolink (1.0.4)
- rails (>= 3.1.0)
+ rails_autolink (1.0.6)
+ rails (~> 3.1)
railties (3.1.1)
actionpack (= 3.1.1)
activesupport (= 3.1.1)
@@ -169,83 +116,63 @@ GEM
rake (0.9.2.2)
rdoc (3.11)
json (~> 1.4)
- redis (2.2.2)
- redis-namespace (1.0.3)
- redis (< 3.0.0)
- redis-objects (0.5.2)
- redis (>= 2.1.1)
- redis-search (0.6.3)
- chinese_pinyin (>= 0.3.0)
- redis (>= 2.1.1)
- redis-namespace (~> 1.0.2)
- rmmseg-cpp-huacnlee (>= 0.2.8)
- redis-store (1.0.0.1)
- redis (~> 2.2.1)
- rest-client (1.6.7)
- mime-types (>= 1.16)
- rmmseg-cpp-huacnlee (0.2.8)
- ruby-openid (2.1.8)
- ruby-openid-apps-discovery (1.2.0)
- ruby-openid (>= 2.1.7)
- rubyntlm (0.1.1)
- sass (3.1.10)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
+ rubyzip (0.9.6.1)
+ sass (3.1.16)
sass-rails (3.1.4)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.4)
sprockets (~> 2.0.0)
tilt (~> 1.3.2)
- settingslogic (2.0.6)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- subexec (0.1.0)
- systemu (2.2.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.30)
- uglifier (1.0.4)
- execjs (>= 0.3.0)
- multi_json (>= 1.0.2)
- uuid (2.3.4)
- macaddr (~> 1.0)
- warden (1.0.6)
+ warden (1.1.1)
rack (>= 1.0)
will_paginate (3.0.pre2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
+ anjlab-bootstrap-rails (>= 2.0)
bluecloth (= 2.1.0)
- bson_ext (= 1.4.1)
- carrierwave (= 0.5.6)
- carrierwave-mongoid (= 0.1.2)
- chinese_pinyin (= 0.4.1)
- coffee-rails (~> 3.1.1)
- devise (= 1.4.5)
- jquery-rails (= 1.0.16)
- mini_magick (= 3.3)
- mongo-rails-instrumentation (= 0.2.4)
- mongoid (= 2.2.0)
- mongoid-eager-loading (= 0.3.1)
- mongoid_auto_increment_id (= 0.2)
- nokogiri (= 1.5.0)
- oa-openid (= 0.3.0)
- omniauth (= 0.3.0)
+ bson_ext (= 1.6.2)
+ capybara
+ coffee-rails
+ devise
+ jquery-atwho-rails
+ jquery-rails
+ mongoid (= 2.4.8)
rails (= 3.1.1)
- rails-i18n (= 0.1.8)
- rails_autolink (>= 1.0.4)
- redis-namespace (~> 1.0.2)
- redis-objects (= 0.5.2)
- redis-search (= 0.6.3)
- redis-store (= 1.0.0.1)
- rmmseg-cpp-huacnlee (= 0.2.8)
- sass-rails (~> 3.1.4)
- settingslogic (~> 2.0.6)
- uglifier
+ rails_autolink
+ rspec-rails
+ sass-rails
will_paginate (= 3.0.pre2)
View
7 spec/dummy/Rakefile
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Dummy::Application.load_tasks
View
2  spec/dummy/app/assets/javascripts/app.coffee
@@ -0,0 +1,2 @@
+#= require jquery
+#= require jquery_ujs
View
8 spec/dummy/app/assets/stylesheets/app.scss
@@ -0,0 +1,8 @@
+/*
+ *= require bootstrap
+ *= require homeland
+ *= require_self
+ */
+
+* { margin:0; padding:0; }
+body { font-size:100%; }
View
12 spec/dummy/app/controllers/application_controller.rb
@@ -0,0 +1,12 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ before_filter :authenticate_user!
+
+ def require_user
+ if !current_user
+ redirect_to new_session_path(:user)
+ return false
+ end
+ end
+end
View
7 spec/dummy/app/controllers/users_controller.rb
@@ -0,0 +1,7 @@
+class UsersController < ApplicationController
+ def index
+ end
+
+ def show
+ end
+end
View
2  spec/dummy/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
View
20 spec/dummy/app/models/user.rb
@@ -0,0 +1,20 @@
+# coding: utf-8
+class User
+ include Mongoid::Document
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
+ devise :database_authenticatable, :registerable
+
+ ## Database authenticatable
+ field :email, :type => String, :null => false, :default => ""
+ field :encrypted_password, :type => String, :null => false, :default => ""
+ field :name
+
+ def avatar_small_url
+ ""
+ end
+
+ def to_param
+ self.id.to_s
+ end
+end
View
26 spec/dummy/app/views/layouts/application.html.erb
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Dummy</title>
+ <%= stylesheet_link_tag "app" %>
+ <%= javascript_include_tag "app" %>
+ <%= csrf_meta_tag %>
+</head>
+<body>
+
+ <div class="container">
+ <div class="navbar">
+ <li><%= link_to "BBS", homeland.topics_path %></li>
+ <% if current_user %>
+ Hello, <%= link_to current_user.email, main_app.user_path(current_user) %>
+ <%= link_to "Sign out", main_app.destroy_user_session_path, :method => :delete %>
+ <% else %>
+ <%= link_to "Sign in", main_app.session_path(:user) %> /
+ <%= link_to "Sign up", main_app.new_user_registration_path %>
+ <% end %>
+ </div>
+ <%= yield %>
+ </div>
+
+</body>
+</html>
View
1  spec/dummy/app/views/users/index.html.erb
@@ -0,0 +1 @@
+Root
View
4 spec/dummy/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Dummy::Application
View
52 spec/dummy/config/application.rb
@@ -0,0 +1,52 @@
+require File.expand_path('../boot', __FILE__)
+
+require "action_controller/railtie"
+require "action_mailer/railtie"
+require "active_resource/railtie"
+require "rails/test_unit/railtie"
+require "sprockets/railtie"
+
+if defined?(Bundler)
+ Bundler.require *Rails.groups(:assets => %w(production development test))
+end
+
+require "homeland"
+
+module Dummy
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ config.assets.enabled = true
+
+
+ end
+end
View
10 spec/dummy/config/boot.rb
@@ -0,0 +1,10 @@
+require 'rubygems'
+gemfile = File.expand_path('../../../../Gemfile', __FILE__)
+
+if File.exist?(gemfile)
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+end
+
+$:.unshift File.expand_path('../../../../lib', __FILE__)
View
5 spec/dummy/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Dummy::Application.initialize!
View
39 spec/dummy/config/environments/development.rb
@@ -0,0 +1,39 @@
+Dummy::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = true
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
+
+ # Raise exception on mass assignment protection for Active Record models
+ # config.active_record.mass_assignment_sanitizer = :strict
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = false
+end
View
49 spec/dummy/config/environments/production.rb
@@ -0,0 +1,49 @@
+Dummy::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The production environment is meant for finished, "live" apps.
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Specifies the header that your server uses for sending files
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
+
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Disable Rails's static asset server
+ # In production, Apache or nginx will already do this
+ config.serve_static_assets = false
+
+ # Enable serving of images, stylesheets, and javascripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
View
37 spec/dummy/config/environments/test.rb
@@ -0,0 +1,37 @@
+Dummy::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Log error messages when you accidentally call methods on nil
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
View
7 spec/dummy/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
View
223 spec/dummy/config/initializers/devise.rb
@@ -0,0 +1,223 @@
+# Use this hook to configure devise mailer, warden hooks and so forth.
+# Many of these configuration options can be set straight in your model.
+Devise.setup do |config|
+ # ==> Mailer Configuration
+ # Configure the e-mail address which will be shown in Devise::Mailer,
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
+
+ # Configure the class responsible to send e-mails.
+ # config.mailer = "Devise::Mailer"
+
+ # Automatically apply schema changes in tableless databases
+ config.apply_schema = false
+
+ # ==> ORM configuration
+ # Load and configure the ORM. Supports :active_record (default) and
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
+ # available as additional gems.
+ require 'devise/orm/mongoid'
+
+ # ==> Configuration for any authentication mechanism
+ # Configure which keys are used when authenticating a user. The default is
+ # just :email. You can configure it to use [:username, :subdomain], so for
+ # authenticating a user, both parameters are required. Remember that those
+ # parameters are used only when authenticating and not when retrieving from
+ # session. If you need permissions, you should implement that in a before filter.
+ # You can also supply a hash where the value is a boolean determining whether
+ # or not authentication should be aborted when the value is not present.
+ # config.authentication_keys = [ :email ]
+
+ # Configure parameters from the request object used for authentication. Each entry
+ # given should be a request method and it will automatically be passed to the
+ # find_for_authentication method and considered in your model lookup. For instance,
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
+ # config.request_keys = []
+
+ # Configure which authentication keys should be case-insensitive.
+ # These keys will be downcased upon creating or modifying a user and when used
+ # to authenticate or find a user. Default is :email.
+ config.case_insensitive_keys = [ :email ]
+
+ # Configure which authentication keys should have whitespace stripped.
+ # These keys will have whitespace before and after removed upon creating or
+ # modifying a user and when used to authenticate or find a user. Default is :email.
+ config.strip_whitespace_keys = [ :email ]
+
+ # Tell if authentication through request.params is enabled. True by default.
+ # It can be set to an array that will enable params authentication only for the
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
+ # enable it only for database (email + password) authentication.
+ # config.params_authenticatable = true
+
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
+ # It can be set to an array that will enable http authentication only for the
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
+ # enable it only for token authentication.
+ # config.http_authenticatable = false
+
+ # If http headers should be returned for AJAX requests. True by default.
+ # config.http_authenticatable_on_xhr = true
+
+ # The realm used in Http Basic Authentication. "Application" by default.
+ # config.http_authentication_realm = "Application"
+
+ # It will change confirmation, password recovery and other workflows
+ # to behave the same regardless if the e-mail provided was right or wrong.
+ # Does not affect registerable.
+ # config.paranoid = true
+
+ # By default Devise will store the user in session. You can skip storage for
+ # :http_auth and :token_auth by adding those symbols to the array below.
+ # Notice that if you are skipping storage for all authentication paths, you
+ # may want to disable generating routes to Devise's sessions controller by
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
+ config.skip_session_storage = [:http_auth]
+
+ # ==> Configuration for :database_authenticatable
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
+ # using other encryptors, it sets how many times you want the password re-encrypted.
+ #
+ # Limiting the stretches to just one in testing will increase the performance of
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
+ # a value less than 10 in other environments.
+ config.stretches = Rails.env.test? ? 1 : 10
+
+ # Setup a pepper to generate the encrypted password.
+ # config.pepper = "c94e2e3a0e5147248ca77c10d1d0800e264ab6294a51188850c4b99d44a126668bf9fb8089079f0bb0a01340042f7c4c49e6a350976fd5dd84d50418eb8f39c5"
+
+ # ==> Configuration for :confirmable
+ # A period that the user is allowed to access the website even without
+ # confirming his account. For instance, if set to 2.days, the user will be
+ # able to access the website for two days without confirming his account,
+ # access will be blocked just in the third day. Default is 0.days, meaning
+ # the user cannot access the website without confirming his account.
+ # config.allow_unconfirmed_access_for = 2.days
+
+ # If true, requires any email changes to be confirmed (exctly the same way as
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
+ # db field (see migrations). Until confirmed new email is stored in
+ # unconfirmed email column, and copied to email column on successful confirmation.
+ config.reconfirmable = true
+
+ # Defines which key will be used when confirming an account
+ # config.confirmation_keys = [ :email ]
+
+ # ==> Configuration for :rememberable
+ # The time the user will be remembered without asking for credentials again.
+ # config.remember_for = 2.weeks
+
+ # If true, extends the user's remember period when remembered via cookie.
+ # config.extend_remember_period = false
+
+ # If true, uses the password salt as remember token. This should be turned
+ # to false if you are not using database authenticatable.
+ config.use_salt_as_remember_token = true
+
+ # Options to be passed to the created cookie. For instance, you can set
+ # :secure => true in order to force SSL only cookies.
+ # config.cookie_options = {}
+
+ # ==> Configuration for :validatable
+ # Range for password length. Default is 6..128.
+ # config.password_length = 6..128
+
+ # Email regex used to validate email formats. It simply asserts that
+ # an one (and only one) @ exists in the given string. This is mainly
+ # to give user feedback and not to assert the e-mail validity.
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
+
+ # ==> Configuration for :timeoutable
+ # The time you want to timeout the user session without activity. After this
+ # time the user will be asked for credentials again. Default is 30 minutes.
+ # config.timeout_in = 30.minutes
+
+ # ==> Configuration for :lockable
+ # Defines which strategy will be used to lock an account.
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
+ # :none = No lock strategy. You should handle locking by yourself.
+ # config.lock_strategy = :failed_attempts
+
+ # Defines which key will be used when locking and unlocking an account
+ # config.unlock_keys = [ :email ]
+
+ # Defines which strategy will be used to unlock an account.
+ # :email = Sends an unlock link to the user email
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
+ # :both = Enables both strategies
+ # :none = No unlock strategy. You should handle unlocking by yourself.
+ # config.unlock_strategy = :both
+
+ # Number of authentication tries before locking an account if lock_strategy
+ # is failed attempts.
+ # config.maximum_attempts = 20
+
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
+ # config.unlock_in = 1.hour
+
+ # ==> Configuration for :recoverable
+ #
+ # Defines which key will be used when recovering the password for an account
+ # config.reset_password_keys = [ :email ]
+
+ # Time interval you can reset your password with a reset password key.
+ # Don't put a too small interval or your users won't have the time to
+ # change their passwords.
+ config.reset_password_within = 6.hours
+
+ # ==> Configuration for :encryptable
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
+ # REST_AUTH_SITE_KEY to pepper)
+ # config.encryptor = :sha512
+
+ # ==> Configuration for :token_authenticatable
+ # Defines name of the authentication token params key
+ # config.token_authentication_key = :auth_token
+
+ # ==> Scopes configuration
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
+ # "users/sessions/new". It's turned off by default because it's slower if you
+ # are using only default views.
+ # config.scoped_views = false
+
+ # Configure the default scope given to Warden. By default it's the first
+ # devise role declared in your routes (usually :user).
+ # config.default_scope = :user
+
+ # Configure sign_out behavior.
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
+ # The default is true, which means any logout action will sign out all active scopes.
+ # config.sign_out_all_scopes = true
+
+ # ==> Navigation configuration
+ # Lists the formats that should be treated as navigational. Formats like
+ # :html, should redirect to the sign in page when the user does not have
+ # access, but formats like :xml or :json, should return 401.
+ #
+ # If you have any extra navigational formats, like :iphone or :mobile, you
+ # should add them to the navigational formats lists.
+ #
+ # The "*/*" below is required to match Internet Explorer requests.
+ # config.navigational_formats = ["*/*", :html]
+
+ # The default HTTP method used to sign out a resource. Default is :delete.
+ config.sign_out_via = :delete
+
+ # ==> OmniAuth
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
+ # up on your models and hooks.
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
+
+ # ==> Warden configuration
+ # If you want to use other strategies, that are not supported by Devise, or
+ # change the failure app, you can configure them inside the config.warden block.
+ #
+ # config.warden do |manager|
+ # manager.intercept_401 = false
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
+ # end
+end
View
7 spec/dummy/config/initializers/homeland.rb
@@ -0,0 +1,7 @@
+Homeland.app_name = "Homeland Test"
+# Homeland.user_class = "User"
+# Homeland.current_user_method = :current_user
+# Homeland.require_user_method = :require_user
+Homeland.user_avatar_method = :avatar_small_url
+# Homeland.user_path_method = :user_path
+# Homeland.per_page = 20
View
10 spec/dummy/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
View
5 spec/dummy/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
View
7 spec/dummy/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Dummy::Application.config.secret_token = '43dc5743b85717d80d3b43dc135dbbf0fe0bbcb446943c2e0de76e23288acd453fa163900a284ce590c926f10bface0e555c7a21eb29d58bddd05495b5199572'
View
8 spec/dummy/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# Dummy::Application.config.session_store :active_record_store
View
57 spec/dummy/config/locales/devise.en.yml
@@ -0,0 +1,57 @@
+# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
+
+en:
+ errors:
+ messages:
+ expired: "has expired, please request a new one"
+ not_found: "not found"
+ already_confirmed: "was already confirmed, please try signing in"
+ not_locked: "was not locked"
+ not_saved:
+ one: "1 error prohibited this %{resource} from being saved:"
+ other: "%{count} errors prohibited this %{resource} from being saved:"
+
+ devise:
+ failure:
+ already_authenticated: 'You are already signed in.'
+ unauthenticated: 'You need to sign in or sign up before continuing.'
+ unconfirmed: 'You have to confirm your account before continuing.'
+ locked: 'Your account is locked.'
+ invalid: 'Invalid email or password.'
+ invalid_token: 'Invalid authentication token.'
+ timeout: 'Your session expired, please sign in again to continue.'
+ inactive: 'Your account was not activated yet.'
+ sessions:
+ signed_in: 'Signed in successfully.'
+ signed_out: 'Signed out successfully.'
+ passwords:
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
+ updated: 'Your password was changed successfully. You are now signed in.'
+ updated_not_active: 'Your password was changed successfully.'
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
+ confirmations:
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
+ registrations:
+ signed_up: 'Welcome! You have signed up successfully.'
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
+ updated: 'You updated your account successfully.'
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
+ unlocks:
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
+ omniauth_callbacks:
+ success: 'Successfully authorized from %{kind} account.'
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
+ mailer:
+ confirmation_instructions:
+ subject: 'Confirmation instructions'
+ reset_password_instructions:
+ subject: 'Reset password instructions'
+ unlock_instructions:
+ subject: 'Unlock Instructions'
View
5 spec/dummy/config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
View
14 spec/dummy/config/locales/homeland.zh-CN.yml
@@ -0,0 +1,14 @@
+'zh-CN':
+ mongoid:
+ models:
+ homeland/topic: "话题"
+ homeland/reply: "回复"
+ homeland/section: "大节点"
+ homeland/node: "节点"
+ attributes:
+ homeland/topic:
+ title: "标题"
+ body: "正文"
+ user_id: "用户"
+ homeland/reply:
+ body: "回复内容"
View
19 spec/dummy/config/mongoid.yml
@@ -0,0 +1,19 @@
+defaults: &defaults
+ host: '127.0.0.1'
+ identity_map_enabled: true
+
+development:
+ <<: *defaults
+ host: localhost
+ database: homeland_dump_dev
+ identity_map_enabled: true
+
+test:
+ <<: *defaults
+ host: localhost
+ database: homeland_dump_test
+
+production:
+ <<: *defaults
+ host: localhost
+ database: homeland_dump
View
8 spec/dummy/config/routes.rb
@@ -0,0 +1,8 @@
+Dummy::Application.routes.draw do
+ root :to => "users#index"
+ devise_for :users
+
+ resources :users
+
+ mount Homeland::Engine, :at => "/bbs"
+end
View
7 spec/dummy/db/seeds.rb
@@ -0,0 +1,7 @@
+if Homeland::Section.count == 0
+ Homeland::Section.create(:name => "Foo")
+end
+
+if Homeland::Node.count == 0
+ Homeland::Node.create(:name => "Bar", :summary => "Foo bar.", :section => Homeland::Section.first)
+end
View
26 spec/dummy/public/404.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
View
26 spec/dummy/public/422.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
View
26 spec/dummy/public/500.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
View
0  spec/dummy/public/favicon.ico
No changes.
View
6 spec/dummy/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
View
BIN  spec/dummy/vendor/assets/images/jquery.chosen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
898 spec/dummy/vendor/assets/javascripts/jquery.chosen.js
@@ -0,0 +1,898 @@
+// Chosen, a Select Box Enhancer for jQuery and Protoype
+// by Patrick Filler for Harvest, http://getharvest.com
+//
+// Version 0.9.5
+// Full source at https://github.com/harvesthq/chosen
+// Copyright (c) 2011 Harvest http://getharvest.com
+
+// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
+// This file is generated by `cake build`, do not edit it by hand.
+(function() {
+ var SelectParser;
+ SelectParser = (function() {
+ function SelectParser() {
+ this.options_index = 0;
+ this.parsed = [];
+ }
+ SelectParser.prototype.add_node = function(child) {
+ if (child.nodeName === "OPTGROUP") {
+ return this.add_group(child);
+ } else {
+ return this.add_option(child);
+ }
+ };
+ SelectParser.prototype.add_group = function(group) {
+ var group_position, option, _i, _len, _ref, _results;
+ group_position = this.parsed.length;
+ this.parsed.push({
+ array_index: group_position,
+ group: true,
+ label: group.label,
+ children: 0,
+ disabled: group.disabled
+ });
+ _ref = group.childNodes;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ option = _ref[_i];
+ _results.push(this.add_option(option, group_position, group.disabled));
+ }
+ return _results;
+ };
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
+ if (option.nodeName === "OPTION") {
+ if (option.text !== "") {
+ if (group_position != null) {
+ this.parsed[group_position].children += 1;
+ }
+ this.parsed.push({
+ array_index: this.parsed.length,
+ options_index: this.options_index,
+ value: option.value,
+ text: option.text,
+ html: option.innerHTML,
+ selected: option.selected,
+ disabled: group_disabled === true ? group_disabled : option.disabled,
+ group_array_index: group_position,
+ classes: option.className,
+ style: option.style.cssText
+ });
+ } else {
+ this.parsed.push({
+ array_index: this.parsed.length,
+ options_index: this.options_index,
+ empty: true
+ });
+ }
+ return this.options_index += 1;
+ }
+ };
+ return SelectParser;
+ })();
+ SelectParser.select_to_array = function(select) {
+ var child, parser, _i, _len, _ref;
+ parser = new SelectParser();
+ _ref = select.childNodes;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ child = _ref[_i];
+ parser.add_node(child);
+ }
+ return parser.parsed;
+ };
+ this.SelectParser = SelectParser;
+}).call(this);
+(function() {
+ /*
+ Chosen source: generate output using 'cake build'
+ Copyright (c) 2011 by Harvest
+ */
+ var AbstractChosen, root;
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+ root = this;
+ AbstractChosen = (function() {
+ function AbstractChosen(form_field, options) {
+ this.form_field = form_field;
+ this.options = options != null ? options : {};
+ this.set_default_values();
+ this.is_multiple = this.form_field.multiple;
+ this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option";
+ this.setup();
+ this.set_up_html();
+ this.register_observers();
+ this.finish_setup();
+ }
+ AbstractChosen.prototype.set_default_values = function() {
+ this.click_test_action = __bind(function(evt) {
+ return this.test_active_click(evt);
+ }, this);
+ this.activate_action = __bind(function(evt) {
+ return this.activate_field(evt);
+ }, this);
+ this.active_field = false;
+ this.mouse_on_container = false;
+ this.results_showing = false;
+ this.result_highlighted = null;
+ this.result_single_selected = null;
+ this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
+ this.choices = 0;
+ return this.results_none_found = this.options.no_results_text || "No results match";
+ };
+ AbstractChosen.prototype.mouse_enter = function() {
+ return this.mouse_on_container = true;
+ };
+ AbstractChosen.prototype.mouse_leave = function() {
+ return this.mouse_on_container = false;
+ };
+ AbstractChosen.prototype.input_focus = function(evt) {
+ if (!this.active_field) {
+ return setTimeout((__bind(function() {
+ return this.container_mousedown();
+ }, this)), 50);
+ }
+ };
+ AbstractChosen.prototype.input_blur = function(evt) {
+ if (!this.mouse_on_container) {
+ this.active_field = false;
+ return setTimeout((__bind(function() {
+ return this.blur_test();
+ }, this)), 100);
+ }
+ };
+ AbstractChosen.prototype.result_add_option = function(option) {
+ var classes, style;
+ if (!option.disabled) {
+ option.dom_id = this.container_id + "_o_" + option.array_index;
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
+ if (option.selected) {
+ classes.push("result-selected");
+ }
+ if (option.group_array_index != null) {
+ classes.push("group-option");
+ }
+ if (option.classes !== "") {
+ classes.push(option.classes);
+ }
+ style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
+ } else {
+ return "";
+ }
+ };
+ AbstractChosen.prototype.results_update_field = function() {
+ this.result_clear_highlight();
+ this.result_single_selected = null;
+ return this.results_build();
+ };
+ AbstractChosen.prototype.results_toggle = function() {
+ if (this.results_showing) {
+ return this.results_hide();
+ } else {
+ return this.results_show();
+ }
+ };
+ AbstractChosen.prototype.results_search = function(evt) {
+ if (this.results_showing) {
+ return this.winnow_results();
+ } else {
+ return this.results_show();
+ }
+ };
+ AbstractChosen.prototype.keyup_checker = function(evt) {
+ var stroke, _ref;
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
+ this.search_field_scale();
+ switch (stroke) {
+ case 8:
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
+ return this.keydown_backstroke();
+ } else if (!this.pending_backstroke) {
+ this.result_clear_highlight();
+ return this.results_search();
+ }
+ break;
+ case 13:
+ evt.preventDefault();
+ if (this.results_showing) {
+ return this.result_select(evt);
+ }
+ break;
+ case 27:
+ if (this.results_showing) {
+ return this.results_hide();
+ }
+ break;
+ case 9:
+ case 38:
+ case 40:
+ case 16:
+ case 91:
+ case 17:
+ break;
+ default:
+ return this.results_search();
+ }
+ };
+ AbstractChosen.prototype.generate_field_id = function() {
+ var new_id;
+ new_id = this.generate_random_id();
+ this.form_field.id = new_id;
+ return new_id;
+ };
+ AbstractChosen.prototype.generate_random_char = function() {
+ var chars, newchar, rand;
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
+ rand = Math.floor(Math.random() * chars.length);
+ return newchar = chars.substring(rand, rand + 1);
+ };
+ return AbstractChosen;
+ })();
+ root.AbstractChosen = AbstractChosen;
+}).call(this);
+(function() {
+ /*
+ Chosen source: generate output using 'cake build'
+ Copyright (c) 2011 by Harvest
+ */
+ var $, Chosen, get_side_border_padding, root;
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
+ function ctor() { this.constructor = child; }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor;
+ child.__super__ = parent.prototype;
+ return child;
+ }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+ root = this;
+ $ = jQuery;
+ $.fn.extend({
+ chosen: function(options) {
+ if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
+ return this;
+ }
+ return $(this).each(function(input_field) {
+ if (!($(this)).hasClass("chzn-done")) {
+ return new Chosen(this, options);
+ }
+ });
+ }
+ });
+ Chosen = (function() {
+ __extends(Chosen, AbstractChosen);
+ function Chosen() {
+ Chosen.__super__.constructor.apply(this, arguments);
+ }
+ Chosen.prototype.setup = function() {
+ this.form_field_jq = $(this.form_field);
+ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
+ };
+ Chosen.prototype.finish_setup = function() {
+ return this.form_field_jq.addClass("chzn-done");
+ };
+ Chosen.prototype.set_up_html = function() {
+ var container_div, dd_top, dd_width, sf_width;
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
+ this.container_id += "_chzn";
+ this.f_width = this.form_field_jq.outerWidth();
+ this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
+ container_div = $("<div />", {
+ id: this.container_id,
+ "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
+ style: 'width: ' + this.f_width + 'px;'
+ });
+ if (this.is_multiple) {
+ container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
+ } else {
+ container_div.html('<a href="javascript:void(0)" class="chzn-single"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
+ }
+ this.form_field_jq.hide().after(container_div);
+ this.container = $('#' + this.container_id);
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
+ this.dropdown = this.container.find('div.chzn-drop').first();
+ dd_top = this.container.height();
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
+ this.dropdown.css({
+ "width": dd_width + "px",
+ "top": dd_top + "px"
+ });
+ this.search_field = this.container.find('input').first();
+ this.search_results = this.container.find('ul.chzn-results').first();
+ this.search_field_scale();
+ this.search_no_results = this.container.find('li.no-results').first();
+ if (this.is_multiple) {
+ this.search_choices = this.container.find('ul.chzn-choices').first();
+ this.search_container = this.container.find('li.search-field').first();
+ } else {
+ this.search_container = this.container.find('div.chzn-search').first();
+ this.selected_item = this.container.find('.chzn-single').first();
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
+ this.search_field.css({
+ "width": sf_width + "px"
+ });
+ }
+ this.results_build();
+ this.set_tab_index();
+ return this.form_field_jq.trigger("liszt:ready", {
+ chosen: this
+ });
+ };
+ Chosen.prototype.register_observers = function() {
+ this.container.mousedown(__bind(function(evt) {
+ return this.container_mousedown(evt);
+ }, this));
+ this.container.mouseup(__bind(function(evt) {
+ return this.container_mouseup(evt);
+ }, this));
+ this.container.mouseenter(__bind(function(evt) {
+ return this.mouse_enter(evt);
+ }, this));
+ this.container.mouseleave(__bind(function(evt) {
+ return this.mouse_leave(evt);
+ }, this));
+ this.search_results.mouseup(__bind(function(evt) {
+ return this.search_results_mouseup(evt);
+ }, this));
+ this.search_results.mouseover(__bind(function(evt) {
+ return this.search_results_mouseover(evt);
+ }, this));
+ this.search_results.mouseout(__bind(function(evt) {
+ return this.search_results_mouseout(evt);
+ }, this));
+ this.form_field_jq.bind("liszt:updated", __bind(function(evt) {
+ return this.results_update_field(evt);
+ }, this));
+ this.search_field.blur(__bind(function(evt) {
+ return this.input_blur(evt);
+ }, this));
+ this.search_field.keyup(__bind(function(evt) {
+ return this.keyup_checker(evt);
+ }, this));
+ this.search_field.keydown(__bind(function(evt) {
+ return this.keydown_checker(evt);
+ }, this));
+ if (this.is_multiple) {
+ this.search_choices.click(__bind(function(evt) {
+ return this.choices_click(evt);
+ }, this));
+ return this.search_field.focus(__bind(function(evt) {
+ return this.input_focus(evt);
+ }, this));
+ }
+ };
+ Chosen.prototype.search_field_disabled = function() {
+ this.is_disabled = this.form_field_jq[0].disabled;
+ if (this.is_disabled) {
+ this.container.addClass('chzn-disabled');
+ this.search_field[0].disabled = true;
+ if (!this.is_multiple) {
+ this.selected_item.unbind("focus", this.activate_action);
+ }
+ return this.close_field();
+ } else {
+ this.container.removeClass('chzn-disabled');
+ this.search_field[0].disabled = false;
+ if (!this.is_multiple) {
+ return this.selected_item.bind("focus", this.activate_action);
+ }
+ }
+ };
+ Chosen.prototype.container_mousedown = function(evt) {
+ var target_closelink;
+ if (!this.is_disabled) {
+ target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
+ if (evt && evt.type === "mousedown") {
+ evt.stopPropagation();
+ }
+ if (!this.pending_destroy_click && !target_closelink) {
+ if (!this.active_field) {
+ if (this.is_multiple) {
+ this.search_field.val("");
+ }
+ $(document).click(this.click_test_action);
+ this.results_show();
+ } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
+ evt.preventDefault();
+ this.results_toggle();
+ }
+ return this.activate_field();
+ } else {
+ return this.pending_destroy_click = false;
+ }
+ }
+ };
+ Chosen.prototype.container_mouseup = function(evt) {
+ if (evt.target.nodeName === "ABBR") {
+ return this.results_reset(evt);
+ }
+ };
+ Chosen.prototype.blur_test = function(evt) {
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
+ return this.close_field();
+ }
+ };
+ Chosen.prototype.close_field = function() {
+ $(document).unbind("click", this.click_test_action);
+ if (!this.is_multiple) {
+ this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
+ this.search_field.attr("tabindex", -1);
+ }
+ this.active_field = false;
+ this.results_hide();
+ this.container.removeClass("chzn-container-active");
+ this.winnow_results_clear();
+ this.clear_backstroke();
+ this.show_search_field_default();
+ return this.search_field_scale();
+ };
+ Chosen.prototype.activate_field = function() {
+ if (!this.is_multiple && !this.active_field) {
+ this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
+ this.selected_item.attr("tabindex", -1);
+ }
+ this.container.addClass("chzn-container-active");
+ this.active_field = true;
+ this.search_field.val(this.search_field.val());
+ return this.search_field.focus();
+ };
+ Chosen.prototype.test_active_click = function(evt) {
+ if ($(evt.target).parents('#' + this.container_id).length) {
+ return this.active_field = true;
+ } else {
+ return this.close_field();
+ }
+ };
+ Chosen.prototype.results_build = function() {
+ var content, data, _i, _len, _ref;
+ this.parsing = true;
+ this.results_data = root.SelectParser.select_to_array(this.form_field);
+ if (this.is_multiple && this.choices > 0) {
+ this.search_choices.find("li.search-choice").remove();
+ this.choices = 0;
+ } else if (!this.is_multiple) {
+ this.selected_item.find("span").text(this.default_text);
+ if (this.form_field.options.length <= this.disable_search_threshold) {
+ this.container.addClass("chzn-container-single-nosearch");
+ } else {
+ this.container.removeClass("chzn-container-single-nosearch");
+ }
+ }
+ content = '';
+ _ref = this.results_data;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ data = _ref[_i];
+ if (data.group) {
+ content += this.result_add_group(data);
+ } else if (!data.empty) {
+ content += this.result_add_option(data);
+ if (data.selected && this.is_multiple) {
+ this.choice_build(data);
+ } else if (data.selected && !this.is_multiple) {
+ this.selected_item.find("span").text(data.text);
+ if (this.allow_single_deselect) {
+ this.single_deselect_control_build();
+ }
+ }
+ }
+ }
+ this.search_field_disabled();
+ this.show_search_field_default();
+ this.search_field_scale();
+ this.search_results.html(content);
+ return this.parsing = false;
+ };
+ Chosen.prototype.result_add_group = function(group) {
+ if (!group.disabled) {
+ group.dom_id = this.container_id + "_g_" + group.array_index;
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
+ } else {
+ return "";
+ }
+ };
+ Chosen.prototype.result_do_highlight = function(el) {
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
+ if (el.length) {
+ this.result_clear_highlight();
+ this.result_highlight = el;
+ this.result_highlight.addClass("highlighted");
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
+ visible_top = this.search_results.scrollTop();
+ visible_bottom = maxHeight + visible_top;
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
+ high_bottom = high_top + this.result_highlight.outerHeight();
+ if (high_bottom >= visible_bottom) {
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
+ } else if (high_top < visible_top) {
+ return this.search_results.scrollTop(high_top);
+ }
+ }
+ };
+ Chosen.prototype.result_clear_highlight = function() {
+ if (this.result_highlight) {
+ this.result_highlight.removeClass("highlighted");
+ }
+ return this.result_highlight = null;
+ };
+ Chosen.prototype.results_show = function() {
+ var dd_top;
+ if (!this.is_multiple) {
+ this.selected_item.addClass("chzn-single-with-drop");
+ if (this.result_single_selected) {
+ this.result_do_highlight(this.result_single_selected);
+ }
+ }
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
+ this.dropdown.css({
+ "top": dd_top + "px",
+ "left": 0
+ });
+ this.results_showing = true;
+ this.search_field.focus();
+ this.search_field.val(this.search_field.val());
+ return this.winnow_results();
+ };
+ Chosen.prototype.results_hide = function() {
+ if (!this.is_multiple) {
+ this.selected_item.removeClass("chzn-single-with-drop");
+ }
+ this.result_clear_highlight();
+ this.dropdown.css({
+ "left": "-9000px"
+ });
+ return this.results_showing = false;
+ };
+ Chosen.prototype.set_tab_index = function(el) {
+ var ti;
+ if (this.form_field_jq.attr("tabindex")) {
+ ti = this.form_field_jq.attr("tabindex");
+ this.form_field_jq.attr("tabindex", -1);
+ if (this.is_multiple) {
+ return this.search_field.attr("tabindex", ti);
+ } else {
+ this.selected_item.attr("tabindex", ti);
+ return this.search_field.attr("tabindex", -1);
+ }
+ }
+ };
+ Chosen.prototype.show_search_field_default = function() {
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
+ this.search_field.val(this.default_text);
+ return this.search_field.addClass("default");
+ } else {
+ this.search_field.val("");
+ return this.search_field.removeClass("default");
+ }
+ };
+ Chosen.prototype.search_results_mouseup = function(evt) {
+ var target;
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
+ if (target.length) {
+ this.result_highlight = target;
+ return this.result_select(evt);
+ }
+ };
+ Chosen.prototype.search_results_mouseover = function(evt) {
+ var target;
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
+ if (target) {
+ return this.result_do_highlight(target);
+ }
+ };
+ Chosen.prototype.search_results_mouseout = function(evt) {
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
+ return this.result_clear_highlight();
+ }
+ };
+ Chosen.prototype.choices_click = function(evt) {
+ evt.preventDefault();
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
+ return this.results_show();
+ }
+ };
+ Chosen.prototype.choice_build = function(item) {
+ var choice_id, link;
+ choice_id = this.container_id + "_c_" + item.array_index;
+ this.choices += 1;
+ this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>');
+ link = $('#' + choice_id).find("a").first();
+ return link.click(__bind(function(evt) {
+ return this.choice_destroy_link_click(evt);
+ }, this));
+ };
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
+ evt.preventDefault();
+ if (!this.is_disabled) {
+ this.pending_destroy_click = true;
+ return this.choice_destroy($(evt.target));
+ } else {
+ return evt.stopPropagation;
+ }
+ };
+ Chosen.prototype.choice_destroy = function(link) {
+ this.choices -= 1;
+ this.show_search_field_default();
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
+ this.results_hide();
+ }
+ this.result_deselect(link.attr("rel"));
+ return link.parents('li').first().remove();
+ };
+ Chosen.prototype.results_reset = function(evt) {
+ this.form_field.options[0].selected = true;
+ this.selected_item.find("span").text(this.default_text);
+ this.show_search_field_default();
+ $(evt.target).remove();
+ this.form_field_jq.trigger("change");
+ if (this.active_field) {
+ return this.results_hide();
+ }
+ };
+ Chosen.prototype.result_select = function(evt) {
+ var high, high_id, item, position;
+ if (this.result_highlight) {
+ high = this.result_highlight;
+ high_id = high.attr("id");
+ this.result_clear_highlight();
+ if (this.is_multiple) {
+ this.result_deactivate(high);
+ } else {
+ this.search_results.find(".result-selected").removeClass("result-selected");
+ this.result_single_selected = high;
+ }
+ high.addClass("result-selected");
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
+ item = this.results_data[position];
+ item.selected = true;
+ this.form_field.options[item.options_index].selected = true;
+ if (this.is_multiple) {
+ this.choice_build(item);
+ } else {
+ this.selected_item.find("span").first().text(item.text);
+ if (this.allow_single_deselect) {
+ this.single_deselect_control_build();
+ }
+ }
+ if (!(evt.metaKey && this.is_multiple)) {
+ this.results_hide();
+ }
+ this.search_field.val("");
+ this.form_field_jq.trigger("change");
+ return this.search_field_scale();
+ }
+ };
+ Chosen.prototype.result_activate = function(el) {
+ return el.addClass("active-result");
+ };
+ Chosen.prototype.result_deactivate = function(el) {
+ return el.removeClass("active-result");
+ };
+ Chosen.prototype.result_deselect = function(pos) {
+ var result, result_data;
+ result_data = this.results_data[pos];
+ result_data.selected = false;
+ this.form_field.options[result_data.options_index].selected = false;
+ result = $("#" + this.container_id + "_o_" + pos);
+ result.removeClass("result-selected").addClass("active-result").show();
+ this.result_clear_highlight();
+ this.winnow_results();
+ this.form_field_jq.trigger("change");
+ return this.search_field_scale();
+ };
+ Chosen.prototype.single_deselect_control_build = function() {
+ if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
+ return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
+ }
+ };
+ Chosen.prototype.winnow_results = function() {
+ var found, option, part, parts, regex, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
+ this.no_results_clear();
+ results = 0;
+ searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
+ regex = new RegExp('^' + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
+ _ref = this.results_data;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ option = _ref[_i];
+ if (!option.disabled && !option.empty) {
+ if (option.group) {
+ $('#' + option.dom_id).css('display', 'none');
+ } else if (!(this.is_multiple && option.selected)) {
+ found = false;
+ result_id = option.dom_id;
+ result = $("#" + result_id);
+ if (regex.test(option.html)) {
+ found = true;
+ results += 1;
+ } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
+ parts = option.html.replace(/\[|\]/g, "").split(" ");
+ if (parts.length) {
+ for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
+ part = parts[_j];
+ if (regex.test(part)) {
+ found = true;
+ results += 1;
+ }
+ }
+ }
+ }
+ if (found) {
+ if (searchText.length) {
+ startpos = option.html.search(zregex);
+ text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
+ } else {
+ text = option.html;
+ }
+ result.html(text);
+ this.result_activate(result);
+ if (option.group_array_index != null) {
+ $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
+ }
+ } else {
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
+ this.result_clear_highlight();
+ }
+ this.result_deactivate(result);
+ }
+ }
+ }
+ }
+ if (results < 1 && searchText.length) {
+ return this.no_results(searchText);
+ } else {
+ return this.winnow_results_set_highlight();
+ }
+ };
+ Chosen.prototype.winnow_results_clear = function() {
+ var li, lis, _i, _len, _results;
+ this.search_field.val("");
+ lis = this.search_results.find("li");
+ _results = [];
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
+ li = lis[_i];
+ li = $(li);
+ _results.push(li.hasClass("group-result") ? li.css('display', 'auto') : !this.is_multiple || !li.hasClass("result-selected") ? this.result_activate(li) : void 0);
+ }
+ return _results;
+ };
+ Chosen.prototype.winnow_results_set_highlight = function() {
+ var do_high, selected_results;
+ if (!this.result_highlight) {
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
+ do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
+ if (do_high != null) {
+ return this.result_do_highlight(do_high);
+ }
+ }
+ };
+ Chosen.prototype.no_results = function(terms) {
+ var no_results_html;
+ no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
+ no_results_html.find("span").first().html(terms);
+ return this.search_results.append(no_results_html);
+ };
+ Chosen.prototype.no_results_clear = function() {
+ return this.search_results.find(".no-results").remove();
+ };
+ Chosen.prototype.keydown_arrow = function() {
+ var first_active, next_sib;
+ if (!this.result_highlight) {
+ first_active = this.search_results.find("li.active-result").first();
+ if (first_active) {
+ this.result_do_highlight($(first_active));
+ }
+ } else if (this.results_showing) {
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
+ if (next_sib) {
+ this.result_do_highlight(next_sib);
+ }
+ }
+ if (!this.results_showing) {
+ return this.results_show();
+ }
+ };
+ Chosen.prototype.keyup_arrow = function() {
+ var prev_sibs;
+ if (!this.results_showing && !this.is_multiple) {
+ return this.results_show();
+ } else if (this.result_highlight) {
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
+ if (prev_sibs.length) {
+ return this.result_do_highlight(prev_sibs.first());
+ } else {
+ if (this.choices > 0) {
+ this.results_hide();
+ }
+ return this.result_clear_highlight();
+ }
+ }
+ };
+ Chosen.prototype.keydown_backstroke = function() {
+ if (this.pending_backstroke) {
+ this.choice_destroy(this.pending_backstroke.find("a").first());
+ return this.clear_backstroke();
+ } else {
+ this.pending_backstroke = this.search_container.siblings("li.search-choice").last();
+ return this.pending_backstroke.addClass("search-choice-focus");
+ }
+ };
+ Chosen.prototype.clear_backstroke = function() {
+ if (this.pending_backstroke) {
+ this.pending_backstroke.removeClass("search-choice-focus");
+ }
+ return this.pending_backstroke = null;
+ };
+ Chosen.prototype.keydown_checker = function(evt) {
+ var stroke, _ref;
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
+ this.search_field_scale();
+ if (stroke !== 8 && this.pending_backstroke) {
+ this.clear_backstroke();
+ }
+ switch (stroke) {
+ case 8:
+ this.backstroke_length = this.search_field.val().length;
+ break;
+ case 9:
+ if (this.results_showing && !this.is_multiple) {
+ this.result_select(evt);
+ }
+ this.mouse_on_container = false;
+ break;
+ case 13:
+ evt.preventDefault();
+ break;
+ case 38:
+ evt.preventDefault();
+ this.keyup_arrow();
+ break;
+ case 40:
+ this.keydown_arrow();
+ break;
+ }
+ };
+ Chosen.prototype.search_field_scale = function() {
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
+ if (this.is_multiple) {
+ h = 0;
+ w = 0;
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
+ style = styles[_i];
+ style_block += style + ":" + this.search_field.css(style) + ";";
+ }
+ div = $('<div />', {
+ 'style': style_block
+ });
+ div.text(this.search_field.val());
+ $('body').append(div);
+ w = div.width() + 25;
+ div.remove();
+ if (w > this.f_width - 10) {
+ w = this.f_width - 10;
+ }
+ this.search_field.css({
+ 'width': w + 'px'
+ });
+ dd_top = this.container.height();
+ return this.dropdown.css({
+ "top": dd_top + "px"
+ });
+ }
+ };
+ Chosen.prototype.generate_random_id = function() {
+ var string;
+ string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
+ while ($("#" + string).length > 0) {
+ string += this.generate_random_char();
+ }
+ return string;
+ };
+ return Chosen;
+ })();
+ get_side_border_padding = function(elmt) {
+ var side_border_padding;
+ return side_border_padding = elmt.outerWidth() - elmt.width();
+ };
+ root.get_side_border_padding = get_side_border_padding;
+}).call(this);
View
99 spec/dummy/vendor/assets/javascripts/jquery.hotkeys.js
@@ -0,0 +1,99 @@
+/*
+ * jQuery Hotkeys Plugin
+ * Copyright 2010, John Resig
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ *
+ * Based upon the plugin by Tzury Bar Yochay:
+ * http://github.com/tzuryby/hotkeys
+ *
+ * Original idea by:
+ * Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
+*/
+
+(function(jQuery){
+
+ jQuery.hotkeys = {
+ version: "0.8",
+
+ specialKeys: {
+ 8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
+ 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
+ 37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del",
+ 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
+ 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/",
+ 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8",
+ 120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta"
+ },
+
+ shiftNums: {
+ "`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&",
+ "8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<",
+ ".": ">", "/": "?", "\\": "|"
+ }
+ };
+
+ function keyHandler( handleObj ) {
+ // Only care when a possible input has been specified
+ if ( typeof handleObj.data !== "string" ) {
+ return;
+ }
+
+ var origHandler = handleObj.handler,
+ keys = handleObj.data.toLowerCase().split(" ");
+
+ handleObj.handler = function( event ) {
+ // Don't fire in text-accepting inputs that we didn't directly bind to
+ if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
+ event.target.type === "text") ) {
+ return;
+ }
+
+ // Keypress represents characters, not special keys
+ var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ],
+ charact