calendarjs-rails 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +2 -0
- data/lib/calendarjs-rails.rb +7 -0
- data/news.md +2 -0
- data/test/calendarjs_rails_test.rb +7 -0
- data/test/dummy/Rakefile +8 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +64 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +63 -0
- data/test/dummy/config/environments/test.rb +34 -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 +9 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/-j/-jX6MoF1gOaOZHxINZZpMRHTn2kF9xfDHriD08Mq00s.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/0V/0VyeLwtys3zoO0lGDBiFmH2ncDxv-QM0UnEeiRvvEOg.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/29/29z91GF7Jdd6-ZvvN_9P3veprmZggQJbiZgKrZs-UI4.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/4J/4JzoxrC9KC4LiJqiajkI9-3K5-2NdFy4M_cFaj6eTEs.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/76/76rZCUXXl9eSYVRC7ZNyLGrJDpgwxEDAE-wn3wvHjRw.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/CC/CCY-6ieyRqrrB1PH687qeY6LDpwtCRzzlkbBgAlCM84.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/FP/FPNvsGsm0uotkevOb2NHkDa_8GdCbRgn5zF9Pzi0rjo.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/KE/KE54S4D96FMdc6-Xj2izBJAChedLDCBpamIR5NDZbHM.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/L9/L9JZ807nqCi_-g6HbJU4gd38QdFKkWtnAoxr90ymOSg.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/LK/LK0j1_AEtvrRUHEHZHhegGwJOZFh_bQ073S4m3OgrMA.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1qcrf38TQ_-2TwAK9ayGq2OdoQju3bZALLzfJok2Z8.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Re/Re1zH3S_FMcunhZmCxaXFvCwdAK6JdLuIJU0vGX6jVY.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ww/WwwxBKzI2nK7E6S4bvev_XaMP6VYFlDAoE6T-suuH20.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/a1/a1U4RlX-h_CSLpnWmM188oG7iH3dpBndcO5PwsnFPvc.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/aD/aD9vsmOUiytCNsyXonYHSjxnWJHvDBI36z1ZgG1rNaM.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/dT/dTwKpWBP570vthdHFZCVcZ6lwdGEPPFPrwgIHh4ApRw.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/dx/dxfL5DH54Gm9f5VadebVrJTsZ9aV2vT91Wh5DXJxCS4.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/lD/lDIiAPN5ZE3rTTxeci6JGLHarEfNhKD_bKxzQIHNqh0.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/lL/lL3bM8saW7SfiHHUn4zLOECqmaH5pENG5A4_2i0jSpE.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/q5/q5QHvwif5zHCewYT81wwztvjF6UasJLLQR0UVGML6yQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/v8/v8ysLZl-Y9QdSJty-2bv7-gxgBI66Nm9GLDbkeBpPvs.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/vg/vgxyzvY-w7qdQGnOEfxXFL6xR2jnWM0buoU_geEYUIc.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/vn/vncjI19OzgdPPQwTdvdz5ApUeBGO0_KaznNJa3haYgQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/xV/xVmK48WqdaLwOGpahnASPN6d0wq88FkAoHIjsBOCh6Q.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yE/yEBl6HzyqwjnY1VQux89nkXU8EIknmxBjWU8w2s4qoU.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yw/ywj5LBveIytjjWIHwZN5BZ0Cgub3AG_av9f-ekoPzPE.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/zC/zCm6IZvmdtCx2iyLAHFwSjqX8R2IiCOVM_zY2k-B0Hw.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/zD/zDX8JWTGnCOVj1kqIevdJP1mNzNEIibIVEYQDJEGfZE.cache +2 -0
- data/test/integration/navigation_test.rb +23 -0
- data/test/test_helper.rb +15 -0
- data/vendor/assets/javascripts/Calendar.js +794 -0
- data/vendor/assets/stylesheets/Calendar.css +5 -0
- metadata +188 -0
@@ -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 = '49dfd6e5e224394dc63086a6507249b44ff1ca26e4a474ceb4e57f19aeacc345d514ee349e42e82b7a83d287041cf85487c0753f213534e4dbd02f355202a00b'
|
@@ -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,9 @@
|
|
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
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/-j/-jX6MoF1gOaOZHxINZZpMRHTn2kF9xfDHriD08Mq00s.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/0V/0VyeLwtys3zoO0lGDBiFmH2ncDxv-QM0UnEeiRvvEOg.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/stylesheets/Calendar.css?type=text/css&id=09a5b91b758f6cbe82085ea1a7964b86975cab6d9378048f9d2ac41276e381a4:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/29/29z91GF7Jdd6-ZvvN_9P3veprmZggQJbiZgKrZs-UI4.cache
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"zfile-digest:///Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTF
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/4J/4JzoxrC9KC4LiJqiajkI9-3K5-2NdFy4M_cFaj6eTEs.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/stylesheets/Calendar.css?type=text/css&pipeline=self&id=0d93802a45553bea37ea113d56f020d07f3453fe885bdd158e7f89fe52c79af2:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/76/76rZCUXXl9eSYVRC7ZNyLGrJDpgwxEDAE-wn3wvHjRw.cache
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}
|
3
|
+
I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"zfile-digest:///Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js;TTF
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/CC/CCY-6ieyRqrrB1PH687qeY6LDpwtCRzzlkbBgAlCM84.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/stylesheets/Calendar.css?type=text/css&pipeline=self&id=637f804f22bf841b541bbb6af38b06d6ceaed5b51f1923c56d534b94288ff2f9:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/KE/KE54S4D96FMdc6-Xj2izBJAChedLDCBpamIR5NDZbHM.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js?type=application/javascript&id=9f382dfe35f3aa7fc3c20ac6aeb4cb02e859bef87b366e74dd456225c59732c2:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1qcrf38TQ_-2TwAK9ayGq2OdoQju3bZALLzfJok2Z8.cache
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}
|
3
|
+
I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"zfile-digest:///Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js;TTF
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/Re/Re1zH3S_FMcunhZmCxaXFvCwdAK6JdLuIJU0vGX6jVY.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ww/WwwxBKzI2nK7E6S4bvev_XaMP6VYFlDAoE6T-suuH20.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/stylesheets/Calendar.css?type=text/css&id=75a82ed0a713320463da6771e8defefe588991c8c65e19d71fe3fe2fbb44a03e:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/a1/a1U4RlX-h_CSLpnWmM188oG7iH3dpBndcO5PwsnFPvc.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/aD/aD9vsmOUiytCNsyXonYHSjxnWJHvDBI36z1ZgG1rNaM.cache
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"zfile-digest:///Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTF
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/dT/dTwKpWBP570vthdHFZCVcZ6lwdGEPPFPrwgIHh4ApRw.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/dx/dxfL5DH54Gm9f5VadebVrJTsZ9aV2vT91Wh5DXJxCS4.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/lD/lDIiAPN5ZE3rTTxeci6JGLHarEfNhKD_bKxzQIHNqh0.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"%'�����|F�^��XA�א�vw�I�.a�p��7�
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/lL/lL3bM8saW7SfiHHUn4zLOECqmaH5pENG5A4_2i0jSpE.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/q5/q5QHvwif5zHCewYT81wwztvjF6UasJLLQR0UVGML6yQ.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js?type=application/javascript&id=3c3e0de650ce2bd3ac0eba4bad7138d16dd4810b89d17135fde16a6eb8d64232:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/v8/v8ysLZl-Y9QdSJty-2bv7-gxgBI66Nm9GLDbkeBpPvs.cache
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"0processors:type=text/css&file_type=text/css;TTI"{file-digest:///Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/stylesheets/Calendar.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTF
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/vg/vgxyzvY-w7qdQGnOEfxXFL6xR2jnWM0buoU_geEYUIc.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/vn/vncjI19OzgdPPQwTdvdz5ApUeBGO0_KaznNJa3haYgQ.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js?type=application/javascript&pipeline=self&id=7a8641c7cdfcbba2e88b82335eaebcc987ce70ef913c5e27bdf02c13a6b49018:ET
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/yE/yEBl6HzyqwjnY1VQux89nkXU8EIknmxBjWU8w2s4qoU.cache
ADDED
Binary file
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/yw/ywj5LBveIytjjWIHwZN5BZ0Cgub3AG_av9f-ekoPzPE.cache
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"0processors:type=text/css&file_type=text/css;TTI"{file-digest:///Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/stylesheets/Calendar.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTF
|
data/test/dummy/tmp/cache/assets/sprockets/v3.0/zC/zCm6IZvmdtCx2iyLAHFwSjqX8R2IiCOVM_zY2k-B0Hw.cache
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
I"�/Users/viniciusmagalhaes/Development/vkmagalhaes/calendarjs-rails/vendor/assets/javascripts/Calendar.js?type=application/javascript&pipeline=self&id=2236af4e8767fd64a644b23547019d0c94d463809947ab4eb3d84626e21ab267:ET
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NavigationTest < ActionDispatch::IntegrationTest
|
4
|
+
test 'can access calendarjs' do
|
5
|
+
get '/assets/Calendar.js'
|
6
|
+
assert_response :success
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'calendarjs response is for the expected version' do
|
10
|
+
get '/assets/Calendar.js'
|
11
|
+
assert_match(/version : 1\.0\.10/, @response.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'can access calendarjs css' do
|
15
|
+
get '/assets/Calendar.css'
|
16
|
+
assert_response :success
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'calendarjs css response is for the expected version' do
|
20
|
+
get '/assets/Calendar.css'
|
21
|
+
assert_match(/version : 1\.0\.10/, @response.body)
|
22
|
+
end
|
23
|
+
end
|
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,794 @@
|
|
1
|
+
//! https://github.com/Baremetrics/calendar
|
2
|
+
//! version : 1.0.10
|
3
|
+
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
(function(root, factory) {
|
7
|
+
if (typeof define === 'function' && define.amd) {
|
8
|
+
// AMD. Register as an anonymous module.
|
9
|
+
define(['jquery', 'moment'], factory);
|
10
|
+
} else if (typeof exports === 'object') {
|
11
|
+
// Node/CommonJS
|
12
|
+
module.exports = factory(require('jquery'), require('moment'));
|
13
|
+
} else {
|
14
|
+
// Browser globals
|
15
|
+
root.Calendar = factory(jQuery, moment);
|
16
|
+
}
|
17
|
+
}(this, function($, moment) {
|
18
|
+
function Calendar(settings) {
|
19
|
+
var self = this;
|
20
|
+
|
21
|
+
this.settings = settings;
|
22
|
+
|
23
|
+
this.calIsOpen = false;
|
24
|
+
this.presetIsOpen = false;
|
25
|
+
this.sameDayRange = settings.same_day_range || false;
|
26
|
+
|
27
|
+
this.element = settings.element || $('.daterange');
|
28
|
+
this.selected = null;
|
29
|
+
|
30
|
+
this.type = this.element.hasClass('daterange--single') ? 'single' : 'double';
|
31
|
+
this.required = settings.required == false ? false : true;
|
32
|
+
|
33
|
+
this.format = settings.format || {};
|
34
|
+
this.format.input = settings.format && settings.format.input || 'MMMM D, YYYY';
|
35
|
+
this.format.preset = settings.format && settings.format.preset || 'll';
|
36
|
+
this.format.jump_month = settings.format && settings.format.jump_month || 'MMMM';
|
37
|
+
this.format.jump_year = settings.format && settings.format.jump_year || 'YYYY';
|
38
|
+
|
39
|
+
this.placeholder = settings.placeholder || this.format.input;
|
40
|
+
|
41
|
+
this.days_array = settings.days_array && settings.days_array.length == 7 ?
|
42
|
+
settings.days_array : moment.weekdaysMin();
|
43
|
+
|
44
|
+
this.orig_start_date = null;
|
45
|
+
this.orig_end_date = null;
|
46
|
+
this.orig_current_date = null;
|
47
|
+
|
48
|
+
this.earliest_date = settings.earliest_date ? moment(settings.earliest_date) :
|
49
|
+
moment('1900-01-01');
|
50
|
+
this.latest_date = settings.latest_date ? moment(settings.latest_date) :
|
51
|
+
moment('2900-12-31');
|
52
|
+
this.end_date = settings.end_date ? moment(settings.end_date) :
|
53
|
+
(this.type == 'double' ? moment() : null);
|
54
|
+
this.start_date = settings.start_date ? moment(settings.start_date) :
|
55
|
+
(this.type == 'double' ? this.end_date.clone().subtract(1, 'month') : null);
|
56
|
+
this.current_date = settings.current_date ? moment(settings.current_date) :
|
57
|
+
(this.type == 'single' ? moment() : null);
|
58
|
+
|
59
|
+
this.presets = settings.presets == false || this.type == 'single' ? false : true;
|
60
|
+
|
61
|
+
this.callback = settings.callback || this.calendarSetDates;
|
62
|
+
|
63
|
+
this.calendarHTML(this.type);
|
64
|
+
|
65
|
+
$('.dr-presets', this.element).click(function() {
|
66
|
+
self.presetToggle();
|
67
|
+
});
|
68
|
+
|
69
|
+
$('.dr-list-item', this.element).click(function() {
|
70
|
+
var start = $('.dr-item-aside', this).data('start');
|
71
|
+
var end = $('.dr-item-aside', this).data('end');
|
72
|
+
|
73
|
+
self.start_date = self.calendarCheckDate(start);
|
74
|
+
self.end_date = self.calendarCheckDate(end);
|
75
|
+
|
76
|
+
self.calendarSetDates();
|
77
|
+
self.presetToggle();
|
78
|
+
self.calendarSaveDates();
|
79
|
+
});
|
80
|
+
|
81
|
+
$('.dr-date', this.element).on({
|
82
|
+
'click': function() {
|
83
|
+
self.calendarOpen(this);
|
84
|
+
},
|
85
|
+
|
86
|
+
'keyup': function(event) {
|
87
|
+
if (event.keyCode == 9 && !self.calIsOpen && !self.start_date && !self.end_date)
|
88
|
+
self.calendarOpen(this);
|
89
|
+
},
|
90
|
+
|
91
|
+
'keydown': function(event) {
|
92
|
+
switch (event.keyCode) {
|
93
|
+
|
94
|
+
case 9: // Tab
|
95
|
+
if ($(self.selected).hasClass('dr-date-start')) {
|
96
|
+
event.preventDefault();
|
97
|
+
self.calendarCheckDates();
|
98
|
+
self.calendarSetDates();
|
99
|
+
$('.dr-date-end', self.element).trigger('click');
|
100
|
+
} else {
|
101
|
+
self.calendarCheckDates();
|
102
|
+
self.calendarSetDates();
|
103
|
+
self.calendarSaveDates();
|
104
|
+
self.calendarClose('force');
|
105
|
+
}
|
106
|
+
break;
|
107
|
+
|
108
|
+
case 13: // Enter
|
109
|
+
event.preventDefault();
|
110
|
+
self.calendarCheckDates();
|
111
|
+
self.calendarSetDates();
|
112
|
+
self.calendarSaveDates();
|
113
|
+
self.calendarClose('force');
|
114
|
+
break;
|
115
|
+
|
116
|
+
case 27: // ESC
|
117
|
+
self.calendarSetDates();
|
118
|
+
self.calendarClose('force');
|
119
|
+
break;
|
120
|
+
|
121
|
+
case 38: // Up
|
122
|
+
event.preventDefault();
|
123
|
+
var timeframe = 'day';
|
124
|
+
|
125
|
+
if (event.shiftKey)
|
126
|
+
timeframe = 'week';
|
127
|
+
|
128
|
+
if (event.metaKey)
|
129
|
+
timeframe = 'month';
|
130
|
+
|
131
|
+
var back = moment(self.current_date).subtract(1, timeframe);
|
132
|
+
|
133
|
+
$(this).html(back.format(self.format.input));
|
134
|
+
self.current_date = back;
|
135
|
+
break;
|
136
|
+
|
137
|
+
case 40: // Down
|
138
|
+
event.preventDefault();
|
139
|
+
var timeframe = 'day';
|
140
|
+
|
141
|
+
if (event.shiftKey)
|
142
|
+
timeframe = 'week';
|
143
|
+
|
144
|
+
if (event.metaKey)
|
145
|
+
timeframe = 'month';
|
146
|
+
|
147
|
+
var forward = moment(self.current_date).add(1, timeframe);
|
148
|
+
|
149
|
+
$(this).html(forward.format(self.format.input));
|
150
|
+
self.current_date = forward;
|
151
|
+
break;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
});
|
155
|
+
|
156
|
+
$('.dr-month-switcher i', this.element).click(function() {
|
157
|
+
var m = $('.dr-month-switcher span', self.element).data('month');
|
158
|
+
var y = $('.dr-year-switcher span', self.element).data('year');
|
159
|
+
var this_moment = moment([y, m, 1]);
|
160
|
+
var back = this_moment.clone().subtract(1, 'month');
|
161
|
+
var forward = this_moment.clone().add(1, 'month').startOf('day');
|
162
|
+
|
163
|
+
if ($(this).hasClass('dr-left')) {
|
164
|
+
self.calendarOpen(self.selected, back);
|
165
|
+
} else if ($(this).hasClass('dr-right')) {
|
166
|
+
self.calendarOpen(self.selected, forward);
|
167
|
+
}
|
168
|
+
});
|
169
|
+
|
170
|
+
$('.dr-year-switcher i', this.element).click(function() {
|
171
|
+
var m = $('.dr-month-switcher span', self.element).data('month');
|
172
|
+
var y = $('.dr-year-switcher span', self.element).data('year');
|
173
|
+
var this_moment = moment([y, m, 1]);
|
174
|
+
var back = this_moment.clone().subtract(1, 'year');
|
175
|
+
var forward = this_moment.clone().add(1, 'year').startOf('day');
|
176
|
+
|
177
|
+
|
178
|
+
if ($(this).hasClass('dr-left')) {
|
179
|
+
self.calendarOpen(self.selected, back);
|
180
|
+
} else if ($(this).hasClass('dr-right')) {
|
181
|
+
self.calendarOpen(self.selected, forward);
|
182
|
+
}
|
183
|
+
});
|
184
|
+
|
185
|
+
$('.dr-dates-dash', this.element).click(function() {
|
186
|
+
$('.dr-date-start', self.element).trigger('click');
|
187
|
+
});
|
188
|
+
|
189
|
+
// Once you click into a selection.. this lets you click out
|
190
|
+
this.element.on('click', function() {
|
191
|
+
document.addEventListener('click', function(f) {
|
192
|
+
var contains = self.element.find(f.path[0]);
|
193
|
+
|
194
|
+
if (!contains.length) {
|
195
|
+
if (self.presetIsOpen)
|
196
|
+
self.presetToggle();
|
197
|
+
|
198
|
+
if (self.calIsOpen) {
|
199
|
+
if ($(self.selected).hasClass('dr-date-end'))
|
200
|
+
self.calendarSaveDates();
|
201
|
+
|
202
|
+
self.calendarSetDates();
|
203
|
+
self.calendarClose('force');
|
204
|
+
}
|
205
|
+
}
|
206
|
+
});
|
207
|
+
});
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
Calendar.prototype.presetToggle = function() {
|
212
|
+
if (this.presetIsOpen == false) {
|
213
|
+
this.orig_start_date = this.start_date;
|
214
|
+
this.orig_end_date = this.end_date;
|
215
|
+
this.orig_current_date = this.current_date;
|
216
|
+
|
217
|
+
this.presetIsOpen = true;
|
218
|
+
} else if (this.presetIsOpen) {
|
219
|
+
this.presetIsOpen = false;
|
220
|
+
}
|
221
|
+
|
222
|
+
if (this.calIsOpen == true)
|
223
|
+
this.calendarClose();
|
224
|
+
|
225
|
+
$('.dr-preset-list', this.element).slideToggle(200);
|
226
|
+
$('.dr-input', this.element).toggleClass('dr-active');
|
227
|
+
$('.dr-presets', this.element).toggleClass('dr-active');
|
228
|
+
this.element.toggleClass('dr-active');
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
Calendar.prototype.presetCreate = function() {
|
233
|
+
var self = this;
|
234
|
+
var ul_presets = $('<ul class="dr-preset-list" style="display: none;"></ul>');
|
235
|
+
var presets = typeof self.settings.presets === 'object' ? self.settings.presets : [{
|
236
|
+
label: 'Last 30 days',
|
237
|
+
start: moment(self.latest_date).subtract(29, 'days'),
|
238
|
+
end: self.latest_date
|
239
|
+
}, {
|
240
|
+
label: 'Last month',
|
241
|
+
start: moment(self.latest_date).subtract(1, 'month').startOf('month'),
|
242
|
+
end: moment(self.latest_date).subtract(1, 'month').endOf('month')
|
243
|
+
}, {
|
244
|
+
label: 'Last 3 months',
|
245
|
+
start: moment(self.latest_date).subtract(3, 'month').startOf('month'),
|
246
|
+
end: moment(self.latest_date).subtract(1, 'month').endOf('month')
|
247
|
+
}, {
|
248
|
+
label: 'Last 6 months',
|
249
|
+
start: moment(self.latest_date).subtract(6, 'month').startOf('month'),
|
250
|
+
end: moment(self.latest_date).subtract(1, 'month').endOf('month')
|
251
|
+
}, {
|
252
|
+
label: 'Last year',
|
253
|
+
start: moment(self.latest_date).subtract(12, 'month').startOf('month'),
|
254
|
+
end: moment(self.latest_date).subtract(1, 'month').endOf('month')
|
255
|
+
}, {
|
256
|
+
label: 'All time',
|
257
|
+
start: self.earliest_date,
|
258
|
+
end: self.latest_date
|
259
|
+
}];
|
260
|
+
|
261
|
+
if (moment(self.latest_date).diff(moment(self.latest_date).startOf('month'), 'days') >= 6 &&
|
262
|
+
typeof self.settings.presets !== 'object'
|
263
|
+
) {
|
264
|
+
presets.splice(1, 0, {
|
265
|
+
label: 'This month',
|
266
|
+
start: moment(self.latest_date).startOf('month'),
|
267
|
+
end: self.latest_date
|
268
|
+
});
|
269
|
+
}
|
270
|
+
|
271
|
+
$.each(presets, function(i, d) {
|
272
|
+
if (moment(d.start).isBefore(self.earliest_date)) {
|
273
|
+
d.start = self.earliest_date;
|
274
|
+
}
|
275
|
+
if (moment(d.start).isAfter(self.latest_date)) {
|
276
|
+
d.start = self.latest_date;
|
277
|
+
}
|
278
|
+
if (moment(d.end).isBefore(self.earliest_date)) {
|
279
|
+
d.end = self.earliest_date;
|
280
|
+
}
|
281
|
+
if (moment(d.end).isAfter(self.latest_date)) {
|
282
|
+
d.end = self.latest_date;
|
283
|
+
}
|
284
|
+
|
285
|
+
var startISO = moment(d.start).toISOString();
|
286
|
+
var endISO = moment(d.end).toISOString();
|
287
|
+
var string = moment(d.start).format(self.format.preset) + ' – ' + moment(d.end).format(self.format.preset);
|
288
|
+
|
289
|
+
if ($('.dr-preset-list', self.element).length) {
|
290
|
+
var item = $('.dr-preset-list .dr-list-item:nth-of-type(' + (i + 1) + ') .dr-item-aside', self.element);
|
291
|
+
item.data('start', startISO);
|
292
|
+
item.data('end', endISO);
|
293
|
+
item.html(string);
|
294
|
+
} else {
|
295
|
+
ul_presets.append('<li class="dr-list-item">' + d.label +
|
296
|
+
'<span class="dr-item-aside" data-start="' + startISO + '" data-end="' + endISO + '">' + string + '</span>' +
|
297
|
+
'</li>');
|
298
|
+
}
|
299
|
+
});
|
300
|
+
|
301
|
+
return ul_presets;
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
Calendar.prototype.calendarSetDates = function() {
|
306
|
+
$('.dr-date-start', this.element).html(moment(this.start_date).format(this.format.input));
|
307
|
+
$('.dr-date-end', this.element).html(moment(this.end_date).format(this.format.input));
|
308
|
+
|
309
|
+
if (!this.start_date && !this.end_date) {
|
310
|
+
var old_date = $('.dr-date', this.element).html();
|
311
|
+
var new_date = moment(this.current_date).format(this.format.input);
|
312
|
+
|
313
|
+
if (old_date.length === 0 && !this.required)
|
314
|
+
new_date = '';
|
315
|
+
|
316
|
+
if (old_date != new_date)
|
317
|
+
$('.dr-date', this.element).html(new_date);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
Calendar.prototype.calendarSaveDates = function() {
|
323
|
+
if (this.type === 'double') {
|
324
|
+
if (!moment(this.orig_end_date).isSame(this.end_date) || !moment(this.orig_start_date).isSame(this.start_date))
|
325
|
+
return this.callback();
|
326
|
+
} else {
|
327
|
+
if (!this.required || !moment(this.orig_current_date).isSame(this.current_date))
|
328
|
+
return this.callback();
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
Calendar.prototype.calendarCheckDate = function(d) {
|
333
|
+
// Today
|
334
|
+
if (d === 'today' || d === 'now')
|
335
|
+
return moment().isAfter(this.latest_date) ? this.latest_date :
|
336
|
+
moment().isBefore(this.earliest_date) ? this.earliest_date : moment();
|
337
|
+
|
338
|
+
// Earliest
|
339
|
+
if (d === 'earliest')
|
340
|
+
return this.earliest_date;
|
341
|
+
|
342
|
+
// Latest
|
343
|
+
if (d === 'latest')
|
344
|
+
return this.latest_date;
|
345
|
+
|
346
|
+
// Convert string to a date if keyword ago or ahead exists
|
347
|
+
if (d && (/\bago\b/.test(d) || /\bahead\b/.test(d)))
|
348
|
+
return this.stringToDate(d);
|
349
|
+
|
350
|
+
var regex = /(?:\d)((?:st|nd|rd|th)?,?)/;
|
351
|
+
var d_array = d ? d.replace(regex, '').split(' ') : [];
|
352
|
+
|
353
|
+
// Add current year if year is not included
|
354
|
+
if (d_array.length == 2) {
|
355
|
+
d_array.push(moment().format(this.format.jump_year));
|
356
|
+
d = d_array.join(' ');
|
357
|
+
}
|
358
|
+
|
359
|
+
// Convert using settings format
|
360
|
+
var parsed_d = this.parseDate(d);
|
361
|
+
|
362
|
+
if (!parsed_d.isValid())
|
363
|
+
return moment(d); // occurs when parsing preset dates
|
364
|
+
|
365
|
+
return parsed_d;
|
366
|
+
}
|
367
|
+
|
368
|
+
Calendar.prototype.calendarCheckDates = function() {
|
369
|
+
var startTxt = $('.dr-date-start', this.element).html();
|
370
|
+
var endTxt = $('.dr-date-end', this.element).html();
|
371
|
+
var c = this.calendarCheckDate($(this.selected).html());
|
372
|
+
var s;
|
373
|
+
var e;
|
374
|
+
|
375
|
+
// Modify strings via some specific keywords to create valid dates
|
376
|
+
// Finally set all strings as dates
|
377
|
+
if (startTxt === 'ytd' || endTxt === 'ytd') { // Year to date
|
378
|
+
s = moment().startOf('year');
|
379
|
+
e = moment().endOf('year');
|
380
|
+
} else {
|
381
|
+
s = this.calendarCheckDate(startTxt);
|
382
|
+
e = this.calendarCheckDate(endTxt);
|
383
|
+
}
|
384
|
+
|
385
|
+
if (c.isBefore(this.earliest_date))
|
386
|
+
c = this.earliest_date;
|
387
|
+
if (s.isBefore(this.earliest_date))
|
388
|
+
s = this.earliest_date;
|
389
|
+
if (e.isBefore(this.earliest_date) || e.isBefore(s))
|
390
|
+
e = s.clone().add(6, 'day');
|
391
|
+
|
392
|
+
if (c.isAfter(this.latest_date))
|
393
|
+
c = this.latest_date;
|
394
|
+
if (e.isAfter(this.latest_date))
|
395
|
+
e = this.latest_date;
|
396
|
+
if (s.isAfter(this.latest_date) || s.isAfter(e))
|
397
|
+
s = e.clone().subtract(6, 'day');
|
398
|
+
|
399
|
+
// Push and save if it's valid otherwise return to previous state
|
400
|
+
if (this.type === 'double') {
|
401
|
+
|
402
|
+
// Is this a valid date?
|
403
|
+
if (s.isSame(e) && !this.sameDayRange)
|
404
|
+
return this.calendarSetDates();
|
405
|
+
|
406
|
+
this.start_date = s.isValid() ? s : this.start_date;
|
407
|
+
this.end_date = e.isValid() ? e : this.end_date;
|
408
|
+
}
|
409
|
+
|
410
|
+
this.current_date = c.isValid() ? c : this.current_date;
|
411
|
+
}
|
412
|
+
|
413
|
+
|
414
|
+
Calendar.prototype.stringToDate = function(str) {
|
415
|
+
var date_arr = str.split(' ');
|
416
|
+
|
417
|
+
if (date_arr[2] === 'ago') {
|
418
|
+
return moment(this.current_date).subtract(date_arr[0], date_arr[1]);
|
419
|
+
} else if (date_arr[2] === 'ahead') {
|
420
|
+
return moment(this.current_date).add(date_arr[0], date_arr[1]);
|
421
|
+
}
|
422
|
+
|
423
|
+
return this.current_date;
|
424
|
+
}
|
425
|
+
|
426
|
+
|
427
|
+
Calendar.prototype.calendarOpen = function(selected, switcher) {
|
428
|
+
var self = this;
|
429
|
+
var other;
|
430
|
+
var cal_width = $('.dr-dates', this.element).innerWidth() - 8;
|
431
|
+
|
432
|
+
this.selected = selected || this.selected;
|
433
|
+
|
434
|
+
if (this.presetIsOpen == true)
|
435
|
+
this.presetToggle();
|
436
|
+
|
437
|
+
if (this.calIsOpen == true) {
|
438
|
+
this.calendarClose(switcher ? 'switcher' : undefined);
|
439
|
+
} else if ($(this.selected).html().length) {
|
440
|
+
this.orig_start_date = this.start_date;
|
441
|
+
this.orig_end_date = this.end_date;
|
442
|
+
this.orig_current_date = this.current_date;
|
443
|
+
}
|
444
|
+
|
445
|
+
this.calendarCheckDates();
|
446
|
+
this.calendarCreate(switcher);
|
447
|
+
this.calendarSetDates();
|
448
|
+
|
449
|
+
var next_month = moment(switcher || this.current_date).add(1, 'month').startOf('month').startOf('day');
|
450
|
+
var past_month = moment(switcher || this.current_date).subtract(1, 'month').endOf('month');
|
451
|
+
var next_year = moment(switcher || this.current_date).add(1, 'year').startOf('month').startOf('day');
|
452
|
+
var past_year = moment(switcher || this.current_date).subtract(1, 'year').endOf('month');
|
453
|
+
var this_moment = moment(switcher || this.current_date);
|
454
|
+
|
455
|
+
$('.dr-month-switcher span', this.element)
|
456
|
+
.data('month', this_moment.month())
|
457
|
+
.html(this_moment.format(this.format.jump_month));
|
458
|
+
$('.dr-year-switcher span', this.element)
|
459
|
+
.data('year', this_moment.year())
|
460
|
+
.html(this_moment.format(this.format.jump_year));
|
461
|
+
|
462
|
+
$('.dr-switcher i', this.element).removeClass('dr-disabled');
|
463
|
+
|
464
|
+
if (next_month.isAfter(this.latest_date))
|
465
|
+
$('.dr-month-switcher .dr-right', this.element).addClass('dr-disabled');
|
466
|
+
|
467
|
+
if (past_month.isBefore(this.earliest_date))
|
468
|
+
$('.dr-month-switcher .dr-left', this.element).addClass('dr-disabled');
|
469
|
+
|
470
|
+
if (next_year.isAfter(this.latest_date))
|
471
|
+
$('.dr-year-switcher .dr-right', this.element).addClass('dr-disabled');
|
472
|
+
|
473
|
+
if (past_year.isBefore(this.earliest_date))
|
474
|
+
$('.dr-year-switcher .dr-left', this.element).addClass('dr-disabled');
|
475
|
+
|
476
|
+
$('.dr-day', this.element).on({
|
477
|
+
mouseenter: function() {
|
478
|
+
var selected = $(this);
|
479
|
+
var start_date = moment(self.start_date);
|
480
|
+
var end_date = moment(self.end_date);
|
481
|
+
var current_date = moment(self.current_date);
|
482
|
+
|
483
|
+
if ($(self.selected).hasClass("dr-date-start")) {
|
484
|
+
selected.addClass('dr-hover dr-hover-before');
|
485
|
+
$('.dr-start', self.element).css({
|
486
|
+
'border': 'none',
|
487
|
+
'padding-left': '0.3125rem'
|
488
|
+
});
|
489
|
+
setMaybeRange('start');
|
490
|
+
}
|
491
|
+
|
492
|
+
if ($(self.selected).hasClass("dr-date-end")) {
|
493
|
+
selected.addClass('dr-hover dr-hover-after');
|
494
|
+
$('.dr-end', self.element).css({
|
495
|
+
'border': 'none',
|
496
|
+
'padding-right': '0.3125rem'
|
497
|
+
});
|
498
|
+
setMaybeRange('end');
|
499
|
+
}
|
500
|
+
|
501
|
+
if (!self.start_date && !self.end_date)
|
502
|
+
selected.addClass('dr-maybe');
|
503
|
+
|
504
|
+
$('.dr-selected', self.element).css('background-color', 'transparent');
|
505
|
+
|
506
|
+
function setMaybeRange(type) {
|
507
|
+
other = undefined;
|
508
|
+
|
509
|
+
self.range(6 * 7).forEach(function(i) {
|
510
|
+
var next = selected.next().data('date');
|
511
|
+
var prev = selected.prev().data('date');
|
512
|
+
var curr = selected.data('date');
|
513
|
+
|
514
|
+
if (!curr)
|
515
|
+
return false;
|
516
|
+
|
517
|
+
if (!prev)
|
518
|
+
prev = curr;
|
519
|
+
|
520
|
+
if (!next)
|
521
|
+
next = curr;
|
522
|
+
|
523
|
+
if (type == 'start') {
|
524
|
+
if (moment(next).isSame(self.end_date) || (self.sameDayRange && moment(curr).isSame(self.end_date)))
|
525
|
+
return false;
|
526
|
+
|
527
|
+
if (moment(curr).isAfter(self.end_date)) {
|
528
|
+
other = other || moment(curr).add(6, 'day').startOf('day');
|
529
|
+
|
530
|
+
if (i > 5 || (next ? moment(next).isAfter(self.latest_date) : false)) {
|
531
|
+
$(selected).addClass('dr-end');
|
532
|
+
other = moment(curr);
|
533
|
+
return false;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
|
537
|
+
selected = selected.next().addClass('dr-maybe');
|
538
|
+
} else if (type == 'end') {
|
539
|
+
if (moment(prev).isSame(self.start_date) || (self.sameDayRange && moment(curr).isSame(self.start_date)))
|
540
|
+
return false;
|
541
|
+
|
542
|
+
if (moment(curr).isBefore(self.start_date)) {
|
543
|
+
other = other || moment(curr).subtract(6, 'day');
|
544
|
+
|
545
|
+
if (i > 5 || (prev ? moment(prev).isBefore(self.earliest_date) : false)) {
|
546
|
+
$(selected).addClass('dr-start');
|
547
|
+
other = moment(curr);
|
548
|
+
return false;
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
selected = selected.prev().addClass('dr-maybe');
|
553
|
+
}
|
554
|
+
});
|
555
|
+
}
|
556
|
+
},
|
557
|
+
mouseleave: function() {
|
558
|
+
if ($(this).hasClass('dr-hover-before dr-end'))
|
559
|
+
$(this).removeClass('dr-end');
|
560
|
+
|
561
|
+
if ($(this).hasClass('dr-hover-after dr-start'))
|
562
|
+
$(this).removeClass('dr-start');
|
563
|
+
|
564
|
+
$(this).removeClass('dr-hover dr-hover-before dr-hover-after');
|
565
|
+
$('.dr-start, .dr-end', self.element).css({
|
566
|
+
'border': '',
|
567
|
+
'padding': ''
|
568
|
+
});
|
569
|
+
$('.dr-maybe:not(.dr-current)', self.element).removeClass('dr-start dr-end');
|
570
|
+
$('.dr-day', self.element).removeClass('dr-maybe');
|
571
|
+
$('.dr-selected', self.element).css('background-color', '');
|
572
|
+
}
|
573
|
+
});
|
574
|
+
|
575
|
+
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
|
576
|
+
$('.dr-day', this.element).on({
|
577
|
+
touchstart: function() {
|
578
|
+
selectOneDate(other, self, $(this).data('date'));
|
579
|
+
}
|
580
|
+
});
|
581
|
+
|
582
|
+
$('div[contenteditable]', this.element).removeAttr('contenteditable');
|
583
|
+
} else {
|
584
|
+
$('.dr-day', this.element).on({
|
585
|
+
mousedown: function() {
|
586
|
+
selectOneDate(other, self, $(this).data('date'));
|
587
|
+
}
|
588
|
+
});
|
589
|
+
}
|
590
|
+
|
591
|
+
$('.dr-calendar', this.element)
|
592
|
+
.css('width', cal_width)
|
593
|
+
.slideDown(200);
|
594
|
+
$('.dr-input', this.element).addClass('dr-active');
|
595
|
+
$(selected).addClass('dr-active').focus();
|
596
|
+
this.element.addClass('dr-active');
|
597
|
+
|
598
|
+
this.calIsOpen = true;
|
599
|
+
}
|
600
|
+
|
601
|
+
|
602
|
+
Calendar.prototype.calendarClose = function(type) {
|
603
|
+
var self = this;
|
604
|
+
|
605
|
+
if (!this.calIsOpen || this.presetIsOpen || type == 'force') {
|
606
|
+
$('.dr-calendar', this.element).slideUp(200, function() {
|
607
|
+
$('.dr-day', self.element).remove();
|
608
|
+
});
|
609
|
+
} else {
|
610
|
+
$('.dr-day', this.element).remove();
|
611
|
+
}
|
612
|
+
|
613
|
+
if (type == 'switcher') {
|
614
|
+
return false;
|
615
|
+
}
|
616
|
+
|
617
|
+
$('.dr-input, .dr-date', this.element).removeClass('dr-active');
|
618
|
+
this.element.removeClass('dr-active');
|
619
|
+
|
620
|
+
this.calIsOpen = false;
|
621
|
+
}
|
622
|
+
|
623
|
+
|
624
|
+
Calendar.prototype.calendarCreate = function(switcher) {
|
625
|
+
var self = this;
|
626
|
+
var array = this.calendarArray(this.start_date, this.end_date, this.current_date, switcher);
|
627
|
+
|
628
|
+
array.forEach(function(d, i) {
|
629
|
+
var classString = "dr-day";
|
630
|
+
|
631
|
+
if (d.fade)
|
632
|
+
classString += " dr-fade";
|
633
|
+
|
634
|
+
if (d.start)
|
635
|
+
classString += " dr-start";
|
636
|
+
|
637
|
+
if (d.end)
|
638
|
+
classString += " dr-end";
|
639
|
+
|
640
|
+
if (d.current)
|
641
|
+
classString += " dr-current";
|
642
|
+
|
643
|
+
if (d.selected)
|
644
|
+
classString += " dr-selected";
|
645
|
+
|
646
|
+
if (d.outside)
|
647
|
+
classString += " dr-outside";
|
648
|
+
|
649
|
+
$('.dr-day-list', self.element).append('<li class="' + classString + '" data-date="' + d.date + '">' + d.str + '</li>');
|
650
|
+
});
|
651
|
+
}
|
652
|
+
|
653
|
+
|
654
|
+
Calendar.prototype.calendarArray = function(start, end, current, switcher) {
|
655
|
+
var self = this;
|
656
|
+
current = moment(current || start || end).startOf('day');
|
657
|
+
|
658
|
+
var reference = switcher || current || start || end;
|
659
|
+
|
660
|
+
var startRange = moment(reference).startOf('month').startOf('week');
|
661
|
+
var endRange = moment(startRange).add(6 * 7 - 1, 'days').endOf('day');
|
662
|
+
|
663
|
+
var daysInRange = [];
|
664
|
+
var d = moment(startRange);
|
665
|
+
while (d.isBefore(endRange)) {
|
666
|
+
daysInRange.push({
|
667
|
+
str: +d.format('D'),
|
668
|
+
start: start && d.isSame(start, 'day'),
|
669
|
+
end: end && d.isSame(end, 'day'),
|
670
|
+
current: current && d.isSame(current, 'day'),
|
671
|
+
selected: start && end && d.isBetween(start, end),
|
672
|
+
date: d.toISOString(),
|
673
|
+
outside: d.isBefore(self.earliest_date) || d.isAfter(self.latest_date),
|
674
|
+
fade: !d.isSame(reference, 'month')
|
675
|
+
});
|
676
|
+
d.add(1, 'd');
|
677
|
+
}
|
678
|
+
|
679
|
+
return daysInRange;
|
680
|
+
}
|
681
|
+
|
682
|
+
|
683
|
+
Calendar.prototype.calendarHTML = function(type) {
|
684
|
+
var ul_days_of_the_week = $('<ul class="dr-days-of-week-list"></ul>');
|
685
|
+
var days = this.days_array.splice(moment.localeData().firstDayOfWeek()).concat(this.days_array.splice(0, moment.localeData().firstDayOfWeek()));
|
686
|
+
|
687
|
+
$.each(days, function(i, elem) {
|
688
|
+
ul_days_of_the_week.append('<li class="dr-day-of-week">' + elem + '</li>');
|
689
|
+
});
|
690
|
+
|
691
|
+
if (type == "double")
|
692
|
+
return this.element.append('<div class="dr-input">' +
|
693
|
+
'<div class="dr-dates">' +
|
694
|
+
'<div class="dr-date dr-date-start" contenteditable>' + moment(this.start_date).format(this.format.input) + '</div>' +
|
695
|
+
'<span class="dr-dates-dash">–</span>' +
|
696
|
+
'<div class="dr-date dr-date-end" contenteditable>' + moment(this.end_date).format(this.format.input) + '</div>' +
|
697
|
+
'</div>' +
|
698
|
+
|
699
|
+
(this.presets ? '<div class="dr-presets">' +
|
700
|
+
'<span class="dr-preset-bar"></span>' +
|
701
|
+
'<span class="dr-preset-bar"></span>' +
|
702
|
+
'<span class="dr-preset-bar"></span>' +
|
703
|
+
'</div>' : '') +
|
704
|
+
'</div>' +
|
705
|
+
|
706
|
+
'<div class="dr-selections">' +
|
707
|
+
'<div class="dr-calendar" style="display: none;">' +
|
708
|
+
'<div class="dr-range-switcher">' +
|
709
|
+
'<div class="dr-switcher dr-month-switcher">' +
|
710
|
+
'<i class="dr-left"></i>' +
|
711
|
+
'<span>April</span>' +
|
712
|
+
'<i class="dr-right"></i>' +
|
713
|
+
'</div>' +
|
714
|
+
'<div class="dr-switcher dr-year-switcher">' +
|
715
|
+
'<i class="dr-left"></i>' +
|
716
|
+
'<span>2015</span>' +
|
717
|
+
'<i class="dr-right"></i>' +
|
718
|
+
'</div>' +
|
719
|
+
'</div>' +
|
720
|
+
ul_days_of_the_week[0].outerHTML +
|
721
|
+
'<ul class="dr-day-list"></ul>' +
|
722
|
+
'</div>' +
|
723
|
+
(this.presets ? this.presetCreate()[0].outerHTML : '') +
|
724
|
+
'</div>');
|
725
|
+
|
726
|
+
return this.element.append('<div class="dr-input">' +
|
727
|
+
'<div class="dr-dates">' +
|
728
|
+
'<div class="dr-date" contenteditable placeholder="' + this.placeholder + '">' + (this.settings.current_date ? moment(this.current_date).format(this.format.input) : '') + '</div>' +
|
729
|
+
'</div>' +
|
730
|
+
'</div>' +
|
731
|
+
|
732
|
+
'<div class="dr-selections">' +
|
733
|
+
'<div class="dr-calendar" style="display: none;">' +
|
734
|
+
'<div class="dr-range-switcher">' +
|
735
|
+
'<div class="dr-switcher dr-month-switcher">' +
|
736
|
+
'<i class="dr-left"></i>' +
|
737
|
+
'<span></span>' +
|
738
|
+
'<i class="dr-right"></i>' +
|
739
|
+
'</div>' +
|
740
|
+
'<div class="dr-switcher dr-year-switcher">' +
|
741
|
+
'<i class="dr-left"></i>' +
|
742
|
+
'<span></span>' +
|
743
|
+
'<i class="dr-right"></i>' +
|
744
|
+
'</div>' +
|
745
|
+
'</div>' +
|
746
|
+
ul_days_of_the_week[0].outerHTML +
|
747
|
+
'<ul class="dr-day-list"></ul>' +
|
748
|
+
'</div>' +
|
749
|
+
'</div>');
|
750
|
+
}
|
751
|
+
|
752
|
+
|
753
|
+
Calendar.prototype.parseDate = function(d) {
|
754
|
+
if (moment.defaultZone !== null && moment.hasOwnProperty('tz')) {
|
755
|
+
return moment.tz(d, this.format.input, moment.defaultZone.name);
|
756
|
+
} else {
|
757
|
+
return moment(d, this.format.input);
|
758
|
+
}
|
759
|
+
}
|
760
|
+
|
761
|
+
|
762
|
+
Calendar.prototype.range = function(length) {
|
763
|
+
var range = new Array(length);
|
764
|
+
|
765
|
+
for (var idx = 0; idx < length; idx++) {
|
766
|
+
range[idx] = idx;
|
767
|
+
}
|
768
|
+
|
769
|
+
return range;
|
770
|
+
}
|
771
|
+
|
772
|
+
function selectOneDate(other, cal, date) {
|
773
|
+
var string = moment(date).format(cal.format.input);
|
774
|
+
|
775
|
+
if (other) {
|
776
|
+
$('.dr-date', cal.element)
|
777
|
+
.not(cal.selected)
|
778
|
+
.html(other.format(cal.format.input));
|
779
|
+
}
|
780
|
+
|
781
|
+
$(cal.selected).html(string);
|
782
|
+
cal.calendarOpen(cal.selected);
|
783
|
+
|
784
|
+
if ($(cal.selected).hasClass('dr-date-start')) {
|
785
|
+
$('.dr-date-end', cal.element).trigger('click');
|
786
|
+
} else {
|
787
|
+
cal.calendarSaveDates();
|
788
|
+
cal.calendarClose('force');
|
789
|
+
}
|
790
|
+
}
|
791
|
+
|
792
|
+
|
793
|
+
return Calendar;
|
794
|
+
}));
|