bootstrap-multiselect-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +0 -0
- data/README.rdoc +3 -0
- data/Rakefile +38 -0
- data/lib/bootstrap-multiselect-rails.rb +4 -0
- data/lib/bootstrap-multiselect-rails/version.rb +3 -0
- data/lib/tasks/bootstrap-multiselect-rails_tasks.rake +4 -0
- data/test/bootstrap-multiselect-rails_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/test_helper.rb +15 -0
- data/vendor/assets/javascripts/bootstrap-multiselect.js +538 -0
- data/vendor/assets/stylesheets/bootstrap-multiselect.css +1 -0
- metadata +153 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Raise exception on mass assignment protection for Active Record models
|
26
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
+
|
28
|
+
# Log the query plan for queries taking more than this (works
|
29
|
+
# with SQLite, MySQL, and PostgreSQL)
|
30
|
+
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
+
|
32
|
+
# Do not compress assets
|
33
|
+
config.assets.compress = false
|
34
|
+
|
35
|
+
# Expands the lines which load the assets
|
36
|
+
config.assets.debug = true
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
+
config.serve_static_assets = false
|
13
|
+
|
14
|
+
# Compress JavaScripts and CSS
|
15
|
+
config.assets.compress = true
|
16
|
+
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to nil and saved in location specified by config.assets.prefix
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
26
|
+
# Specifies the header that your server uses for sending files
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
+
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
+
# config.force_ssl = true
|
32
|
+
|
33
|
+
# See everything in the log (default is :info)
|
34
|
+
# config.log_level = :debug
|
35
|
+
|
36
|
+
# Prepend all log lines with the following tags
|
37
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
+
|
39
|
+
# Use a different logger for distributed setups
|
40
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
+
|
42
|
+
# Use a different cache store in production
|
43
|
+
# config.cache_store = :mem_cache_store
|
44
|
+
|
45
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
+
|
48
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
+
# config.assets.precompile += %w( search.js )
|
50
|
+
|
51
|
+
# Disable delivery errors, bad email addresses will be ignored
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
53
|
+
|
54
|
+
# Enable threaded mode
|
55
|
+
# config.threadsafe!
|
56
|
+
|
57
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
+
# the I18n.default_locale when a translation can not be found)
|
59
|
+
config.i18n.fallbacks = true
|
60
|
+
|
61
|
+
# Send deprecation notices to registered listeners
|
62
|
+
config.active_support.deprecation = :notify
|
63
|
+
|
64
|
+
# Log the query plan for queries taking more than this (works
|
65
|
+
# with SQLite, MySQL, and PostgreSQL)
|
66
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Raise exception on mass assignment protection for Active Record models
|
33
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
34
|
+
|
35
|
+
# Print deprecation notices to the stderr
|
36
|
+
config.active_support.deprecation = :stderr
|
37
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
14
|
+
# inflect.acronym 'RESTful'
|
15
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '80f3f36d1679d5a8dcf4f62275ef8a90a9d2602629ec2784c9799380d76315bdf605be55a39dba2f463ab97f9a35ac34451dcdbe6a4046bec024a1b337336c91'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get 'short'
|
20
|
+
# post 'toggle'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get 'sold'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get 'recent', :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
# root :to => 'welcome#index'
|
52
|
+
|
53
|
+
# See how all your routes lay out with "rake routes"
|
54
|
+
|
55
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
+
# match ':controller(/:action(/:id))(.:format)'
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
@@ -0,0 +1,538 @@
|
|
1
|
+
/**
|
2
|
+
* bootstrap-multiselect.js 1.0.0
|
3
|
+
* https://github.com/davidstutz/bootstrap-multiselect
|
4
|
+
*
|
5
|
+
* Copyright 2012 David Stutz
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*/
|
19
|
+
!function($) {"use strict";// jshint ;_;
|
20
|
+
|
21
|
+
if ( typeof ko != 'undefined' && ko.bindingHandlers && !ko.bindingHandlers.multiselect) {
|
22
|
+
ko.bindingHandlers.multiselect = {
|
23
|
+
init : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
|
24
|
+
},
|
25
|
+
update : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
|
26
|
+
var ms = $(element).data('multiselect');
|
27
|
+
if (!ms) {
|
28
|
+
$(element).multiselect(ko.utils.unwrapObservable(valueAccessor()));
|
29
|
+
}
|
30
|
+
else
|
31
|
+
if (allBindingsAccessor().options && allBindingsAccessor().options().length !== ms.originalOptions.length) {
|
32
|
+
ms.updateOriginalOptions();
|
33
|
+
$(element).multiselect('rebuild');
|
34
|
+
}
|
35
|
+
}
|
36
|
+
};
|
37
|
+
}
|
38
|
+
|
39
|
+
function Multiselect(select, options) {
|
40
|
+
|
41
|
+
this.options = this.getOptions(options);
|
42
|
+
this.$select = $(select);
|
43
|
+
this.originalOptions = this.$select.clone()[0].options;
|
44
|
+
//we have to clone to create a new reference
|
45
|
+
this.query = '';
|
46
|
+
this.searchTimeout = null;
|
47
|
+
|
48
|
+
this.options.multiple = this.$select.attr('multiple') == "multiple";
|
49
|
+
|
50
|
+
this.$container = $(this.options.buttonContainer).append('<button type="button" class="multiselect dropdown-toggle ' + this.options.buttonClass + '" data-toggle="dropdown">' + this.options.buttonText(this.getSelected(), this.$select) + '</button>')
|
51
|
+
.append('<ul class="multiselect-container dropdown-menu' + (this.options.dropRight ? ' pull-right' : '') + '"></ul>');
|
52
|
+
|
53
|
+
if (this.options.buttonWidth) {
|
54
|
+
$('button', this.$container).css({
|
55
|
+
'width' : this.options.buttonWidth
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
// Set max height of dropdown menu to activate auto scrollbar.
|
60
|
+
if (this.options.maxHeight) {
|
61
|
+
// TODO: Add a class for this option to move the css declarations.
|
62
|
+
$('.multiselect-container', this.$container).css({
|
63
|
+
'max-height' : this.options.maxHeight + 'px',
|
64
|
+
'overflow-y' : 'auto',
|
65
|
+
'overflow-x' : 'hidden'
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
// Enable filtering.
|
70
|
+
if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) {
|
71
|
+
this.buildFilter();
|
72
|
+
}
|
73
|
+
|
74
|
+
this.buildDropdown();
|
75
|
+
this.updateButtonText();
|
76
|
+
|
77
|
+
this.$select.hide().after(this.$container);
|
78
|
+
};
|
79
|
+
|
80
|
+
Multiselect.prototype = {
|
81
|
+
|
82
|
+
defaults : {
|
83
|
+
// Default text function will either print 'None selected' in case no
|
84
|
+
// option is selected, or a list of the selected options up to a length of 3 selected options.
|
85
|
+
// If more than 3 options are selected, the number of selected options is printed.
|
86
|
+
buttonText : function(options, select) {
|
87
|
+
if (options.length == 0) {
|
88
|
+
return this.nonSelectedText + '<b class="caret"></b>';
|
89
|
+
}
|
90
|
+
else
|
91
|
+
if (options.length > 3) {
|
92
|
+
return options.length + ' ' + this.nSelectedText + ' <b class="caret"></b>';
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
var selected = '';
|
96
|
+
options.each(function() {
|
97
|
+
var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).html();
|
98
|
+
|
99
|
+
selected += label + ', ';
|
100
|
+
});
|
101
|
+
return selected.substr(0, selected.length - 2) + ' <b class="caret"></b>';
|
102
|
+
}
|
103
|
+
},
|
104
|
+
// Is triggered on change of the selected options.
|
105
|
+
onChange : function(option, checked) {
|
106
|
+
|
107
|
+
},
|
108
|
+
buttonClass : 'btn',
|
109
|
+
dropRight : false,
|
110
|
+
selectedClass : 'active',
|
111
|
+
buttonWidth : 'auto',
|
112
|
+
buttonContainer : '<div class="btn-group" />',
|
113
|
+
// Maximum height of the dropdown menu.
|
114
|
+
// If maximum height is exceeded a scrollbar will be displayed.
|
115
|
+
maxHeight : false,
|
116
|
+
includeSelectAllOption : false,
|
117
|
+
selectAllText : ' Select all',
|
118
|
+
selectAllValue : 'multiselect-all',
|
119
|
+
enableFiltering : false,
|
120
|
+
enableCaseInsensitiveFiltering : false,
|
121
|
+
filterPlaceholder : 'Search',
|
122
|
+
// possible options: 'text', 'value', 'both'
|
123
|
+
filterBehavior : 'text',
|
124
|
+
preventInputChangeEvent: false,
|
125
|
+
nonSelectedText: 'None selected',
|
126
|
+
nSelectedText: 'selected'
|
127
|
+
},
|
128
|
+
|
129
|
+
constructor : Multiselect,
|
130
|
+
|
131
|
+
// Will build an dropdown element for the given option.
|
132
|
+
createOptionValue : function(element) {
|
133
|
+
if ($(element).is(':selected')) {
|
134
|
+
$(element).attr('selected', 'selected').prop('selected', true);
|
135
|
+
}
|
136
|
+
|
137
|
+
// Support the label attribute on options.
|
138
|
+
var label = $(element).attr('label') || $(element).html();
|
139
|
+
var value = $(element).val();
|
140
|
+
var inputType = this.options.multiple ? "checkbox" : "radio";
|
141
|
+
|
142
|
+
var $li = $('<li><a href="javascript:void(0);"><label class="' + inputType + '"><input type="' + inputType + '" /></label></a></li>');
|
143
|
+
|
144
|
+
var selected = $(element).prop('selected') || false;
|
145
|
+
var $checkbox = $('input', $li);
|
146
|
+
$checkbox.val(value);
|
147
|
+
|
148
|
+
if (value == this.options.selectAllValue) {
|
149
|
+
$checkbox.parent().parent().addClass('multiselect-all');
|
150
|
+
}
|
151
|
+
|
152
|
+
$('label', $li).append(" " + label);
|
153
|
+
|
154
|
+
$('.multiselect-container', this.$container).append($li);
|
155
|
+
|
156
|
+
if ($(element).is(':disabled')) {
|
157
|
+
$checkbox.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled');
|
158
|
+
}
|
159
|
+
|
160
|
+
$checkbox.prop('checked', selected);
|
161
|
+
|
162
|
+
if (selected && this.options.selectedClass) {
|
163
|
+
$checkbox.parents('li').addClass(this.options.selectedClass);
|
164
|
+
}
|
165
|
+
},
|
166
|
+
|
167
|
+
toggleActiveState : function(shouldBeActive) {
|
168
|
+
if (this.$select.attr('disabled') == undefined) {
|
169
|
+
$('button.multiselect.dropdown-toggle', this.$container).removeClass('disabled');
|
170
|
+
}
|
171
|
+
else {
|
172
|
+
$('button.multiselect.dropdown-toggle', this.$container).addClass('disabled');
|
173
|
+
}
|
174
|
+
},
|
175
|
+
|
176
|
+
// Build the dropdown and bind event handling.
|
177
|
+
buildDropdown : function() {
|
178
|
+
var alreadyHasSelectAll = this.$select[0][0] ? this.$select[0][0].value == this.options.selectAllValue : false;
|
179
|
+
|
180
|
+
// If options.includeSelectAllOption === true, add the include all
|
181
|
+
// checkbox.
|
182
|
+
if (this.options.includeSelectAllOption && this.options.multiple && !alreadyHasSelectAll) {
|
183
|
+
this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>');
|
184
|
+
}
|
185
|
+
|
186
|
+
this.toggleActiveState();
|
187
|
+
|
188
|
+
this.$select.children().each($.proxy(function(index, element) {
|
189
|
+
// Support optgroups and options without a group simultaneously.
|
190
|
+
var tag = $(element).prop('tagName').toLowerCase();
|
191
|
+
if (tag == 'optgroup') {
|
192
|
+
var group = element;
|
193
|
+
var groupName = $(group).prop('label');
|
194
|
+
|
195
|
+
// Add a header for the group.
|
196
|
+
var $li = $('<li><label class="multiselect-group"></label></li>');
|
197
|
+
$('label', $li).text(groupName);
|
198
|
+
$('.multiselect-container', this.$container).append($li);
|
199
|
+
|
200
|
+
// Add the options of the group.
|
201
|
+
$('option', group).each($.proxy(function(index, element) {
|
202
|
+
this.createOptionValue(element);
|
203
|
+
}, this));
|
204
|
+
}
|
205
|
+
else
|
206
|
+
if (tag == 'option') {
|
207
|
+
this.createOptionValue(element);
|
208
|
+
}
|
209
|
+
else {
|
210
|
+
// Ignore illegal tags.
|
211
|
+
}
|
212
|
+
}, this));
|
213
|
+
|
214
|
+
// Bind the change event on the dropdown elements.
|
215
|
+
$('.multiselect-container li input', this.$container).on('change', $.proxy(function(event) {
|
216
|
+
var checked = $(event.target).prop('checked') || false;
|
217
|
+
var isSelectAllOption = $(event.target).val() == this.options.selectAllValue;
|
218
|
+
|
219
|
+
// Apply or unapply the configured selected class.
|
220
|
+
if (this.options.selectedClass) {
|
221
|
+
if (checked) {
|
222
|
+
$(event.target).parents('li').addClass(this.options.selectedClass);
|
223
|
+
}
|
224
|
+
else {
|
225
|
+
$(event.target).parents('li').removeClass(this.options.selectedClass);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
var $option = $('option', this.$select).filter(function() {
|
230
|
+
return $(this).val() == $(event.target).val();
|
231
|
+
});
|
232
|
+
|
233
|
+
var $optionsNotThis = $('option', this.$select).not($option);
|
234
|
+
var $checkboxesNotThis = $('input', this.$container).not($(event.target));
|
235
|
+
|
236
|
+
// Toggle all options if the select all option was changed.
|
237
|
+
if (isSelectAllOption) {
|
238
|
+
$checkboxesNotThis.filter(function() {
|
239
|
+
return $(this).is(':checked') != checked;
|
240
|
+
}).trigger('click');
|
241
|
+
}
|
242
|
+
|
243
|
+
if (checked) {
|
244
|
+
$option.prop('selected', true);
|
245
|
+
|
246
|
+
if (this.options.multiple) {
|
247
|
+
$option.attr('selected', 'selected');
|
248
|
+
}
|
249
|
+
else {
|
250
|
+
if (this.options.selectedClass) {
|
251
|
+
$($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass);
|
252
|
+
}
|
253
|
+
|
254
|
+
$($checkboxesNotThis).prop('checked', false);
|
255
|
+
|
256
|
+
$optionsNotThis.removeAttr('selected').prop('selected', false);
|
257
|
+
|
258
|
+
// It's a single selection, so close.
|
259
|
+
$(this.$container).find(".multiselect.dropdown-toggle").click();
|
260
|
+
}
|
261
|
+
|
262
|
+
if (this.options.selectedClass == "active") {
|
263
|
+
$optionsNotThis.parents("a").css("outline", "");
|
264
|
+
}
|
265
|
+
|
266
|
+
}
|
267
|
+
else {
|
268
|
+
$option.removeAttr('selected').prop('selected', false);
|
269
|
+
}
|
270
|
+
|
271
|
+
this.updateButtonText();
|
272
|
+
|
273
|
+
this.options.onChange($option, checked);
|
274
|
+
|
275
|
+
this.$select.change();
|
276
|
+
|
277
|
+
if(this.options.preventInputChangeEvent) {
|
278
|
+
return false;
|
279
|
+
}
|
280
|
+
}, this));
|
281
|
+
|
282
|
+
$('.multiselect-container li a', this.$container).on('touchstart click', function(event) {
|
283
|
+
event.stopPropagation();
|
284
|
+
$(event.target).blur();
|
285
|
+
});
|
286
|
+
|
287
|
+
// Keyboard support.
|
288
|
+
this.$container.on('keydown', $.proxy(function(event) {
|
289
|
+
if ($('input[type="text"]', this.$container).is(':focus'))
|
290
|
+
return;
|
291
|
+
if ((event.keyCode == 9 || event.keyCode == 27) && this.$container.hasClass('open')) {
|
292
|
+
// Close on tab or escape.
|
293
|
+
$(this.$container).find(".multiselect.dropdown-toggle").click();
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
var $items = $(this.$container).find("li:not(.divider):visible a");
|
297
|
+
|
298
|
+
if (!$items.length) {
|
299
|
+
return;
|
300
|
+
}
|
301
|
+
|
302
|
+
var index = $items.index($items.filter(':focus'));
|
303
|
+
|
304
|
+
// Navigation up.
|
305
|
+
if (event.keyCode == 38 && index > 0) {
|
306
|
+
index--;
|
307
|
+
}
|
308
|
+
// Navigate down.
|
309
|
+
else
|
310
|
+
if (event.keyCode == 40 && index < $items.length - 1) {
|
311
|
+
index++;
|
312
|
+
}
|
313
|
+
else
|
314
|
+
if (!~index) {
|
315
|
+
index = 0;
|
316
|
+
}
|
317
|
+
|
318
|
+
var $current = $items.eq(index);
|
319
|
+
$current.focus();
|
320
|
+
|
321
|
+
// Override style for items in li:active.
|
322
|
+
if (this.options.selectedClass == "active") {
|
323
|
+
$current.css("outline", "thin dotted #333").css("outline", "5px auto -webkit-focus-ring-color");
|
324
|
+
|
325
|
+
$items.not($current).css("outline", "");
|
326
|
+
}
|
327
|
+
|
328
|
+
if (event.keyCode == 32 || event.keyCode == 13) {
|
329
|
+
var $checkbox = $current.find('input');
|
330
|
+
|
331
|
+
$checkbox.prop("checked", !$checkbox.prop("checked"));
|
332
|
+
$checkbox.change();
|
333
|
+
}
|
334
|
+
|
335
|
+
event.stopPropagation();
|
336
|
+
event.preventDefault();
|
337
|
+
}
|
338
|
+
}, this));
|
339
|
+
},
|
340
|
+
|
341
|
+
// Build and bind filter.
|
342
|
+
buildFilter: function() {
|
343
|
+
$('.multiselect-container', this.$container).prepend('<div class="input-prepend"><span class="add-on"><i class="icon-search"></i></span><input class="multiselect-search" type="text" placeholder="' + this.options.filterPlaceholder + '"></div>');
|
344
|
+
|
345
|
+
$('.multiselect-search', this.$container).val(this.query).on('click', function(event) {
|
346
|
+
event.stopPropagation();
|
347
|
+
}).on('keydown', $.proxy(function(event) {
|
348
|
+
// This is useful to catch "keydown" events after the browser has
|
349
|
+
// updated the control.
|
350
|
+
clearTimeout(this.searchTimeout);
|
351
|
+
|
352
|
+
this.searchTimeout = this.asyncFunction($.proxy(function() {
|
353
|
+
|
354
|
+
if (this.query != event.target.value) {
|
355
|
+
this.query = event.target.value;
|
356
|
+
|
357
|
+
$.each($('.multiselect-container li', this.$container), $.proxy(function(index, element) {
|
358
|
+
var value = $('input', element).val();
|
359
|
+
if (value != this.options.selectAllValue) {
|
360
|
+
var text = $('label', element).text();
|
361
|
+
var value = $('input', element).val();
|
362
|
+
if (value && text && value != this.options.selectAllValue) {
|
363
|
+
// by default lets assume that element is not
|
364
|
+
// interesting for this search
|
365
|
+
var showElement = false;
|
366
|
+
|
367
|
+
var filterCandidate = '';
|
368
|
+
if ((this.options.filterBehavior == 'text' || this.options.filterBehavior == 'both')) {
|
369
|
+
filterCandidate = text;
|
370
|
+
}
|
371
|
+
if ((this.options.filterBehavior == 'value' || this.options.filterBehavior == 'both')) {
|
372
|
+
filterCandidate = value;
|
373
|
+
}
|
374
|
+
|
375
|
+
if (this.options.enableCaseInsensitiveFiltering && filterCandidate.toLowerCase().indexOf(this.query.toLowerCase()) > -1) {
|
376
|
+
showElement = true;
|
377
|
+
}
|
378
|
+
else if (filterCandidate.indexOf(this.query) > -1) {
|
379
|
+
showElement = true;
|
380
|
+
}
|
381
|
+
|
382
|
+
if (showElement) {
|
383
|
+
$(element).show();
|
384
|
+
}
|
385
|
+
else {
|
386
|
+
$(element).hide();
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}
|
390
|
+
}, this));
|
391
|
+
}
|
392
|
+
}, this), 300, this);
|
393
|
+
}, this));
|
394
|
+
},
|
395
|
+
|
396
|
+
// Destroy - unbind - the plugin.
|
397
|
+
destroy : function() {
|
398
|
+
this.$container.remove();
|
399
|
+
this.$select.show();
|
400
|
+
},
|
401
|
+
|
402
|
+
// Refreshs the checked options based on the current state of the select.
|
403
|
+
refresh : function() {
|
404
|
+
$('option', this.$select).each($.proxy(function(index, element) {
|
405
|
+
var $input = $('.multiselect-container li input', this.$container).filter(function() {
|
406
|
+
return $(this).val() == $(element).val();
|
407
|
+
});
|
408
|
+
|
409
|
+
if ($(element).is(':selected')) {
|
410
|
+
$input.prop('checked', true);
|
411
|
+
|
412
|
+
if (this.options.selectedClass) {
|
413
|
+
$input.parents('li').addClass(this.options.selectedClass);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
else {
|
417
|
+
$input.prop('checked', false);
|
418
|
+
|
419
|
+
if (this.options.selectedClass) {
|
420
|
+
$input.parents('li').removeClass(this.options.selectedClass);
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
if ($(element).is(":disabled")) {
|
425
|
+
$input.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled');
|
426
|
+
}
|
427
|
+
else {
|
428
|
+
$input.removeAttr('disabled').prop('disabled', false).parents('li').removeClass('disabled');
|
429
|
+
}
|
430
|
+
}, this));
|
431
|
+
|
432
|
+
this.updateButtonText();
|
433
|
+
},
|
434
|
+
|
435
|
+
// Select an option by its value.
|
436
|
+
select : function(value) {
|
437
|
+
var $option = $('option', this.$select).filter(function() {
|
438
|
+
return $(this).val() == value;
|
439
|
+
});
|
440
|
+
var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
|
441
|
+
return $(this).val() == value;
|
442
|
+
});
|
443
|
+
|
444
|
+
if (this.options.selectedClass) {
|
445
|
+
$checkbox.parents('li').addClass(this.options.selectedClass);
|
446
|
+
}
|
447
|
+
|
448
|
+
$checkbox.prop('checked', true);
|
449
|
+
|
450
|
+
$option.attr('selected', 'selected').prop('selected', true);
|
451
|
+
|
452
|
+
this.updateButtonText();
|
453
|
+
this.options.onChange($option, true);
|
454
|
+
},
|
455
|
+
|
456
|
+
// Deselect an option by its value.
|
457
|
+
deselect : function(value) {
|
458
|
+
var $option = $('option', this.$select).filter(function() {
|
459
|
+
return $(this).val() == value;
|
460
|
+
});
|
461
|
+
var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
|
462
|
+
return $(this).val() == value;
|
463
|
+
});
|
464
|
+
|
465
|
+
if (this.options.selectedClass) {
|
466
|
+
$checkbox.parents('li').removeClass(this.options.selectedClass);
|
467
|
+
}
|
468
|
+
|
469
|
+
$checkbox.prop('checked', false);
|
470
|
+
|
471
|
+
$option.removeAttr('selected').prop('selected', false);
|
472
|
+
|
473
|
+
this.updateButtonText();
|
474
|
+
this.options.onChange($option, false);
|
475
|
+
},
|
476
|
+
|
477
|
+
// Rebuild the whole dropdown menu.
|
478
|
+
rebuild : function() {
|
479
|
+
$('.multiselect-container', this.$container).html('');
|
480
|
+
this.buildDropdown(this.$select, this.options);
|
481
|
+
this.updateButtonText();
|
482
|
+
|
483
|
+
// Enable filtering.
|
484
|
+
if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) {
|
485
|
+
this.buildFilter();
|
486
|
+
}
|
487
|
+
},
|
488
|
+
|
489
|
+
// Get options by merging defaults and given options.
|
490
|
+
getOptions : function(options) {
|
491
|
+
return $.extend({}, this.defaults, options);
|
492
|
+
},
|
493
|
+
|
494
|
+
updateButtonText : function() {
|
495
|
+
var options = this.getSelected();
|
496
|
+
$('button', this.$container).html(this.options.buttonText(options, this.$select));
|
497
|
+
},
|
498
|
+
|
499
|
+
// Get all selected options.
|
500
|
+
getSelected : function() {
|
501
|
+
return $('option:selected[value!="' + this.options.selectAllValue + '"]', this.$select);
|
502
|
+
},
|
503
|
+
|
504
|
+
updateOriginalOptions : function() {
|
505
|
+
this.originalOptions = this.$select.clone()[0].options;
|
506
|
+
},
|
507
|
+
|
508
|
+
asyncFunction : function(callback, timeout, self) {
|
509
|
+
var args = Array.prototype.slice.call(arguments, 3);
|
510
|
+
return setTimeout(function() {
|
511
|
+
callback.apply(self || window, args);
|
512
|
+
}, timeout);
|
513
|
+
}
|
514
|
+
};
|
515
|
+
|
516
|
+
$.fn.multiselect = function(option, parameter) {
|
517
|
+
return this.each(function() {
|
518
|
+
var data = $(this).data('multiselect'), options = typeof option == 'object' && option;
|
519
|
+
|
520
|
+
// Initialize the multiselect.
|
521
|
+
if (!data) {
|
522
|
+
$(this).data('multiselect', ( data = new Multiselect(this, options)));
|
523
|
+
}
|
524
|
+
|
525
|
+
// Call multiselect method.
|
526
|
+
if ( typeof option == 'string') {
|
527
|
+
data[option](parameter);
|
528
|
+
}
|
529
|
+
});
|
530
|
+
};
|
531
|
+
|
532
|
+
$.fn.multiselect.Constructor = Multiselect;
|
533
|
+
|
534
|
+
$(function() {
|
535
|
+
$("select[data-role=multiselect]").multiselect();
|
536
|
+
});
|
537
|
+
|
538
|
+
}(window.jQuery);
|