spree_core 4.1.5 → 4.2.0.beta
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.
- checksums.yaml +4 -4
- data/app/controllers/spree/base_controller.rb +1 -0
- data/app/finders/spree/products/find.rb +46 -11
- data/app/helpers/spree/base_helper.rb +26 -3
- data/app/helpers/spree/mail_helper.rb +24 -0
- data/app/helpers/spree/products_helper.rb +15 -14
- data/app/mailers/spree/base_mailer.rb +17 -3
- data/app/mailers/spree/order_mailer.rb +11 -2
- data/app/mailers/spree/reimbursement_mailer.rb +4 -2
- data/app/mailers/spree/shipment_mailer.rb +4 -2
- data/app/models/concerns/spree/default_price.rb +2 -1
- data/app/models/concerns/spree/product_scopes.rb +2 -2
- data/app/models/concerns/spree/user_methods.rb +11 -5
- data/app/models/spree/app_configuration.rb +6 -0
- data/app/models/spree/line_item.rb +10 -1
- data/app/models/spree/option_type.rb +5 -1
- data/app/models/spree/order.rb +26 -5
- data/app/models/spree/price.rb +26 -2
- data/app/models/spree/product.rb +19 -9
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +1 -1
- data/app/models/spree/promotion_handler/coupon.rb +1 -1
- data/app/models/spree/reimbursement.rb +2 -0
- data/app/models/spree/shipment.rb +2 -5
- data/app/models/spree/stock_location.rb +13 -2
- data/app/models/spree/store.rb +19 -2
- data/app/models/spree/taxon.rb +6 -0
- data/app/models/spree/variant.rb +29 -2
- data/app/presenters/spree/variant_presenter.rb +7 -0
- data/app/presenters/spree/variants/option_types_presenter.rb +1 -0
- data/app/services/spree/checkout/get_shipping_rates.rb +7 -10
- data/app/views/layouts/spree/base_mailer.html.erb +45 -40
- data/app/views/spree/order_mailer/cancel_email.html.erb +19 -25
- data/app/views/spree/order_mailer/cancel_email.text.erb +24 -2
- data/app/views/spree/order_mailer/confirm_email.html.erb +18 -65
- data/app/views/spree/order_mailer/confirm_email.text.erb +2 -1
- data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +23 -0
- data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +38 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +53 -58
- data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +3 -1
- data/app/views/spree/shared/_base_mailer_footer.html.erb +6 -14
- data/app/views/spree/shared/_base_mailer_header.html.erb +12 -32
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +293 -625
- data/app/views/spree/shared/_purchased_items_table.html.erb +60 -0
- data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +13 -0
- data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +27 -0
- data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +13 -0
- data/app/views/spree/shared/purchased_items_table/_total.html.erb +13 -0
- data/app/views/spree/shipment_mailer/shipped_email.html.erb +31 -36
- data/app/views/spree/shipment_mailer/shipped_email.text.erb +2 -1
- data/config/initializers/assets.rb +1 -0
- data/config/locales/en.yml +113 -13
- data/db/default/spree/stores.rb +11 -10
- data/db/migrate/20140309033438_create_store_from_preferences.rb +1 -1
- data/db/migrate/20191017121054_add_supported_currencies_to_store.rb +10 -0
- data/db/migrate/20200102141311_add_social_to_spree_stores.rb +3 -0
- data/db/migrate/20200308210757_add_default_locale_to_spree_store.rb +7 -0
- data/db/migrate/20200310145140_add_customer_support_email_to_spree_store.rb +7 -0
- data/db/migrate/20200421095017_add_compare_at_amount_to_spree_prices.rb +7 -0
- data/db/migrate/20200423123001_add_default_country_id_to_spree_store.rb +9 -0
- data/db/migrate/20200430072209_add_footer_fields_to_spree_stores.rb +8 -0
- data/db/migrate/20200513154939_add_show_property_to_spree_product_properties.rb +5 -0
- data/db/migrate/20200607161221_add_store_owner_order_notification_delivered_to_spree_orders.rb +7 -0
- data/db/migrate/20200607161222_add_new_order_notifications_email_to_spree_stores.rb +7 -0
- data/db/migrate/20200826075557_add_unique_index_on_taxon_id_and_product_id_to_spree_products_taxons.rb +5 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +1 -0
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -2
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -2
- data/lib/generators/spree/mailers_preview/mailers_preview_generator.rb +23 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/order_preview.rb +13 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/reimbursement_preview.rb +5 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/shipment_preview.rb +5 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/user_preview.rb +11 -0
- data/lib/spree/core.rb +1 -0
- data/lib/spree/core/controller_helpers/common.rb +1 -0
- data/lib/spree/core/controller_helpers/currency_helpers.rb +15 -0
- data/lib/spree/core/controller_helpers/store.rb +12 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/permitted_attributes.rb +7 -4
- data/lib/spree/testing_support/authorization_helpers.rb +7 -4
- data/lib/spree/testing_support/factories/store_factory.rb +11 -8
- data/spree_core.gemspec +14 -8
- data/vendor/assets/javascripts/cleave.js +1669 -0
- metadata +43 -22
- data/app/views/spree/order_mailer/_adjustment.html.erb +0 -8
- data/app/views/spree/order_mailer/_subtotal.html.erb +0 -8
- data/app/views/spree/order_mailer/_total.html.erb +0 -8
data/db/default/spree/stores.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# Possibly already created by a migration.
|
2
2
|
unless Spree::Store.default.persisted?
|
3
3
|
Spree::Store.new do |s|
|
4
|
-
s.name
|
5
|
-
s.code
|
6
|
-
s.url
|
7
|
-
s.mail_from_address
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
4
|
+
s.name = 'Spree Demo Site'
|
5
|
+
s.code = 'spree'
|
6
|
+
s.url = Rails.application.routes.default_url_options[:host] || 'demo.spreecommerce.org'
|
7
|
+
s.mail_from_address = 'no-reply@example.com'
|
8
|
+
s.customer_support_email = 'support@example.com'
|
9
|
+
s.default_currency = 'USD'
|
10
|
+
s.seo_title = 'Spree Commerce Demo Shop'
|
11
|
+
s.meta_description = 'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'
|
12
|
+
s.facebook = 'spreecommerce'
|
13
|
+
s.twitter = 'spreecommerce'
|
14
|
+
s.instagram = 'spreecommerce'
|
14
15
|
end.save!
|
15
16
|
end
|
@@ -28,7 +28,7 @@ class CreateStoreFromPreferences < ActiveRecord::Migration[4.2]
|
|
28
28
|
end
|
29
29
|
|
30
30
|
s.meta_description = preference_store.get('spree/app_configuration/default_meta_description') do
|
31
|
-
'
|
31
|
+
'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'
|
32
32
|
end
|
33
33
|
s.meta_keywords = preference_store.get('spree/app_configuration/default_meta_keywords') {}
|
34
34
|
s.seo_title = preference_store.get('spree/app_configuration/default_seo_title') do
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class AddSupportedCurrenciesToStore < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
unless column_exists?(:spree_stores, :supported_currencies)
|
4
|
+
add_column :spree_stores, :supported_currencies, :string
|
5
|
+
Spree::Store.all.each do |store|
|
6
|
+
store.update_attribute(:supported_currencies, store.default_currency)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -3,5 +3,8 @@ class AddSocialToSpreeStores < ActiveRecord::Migration[6.0]
|
|
3
3
|
add_column :spree_stores, :facebook, :string
|
4
4
|
add_column :spree_stores, :twitter, :string
|
5
5
|
add_column :spree_stores, :instagram, :string
|
6
|
+
|
7
|
+
# Fix cache issue #10381
|
8
|
+
Rails.cache.delete('default_store')
|
6
9
|
end
|
7
10
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class AddDefaultCountryIdToSpreeStore < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
unless column_exists?(:spree_stores, :default_country_id)
|
4
|
+
add_column :spree_stores, :default_country_id, :integer
|
5
|
+
Spree::Store.reset_column_information
|
6
|
+
Spree::Store.update_all(default_country_id: Spree::Config[:default_country_id])
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddFooterFieldsToSpreeStores < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
add_column :spree_stores, :description, :text unless column_exists?(:spree_stores, :description)
|
4
|
+
add_column :spree_stores, :address, :text unless column_exists?(:spree_stores, :address)
|
5
|
+
add_column :spree_stores, :contact_phone, :string unless column_exists?(:spree_stores, :contact_phone)
|
6
|
+
add_column :spree_stores, :contact_email, :string unless column_exists?(:spree_stores, :contact_email)
|
7
|
+
end
|
8
|
+
end
|
data/db/migrate/20200607161221_add_store_owner_order_notification_delivered_to_spree_orders.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
class AddStoreOwnerOrderNotificationDeliveredToSpreeOrders < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
unless column_exists?(:spree_orders, :store_owner_notification_delivered)
|
4
|
+
add_column :spree_orders, :store_owner_notification_delivered, :boolean
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -26,5 +26,6 @@ Spree.dependencies do |dependencies|
|
|
26
26
|
# dependencies.cart_add_item_service = 'MyNewAwesomeService'
|
27
27
|
end
|
28
28
|
|
29
|
+
# Spree::Api::Dependencies.storefront_cart_serializer = 'MyRailsApp::CartSerializer'
|
29
30
|
|
30
31
|
Spree.user_class = <%= (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]).inspect %>
|
@@ -4,8 +4,6 @@
|
|
4
4
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
5
|
// the compiled file.
|
6
6
|
//
|
7
|
-
//= require jquery
|
8
|
-
//= require jquery_ujs
|
9
7
|
//= require spree/backend
|
10
8
|
<% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/backend' %>
|
11
9
|
<% filename = "spree/backend/#{ options[:lib_name].gsub("/", "_") }" %>
|
@@ -4,8 +4,6 @@
|
|
4
4
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
5
|
// the compiled file.
|
6
6
|
//
|
7
|
-
//= require jquery
|
8
|
-
//= require jquery_ujs
|
9
7
|
//= require accounting.min
|
10
8
|
//= require spree/frontend
|
11
9
|
<% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/frontend' %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'spree/core'
|
3
|
+
|
4
|
+
module Spree
|
5
|
+
class MailersPreviewGenerator < Rails::Generators::Base
|
6
|
+
desc 'Generates mailers preview for development proposes'
|
7
|
+
|
8
|
+
def self.source_paths
|
9
|
+
[
|
10
|
+
File.expand_path('templates', __dir__)
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_mailers_previews
|
15
|
+
preview_path = Rails.application.config.action_mailer.preview_path || 'test/mailers/previews'
|
16
|
+
|
17
|
+
template 'mailers/previews/order_preview.rb', "#{preview_path}/order_preview.rb"
|
18
|
+
template 'mailers/previews/shipment_preview.rb', "#{preview_path}/shipment_preview.rb"
|
19
|
+
template 'mailers/previews/reimbursement_preview.rb', "#{preview_path}/reimbursement_preview.rb"
|
20
|
+
template 'mailers/previews/user_preview.rb', "#{preview_path}/user_preview.rb"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class OrderPreview < ActionMailer::Preview
|
2
|
+
def confirm_email
|
3
|
+
Spree::OrderMailer.confirm_email(Spree::Order.complete.first)
|
4
|
+
end
|
5
|
+
|
6
|
+
def cancel_email
|
7
|
+
Spree::OrderMailer.cancel_email(Spree::Order.complete.first)
|
8
|
+
end
|
9
|
+
|
10
|
+
def store_owner_notification_email
|
11
|
+
Spree::OrderMailer.store_owner_notification_email(Spree::Order.complete.first)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class UserPreview < ActionMailer::Preview
|
2
|
+
def reset_password_instructions
|
3
|
+
Spree::UserMailer.reset_password_instructions(Spree.user_class.first, 'your_token', { current_store_id: Spree::Store.default.id })
|
4
|
+
end
|
5
|
+
|
6
|
+
if Spree::Auth::Config[:confirmable]
|
7
|
+
def confirmation_instructions
|
8
|
+
Spree::UserMailer.confirmation_instructions(Spree.user_class.first, 'your_token')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/spree/core.rb
CHANGED
@@ -104,3 +104,4 @@ require 'spree/core/controller_helpers/order'
|
|
104
104
|
require 'spree/core/controller_helpers/search'
|
105
105
|
require 'spree/core/controller_helpers/store'
|
106
106
|
require 'spree/core/controller_helpers/strong_parameters'
|
107
|
+
require 'spree/core/controller_helpers/currency_helpers'
|
@@ -44,6 +44,7 @@ module Spree
|
|
44
44
|
|
45
45
|
def set_user_language
|
46
46
|
locale = session[:locale]
|
47
|
+
locale = store_locale if respond_to?(:store_locale, true) && locale.blank?
|
47
48
|
locale = config_locale if respond_to?(:config_locale, true) && locale.blank?
|
48
49
|
locale = Rails.application.config.i18n.default_locale if locale.blank?
|
49
50
|
locale = I18n.default_locale unless I18n.available_locales.map(&:to_s).include?(locale.to_s)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
module Core
|
3
|
+
module ControllerHelpers
|
4
|
+
module CurrencyHelpers
|
5
|
+
def self.included(receiver)
|
6
|
+
receiver.send :helper_method, :supported_currencies
|
7
|
+
end
|
8
|
+
|
9
|
+
def supported_currencies
|
10
|
+
current_store.supported_currencies_list
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -5,13 +5,24 @@ module Spree
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
+
helper_method :supported_currencies
|
8
9
|
helper_method :current_currency
|
9
10
|
helper_method :current_store
|
10
11
|
helper_method :current_price_options
|
11
12
|
end
|
12
13
|
|
13
14
|
def current_currency
|
14
|
-
|
15
|
+
if defined?(session) && session.key?(:currency) && supported_currencies.map(&:iso_code).include?(session[:currency])
|
16
|
+
session[:currency]
|
17
|
+
elsif params[:currency].present? && supported_currencies.map(&:iso_code).include?(params[:currency])
|
18
|
+
params[:currency]
|
19
|
+
else
|
20
|
+
current_store.default_currency
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def supported_currencies
|
25
|
+
current_store.supported_currencies_list
|
15
26
|
end
|
16
27
|
|
17
28
|
def current_store
|
data/lib/spree/core/version.rb
CHANGED
@@ -64,7 +64,7 @@ module Spree
|
|
64
64
|
:meta_keywords, :price, :sku, :deleted_at, :prototype_id,
|
65
65
|
:option_values_hash, :weight, :height, :width, :depth,
|
66
66
|
:shipping_category_id, :tax_category_id,
|
67
|
-
:cost_currency, :cost_price,
|
67
|
+
:cost_currency, :cost_price, :compare_at_price,
|
68
68
|
option_type_ids: [], taxon_ids: []
|
69
69
|
]
|
70
70
|
|
@@ -96,9 +96,12 @@ module Spree
|
|
96
96
|
:quantity, :stock_item, :stock_item_id, :originator, :action
|
97
97
|
]
|
98
98
|
|
99
|
-
@@store_attributes = [:name, :url, :seo_title, :code, :meta_keywords,
|
99
|
+
@@store_attributes = [:name, :url, :seo_title, :code, :meta_keywords, :logo,
|
100
100
|
:meta_description, :default_currency, :mail_from_address,
|
101
|
-
:facebook, :twitter, :instagram
|
101
|
+
:customer_support_email, :facebook, :twitter, :instagram,
|
102
|
+
:description, :address, :contact_email, :contact_phone,
|
103
|
+
:default_locale, :default_country_id, :supported_currencies,
|
104
|
+
:new_order_notifications_email]
|
102
105
|
|
103
106
|
@@store_credit_attributes = %i[amount currency category_id memo]
|
104
107
|
|
@@ -115,7 +118,7 @@ module Spree
|
|
115
118
|
@@variant_attributes = [
|
116
119
|
:name, :presentation, :cost_price, :discontinue_on, :lock_version,
|
117
120
|
:position, :track_inventory,
|
118
|
-
:product_id, :product, :option_values_attributes, :price,
|
121
|
+
:product_id, :product, :option_values_attributes, :price, :compare_at_price,
|
119
122
|
:weight, :height, :width, :depth, :sku, :cost_currency,
|
120
123
|
options: [:name, :value], option_value_ids: []
|
121
124
|
]
|
@@ -27,13 +27,14 @@ module Spree
|
|
27
27
|
|
28
28
|
def stub_authorization!
|
29
29
|
ability = build_ability
|
30
|
+
ability_class = Spree::Dependencies.ability_class.constantize
|
30
31
|
|
31
32
|
after(:all) do
|
32
|
-
|
33
|
+
ability_class.remove_ability(ability)
|
33
34
|
end
|
34
35
|
|
35
36
|
before(:all) do
|
36
|
-
|
37
|
+
ability_class.register_ability(ability)
|
37
38
|
end
|
38
39
|
|
39
40
|
before do
|
@@ -45,11 +46,13 @@ module Spree
|
|
45
46
|
|
46
47
|
def custom_authorization!(&block)
|
47
48
|
ability = build_ability(&block)
|
49
|
+
ability_class = Spree::Dependencies.ability_class.constantize
|
50
|
+
|
48
51
|
after(:all) do
|
49
|
-
|
52
|
+
ability_class.remove_ability(ability)
|
50
53
|
end
|
51
54
|
before(:all) do
|
52
|
-
|
55
|
+
ability_class.register_ability(ability)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :store, class: Spree::Store do
|
3
|
-
sequence(:code)
|
4
|
-
name
|
5
|
-
url
|
6
|
-
mail_from_address
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
sequence(:code) { |i| "spree_#{i}" }
|
4
|
+
name { 'Spree Test Store' }
|
5
|
+
url { 'www.example.com' }
|
6
|
+
mail_from_address { 'no-reply@example.com' }
|
7
|
+
customer_support_email { 'support@example.com' }
|
8
|
+
new_order_notifications_email { 'store-owner@example.com' }
|
9
|
+
default_currency { 'USD' }
|
10
|
+
supported_currencies { 'USD,EUR,GBP' }
|
11
|
+
facebook { 'spreecommerce' }
|
12
|
+
twitter { 'spreecommerce' }
|
13
|
+
instagram { 'spreecommerce' }
|
11
14
|
end
|
12
15
|
end
|
data/spree_core.gemspec
CHANGED
@@ -6,17 +6,23 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
s.name = 'spree_core'
|
8
8
|
s.version = Spree.version
|
9
|
+
s.authors = ['Sean Schofield', 'Spark Solutions']
|
10
|
+
s.email = 'hello@spreecommerce.org'
|
9
11
|
s.summary = 'The bare bones necessary for Spree.'
|
10
12
|
s.description = 'The bare bones necessary for Spree.'
|
13
|
+
s.homepage = 'https://spreecommerce.org'
|
14
|
+
s.license = 'BSD-3-Clause'
|
15
|
+
|
16
|
+
s.metadata = {
|
17
|
+
"bug_tracker_uri" => "https://github.com/spree/spree/issues",
|
18
|
+
"changelog_uri" => "https://github.com/spree/spree/releases/tag/v#{s.version}",
|
19
|
+
"documentation_uri" => "https://guides.spreecommerce.org/",
|
20
|
+
"source_code_uri" => "https://github.com/spree/spree/tree/v#{s.version}",
|
21
|
+
}
|
11
22
|
|
12
23
|
s.required_ruby_version = '>= 2.5.0'
|
13
24
|
s.required_rubygems_version = '>= 1.8.23'
|
14
25
|
|
15
|
-
s.author = 'Sean Schofield'
|
16
|
-
s.email = 'sean@spreecommerce.com'
|
17
|
-
s.homepage = 'http://spreecommerce.org'
|
18
|
-
s.license = 'BSD-3-Clause'
|
19
|
-
|
20
26
|
s.files = `git ls-files`.split("\n").reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
|
21
27
|
s.require_path = 'lib'
|
22
28
|
|
@@ -26,9 +32,9 @@ Gem::Specification.new do |s|
|
|
26
32
|
s.add_dependency 'carmen', '>= 1.0', '< 1.2'
|
27
33
|
s.add_dependency 'cancancan', '~> 3.0'
|
28
34
|
s.add_dependency 'ffaker', '~> 2.9'
|
29
|
-
s.add_dependency 'friendly_id', '>= 5.2.1', '< 5.
|
35
|
+
s.add_dependency 'friendly_id', '>= 5.2.1', '< 5.5.0'
|
30
36
|
s.add_dependency 'highline', '~> 2.0.0' # Necessary for the install generator
|
31
|
-
s.add_dependency 'kaminari', '
|
37
|
+
s.add_dependency 'kaminari', '~> 1.2.1'
|
32
38
|
s.add_dependency 'money', '~> 6.13'
|
33
39
|
s.add_dependency 'monetize', '~> 1.9'
|
34
40
|
s.add_dependency 'paranoia', '~> 2.4.2'
|
@@ -39,7 +45,7 @@ Gem::Specification.new do |s|
|
|
39
45
|
s.add_dependency 'state_machines-activerecord', '~> 0.6'
|
40
46
|
s.add_dependency 'state_machines-activemodel', '~> 0.7'
|
41
47
|
s.add_dependency 'stringex'
|
42
|
-
s.add_dependency 'twitter_cldr', '>= 4.3', '<
|
48
|
+
s.add_dependency 'twitter_cldr', '>= 4.3', '< 7.0'
|
43
49
|
s.add_dependency 'sprockets', '~> 3.7'
|
44
50
|
s.add_dependency 'sprockets-rails'
|
45
51
|
s.add_dependency 'mini_magick', '>= 4.9.4', '< 4.11.0'
|
@@ -0,0 +1,1669 @@
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
3
|
+
module.exports = factory();
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
5
|
+
define([], factory);
|
6
|
+
else if(typeof exports === 'object')
|
7
|
+
exports["Cleave"] = factory();
|
8
|
+
else
|
9
|
+
root["Cleave"] = factory();
|
10
|
+
})(this, function() {
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
12
|
+
/******/ // The module cache
|
13
|
+
/******/ var installedModules = {};
|
14
|
+
|
15
|
+
/******/ // The require function
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
17
|
+
|
18
|
+
/******/ // Check if module is in cache
|
19
|
+
/******/ if(installedModules[moduleId])
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
21
|
+
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
24
|
+
/******/ exports: {},
|
25
|
+
/******/ id: moduleId,
|
26
|
+
/******/ loaded: false
|
27
|
+
/******/ };
|
28
|
+
|
29
|
+
/******/ // Execute the module function
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31
|
+
|
32
|
+
/******/ // Flag the module as loaded
|
33
|
+
/******/ module.loaded = true;
|
34
|
+
|
35
|
+
/******/ // Return the exports of the module
|
36
|
+
/******/ return module.exports;
|
37
|
+
/******/ }
|
38
|
+
|
39
|
+
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
41
|
+
/******/ __webpack_require__.m = modules;
|
42
|
+
|
43
|
+
/******/ // expose the module cache
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
45
|
+
|
46
|
+
/******/ // __webpack_public_path__
|
47
|
+
/******/ __webpack_require__.p = "";
|
48
|
+
|
49
|
+
/******/ // Load entry module and return exports
|
50
|
+
/******/ return __webpack_require__(0);
|
51
|
+
/******/ })
|
52
|
+
/************************************************************************/
|
53
|
+
/******/ ([
|
54
|
+
/* 0 */
|
55
|
+
/***/ (function(module, exports, __webpack_require__) {
|
56
|
+
|
57
|
+
/* WEBPACK VAR INJECTION */(function(global) {'use strict';
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Construct a new Cleave instance by passing the configuration object
|
61
|
+
*
|
62
|
+
* @param {String | HTMLElement} element
|
63
|
+
* @param {Object} opts
|
64
|
+
*/
|
65
|
+
var Cleave = function (element, opts) {
|
66
|
+
var owner = this;
|
67
|
+
var hasMultipleElements = false;
|
68
|
+
|
69
|
+
if (typeof element === 'string') {
|
70
|
+
owner.element = document.querySelector(element);
|
71
|
+
hasMultipleElements = document.querySelectorAll(element).length > 1;
|
72
|
+
} else {
|
73
|
+
if (typeof element.length !== 'undefined' && element.length > 0) {
|
74
|
+
owner.element = element[0];
|
75
|
+
hasMultipleElements = element.length > 1;
|
76
|
+
} else {
|
77
|
+
owner.element = element;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
if (!owner.element) {
|
82
|
+
throw new Error('[cleave.js] Please check the element');
|
83
|
+
}
|
84
|
+
|
85
|
+
if (hasMultipleElements) {
|
86
|
+
try {
|
87
|
+
// eslint-disable-next-line
|
88
|
+
console.warn('[cleave.js] Multiple input fields matched, cleave.js will only take the first one.');
|
89
|
+
} catch (e) {
|
90
|
+
// Old IE
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
opts.initValue = owner.element.value;
|
95
|
+
|
96
|
+
owner.properties = Cleave.DefaultProperties.assign({}, opts);
|
97
|
+
|
98
|
+
owner.init();
|
99
|
+
};
|
100
|
+
|
101
|
+
Cleave.prototype = {
|
102
|
+
init: function () {
|
103
|
+
var owner = this, pps = owner.properties;
|
104
|
+
|
105
|
+
// no need to use this lib
|
106
|
+
if (!pps.numeral && !pps.phone && !pps.creditCard && !pps.time && !pps.date && (pps.blocksLength === 0 && !pps.prefix)) {
|
107
|
+
owner.onInput(pps.initValue);
|
108
|
+
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
|
112
|
+
pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);
|
113
|
+
|
114
|
+
owner.isAndroid = Cleave.Util.isAndroid();
|
115
|
+
owner.lastInputValue = '';
|
116
|
+
owner.isBackward = '';
|
117
|
+
|
118
|
+
owner.onChangeListener = owner.onChange.bind(owner);
|
119
|
+
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
|
120
|
+
owner.onFocusListener = owner.onFocus.bind(owner);
|
121
|
+
owner.onCutListener = owner.onCut.bind(owner);
|
122
|
+
owner.onCopyListener = owner.onCopy.bind(owner);
|
123
|
+
|
124
|
+
owner.initSwapHiddenInput();
|
125
|
+
|
126
|
+
owner.element.addEventListener('input', owner.onChangeListener);
|
127
|
+
owner.element.addEventListener('keydown', owner.onKeyDownListener);
|
128
|
+
owner.element.addEventListener('focus', owner.onFocusListener);
|
129
|
+
owner.element.addEventListener('cut', owner.onCutListener);
|
130
|
+
owner.element.addEventListener('copy', owner.onCopyListener);
|
131
|
+
|
132
|
+
|
133
|
+
owner.initPhoneFormatter();
|
134
|
+
owner.initDateFormatter();
|
135
|
+
owner.initTimeFormatter();
|
136
|
+
owner.initNumeralFormatter();
|
137
|
+
|
138
|
+
// avoid touch input field if value is null
|
139
|
+
// otherwise Firefox will add red box-shadow for <input required />
|
140
|
+
if (pps.initValue || (pps.prefix && !pps.noImmediatePrefix)) {
|
141
|
+
owner.onInput(pps.initValue);
|
142
|
+
}
|
143
|
+
},
|
144
|
+
|
145
|
+
initSwapHiddenInput: function () {
|
146
|
+
var owner = this, pps = owner.properties;
|
147
|
+
if (!pps.swapHiddenInput) return;
|
148
|
+
|
149
|
+
var inputFormatter = owner.element.cloneNode(true);
|
150
|
+
owner.element.parentNode.insertBefore(inputFormatter, owner.element);
|
151
|
+
|
152
|
+
owner.elementSwapHidden = owner.element;
|
153
|
+
owner.elementSwapHidden.type = 'hidden';
|
154
|
+
|
155
|
+
owner.element = inputFormatter;
|
156
|
+
owner.element.id = '';
|
157
|
+
},
|
158
|
+
|
159
|
+
initNumeralFormatter: function () {
|
160
|
+
var owner = this, pps = owner.properties;
|
161
|
+
|
162
|
+
if (!pps.numeral) {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
|
166
|
+
pps.numeralFormatter = new Cleave.NumeralFormatter(
|
167
|
+
pps.numeralDecimalMark,
|
168
|
+
pps.numeralIntegerScale,
|
169
|
+
pps.numeralDecimalScale,
|
170
|
+
pps.numeralThousandsGroupStyle,
|
171
|
+
pps.numeralPositiveOnly,
|
172
|
+
pps.stripLeadingZeroes,
|
173
|
+
pps.prefix,
|
174
|
+
pps.signBeforePrefix,
|
175
|
+
pps.tailPrefix,
|
176
|
+
pps.delimiter
|
177
|
+
);
|
178
|
+
},
|
179
|
+
|
180
|
+
initTimeFormatter: function() {
|
181
|
+
var owner = this, pps = owner.properties;
|
182
|
+
|
183
|
+
if (!pps.time) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
|
187
|
+
pps.timeFormatter = new Cleave.TimeFormatter(pps.timePattern, pps.timeFormat);
|
188
|
+
pps.blocks = pps.timeFormatter.getBlocks();
|
189
|
+
pps.blocksLength = pps.blocks.length;
|
190
|
+
pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);
|
191
|
+
},
|
192
|
+
|
193
|
+
initDateFormatter: function () {
|
194
|
+
var owner = this, pps = owner.properties;
|
195
|
+
|
196
|
+
if (!pps.date) {
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
|
200
|
+
pps.dateFormatter = new Cleave.DateFormatter(pps.datePattern, pps.dateMin, pps.dateMax);
|
201
|
+
pps.blocks = pps.dateFormatter.getBlocks();
|
202
|
+
pps.blocksLength = pps.blocks.length;
|
203
|
+
pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);
|
204
|
+
},
|
205
|
+
|
206
|
+
initPhoneFormatter: function () {
|
207
|
+
var owner = this, pps = owner.properties;
|
208
|
+
|
209
|
+
if (!pps.phone) {
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
|
213
|
+
// Cleave.AsYouTypeFormatter should be provided by
|
214
|
+
// external google closure lib
|
215
|
+
try {
|
216
|
+
pps.phoneFormatter = new Cleave.PhoneFormatter(
|
217
|
+
new pps.root.Cleave.AsYouTypeFormatter(pps.phoneRegionCode),
|
218
|
+
pps.delimiter
|
219
|
+
);
|
220
|
+
} catch (ex) {
|
221
|
+
throw new Error('[cleave.js] Please include phone-type-formatter.{country}.js lib');
|
222
|
+
}
|
223
|
+
},
|
224
|
+
|
225
|
+
onKeyDown: function (event) {
|
226
|
+
var owner = this,
|
227
|
+
charCode = event.which || event.keyCode;
|
228
|
+
|
229
|
+
owner.lastInputValue = owner.element.value;
|
230
|
+
owner.isBackward = charCode === 8;
|
231
|
+
},
|
232
|
+
|
233
|
+
onChange: function (event) {
|
234
|
+
var owner = this, pps = owner.properties,
|
235
|
+
Util = Cleave.Util;
|
236
|
+
|
237
|
+
owner.isBackward = owner.isBackward || event.inputType === 'deleteContentBackward';
|
238
|
+
|
239
|
+
var postDelimiter = Util.getPostDelimiter(owner.lastInputValue, pps.delimiter, pps.delimiters);
|
240
|
+
|
241
|
+
if (owner.isBackward && postDelimiter) {
|
242
|
+
pps.postDelimiterBackspace = postDelimiter;
|
243
|
+
} else {
|
244
|
+
pps.postDelimiterBackspace = false;
|
245
|
+
}
|
246
|
+
|
247
|
+
this.onInput(this.element.value);
|
248
|
+
},
|
249
|
+
|
250
|
+
onFocus: function () {
|
251
|
+
var owner = this,
|
252
|
+
pps = owner.properties;
|
253
|
+
owner.lastInputValue = owner.element.value;
|
254
|
+
|
255
|
+
if (pps.prefix && pps.noImmediatePrefix && !owner.element.value) {
|
256
|
+
this.onInput(pps.prefix);
|
257
|
+
}
|
258
|
+
|
259
|
+
Cleave.Util.fixPrefixCursor(owner.element, pps.prefix, pps.delimiter, pps.delimiters);
|
260
|
+
},
|
261
|
+
|
262
|
+
onCut: function (e) {
|
263
|
+
if (!Cleave.Util.checkFullSelection(this.element.value)) return;
|
264
|
+
this.copyClipboardData(e);
|
265
|
+
this.onInput('');
|
266
|
+
},
|
267
|
+
|
268
|
+
onCopy: function (e) {
|
269
|
+
if (!Cleave.Util.checkFullSelection(this.element.value)) return;
|
270
|
+
this.copyClipboardData(e);
|
271
|
+
},
|
272
|
+
|
273
|
+
copyClipboardData: function (e) {
|
274
|
+
var owner = this,
|
275
|
+
pps = owner.properties,
|
276
|
+
Util = Cleave.Util,
|
277
|
+
inputValue = owner.element.value,
|
278
|
+
textToCopy = '';
|
279
|
+
|
280
|
+
if (!pps.copyDelimiter) {
|
281
|
+
textToCopy = Util.stripDelimiters(inputValue, pps.delimiter, pps.delimiters);
|
282
|
+
} else {
|
283
|
+
textToCopy = inputValue;
|
284
|
+
}
|
285
|
+
|
286
|
+
try {
|
287
|
+
if (e.clipboardData) {
|
288
|
+
e.clipboardData.setData('Text', textToCopy);
|
289
|
+
} else {
|
290
|
+
window.clipboardData.setData('Text', textToCopy);
|
291
|
+
}
|
292
|
+
|
293
|
+
e.preventDefault();
|
294
|
+
} catch (ex) {
|
295
|
+
// empty
|
296
|
+
}
|
297
|
+
},
|
298
|
+
|
299
|
+
onInput: function (value) {
|
300
|
+
var owner = this, pps = owner.properties,
|
301
|
+
Util = Cleave.Util;
|
302
|
+
|
303
|
+
// case 1: delete one more character "4"
|
304
|
+
// 1234*| -> hit backspace -> 123|
|
305
|
+
// case 2: last character is not delimiter which is:
|
306
|
+
// 12|34* -> hit backspace -> 1|34*
|
307
|
+
// note: no need to apply this for numeral mode
|
308
|
+
var postDelimiterAfter = Util.getPostDelimiter(value, pps.delimiter, pps.delimiters);
|
309
|
+
if (!pps.numeral && pps.postDelimiterBackspace && !postDelimiterAfter) {
|
310
|
+
value = Util.headStr(value, value.length - pps.postDelimiterBackspace.length);
|
311
|
+
}
|
312
|
+
|
313
|
+
// phone formatter
|
314
|
+
if (pps.phone) {
|
315
|
+
if (pps.prefix && (!pps.noImmediatePrefix || value.length)) {
|
316
|
+
pps.result = pps.prefix + pps.phoneFormatter.format(value).slice(pps.prefix.length);
|
317
|
+
} else {
|
318
|
+
pps.result = pps.phoneFormatter.format(value);
|
319
|
+
}
|
320
|
+
owner.updateValueState();
|
321
|
+
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
|
325
|
+
// numeral formatter
|
326
|
+
if (pps.numeral) {
|
327
|
+
// Do not show prefix when noImmediatePrefix is specified
|
328
|
+
// This mostly because we need to show user the native input placeholder
|
329
|
+
if (pps.prefix && pps.noImmediatePrefix && value.length === 0) {
|
330
|
+
pps.result = '';
|
331
|
+
} else {
|
332
|
+
pps.result = pps.numeralFormatter.format(value);
|
333
|
+
}
|
334
|
+
owner.updateValueState();
|
335
|
+
|
336
|
+
return;
|
337
|
+
}
|
338
|
+
|
339
|
+
// date
|
340
|
+
if (pps.date) {
|
341
|
+
value = pps.dateFormatter.getValidatedDate(value);
|
342
|
+
}
|
343
|
+
|
344
|
+
// time
|
345
|
+
if (pps.time) {
|
346
|
+
value = pps.timeFormatter.getValidatedTime(value);
|
347
|
+
}
|
348
|
+
|
349
|
+
// strip delimiters
|
350
|
+
value = Util.stripDelimiters(value, pps.delimiter, pps.delimiters);
|
351
|
+
|
352
|
+
// strip prefix
|
353
|
+
value = Util.getPrefixStrippedValue(value, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix, pps.signBeforePrefix);
|
354
|
+
|
355
|
+
// strip non-numeric characters
|
356
|
+
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;
|
357
|
+
|
358
|
+
// convert case
|
359
|
+
value = pps.uppercase ? value.toUpperCase() : value;
|
360
|
+
value = pps.lowercase ? value.toLowerCase() : value;
|
361
|
+
|
362
|
+
// prevent from showing prefix when no immediate option enabled with empty input value
|
363
|
+
if (pps.prefix) {
|
364
|
+
if (pps.tailPrefix) {
|
365
|
+
value = value + pps.prefix;
|
366
|
+
} else {
|
367
|
+
value = pps.prefix + value;
|
368
|
+
}
|
369
|
+
|
370
|
+
|
371
|
+
// no blocks specified, no need to do formatting
|
372
|
+
if (pps.blocksLength === 0) {
|
373
|
+
pps.result = value;
|
374
|
+
owner.updateValueState();
|
375
|
+
|
376
|
+
return;
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
// update credit card props
|
381
|
+
if (pps.creditCard) {
|
382
|
+
owner.updateCreditCardPropsByValue(value);
|
383
|
+
}
|
384
|
+
|
385
|
+
// strip over length characters
|
386
|
+
value = Util.headStr(value, pps.maxLength);
|
387
|
+
|
388
|
+
// apply blocks
|
389
|
+
pps.result = Util.getFormattedValue(
|
390
|
+
value,
|
391
|
+
pps.blocks, pps.blocksLength,
|
392
|
+
pps.delimiter, pps.delimiters, pps.delimiterLazyShow
|
393
|
+
);
|
394
|
+
|
395
|
+
owner.updateValueState();
|
396
|
+
},
|
397
|
+
|
398
|
+
updateCreditCardPropsByValue: function (value) {
|
399
|
+
var owner = this, pps = owner.properties,
|
400
|
+
Util = Cleave.Util,
|
401
|
+
creditCardInfo;
|
402
|
+
|
403
|
+
// At least one of the first 4 characters has changed
|
404
|
+
if (Util.headStr(pps.result, 4) === Util.headStr(value, 4)) {
|
405
|
+
return;
|
406
|
+
}
|
407
|
+
|
408
|
+
creditCardInfo = Cleave.CreditCardDetector.getInfo(value, pps.creditCardStrictMode);
|
409
|
+
|
410
|
+
pps.blocks = creditCardInfo.blocks;
|
411
|
+
pps.blocksLength = pps.blocks.length;
|
412
|
+
pps.maxLength = Util.getMaxLength(pps.blocks);
|
413
|
+
|
414
|
+
// credit card type changed
|
415
|
+
if (pps.creditCardType !== creditCardInfo.type) {
|
416
|
+
pps.creditCardType = creditCardInfo.type;
|
417
|
+
|
418
|
+
pps.onCreditCardTypeChanged.call(owner, pps.creditCardType);
|
419
|
+
}
|
420
|
+
},
|
421
|
+
|
422
|
+
updateValueState: function () {
|
423
|
+
var owner = this,
|
424
|
+
Util = Cleave.Util,
|
425
|
+
pps = owner.properties;
|
426
|
+
|
427
|
+
if (!owner.element) {
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
|
431
|
+
var endPos = owner.element.selectionEnd;
|
432
|
+
var oldValue = owner.element.value;
|
433
|
+
var newValue = pps.result;
|
434
|
+
|
435
|
+
endPos = Util.getNextCursorPosition(endPos, oldValue, newValue, pps.delimiter, pps.delimiters);
|
436
|
+
|
437
|
+
// fix Android browser type="text" input field
|
438
|
+
// cursor not jumping issue
|
439
|
+
if (owner.isAndroid) {
|
440
|
+
window.setTimeout(function () {
|
441
|
+
owner.element.value = newValue;
|
442
|
+
Util.setSelection(owner.element, endPos, pps.document, false);
|
443
|
+
owner.callOnValueChanged();
|
444
|
+
}, 1);
|
445
|
+
|
446
|
+
return;
|
447
|
+
}
|
448
|
+
|
449
|
+
owner.element.value = newValue;
|
450
|
+
if (pps.swapHiddenInput) owner.elementSwapHidden.value = owner.getRawValue();
|
451
|
+
|
452
|
+
Util.setSelection(owner.element, endPos, pps.document, false);
|
453
|
+
owner.callOnValueChanged();
|
454
|
+
},
|
455
|
+
|
456
|
+
callOnValueChanged: function () {
|
457
|
+
var owner = this,
|
458
|
+
pps = owner.properties;
|
459
|
+
|
460
|
+
pps.onValueChanged.call(owner, {
|
461
|
+
target: {
|
462
|
+
name: owner.element.name,
|
463
|
+
value: pps.result,
|
464
|
+
rawValue: owner.getRawValue()
|
465
|
+
}
|
466
|
+
});
|
467
|
+
},
|
468
|
+
|
469
|
+
setPhoneRegionCode: function (phoneRegionCode) {
|
470
|
+
var owner = this, pps = owner.properties;
|
471
|
+
|
472
|
+
pps.phoneRegionCode = phoneRegionCode;
|
473
|
+
owner.initPhoneFormatter();
|
474
|
+
owner.onChange();
|
475
|
+
},
|
476
|
+
|
477
|
+
setRawValue: function (value) {
|
478
|
+
var owner = this, pps = owner.properties;
|
479
|
+
|
480
|
+
value = value !== undefined && value !== null ? value.toString() : '';
|
481
|
+
|
482
|
+
if (pps.numeral) {
|
483
|
+
value = value.replace('.', pps.numeralDecimalMark);
|
484
|
+
}
|
485
|
+
|
486
|
+
pps.postDelimiterBackspace = false;
|
487
|
+
|
488
|
+
owner.element.value = value;
|
489
|
+
owner.onInput(value);
|
490
|
+
},
|
491
|
+
|
492
|
+
getRawValue: function () {
|
493
|
+
var owner = this,
|
494
|
+
pps = owner.properties,
|
495
|
+
Util = Cleave.Util,
|
496
|
+
rawValue = owner.element.value;
|
497
|
+
|
498
|
+
if (pps.rawValueTrimPrefix) {
|
499
|
+
rawValue = Util.getPrefixStrippedValue(rawValue, pps.prefix, pps.prefixLength, pps.result, pps.delimiter, pps.delimiters, pps.noImmediatePrefix, pps.tailPrefix, pps.signBeforePrefix);
|
500
|
+
}
|
501
|
+
|
502
|
+
if (pps.numeral) {
|
503
|
+
rawValue = pps.numeralFormatter.getRawValue(rawValue);
|
504
|
+
} else {
|
505
|
+
rawValue = Util.stripDelimiters(rawValue, pps.delimiter, pps.delimiters);
|
506
|
+
}
|
507
|
+
|
508
|
+
return rawValue;
|
509
|
+
},
|
510
|
+
|
511
|
+
getISOFormatDate: function () {
|
512
|
+
var owner = this,
|
513
|
+
pps = owner.properties;
|
514
|
+
|
515
|
+
return pps.date ? pps.dateFormatter.getISOFormatDate() : '';
|
516
|
+
},
|
517
|
+
|
518
|
+
getISOFormatTime: function () {
|
519
|
+
var owner = this,
|
520
|
+
pps = owner.properties;
|
521
|
+
|
522
|
+
return pps.time ? pps.timeFormatter.getISOFormatTime() : '';
|
523
|
+
},
|
524
|
+
|
525
|
+
getFormattedValue: function () {
|
526
|
+
return this.element.value;
|
527
|
+
},
|
528
|
+
|
529
|
+
destroy: function () {
|
530
|
+
var owner = this;
|
531
|
+
|
532
|
+
owner.element.removeEventListener('input', owner.onChangeListener);
|
533
|
+
owner.element.removeEventListener('keydown', owner.onKeyDownListener);
|
534
|
+
owner.element.removeEventListener('focus', owner.onFocusListener);
|
535
|
+
owner.element.removeEventListener('cut', owner.onCutListener);
|
536
|
+
owner.element.removeEventListener('copy', owner.onCopyListener);
|
537
|
+
},
|
538
|
+
|
539
|
+
toString: function () {
|
540
|
+
return '[Cleave Object]';
|
541
|
+
}
|
542
|
+
};
|
543
|
+
|
544
|
+
Cleave.NumeralFormatter = __webpack_require__(1);
|
545
|
+
Cleave.DateFormatter = __webpack_require__(2);
|
546
|
+
Cleave.TimeFormatter = __webpack_require__(3);
|
547
|
+
Cleave.PhoneFormatter = __webpack_require__(4);
|
548
|
+
Cleave.CreditCardDetector = __webpack_require__(5);
|
549
|
+
Cleave.Util = __webpack_require__(6);
|
550
|
+
Cleave.DefaultProperties = __webpack_require__(7);
|
551
|
+
|
552
|
+
// for angular directive
|
553
|
+
((typeof global === 'object' && global) ? global : window)['Cleave'] = Cleave;
|
554
|
+
|
555
|
+
// CommonJS
|
556
|
+
module.exports = Cleave;
|
557
|
+
|
558
|
+
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
559
|
+
|
560
|
+
/***/ }),
|
561
|
+
/* 1 */
|
562
|
+
/***/ (function(module, exports) {
|
563
|
+
|
564
|
+
'use strict';
|
565
|
+
|
566
|
+
var NumeralFormatter = function (numeralDecimalMark,
|
567
|
+
numeralIntegerScale,
|
568
|
+
numeralDecimalScale,
|
569
|
+
numeralThousandsGroupStyle,
|
570
|
+
numeralPositiveOnly,
|
571
|
+
stripLeadingZeroes,
|
572
|
+
prefix,
|
573
|
+
signBeforePrefix,
|
574
|
+
tailPrefix,
|
575
|
+
delimiter) {
|
576
|
+
var owner = this;
|
577
|
+
|
578
|
+
owner.numeralDecimalMark = numeralDecimalMark || '.';
|
579
|
+
owner.numeralIntegerScale = numeralIntegerScale > 0 ? numeralIntegerScale : 0;
|
580
|
+
owner.numeralDecimalScale = numeralDecimalScale >= 0 ? numeralDecimalScale : 2;
|
581
|
+
owner.numeralThousandsGroupStyle = numeralThousandsGroupStyle || NumeralFormatter.groupStyle.thousand;
|
582
|
+
owner.numeralPositiveOnly = !!numeralPositiveOnly;
|
583
|
+
owner.stripLeadingZeroes = stripLeadingZeroes !== false;
|
584
|
+
owner.prefix = (prefix || prefix === '') ? prefix : '';
|
585
|
+
owner.signBeforePrefix = !!signBeforePrefix;
|
586
|
+
owner.tailPrefix = !!tailPrefix;
|
587
|
+
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ',';
|
588
|
+
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
|
589
|
+
};
|
590
|
+
|
591
|
+
NumeralFormatter.groupStyle = {
|
592
|
+
thousand: 'thousand',
|
593
|
+
lakh: 'lakh',
|
594
|
+
wan: 'wan',
|
595
|
+
none: 'none'
|
596
|
+
};
|
597
|
+
|
598
|
+
NumeralFormatter.prototype = {
|
599
|
+
getRawValue: function (value) {
|
600
|
+
return value.replace(this.delimiterRE, '').replace(this.numeralDecimalMark, '.');
|
601
|
+
},
|
602
|
+
|
603
|
+
format: function (value) {
|
604
|
+
var owner = this, parts, partSign, partSignAndPrefix, partInteger, partDecimal = '';
|
605
|
+
|
606
|
+
// strip alphabet letters
|
607
|
+
value = value.replace(/[A-Za-z]/g, '')
|
608
|
+
// replace the first decimal mark with reserved placeholder
|
609
|
+
.replace(owner.numeralDecimalMark, 'M')
|
610
|
+
|
611
|
+
// strip non numeric letters except minus and "M"
|
612
|
+
// this is to ensure prefix has been stripped
|
613
|
+
.replace(/[^\dM-]/g, '')
|
614
|
+
|
615
|
+
// replace the leading minus with reserved placeholder
|
616
|
+
.replace(/^\-/, 'N')
|
617
|
+
|
618
|
+
// strip the other minus sign (if present)
|
619
|
+
.replace(/\-/g, '')
|
620
|
+
|
621
|
+
// replace the minus sign (if present)
|
622
|
+
.replace('N', owner.numeralPositiveOnly ? '' : '-')
|
623
|
+
|
624
|
+
// replace decimal mark
|
625
|
+
.replace('M', owner.numeralDecimalMark);
|
626
|
+
|
627
|
+
// strip any leading zeros
|
628
|
+
if (owner.stripLeadingZeroes) {
|
629
|
+
value = value.replace(/^(-)?0+(?=\d)/, '$1');
|
630
|
+
}
|
631
|
+
|
632
|
+
partSign = value.slice(0, 1) === '-' ? '-' : '';
|
633
|
+
if (typeof owner.prefix != 'undefined') {
|
634
|
+
if (owner.signBeforePrefix) {
|
635
|
+
partSignAndPrefix = partSign + owner.prefix;
|
636
|
+
} else {
|
637
|
+
partSignAndPrefix = owner.prefix + partSign;
|
638
|
+
}
|
639
|
+
} else {
|
640
|
+
partSignAndPrefix = partSign;
|
641
|
+
}
|
642
|
+
|
643
|
+
partInteger = value;
|
644
|
+
|
645
|
+
if (value.indexOf(owner.numeralDecimalMark) >= 0) {
|
646
|
+
parts = value.split(owner.numeralDecimalMark);
|
647
|
+
partInteger = parts[0];
|
648
|
+
partDecimal = owner.numeralDecimalMark + parts[1].slice(0, owner.numeralDecimalScale);
|
649
|
+
}
|
650
|
+
|
651
|
+
if(partSign === '-') {
|
652
|
+
partInteger = partInteger.slice(1);
|
653
|
+
}
|
654
|
+
|
655
|
+
if (owner.numeralIntegerScale > 0) {
|
656
|
+
partInteger = partInteger.slice(0, owner.numeralIntegerScale);
|
657
|
+
}
|
658
|
+
|
659
|
+
switch (owner.numeralThousandsGroupStyle) {
|
660
|
+
case NumeralFormatter.groupStyle.lakh:
|
661
|
+
partInteger = partInteger.replace(/(\d)(?=(\d\d)+\d$)/g, '$1' + owner.delimiter);
|
662
|
+
|
663
|
+
break;
|
664
|
+
|
665
|
+
case NumeralFormatter.groupStyle.wan:
|
666
|
+
partInteger = partInteger.replace(/(\d)(?=(\d{4})+$)/g, '$1' + owner.delimiter);
|
667
|
+
|
668
|
+
break;
|
669
|
+
|
670
|
+
case NumeralFormatter.groupStyle.thousand:
|
671
|
+
partInteger = partInteger.replace(/(\d)(?=(\d{3})+$)/g, '$1' + owner.delimiter);
|
672
|
+
|
673
|
+
break;
|
674
|
+
}
|
675
|
+
|
676
|
+
if (owner.tailPrefix) {
|
677
|
+
return partSign + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '') + owner.prefix;
|
678
|
+
}
|
679
|
+
|
680
|
+
return partSignAndPrefix + partInteger.toString() + (owner.numeralDecimalScale > 0 ? partDecimal.toString() : '');
|
681
|
+
}
|
682
|
+
};
|
683
|
+
|
684
|
+
module.exports = NumeralFormatter;
|
685
|
+
|
686
|
+
|
687
|
+
/***/ }),
|
688
|
+
/* 2 */
|
689
|
+
/***/ (function(module, exports) {
|
690
|
+
|
691
|
+
'use strict';
|
692
|
+
|
693
|
+
var DateFormatter = function (datePattern, dateMin, dateMax) {
|
694
|
+
var owner = this;
|
695
|
+
|
696
|
+
owner.date = [];
|
697
|
+
owner.blocks = [];
|
698
|
+
owner.datePattern = datePattern;
|
699
|
+
owner.dateMin = dateMin
|
700
|
+
.split('-')
|
701
|
+
.reverse()
|
702
|
+
.map(function(x) {
|
703
|
+
return parseInt(x, 10);
|
704
|
+
});
|
705
|
+
if (owner.dateMin.length === 2) owner.dateMin.unshift(0);
|
706
|
+
|
707
|
+
owner.dateMax = dateMax
|
708
|
+
.split('-')
|
709
|
+
.reverse()
|
710
|
+
.map(function(x) {
|
711
|
+
return parseInt(x, 10);
|
712
|
+
});
|
713
|
+
if (owner.dateMax.length === 2) owner.dateMax.unshift(0);
|
714
|
+
|
715
|
+
owner.initBlocks();
|
716
|
+
};
|
717
|
+
|
718
|
+
DateFormatter.prototype = {
|
719
|
+
initBlocks: function () {
|
720
|
+
var owner = this;
|
721
|
+
owner.datePattern.forEach(function (value) {
|
722
|
+
if (value === 'Y') {
|
723
|
+
owner.blocks.push(4);
|
724
|
+
} else {
|
725
|
+
owner.blocks.push(2);
|
726
|
+
}
|
727
|
+
});
|
728
|
+
},
|
729
|
+
|
730
|
+
getISOFormatDate: function () {
|
731
|
+
var owner = this,
|
732
|
+
date = owner.date;
|
733
|
+
|
734
|
+
return date[2] ? (
|
735
|
+
date[2] + '-' + owner.addLeadingZero(date[1]) + '-' + owner.addLeadingZero(date[0])
|
736
|
+
) : '';
|
737
|
+
},
|
738
|
+
|
739
|
+
getBlocks: function () {
|
740
|
+
return this.blocks;
|
741
|
+
},
|
742
|
+
|
743
|
+
getValidatedDate: function (value) {
|
744
|
+
var owner = this, result = '';
|
745
|
+
|
746
|
+
value = value.replace(/[^\d]/g, '');
|
747
|
+
|
748
|
+
owner.blocks.forEach(function (length, index) {
|
749
|
+
if (value.length > 0) {
|
750
|
+
var sub = value.slice(0, length),
|
751
|
+
sub0 = sub.slice(0, 1),
|
752
|
+
rest = value.slice(length);
|
753
|
+
|
754
|
+
switch (owner.datePattern[index]) {
|
755
|
+
case 'd':
|
756
|
+
if (sub === '00') {
|
757
|
+
sub = '01';
|
758
|
+
} else if (parseInt(sub0, 10) > 3) {
|
759
|
+
sub = '0' + sub0;
|
760
|
+
} else if (parseInt(sub, 10) > 31) {
|
761
|
+
sub = '31';
|
762
|
+
}
|
763
|
+
|
764
|
+
break;
|
765
|
+
|
766
|
+
case 'm':
|
767
|
+
if (sub === '00') {
|
768
|
+
sub = '01';
|
769
|
+
} else if (parseInt(sub0, 10) > 1) {
|
770
|
+
sub = '0' + sub0;
|
771
|
+
} else if (parseInt(sub, 10) > 12) {
|
772
|
+
sub = '12';
|
773
|
+
}
|
774
|
+
|
775
|
+
break;
|
776
|
+
}
|
777
|
+
|
778
|
+
result += sub;
|
779
|
+
|
780
|
+
// update remaining string
|
781
|
+
value = rest;
|
782
|
+
}
|
783
|
+
});
|
784
|
+
|
785
|
+
return this.getFixedDateString(result);
|
786
|
+
},
|
787
|
+
|
788
|
+
getFixedDateString: function (value) {
|
789
|
+
var owner = this, datePattern = owner.datePattern, date = [],
|
790
|
+
dayIndex = 0, monthIndex = 0, yearIndex = 0,
|
791
|
+
dayStartIndex = 0, monthStartIndex = 0, yearStartIndex = 0,
|
792
|
+
day, month, year, fullYearDone = false;
|
793
|
+
|
794
|
+
// mm-dd || dd-mm
|
795
|
+
if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') {
|
796
|
+
dayStartIndex = datePattern[0] === 'd' ? 0 : 2;
|
797
|
+
monthStartIndex = 2 - dayStartIndex;
|
798
|
+
day = parseInt(value.slice(dayStartIndex, dayStartIndex + 2), 10);
|
799
|
+
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
|
800
|
+
|
801
|
+
date = this.getFixedDate(day, month, 0);
|
802
|
+
}
|
803
|
+
|
804
|
+
// yyyy-mm-dd || yyyy-dd-mm || mm-dd-yyyy || dd-mm-yyyy || dd-yyyy-mm || mm-yyyy-dd
|
805
|
+
if (value.length === 8) {
|
806
|
+
datePattern.forEach(function (type, index) {
|
807
|
+
switch (type) {
|
808
|
+
case 'd':
|
809
|
+
dayIndex = index;
|
810
|
+
break;
|
811
|
+
case 'm':
|
812
|
+
monthIndex = index;
|
813
|
+
break;
|
814
|
+
default:
|
815
|
+
yearIndex = index;
|
816
|
+
break;
|
817
|
+
}
|
818
|
+
});
|
819
|
+
|
820
|
+
yearStartIndex = yearIndex * 2;
|
821
|
+
dayStartIndex = (dayIndex <= yearIndex) ? dayIndex * 2 : (dayIndex * 2 + 2);
|
822
|
+
monthStartIndex = (monthIndex <= yearIndex) ? monthIndex * 2 : (monthIndex * 2 + 2);
|
823
|
+
|
824
|
+
day = parseInt(value.slice(dayStartIndex, dayStartIndex + 2), 10);
|
825
|
+
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
|
826
|
+
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);
|
827
|
+
|
828
|
+
fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;
|
829
|
+
|
830
|
+
date = this.getFixedDate(day, month, year);
|
831
|
+
}
|
832
|
+
|
833
|
+
// mm-yy || yy-mm
|
834
|
+
if (value.length === 4 && (datePattern[0] === 'y' || datePattern[1] === 'y')) {
|
835
|
+
monthStartIndex = datePattern[0] === 'm' ? 0 : 2;
|
836
|
+
yearStartIndex = 2 - monthStartIndex;
|
837
|
+
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
|
838
|
+
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 2), 10);
|
839
|
+
|
840
|
+
fullYearDone = value.slice(yearStartIndex, yearStartIndex + 2).length === 2;
|
841
|
+
|
842
|
+
date = [0, month, year];
|
843
|
+
}
|
844
|
+
|
845
|
+
// mm-yyyy || yyyy-mm
|
846
|
+
if (value.length === 6 && (datePattern[0] === 'Y' || datePattern[1] === 'Y')) {
|
847
|
+
monthStartIndex = datePattern[0] === 'm' ? 0 : 4;
|
848
|
+
yearStartIndex = 2 - 0.5 * monthStartIndex;
|
849
|
+
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
|
850
|
+
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);
|
851
|
+
|
852
|
+
fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;
|
853
|
+
|
854
|
+
date = [0, month, year];
|
855
|
+
}
|
856
|
+
|
857
|
+
date = owner.getRangeFixedDate(date);
|
858
|
+
owner.date = date;
|
859
|
+
|
860
|
+
var result = date.length === 0 ? value : datePattern.reduce(function (previous, current) {
|
861
|
+
switch (current) {
|
862
|
+
case 'd':
|
863
|
+
return previous + (date[0] === 0 ? '' : owner.addLeadingZero(date[0]));
|
864
|
+
case 'm':
|
865
|
+
return previous + (date[1] === 0 ? '' : owner.addLeadingZero(date[1]));
|
866
|
+
case 'y':
|
867
|
+
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2], false) : '');
|
868
|
+
case 'Y':
|
869
|
+
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2], true) : '');
|
870
|
+
}
|
871
|
+
}, '');
|
872
|
+
|
873
|
+
return result;
|
874
|
+
},
|
875
|
+
|
876
|
+
getRangeFixedDate: function (date) {
|
877
|
+
var owner = this,
|
878
|
+
datePattern = owner.datePattern,
|
879
|
+
dateMin = owner.dateMin || [],
|
880
|
+
dateMax = owner.dateMax || [];
|
881
|
+
|
882
|
+
if (!date.length || (dateMin.length < 3 && dateMax.length < 3)) return date;
|
883
|
+
|
884
|
+
if (
|
885
|
+
datePattern.find(function(x) {
|
886
|
+
return x.toLowerCase() === 'y';
|
887
|
+
}) &&
|
888
|
+
date[2] === 0
|
889
|
+
) return date;
|
890
|
+
|
891
|
+
if (dateMax.length && (dateMax[2] < date[2] || (
|
892
|
+
dateMax[2] === date[2] && (dateMax[1] < date[1] || (
|
893
|
+
dateMax[1] === date[1] && dateMax[0] < date[0]
|
894
|
+
))
|
895
|
+
))) return dateMax;
|
896
|
+
|
897
|
+
if (dateMin.length && (dateMin[2] > date[2] || (
|
898
|
+
dateMin[2] === date[2] && (dateMin[1] > date[1] || (
|
899
|
+
dateMin[1] === date[1] && dateMin[0] > date[0]
|
900
|
+
))
|
901
|
+
))) return dateMin;
|
902
|
+
|
903
|
+
return date;
|
904
|
+
},
|
905
|
+
|
906
|
+
getFixedDate: function (day, month, year) {
|
907
|
+
day = Math.min(day, 31);
|
908
|
+
month = Math.min(month, 12);
|
909
|
+
year = parseInt((year || 0), 10);
|
910
|
+
|
911
|
+
if ((month < 7 && month % 2 === 0) || (month > 8 && month % 2 === 1)) {
|
912
|
+
day = Math.min(day, month === 2 ? (this.isLeapYear(year) ? 29 : 28) : 30);
|
913
|
+
}
|
914
|
+
|
915
|
+
return [day, month, year];
|
916
|
+
},
|
917
|
+
|
918
|
+
isLeapYear: function (year) {
|
919
|
+
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
|
920
|
+
},
|
921
|
+
|
922
|
+
addLeadingZero: function (number) {
|
923
|
+
return (number < 10 ? '0' : '') + number;
|
924
|
+
},
|
925
|
+
|
926
|
+
addLeadingZeroForYear: function (number, fullYearMode) {
|
927
|
+
if (fullYearMode) {
|
928
|
+
return (number < 10 ? '000' : (number < 100 ? '00' : (number < 1000 ? '0' : ''))) + number;
|
929
|
+
}
|
930
|
+
|
931
|
+
return (number < 10 ? '0' : '') + number;
|
932
|
+
}
|
933
|
+
};
|
934
|
+
|
935
|
+
module.exports = DateFormatter;
|
936
|
+
|
937
|
+
|
938
|
+
/***/ }),
|
939
|
+
/* 3 */
|
940
|
+
/***/ (function(module, exports) {
|
941
|
+
|
942
|
+
'use strict';
|
943
|
+
|
944
|
+
var TimeFormatter = function (timePattern, timeFormat) {
|
945
|
+
var owner = this;
|
946
|
+
|
947
|
+
owner.time = [];
|
948
|
+
owner.blocks = [];
|
949
|
+
owner.timePattern = timePattern;
|
950
|
+
owner.timeFormat = timeFormat;
|
951
|
+
owner.initBlocks();
|
952
|
+
};
|
953
|
+
|
954
|
+
TimeFormatter.prototype = {
|
955
|
+
initBlocks: function () {
|
956
|
+
var owner = this;
|
957
|
+
owner.timePattern.forEach(function () {
|
958
|
+
owner.blocks.push(2);
|
959
|
+
});
|
960
|
+
},
|
961
|
+
|
962
|
+
getISOFormatTime: function () {
|
963
|
+
var owner = this,
|
964
|
+
time = owner.time;
|
965
|
+
|
966
|
+
return time[2] ? (
|
967
|
+
owner.addLeadingZero(time[0]) + ':' + owner.addLeadingZero(time[1]) + ':' + owner.addLeadingZero(time[2])
|
968
|
+
) : '';
|
969
|
+
},
|
970
|
+
|
971
|
+
getBlocks: function () {
|
972
|
+
return this.blocks;
|
973
|
+
},
|
974
|
+
|
975
|
+
getTimeFormatOptions: function () {
|
976
|
+
var owner = this;
|
977
|
+
if (String(owner.timeFormat) === '12') {
|
978
|
+
return {
|
979
|
+
maxHourFirstDigit: 1,
|
980
|
+
maxHours: 12,
|
981
|
+
maxMinutesFirstDigit: 5,
|
982
|
+
maxMinutes: 60
|
983
|
+
};
|
984
|
+
}
|
985
|
+
|
986
|
+
return {
|
987
|
+
maxHourFirstDigit: 2,
|
988
|
+
maxHours: 23,
|
989
|
+
maxMinutesFirstDigit: 5,
|
990
|
+
maxMinutes: 60
|
991
|
+
};
|
992
|
+
},
|
993
|
+
|
994
|
+
getValidatedTime: function (value) {
|
995
|
+
var owner = this, result = '';
|
996
|
+
|
997
|
+
value = value.replace(/[^\d]/g, '');
|
998
|
+
|
999
|
+
var timeFormatOptions = owner.getTimeFormatOptions();
|
1000
|
+
|
1001
|
+
owner.blocks.forEach(function (length, index) {
|
1002
|
+
if (value.length > 0) {
|
1003
|
+
var sub = value.slice(0, length),
|
1004
|
+
sub0 = sub.slice(0, 1),
|
1005
|
+
rest = value.slice(length);
|
1006
|
+
|
1007
|
+
switch (owner.timePattern[index]) {
|
1008
|
+
|
1009
|
+
case 'h':
|
1010
|
+
if (parseInt(sub0, 10) > timeFormatOptions.maxHourFirstDigit) {
|
1011
|
+
sub = '0' + sub0;
|
1012
|
+
} else if (parseInt(sub, 10) > timeFormatOptions.maxHours) {
|
1013
|
+
sub = timeFormatOptions.maxHours + '';
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
break;
|
1017
|
+
|
1018
|
+
case 'm':
|
1019
|
+
case 's':
|
1020
|
+
if (parseInt(sub0, 10) > timeFormatOptions.maxMinutesFirstDigit) {
|
1021
|
+
sub = '0' + sub0;
|
1022
|
+
} else if (parseInt(sub, 10) > timeFormatOptions.maxMinutes) {
|
1023
|
+
sub = timeFormatOptions.maxMinutes + '';
|
1024
|
+
}
|
1025
|
+
break;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
result += sub;
|
1029
|
+
|
1030
|
+
// update remaining string
|
1031
|
+
value = rest;
|
1032
|
+
}
|
1033
|
+
});
|
1034
|
+
|
1035
|
+
return this.getFixedTimeString(result);
|
1036
|
+
},
|
1037
|
+
|
1038
|
+
getFixedTimeString: function (value) {
|
1039
|
+
var owner = this, timePattern = owner.timePattern, time = [],
|
1040
|
+
secondIndex = 0, minuteIndex = 0, hourIndex = 0,
|
1041
|
+
secondStartIndex = 0, minuteStartIndex = 0, hourStartIndex = 0,
|
1042
|
+
second, minute, hour;
|
1043
|
+
|
1044
|
+
if (value.length === 6) {
|
1045
|
+
timePattern.forEach(function (type, index) {
|
1046
|
+
switch (type) {
|
1047
|
+
case 's':
|
1048
|
+
secondIndex = index * 2;
|
1049
|
+
break;
|
1050
|
+
case 'm':
|
1051
|
+
minuteIndex = index * 2;
|
1052
|
+
break;
|
1053
|
+
case 'h':
|
1054
|
+
hourIndex = index * 2;
|
1055
|
+
break;
|
1056
|
+
}
|
1057
|
+
});
|
1058
|
+
|
1059
|
+
hourStartIndex = hourIndex;
|
1060
|
+
minuteStartIndex = minuteIndex;
|
1061
|
+
secondStartIndex = secondIndex;
|
1062
|
+
|
1063
|
+
second = parseInt(value.slice(secondStartIndex, secondStartIndex + 2), 10);
|
1064
|
+
minute = parseInt(value.slice(minuteStartIndex, minuteStartIndex + 2), 10);
|
1065
|
+
hour = parseInt(value.slice(hourStartIndex, hourStartIndex + 2), 10);
|
1066
|
+
|
1067
|
+
time = this.getFixedTime(hour, minute, second);
|
1068
|
+
}
|
1069
|
+
|
1070
|
+
if (value.length === 4 && owner.timePattern.indexOf('s') < 0) {
|
1071
|
+
timePattern.forEach(function (type, index) {
|
1072
|
+
switch (type) {
|
1073
|
+
case 'm':
|
1074
|
+
minuteIndex = index * 2;
|
1075
|
+
break;
|
1076
|
+
case 'h':
|
1077
|
+
hourIndex = index * 2;
|
1078
|
+
break;
|
1079
|
+
}
|
1080
|
+
});
|
1081
|
+
|
1082
|
+
hourStartIndex = hourIndex;
|
1083
|
+
minuteStartIndex = minuteIndex;
|
1084
|
+
|
1085
|
+
second = 0;
|
1086
|
+
minute = parseInt(value.slice(minuteStartIndex, minuteStartIndex + 2), 10);
|
1087
|
+
hour = parseInt(value.slice(hourStartIndex, hourStartIndex + 2), 10);
|
1088
|
+
|
1089
|
+
time = this.getFixedTime(hour, minute, second);
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
owner.time = time;
|
1093
|
+
|
1094
|
+
return time.length === 0 ? value : timePattern.reduce(function (previous, current) {
|
1095
|
+
switch (current) {
|
1096
|
+
case 's':
|
1097
|
+
return previous + owner.addLeadingZero(time[2]);
|
1098
|
+
case 'm':
|
1099
|
+
return previous + owner.addLeadingZero(time[1]);
|
1100
|
+
case 'h':
|
1101
|
+
return previous + owner.addLeadingZero(time[0]);
|
1102
|
+
}
|
1103
|
+
}, '');
|
1104
|
+
},
|
1105
|
+
|
1106
|
+
getFixedTime: function (hour, minute, second) {
|
1107
|
+
second = Math.min(parseInt(second || 0, 10), 60);
|
1108
|
+
minute = Math.min(minute, 60);
|
1109
|
+
hour = Math.min(hour, 60);
|
1110
|
+
|
1111
|
+
return [hour, minute, second];
|
1112
|
+
},
|
1113
|
+
|
1114
|
+
addLeadingZero: function (number) {
|
1115
|
+
return (number < 10 ? '0' : '') + number;
|
1116
|
+
}
|
1117
|
+
};
|
1118
|
+
|
1119
|
+
module.exports = TimeFormatter;
|
1120
|
+
|
1121
|
+
|
1122
|
+
/***/ }),
|
1123
|
+
/* 4 */
|
1124
|
+
/***/ (function(module, exports) {
|
1125
|
+
|
1126
|
+
'use strict';
|
1127
|
+
|
1128
|
+
var PhoneFormatter = function (formatter, delimiter) {
|
1129
|
+
var owner = this;
|
1130
|
+
|
1131
|
+
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ' ';
|
1132
|
+
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
|
1133
|
+
|
1134
|
+
owner.formatter = formatter;
|
1135
|
+
};
|
1136
|
+
|
1137
|
+
PhoneFormatter.prototype = {
|
1138
|
+
setFormatter: function (formatter) {
|
1139
|
+
this.formatter = formatter;
|
1140
|
+
},
|
1141
|
+
|
1142
|
+
format: function (phoneNumber) {
|
1143
|
+
var owner = this;
|
1144
|
+
|
1145
|
+
owner.formatter.clear();
|
1146
|
+
|
1147
|
+
// only keep number and +
|
1148
|
+
phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
|
1149
|
+
|
1150
|
+
// strip non-leading +
|
1151
|
+
phoneNumber = phoneNumber.replace(/^\+/, 'B').replace(/\+/g, '').replace('B', '+');
|
1152
|
+
|
1153
|
+
// strip delimiter
|
1154
|
+
phoneNumber = phoneNumber.replace(owner.delimiterRE, '');
|
1155
|
+
|
1156
|
+
var result = '', current, validated = false;
|
1157
|
+
|
1158
|
+
for (var i = 0, iMax = phoneNumber.length; i < iMax; i++) {
|
1159
|
+
current = owner.formatter.inputDigit(phoneNumber.charAt(i));
|
1160
|
+
|
1161
|
+
// has ()- or space inside
|
1162
|
+
if (/[\s()-]/g.test(current)) {
|
1163
|
+
result = current;
|
1164
|
+
|
1165
|
+
validated = true;
|
1166
|
+
} else {
|
1167
|
+
if (!validated) {
|
1168
|
+
result = current;
|
1169
|
+
}
|
1170
|
+
// else: over length input
|
1171
|
+
// it turns to invalid number again
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
// strip ()
|
1176
|
+
// e.g. US: 7161234567 returns (716) 123-4567
|
1177
|
+
result = result.replace(/[()]/g, '');
|
1178
|
+
// replace library delimiter with user customized delimiter
|
1179
|
+
result = result.replace(/[\s-]/g, owner.delimiter);
|
1180
|
+
|
1181
|
+
return result;
|
1182
|
+
}
|
1183
|
+
};
|
1184
|
+
|
1185
|
+
module.exports = PhoneFormatter;
|
1186
|
+
|
1187
|
+
|
1188
|
+
/***/ }),
|
1189
|
+
/* 5 */
|
1190
|
+
/***/ (function(module, exports) {
|
1191
|
+
|
1192
|
+
'use strict';
|
1193
|
+
|
1194
|
+
var CreditCardDetector = {
|
1195
|
+
blocks: {
|
1196
|
+
uatp: [4, 5, 6],
|
1197
|
+
amex: [4, 6, 5],
|
1198
|
+
diners: [4, 6, 4],
|
1199
|
+
discover: [4, 4, 4, 4],
|
1200
|
+
mastercard: [4, 4, 4, 4],
|
1201
|
+
dankort: [4, 4, 4, 4],
|
1202
|
+
instapayment: [4, 4, 4, 4],
|
1203
|
+
jcb15: [4, 6, 5],
|
1204
|
+
jcb: [4, 4, 4, 4],
|
1205
|
+
maestro: [4, 4, 4, 4],
|
1206
|
+
visa: [4, 4, 4, 4],
|
1207
|
+
mir: [4, 4, 4, 4],
|
1208
|
+
unionPay: [4, 4, 4, 4],
|
1209
|
+
general: [4, 4, 4, 4]
|
1210
|
+
},
|
1211
|
+
|
1212
|
+
re: {
|
1213
|
+
// starts with 1; 15 digits, not starts with 1800 (jcb card)
|
1214
|
+
uatp: /^(?!1800)1\d{0,14}/,
|
1215
|
+
|
1216
|
+
// starts with 34/37; 15 digits
|
1217
|
+
amex: /^3[47]\d{0,13}/,
|
1218
|
+
|
1219
|
+
// starts with 6011/65/644-649; 16 digits
|
1220
|
+
discover: /^(?:6011|65\d{0,2}|64[4-9]\d?)\d{0,12}/,
|
1221
|
+
|
1222
|
+
// starts with 300-305/309 or 36/38/39; 14 digits
|
1223
|
+
diners: /^3(?:0([0-5]|9)|[689]\d?)\d{0,11}/,
|
1224
|
+
|
1225
|
+
// starts with 51-55/2221–2720; 16 digits
|
1226
|
+
mastercard: /^(5[1-5]\d{0,2}|22[2-9]\d{0,1}|2[3-7]\d{0,2})\d{0,12}/,
|
1227
|
+
|
1228
|
+
// starts with 5019/4175/4571; 16 digits
|
1229
|
+
dankort: /^(5019|4175|4571)\d{0,12}/,
|
1230
|
+
|
1231
|
+
// starts with 637-639; 16 digits
|
1232
|
+
instapayment: /^63[7-9]\d{0,13}/,
|
1233
|
+
|
1234
|
+
// starts with 2131/1800; 15 digits
|
1235
|
+
jcb15: /^(?:2131|1800)\d{0,11}/,
|
1236
|
+
|
1237
|
+
// starts with 2131/1800/35; 16 digits
|
1238
|
+
jcb: /^(?:35\d{0,2})\d{0,12}/,
|
1239
|
+
|
1240
|
+
// starts with 50/56-58/6304/67; 16 digits
|
1241
|
+
maestro: /^(?:5[0678]\d{0,2}|6304|67\d{0,2})\d{0,12}/,
|
1242
|
+
|
1243
|
+
// starts with 22; 16 digits
|
1244
|
+
mir: /^220[0-4]\d{0,12}/,
|
1245
|
+
|
1246
|
+
// starts with 4; 16 digits
|
1247
|
+
visa: /^4\d{0,15}/,
|
1248
|
+
|
1249
|
+
// starts with 62/81; 16 digits
|
1250
|
+
unionPay: /^(62|81)\d{0,14}/
|
1251
|
+
},
|
1252
|
+
|
1253
|
+
getStrictBlocks: function (block) {
|
1254
|
+
var total = block.reduce(function (prev, current) {
|
1255
|
+
return prev + current;
|
1256
|
+
}, 0);
|
1257
|
+
|
1258
|
+
return block.concat(19 - total);
|
1259
|
+
},
|
1260
|
+
|
1261
|
+
getInfo: function (value, strictMode) {
|
1262
|
+
var blocks = CreditCardDetector.blocks,
|
1263
|
+
re = CreditCardDetector.re;
|
1264
|
+
|
1265
|
+
// Some credit card can have up to 19 digits number.
|
1266
|
+
// Set strictMode to true will remove the 16 max-length restrain,
|
1267
|
+
// however, I never found any website validate card number like
|
1268
|
+
// this, hence probably you don't want to enable this option.
|
1269
|
+
strictMode = !!strictMode;
|
1270
|
+
|
1271
|
+
for (var key in re) {
|
1272
|
+
if (re[key].test(value)) {
|
1273
|
+
var matchedBlocks = blocks[key];
|
1274
|
+
return {
|
1275
|
+
type: key,
|
1276
|
+
blocks: strictMode ? this.getStrictBlocks(matchedBlocks) : matchedBlocks
|
1277
|
+
};
|
1278
|
+
}
|
1279
|
+
}
|
1280
|
+
|
1281
|
+
return {
|
1282
|
+
type: 'unknown',
|
1283
|
+
blocks: strictMode ? this.getStrictBlocks(blocks.general) : blocks.general
|
1284
|
+
};
|
1285
|
+
}
|
1286
|
+
};
|
1287
|
+
|
1288
|
+
module.exports = CreditCardDetector;
|
1289
|
+
|
1290
|
+
|
1291
|
+
/***/ }),
|
1292
|
+
/* 6 */
|
1293
|
+
/***/ (function(module, exports) {
|
1294
|
+
|
1295
|
+
'use strict';
|
1296
|
+
|
1297
|
+
var Util = {
|
1298
|
+
noop: function () {
|
1299
|
+
},
|
1300
|
+
|
1301
|
+
strip: function (value, re) {
|
1302
|
+
return value.replace(re, '');
|
1303
|
+
},
|
1304
|
+
|
1305
|
+
getPostDelimiter: function (value, delimiter, delimiters) {
|
1306
|
+
// single delimiter
|
1307
|
+
if (delimiters.length === 0) {
|
1308
|
+
return value.slice(-delimiter.length) === delimiter ? delimiter : '';
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
// multiple delimiters
|
1312
|
+
var matchedDelimiter = '';
|
1313
|
+
delimiters.forEach(function (current) {
|
1314
|
+
if (value.slice(-current.length) === current) {
|
1315
|
+
matchedDelimiter = current;
|
1316
|
+
}
|
1317
|
+
});
|
1318
|
+
|
1319
|
+
return matchedDelimiter;
|
1320
|
+
},
|
1321
|
+
|
1322
|
+
getDelimiterREByDelimiter: function (delimiter) {
|
1323
|
+
return new RegExp(delimiter.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'), 'g');
|
1324
|
+
},
|
1325
|
+
|
1326
|
+
getNextCursorPosition: function (prevPos, oldValue, newValue, delimiter, delimiters) {
|
1327
|
+
// If cursor was at the end of value, just place it back.
|
1328
|
+
// Because new value could contain additional chars.
|
1329
|
+
if (oldValue.length === prevPos) {
|
1330
|
+
return newValue.length;
|
1331
|
+
}
|
1332
|
+
|
1333
|
+
return prevPos + this.getPositionOffset(prevPos, oldValue, newValue, delimiter ,delimiters);
|
1334
|
+
},
|
1335
|
+
|
1336
|
+
getPositionOffset: function (prevPos, oldValue, newValue, delimiter, delimiters) {
|
1337
|
+
var oldRawValue, newRawValue, lengthOffset;
|
1338
|
+
|
1339
|
+
oldRawValue = this.stripDelimiters(oldValue.slice(0, prevPos), delimiter, delimiters);
|
1340
|
+
newRawValue = this.stripDelimiters(newValue.slice(0, prevPos), delimiter, delimiters);
|
1341
|
+
lengthOffset = oldRawValue.length - newRawValue.length;
|
1342
|
+
|
1343
|
+
return (lengthOffset !== 0) ? (lengthOffset / Math.abs(lengthOffset)) : 0;
|
1344
|
+
},
|
1345
|
+
|
1346
|
+
stripDelimiters: function (value, delimiter, delimiters) {
|
1347
|
+
var owner = this;
|
1348
|
+
|
1349
|
+
// single delimiter
|
1350
|
+
if (delimiters.length === 0) {
|
1351
|
+
var delimiterRE = delimiter ? owner.getDelimiterREByDelimiter(delimiter) : '';
|
1352
|
+
|
1353
|
+
return value.replace(delimiterRE, '');
|
1354
|
+
}
|
1355
|
+
|
1356
|
+
// multiple delimiters
|
1357
|
+
delimiters.forEach(function (current) {
|
1358
|
+
current.split('').forEach(function (letter) {
|
1359
|
+
value = value.replace(owner.getDelimiterREByDelimiter(letter), '');
|
1360
|
+
});
|
1361
|
+
});
|
1362
|
+
|
1363
|
+
return value;
|
1364
|
+
},
|
1365
|
+
|
1366
|
+
headStr: function (str, length) {
|
1367
|
+
return str.slice(0, length);
|
1368
|
+
},
|
1369
|
+
|
1370
|
+
getMaxLength: function (blocks) {
|
1371
|
+
return blocks.reduce(function (previous, current) {
|
1372
|
+
return previous + current;
|
1373
|
+
}, 0);
|
1374
|
+
},
|
1375
|
+
|
1376
|
+
// strip prefix
|
1377
|
+
// Before type | After type | Return value
|
1378
|
+
// PEFIX-... | PEFIX-... | ''
|
1379
|
+
// PREFIX-123 | PEFIX-123 | 123
|
1380
|
+
// PREFIX-123 | PREFIX-23 | 23
|
1381
|
+
// PREFIX-123 | PREFIX-1234 | 1234
|
1382
|
+
getPrefixStrippedValue: function (value, prefix, prefixLength, prevResult, delimiter, delimiters, noImmediatePrefix, tailPrefix, signBeforePrefix) {
|
1383
|
+
// No prefix
|
1384
|
+
if (prefixLength === 0) {
|
1385
|
+
return value;
|
1386
|
+
}
|
1387
|
+
|
1388
|
+
// Value is prefix
|
1389
|
+
if (value === prefix && value !== '') {
|
1390
|
+
return '';
|
1391
|
+
}
|
1392
|
+
|
1393
|
+
if (signBeforePrefix && (value.slice(0, 1) == '-')) {
|
1394
|
+
var prev = (prevResult.slice(0, 1) == '-') ? prevResult.slice(1) : prevResult;
|
1395
|
+
return '-' + this.getPrefixStrippedValue(value.slice(1), prefix, prefixLength, prev, delimiter, delimiters, noImmediatePrefix, tailPrefix, signBeforePrefix);
|
1396
|
+
}
|
1397
|
+
|
1398
|
+
// Pre result prefix string does not match pre-defined prefix
|
1399
|
+
if (prevResult.slice(0, prefixLength) !== prefix && !tailPrefix) {
|
1400
|
+
// Check if the first time user entered something
|
1401
|
+
if (noImmediatePrefix && !prevResult && value) return value;
|
1402
|
+
return '';
|
1403
|
+
} else if (prevResult.slice(-prefixLength) !== prefix && tailPrefix) {
|
1404
|
+
// Check if the first time user entered something
|
1405
|
+
if (noImmediatePrefix && !prevResult && value) return value;
|
1406
|
+
return '';
|
1407
|
+
}
|
1408
|
+
|
1409
|
+
var prevValue = this.stripDelimiters(prevResult, delimiter, delimiters);
|
1410
|
+
|
1411
|
+
// New value has issue, someone typed in between prefix letters
|
1412
|
+
// Revert to pre value
|
1413
|
+
if (value.slice(0, prefixLength) !== prefix && !tailPrefix) {
|
1414
|
+
return prevValue.slice(prefixLength);
|
1415
|
+
} else if (value.slice(-prefixLength) !== prefix && tailPrefix) {
|
1416
|
+
return prevValue.slice(0, -prefixLength - 1);
|
1417
|
+
}
|
1418
|
+
|
1419
|
+
// No issue, strip prefix for new value
|
1420
|
+
return tailPrefix ? value.slice(0, -prefixLength) : value.slice(prefixLength);
|
1421
|
+
},
|
1422
|
+
|
1423
|
+
getFirstDiffIndex: function (prev, current) {
|
1424
|
+
var index = 0;
|
1425
|
+
|
1426
|
+
while (prev.charAt(index) === current.charAt(index)) {
|
1427
|
+
if (prev.charAt(index++) === '') {
|
1428
|
+
return -1;
|
1429
|
+
}
|
1430
|
+
}
|
1431
|
+
|
1432
|
+
return index;
|
1433
|
+
},
|
1434
|
+
|
1435
|
+
getFormattedValue: function (value, blocks, blocksLength, delimiter, delimiters, delimiterLazyShow) {
|
1436
|
+
var result = '',
|
1437
|
+
multipleDelimiters = delimiters.length > 0,
|
1438
|
+
currentDelimiter = '';
|
1439
|
+
|
1440
|
+
// no options, normal input
|
1441
|
+
if (blocksLength === 0) {
|
1442
|
+
return value;
|
1443
|
+
}
|
1444
|
+
|
1445
|
+
blocks.forEach(function (length, index) {
|
1446
|
+
if (value.length > 0) {
|
1447
|
+
var sub = value.slice(0, length),
|
1448
|
+
rest = value.slice(length);
|
1449
|
+
|
1450
|
+
if (multipleDelimiters) {
|
1451
|
+
currentDelimiter = delimiters[delimiterLazyShow ? (index - 1) : index] || currentDelimiter;
|
1452
|
+
} else {
|
1453
|
+
currentDelimiter = delimiter;
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
if (delimiterLazyShow) {
|
1457
|
+
if (index > 0) {
|
1458
|
+
result += currentDelimiter;
|
1459
|
+
}
|
1460
|
+
|
1461
|
+
result += sub;
|
1462
|
+
} else {
|
1463
|
+
result += sub;
|
1464
|
+
|
1465
|
+
if (sub.length === length && index < blocksLength - 1) {
|
1466
|
+
result += currentDelimiter;
|
1467
|
+
}
|
1468
|
+
}
|
1469
|
+
|
1470
|
+
// update remaining string
|
1471
|
+
value = rest;
|
1472
|
+
}
|
1473
|
+
});
|
1474
|
+
|
1475
|
+
return result;
|
1476
|
+
},
|
1477
|
+
|
1478
|
+
// move cursor to the end
|
1479
|
+
// the first time user focuses on an input with prefix
|
1480
|
+
fixPrefixCursor: function (el, prefix, delimiter, delimiters) {
|
1481
|
+
if (!el) {
|
1482
|
+
return;
|
1483
|
+
}
|
1484
|
+
|
1485
|
+
var val = el.value,
|
1486
|
+
appendix = delimiter || (delimiters[0] || ' ');
|
1487
|
+
|
1488
|
+
if (!el.setSelectionRange || !prefix || (prefix.length + appendix.length) <= val.length) {
|
1489
|
+
return;
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
var len = val.length * 2;
|
1493
|
+
|
1494
|
+
// set timeout to avoid blink
|
1495
|
+
setTimeout(function () {
|
1496
|
+
el.setSelectionRange(len, len);
|
1497
|
+
}, 1);
|
1498
|
+
},
|
1499
|
+
|
1500
|
+
// Check if input field is fully selected
|
1501
|
+
checkFullSelection: function(value) {
|
1502
|
+
try {
|
1503
|
+
var selection = window.getSelection() || document.getSelection() || {};
|
1504
|
+
return selection.toString().length === value.length;
|
1505
|
+
} catch (ex) {
|
1506
|
+
// Ignore
|
1507
|
+
}
|
1508
|
+
|
1509
|
+
return false;
|
1510
|
+
},
|
1511
|
+
|
1512
|
+
setSelection: function (element, position, doc) {
|
1513
|
+
if (element !== this.getActiveElement(doc)) {
|
1514
|
+
return;
|
1515
|
+
}
|
1516
|
+
|
1517
|
+
// cursor is already in the end
|
1518
|
+
if (element && element.value.length <= position) {
|
1519
|
+
return;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
if (element.createTextRange) {
|
1523
|
+
var range = element.createTextRange();
|
1524
|
+
|
1525
|
+
range.move('character', position);
|
1526
|
+
range.select();
|
1527
|
+
} else {
|
1528
|
+
try {
|
1529
|
+
element.setSelectionRange(position, position);
|
1530
|
+
} catch (e) {
|
1531
|
+
// eslint-disable-next-line
|
1532
|
+
console.warn('The input element type does not support selection');
|
1533
|
+
}
|
1534
|
+
}
|
1535
|
+
},
|
1536
|
+
|
1537
|
+
getActiveElement: function(parent) {
|
1538
|
+
var activeElement = parent.activeElement;
|
1539
|
+
if (activeElement && activeElement.shadowRoot) {
|
1540
|
+
return this.getActiveElement(activeElement.shadowRoot);
|
1541
|
+
}
|
1542
|
+
return activeElement;
|
1543
|
+
},
|
1544
|
+
|
1545
|
+
isAndroid: function () {
|
1546
|
+
return navigator && /android/i.test(navigator.userAgent);
|
1547
|
+
},
|
1548
|
+
|
1549
|
+
// On Android chrome, the keyup and keydown events
|
1550
|
+
// always return key code 229 as a composition that
|
1551
|
+
// buffers the user’s keystrokes
|
1552
|
+
// see https://github.com/nosir/cleave.js/issues/147
|
1553
|
+
isAndroidBackspaceKeydown: function (lastInputValue, currentInputValue) {
|
1554
|
+
if (!this.isAndroid() || !lastInputValue || !currentInputValue) {
|
1555
|
+
return false;
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
return currentInputValue === lastInputValue.slice(0, -1);
|
1559
|
+
}
|
1560
|
+
};
|
1561
|
+
|
1562
|
+
module.exports = Util;
|
1563
|
+
|
1564
|
+
|
1565
|
+
/***/ }),
|
1566
|
+
/* 7 */
|
1567
|
+
/***/ (function(module, exports) {
|
1568
|
+
|
1569
|
+
/* WEBPACK VAR INJECTION */(function(global) {'use strict';
|
1570
|
+
|
1571
|
+
/**
|
1572
|
+
* Props Assignment
|
1573
|
+
*
|
1574
|
+
* Separate this, so react module can share the usage
|
1575
|
+
*/
|
1576
|
+
var DefaultProperties = {
|
1577
|
+
// Maybe change to object-assign
|
1578
|
+
// for now just keep it as simple
|
1579
|
+
assign: function (target, opts) {
|
1580
|
+
target = target || {};
|
1581
|
+
opts = opts || {};
|
1582
|
+
|
1583
|
+
// credit card
|
1584
|
+
target.creditCard = !!opts.creditCard;
|
1585
|
+
target.creditCardStrictMode = !!opts.creditCardStrictMode;
|
1586
|
+
target.creditCardType = '';
|
1587
|
+
target.onCreditCardTypeChanged = opts.onCreditCardTypeChanged || (function () {});
|
1588
|
+
|
1589
|
+
// phone
|
1590
|
+
target.phone = !!opts.phone;
|
1591
|
+
target.phoneRegionCode = opts.phoneRegionCode || 'AU';
|
1592
|
+
target.phoneFormatter = {};
|
1593
|
+
|
1594
|
+
// time
|
1595
|
+
target.time = !!opts.time;
|
1596
|
+
target.timePattern = opts.timePattern || ['h', 'm', 's'];
|
1597
|
+
target.timeFormat = opts.timeFormat || '24';
|
1598
|
+
target.timeFormatter = {};
|
1599
|
+
|
1600
|
+
// date
|
1601
|
+
target.date = !!opts.date;
|
1602
|
+
target.datePattern = opts.datePattern || ['d', 'm', 'Y'];
|
1603
|
+
target.dateMin = opts.dateMin || '';
|
1604
|
+
target.dateMax = opts.dateMax || '';
|
1605
|
+
target.dateFormatter = {};
|
1606
|
+
|
1607
|
+
// numeral
|
1608
|
+
target.numeral = !!opts.numeral;
|
1609
|
+
target.numeralIntegerScale = opts.numeralIntegerScale > 0 ? opts.numeralIntegerScale : 0;
|
1610
|
+
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
|
1611
|
+
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
|
1612
|
+
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
|
1613
|
+
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
|
1614
|
+
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
|
1615
|
+
target.signBeforePrefix = !!opts.signBeforePrefix;
|
1616
|
+
target.tailPrefix = !!opts.tailPrefix;
|
1617
|
+
|
1618
|
+
// others
|
1619
|
+
target.swapHiddenInput = !!opts.swapHiddenInput;
|
1620
|
+
|
1621
|
+
target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;
|
1622
|
+
|
1623
|
+
target.uppercase = !!opts.uppercase;
|
1624
|
+
target.lowercase = !!opts.lowercase;
|
1625
|
+
|
1626
|
+
target.prefix = (target.creditCard || target.date) ? '' : (opts.prefix || '');
|
1627
|
+
target.noImmediatePrefix = !!opts.noImmediatePrefix;
|
1628
|
+
target.prefixLength = target.prefix.length;
|
1629
|
+
target.rawValueTrimPrefix = !!opts.rawValueTrimPrefix;
|
1630
|
+
target.copyDelimiter = !!opts.copyDelimiter;
|
1631
|
+
|
1632
|
+
target.initValue = (opts.initValue !== undefined && opts.initValue !== null) ? opts.initValue.toString() : '';
|
1633
|
+
|
1634
|
+
target.delimiter =
|
1635
|
+
(opts.delimiter || opts.delimiter === '') ? opts.delimiter :
|
1636
|
+
(opts.date ? '/' :
|
1637
|
+
(opts.time ? ':' :
|
1638
|
+
(opts.numeral ? ',' :
|
1639
|
+
(opts.phone ? ' ' :
|
1640
|
+
' '))));
|
1641
|
+
target.delimiterLength = target.delimiter.length;
|
1642
|
+
target.delimiterLazyShow = !!opts.delimiterLazyShow;
|
1643
|
+
target.delimiters = opts.delimiters || [];
|
1644
|
+
|
1645
|
+
target.blocks = opts.blocks || [];
|
1646
|
+
target.blocksLength = target.blocks.length;
|
1647
|
+
|
1648
|
+
target.root = (typeof global === 'object' && global) ? global : window;
|
1649
|
+
target.document = opts.document || target.root.document;
|
1650
|
+
|
1651
|
+
target.maxLength = 0;
|
1652
|
+
|
1653
|
+
target.backspace = false;
|
1654
|
+
target.result = '';
|
1655
|
+
|
1656
|
+
target.onValueChanged = opts.onValueChanged || (function () {});
|
1657
|
+
|
1658
|
+
return target;
|
1659
|
+
}
|
1660
|
+
};
|
1661
|
+
|
1662
|
+
module.exports = DefaultProperties;
|
1663
|
+
|
1664
|
+
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
1665
|
+
|
1666
|
+
/***/ })
|
1667
|
+
/******/ ])
|
1668
|
+
});
|
1669
|
+
;
|