fanforce-app-factory 0.40.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/fanforce-app-factory.gemspec +3 -3
  2. data/lib/fanforce/app_factory.rake +1 -17
  3. data/lib/fanforce/app_factory.rb +1 -5
  4. data/lib/fanforce/app_factory/_init_sinatra.rb +11 -4
  5. data/lib/fanforce/app_factory/assets/css/add_edit_initiative.scss +1 -0
  6. data/lib/fanforce/app_factory/assets/css/add_source.scss +1 -0
  7. data/lib/fanforce/app_factory/assets/css/convert_pending_initiative.scss +1 -0
  8. data/lib/fanforce/app_factory/assets/css/engage.scss +1 -0
  9. data/lib/fanforce/app_factory/assets/css/new_message.scss +1 -0
  10. data/lib/fanforce/app_factory/assets/css/source_details.scss +1 -0
  11. data/lib/fanforce/app_factory/assets/js/add_edit_initiative.js +1 -0
  12. data/lib/fanforce/app_factory/assets/js/add_source.js +1 -0
  13. data/lib/fanforce/app_factory/assets/js/add_source_popup.js +0 -0
  14. data/lib/fanforce/app_factory/assets/js/convert_pending_initiative.js +1 -0
  15. data/lib/fanforce/app_factory/assets/js/fanforce-engager.js +0 -0
  16. data/lib/fanforce/app_factory/assets/js/fanforce-finder.js +0 -0
  17. data/lib/fanforce/app_factory/assets/js/new_message.js +1 -0
  18. data/lib/fanforce/app_factory/assets/js/source_details.js +0 -0
  19. data/lib/fanforce/app_factory/assets/lib/common/_bootstrap-overrides.scss +16 -0
  20. data/lib/fanforce/app_factory/assets/lib/common/_mixins.scss +1 -1
  21. data/lib/fanforce/app_factory/assets/lib/common/_module-add-initiative-footer.scss +17 -0
  22. data/lib/fanforce/app_factory/assets/lib/common/_module-error.scss +11 -0
  23. data/lib/fanforce/app_factory/assets/lib/common/_module-initiative-searcher.scss +63 -0
  24. data/lib/fanforce/app_factory/assets/lib/common/_module-page-loading.scss +1 -0
  25. data/lib/fanforce/app_factory/assets/lib/common/_module-saving-initiative.scss +6 -0
  26. data/lib/fanforce/app_factory/assets/lib/common/_module-start-here.scss +6 -0
  27. data/lib/fanforce/app_factory/assets/lib/common/_module-video-thumbnail.scss +15 -0
  28. data/lib/fanforce/app_factory/assets/lib/common/_tags.scss +0 -82
  29. data/lib/fanforce/app_factory/assets/lib/common/_variables.scss +1 -1
  30. data/lib/fanforce/app_factory/assets/lib/common/broadcaster-divider-arrow.png +0 -0
  31. data/lib/fanforce/app_factory/assets/lib/common/layouts/_add_edit_initiative.scss +27 -0
  32. data/lib/fanforce/app_factory/assets/lib/common/layouts/_add_source.scss +18 -0
  33. data/lib/fanforce/app_factory/assets/lib/common/layouts/_convert_pending_initiative.scss +27 -0
  34. data/lib/fanforce/app_factory/assets/lib/common/layouts/_engage.scss +80 -0
  35. data/lib/fanforce/app_factory/assets/lib/common/layouts/_new_message.scss +24 -0
  36. data/lib/fanforce/app_factory/assets/lib/common/layouts/_source_details.scss +17 -0
  37. data/lib/fanforce/app_factory/assets/lib/common/layouts/add_edit_initiative.js +6 -0
  38. data/lib/fanforce/app_factory/assets/lib/common/layouts/add_source.js +6 -0
  39. data/lib/fanforce/app_factory/assets/lib/common/layouts/convert_pending_initiative.js +6 -0
  40. data/lib/fanforce/app_factory/assets/lib/common/layouts/engage.js +0 -0
  41. data/lib/fanforce/app_factory/assets/lib/common/layouts/new_message.js +5 -0
  42. data/lib/fanforce/app_factory/assets/lib/common/layouts/source_details.js +5 -0
  43. data/lib/fanforce/app_factory/assets/lib/common/module-error/arrow-left.png +0 -0
  44. data/lib/fanforce/app_factory/assets/lib/common/module-error/icon-error.png +0 -0
  45. data/lib/fanforce/app_factory/assets/lib/common/module-initiative-searcher/icon-search.png +0 -0
  46. data/lib/fanforce/app_factory/assets/lib/common/module-initiative-searcher/spinner.gif +0 -0
  47. data/lib/fanforce/app_factory/assets/lib/common/module-initiative-searcher/sprite-arrows.png +0 -0
  48. data/lib/fanforce/app_factory/assets/lib/common/module-saving-initiative/spinner.gif +0 -0
  49. data/lib/fanforce/app_factory/assets/lib/common/module-start-here/arrow.png +0 -0
  50. data/lib/fanforce/app_factory/assets/lib/common/module-video-thumbnail/icon-play.png +0 -0
  51. data/lib/fanforce/app_factory/assets/lib/vendors/bootstrap-datepicker/datepicker.css +7 -0
  52. data/lib/fanforce/app_factory/assets/lib/vendors/bootstrap-datepicker/datepicker.js +454 -0
  53. data/lib/fanforce/app_factory/assets/lib/vendors/bootstrap-timepicker/timepicker.css +82 -0
  54. data/lib/fanforce/app_factory/assets/lib/vendors/bootstrap-timepicker/timepicker.js +803 -0
  55. data/lib/fanforce/app_factory/assets/lib/vendors/chosen/_chosen_override.scss +6 -0
  56. data/lib/fanforce/app_factory/assets/lib/vendors/chosen/chosen-sprite@2x.png +0 -0
  57. data/lib/fanforce/app_factory/assets/lib/vendors/chosen/chosen.scss +2 -0
  58. data/lib/fanforce/app_factory/assets/lib/vendors/knockout/knockout.custom-handlers.coffee +4 -4
  59. data/lib/fanforce/app_factory/assets/lib/vendors/select2/_select2_override.scss +1 -1
  60. data/lib/fanforce/app_factory/assets/lib/vendors/select2/select2_modified.js +3 -0
  61. data/lib/fanforce/app_factory/config/core_config.rb +52 -8
  62. data/lib/fanforce/app_factory/config/helpers/fanforce.rb +17 -0
  63. data/lib/fanforce/app_factory/config/helpers/ractive.rb +27 -0
  64. data/lib/fanforce/app_factory/layouts/add_edit_initiative.haml +19 -0
  65. data/lib/fanforce/app_factory/layouts/add_source.haml +19 -0
  66. data/lib/fanforce/app_factory/layouts/convert_pending_initiative.haml +19 -0
  67. data/lib/fanforce/app_factory/layouts/engage.haml +38 -0
  68. data/lib/fanforce/app_factory/layouts/new_message.haml +19 -0
  69. data/lib/fanforce/app_factory/layouts/source_details.haml +19 -0
  70. data/lib/fanforce/app_factory/routes_behavior.rb +44 -0
  71. data/lib/fanforce/app_factory/routes_broadcaster.rb +9 -0
  72. data/lib/fanforce/app_factory/routes_connector.rb +21 -0
  73. data/lib/fanforce/app_factory/{routes.rb → routes_core.rb} +6 -6
  74. data/lib/fanforce/app_factory/routes_identifier.rb +3 -0
  75. data/lib/fanforce/app_factory/routes_js_widget.rb +10 -0
  76. data/lib/fanforce/app_factory/sprockets/compiler.rb +5 -0
  77. data/lib/fanforce/app_factory/version.rb +1 -1
  78. data/lib/fanforce/app_factory/views/add_initiative.haml +1 -0
  79. data/lib/fanforce/app_factory/views/add_source.haml +1 -0
  80. data/lib/fanforce/app_factory/views/close_popup.haml +8 -0
  81. data/lib/fanforce/app_factory/views/convert_pending_initiative.haml +1 -0
  82. data/lib/fanforce/app_factory/views/edit_initiative.haml +1 -0
  83. data/lib/fanforce/app_factory/views/engage.haml +1 -0
  84. data/lib/fanforce/app_factory/views/new_message.haml +1 -0
  85. data/lib/fanforce/app_factory/views/source_details.haml +1 -0
  86. data/lib/fanforce/app_factory/views/widget_templates.haml +1 -0
  87. metadata +82 -12
@@ -0,0 +1,27 @@
1
+ //////////////////////////////////////////////////////////////////////////////////////////////////
2
+ // COMPASS AND BOOTSTRAP
3
+ //////////////////////////////////////////////////////////////////////////////////////////////////
4
+ @import 'compass/css3';
5
+ @import 'compass/utilities';
6
+ @import 'vendors/bootstrap/css/bootstrap.min.css';
7
+ @import 'vendors/font-awesome/css/font-awesome.min.css';
8
+
9
+ //////////////////////////////////////////////////////////////////////////////////////////////////
10
+ // COMMON
11
+ //////////////////////////////////////////////////////////////////////////////////////////////////
12
+ @import 'common/mixins';
13
+ @import 'common/variables';
14
+ @import 'common/bootstrap-overrides';
15
+
16
+ @import 'common/module-page-loading';
17
+ @import 'common/module-saving-initiative';
18
+ @import 'common/module-add-initiative-footer';
19
+
20
+ //////////////////////////////////////////////////////////////////////////////////////////////////
21
+ // BASE STYLES (AS FEW AS POSSIBLE)
22
+ //////////////////////////////////////////////////////////////////////////////////////////////////
23
+
24
+ body { overflow:hidden; background: #F4F8FC;
25
+ .hide { display:none !important; }
26
+ .dropdown-menu { @include border-radius(4px); border:1px solid #aec7dd; @include box-shadow(1px 1px 3px rgba(0, 0, 0, 0.2), #ffffff 1px 1px 0 inset); background:#f7fafd; }
27
+ }
@@ -0,0 +1,80 @@
1
+ //////////////////////////////////////////////////////////////////////////////////////////////////
2
+ // FRAMEWORK: CORE VARIABLES & SASS RESET
3
+ //////////////////////////////////////////////////////////////////////////////////////////////////
4
+ //@import "compass/reset";
5
+ @import "common/variables";
6
+
7
+ //////////////////////////////////////////////////////////////////////////////////////////////////
8
+ // FRAMEWORK: SASS LIBRARY
9
+ //////////////////////////////////////////////////////////////////////////////////////////////////
10
+ @import "compass/css3";
11
+ @import "compass/layout/sticky-footer";
12
+ @import "compass/utilities";
13
+
14
+ //////////////////////////////////////////////////////////////////////////////////////////////////
15
+ // FRAMEWORK: COMMON FILES
16
+ //////////////////////////////////////////////////////////////////////////////////////////////////
17
+ @import "common/mixins";
18
+ @import "common/variables";
19
+
20
+ //////////////////////////////////////////////////////////////////////////////////////////////////
21
+ // COMMON TAGS
22
+ //////////////////////////////////////////////////////////////////////////////////////////////////
23
+
24
+ h1, .h1 { font-size: 30px; font-weight:bold; margin:10px 0; line-height:1em; }
25
+ h2, .h2 { font-size: 20px; font-weight:bold; margin:8px 0; line-height:1em; }
26
+ h3, .h3 { font-size: 17px; font-weight:bold; margin:6px 0; line-height:1em; }
27
+ h4, .h4 { font-size: 14px; font-weight:bold; margin:4px 0; line-height:1em; }
28
+ h5, .h5 { font-size: $font-size-large; font-weight: bold; margin:2px 0; line-height:1em; }
29
+ h6, .h6 { font-size: $font-size-normal; font-weight: bold; margin:2px 0; line-height:1em; }
30
+ h7, .h7 { font-size: $font-size-small; font-weight: bold; margin:2px 0; line-height:1em; }
31
+
32
+ p, .p { line-height:$line-height; margin-bottom:10px; }
33
+ a { text-decoration:none; color:$link-color;
34
+ &:hover { text-decoration:underline; }
35
+ }
36
+ strong, .strong { font-weight:bold; }
37
+ emphasis, .emphasis { font-style:italic; }
38
+
39
+ ul { list-style-type: square; list-style-position:outside; padding:0; margin-left:0; line-height:$line-height;
40
+ li { margin-top:5px; margin-left:1em; }
41
+ }
42
+
43
+ ol { list-style-type:decimal; list-style-position:outside; padding:0; margin-left:0; line-height:$line-height;
44
+ li { margin-top:5px; margin-left:1.5em; }
45
+ }
46
+
47
+ pre { font-family:"Courier New", Courier, monospace, sans-serif; color: #555; line-height: 1.6em; }
48
+
49
+ .hide { display:none !important; }
50
+
51
+ //////////////////////////////////////////////////////////////////////////////////////////////////
52
+ // FRAMEWORK: MODULE ACTIVATION
53
+ //////////////////////////////////////////////////////////////////////////////////////////////////
54
+ html { height:100%; }
55
+ body { height: 100%; background-color:#292a2e; @include ff-gradient(#26262a,#2b2d31); text-align:center; margin:0; font-family:$font-family; font-size:$font-size-normal; line-height:$line-height;
56
+ $content-width:content-width('engage');
57
+ @include sticky-footer(40px, ".lyt-root", ".lyt-root-footer", ".lyt-footer");
58
+
59
+ .lyt-root { @include ff-gradient(#26262a,#2b2d31); }
60
+ .lyt-header { min-height:80px;
61
+ .hello { background: #2d2d31; height:40px; line-height: 44px; text-align: right; border-bottom:1px solid #000000; @include box-shadow(#343438 0 1px 0);
62
+ .hello-wrapper { max-width: 960px; margin:0 auto; }
63
+ .greeting { color: #858789; font-style: italic; padding-right:10px; font-weight: 100; }
64
+ a { font-weight: bold; color: #aeb2b4; }
65
+ }
66
+ .logo { border-bottom:1px solid #000000; @include box-shadow(#343438 0 1px 0); background-position: center center; background-repeat:no-repeat;
67
+ img { margin-top:18px; }
68
+ }
69
+ }
70
+ .lyt-footer { color:#565d65; font-size:10px; line-height:40px; border-top:1px solid #343438; @include box-shadow(#000000 0 -1px 0);
71
+ a { color:#565d65;
72
+ &:hover { color:#747d88; }
73
+ }
74
+ }
75
+
76
+ // layout-specific components
77
+ .ff-widget { display:inline-block; @include box-shadow(#000000 2px 2px 2px); border:10px solid #ffffff; @include border-radius(3px); margin:50px 0 50px; color: #444444;
78
+ .loading { line-height: 100px; }
79
+ }
80
+ }
@@ -0,0 +1,24 @@
1
+ //////////////////////////////////////////////////////////////////////////////////////////////////
2
+ // COMPASS AND BOOTSTRAP
3
+ //////////////////////////////////////////////////////////////////////////////////////////////////
4
+ @import 'compass/css3';
5
+ @import 'compass/utilities';
6
+ @import 'vendors/bootstrap/css/bootstrap.min.css';
7
+
8
+ //////////////////////////////////////////////////////////////////////////////////////////////////
9
+ // COMMON
10
+ //////////////////////////////////////////////////////////////////////////////////////////////////
11
+ @import 'common/mixins';
12
+ @import 'common/variables';
13
+ @import 'common/bootstrap-overrides';
14
+
15
+ @import 'common/module-page-loading';
16
+
17
+ //////////////////////////////////////////////////////////////////////////////////////////////////
18
+ // BASE STYLES (AS FEW AS POSSIBLE)
19
+ //////////////////////////////////////////////////////////////////////////////////////////////////
20
+
21
+ body { overflow:hidden; background: #F4F8FC;
22
+ .hide { display:none !important; }
23
+ .dropdown-menu { @include border-radius(4px); border:1px solid #aec7dd; @include box-shadow(1px 1px 3px rgba(0, 0, 0, 0.2), #ffffff 1px 1px 0 inset); background:#f7fafd; }
24
+ }
@@ -0,0 +1,17 @@
1
+ //////////////////////////////////////////////////////////////////////////////////////////////////
2
+ // COMPASS AND BOOTSTRAP
3
+ //////////////////////////////////////////////////////////////////////////////////////////////////
4
+ @import 'compass/css3';
5
+ @import 'compass/utilities';
6
+ @import 'vendors/bootstrap/css/bootstrap.min.css';
7
+
8
+ //////////////////////////////////////////////////////////////////////////////////////////////////
9
+ // COMMON
10
+ //////////////////////////////////////////////////////////////////////////////////////////////////
11
+ @import 'common/mixins';
12
+ @import 'common/variables';
13
+ @import 'common/bootstrap-overrides';
14
+
15
+ //////////////////////////////////////////////////////////////////////////////////////////////////
16
+ // BASE STYLES (AS FEW AS POSSIBLE)
17
+ //////////////////////////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,6 @@
1
+ //= require vendors/jquery/jquery.tmpl.debug
2
+ //= require vendors/jquery/jquery.inputHint
3
+ //= require vendors/bootstrap/js/bootstrap.min
4
+ //= require vendors/knockout/knockout.min
5
+ //= require vendors/knockout/knockout.custom-handlers
6
+ //= require vendors/underscore/underscore.debug
@@ -0,0 +1,6 @@
1
+ //= require vendors/jquery/jquery.tmpl.debug
2
+ //= require vendors/jquery/jquery.inputHint
3
+ //= require vendors/bootstrap/js/bootstrap.min
4
+ //= require vendors/knockout/knockout.min
5
+ //= require vendors/knockout/knockout.custom-handlers
6
+ //= require vendors/underscore/underscore.debug
@@ -0,0 +1,6 @@
1
+ //= require vendors/jquery/jquery.tmpl.debug
2
+ //= require vendors/jquery/jquery.inputHint
3
+ //= require vendors/bootstrap/js/bootstrap.min
4
+ //= require vendors/knockout/knockout.min
5
+ //= require vendors/knockout/knockout.custom-handlers
6
+ //= require vendors/underscore/underscore.debug
@@ -0,0 +1,5 @@
1
+ //= require vendors/bootstrap/js/bootstrap.min
2
+ //= require vendors/jquery/jquery.tmpl.debug
3
+ //= require vendors/jquery/jquery.inputHint
4
+ //= require vendors/knockout/knockout.min
5
+ //= require vendors/knockout/knockout.custom-handlers
@@ -0,0 +1,5 @@
1
+ //= require vendors/bootstrap/js/bootstrap.min
2
+ //= require vendors/jquery/jquery.tmpl.debug
3
+ //= require vendors/jquery/jquery.inputHint
4
+ //= require vendors/knockout/knockout.min
5
+ //= require vendors/knockout/knockout.custom-handlers
@@ -0,0 +1,7 @@
1
+ /*
2
+ Datepicker for Bootstrap
3
+ Copyright 2012 Stefan Petre
4
+ Licensed under the Apache License v2.0
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+ */
7
+ .datepicker { top: 0; left: 0; padding: 4px; margin-top: 1px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; /*.dow { border-top: 1px solid #ddd !important; }*/ } .datepicker:before { content: ''; display: inline-block; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 7px solid #ccc; border-bottom-color: rgba(0, 0, 0, 0.2); position: absolute; top: -7px; left: 6px; } .datepicker:after { content: ''; display: inline-block; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 6px solid #ffffff; position: absolute; top: -6px; left: 7px; } .datepicker > div { display: none; } .datepicker table { width: 100%; margin: 0; } .datepicker td, .datepicker th { text-align: center; width: 20px; height: 20px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .datepicker td.day:hover { background: #eeeeee; cursor: pointer; } .datepicker td.old, .datepicker td.new { color: #999999; } .datepicker td.active, .datepicker td.active:hover { background-color: #006dcc; background-image: -moz-linear-gradient(top, #0088cc, #0044cc); background-image: -ms-linear-gradient(top, #0088cc, #0044cc); background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc)); background-image: -webkit-linear-gradient(top, #0088cc, #0044cc); background-image: -o-linear-gradient(top, #0088cc, #0044cc); background-image: linear-gradient(top, #0088cc, #0044cc); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0); border-color: #0044cc #0044cc #002a80; border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); color: #fff; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); } .datepicker td.active:hover, .datepicker td.active:hover:hover, .datepicker td.active:active, .datepicker td.active:hover:active, .datepicker td.active.active, .datepicker td.active:hover.active, .datepicker td.active.disabled, .datepicker td.active:hover.disabled, .datepicker td.active[disabled], .datepicker td.active:hover[disabled] { background-color: #0044cc; } .datepicker td.active:active, .datepicker td.active:hover:active, .datepicker td.active.active, .datepicker td.active:hover.active { background-color: #003399 \9; } .datepicker td span { display: block; width: 47px; height: 54px; line-height: 54px; float: left; margin: 2px; cursor: pointer; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } .datepicker td span:hover { background: #eeeeee; } .datepicker td span.active { background-color: #006dcc; background-image: -moz-linear-gradient(top, #0088cc, #0044cc); background-image: -ms-linear-gradient(top, #0088cc, #0044cc); background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc)); background-image: -webkit-linear-gradient(top, #0088cc, #0044cc); background-image: -o-linear-gradient(top, #0088cc, #0044cc); background-image: linear-gradient(top, #0088cc, #0044cc); background-repeat: repeat-x; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0); border-color: #0044cc #0044cc #002a80; border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); color: #fff; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); } .datepicker td span.active:hover, .datepicker td span.active:active, .datepicker td span.active.active, .datepicker td span.active.disabled, .datepicker td span.active[disabled] { background-color: #0044cc; } .datepicker td span.active:active, .datepicker td span.active.active { background-color: #003399 \9; } .datepicker td span.old { color: #999999; } .datepicker th.switch { width: 145px; } .datepicker th.next, .datepicker th.prev { font-size: 19.5px; } .datepicker thead tr:first-child th { cursor: pointer; } .datepicker thead tr:first-child th:hover { background: #eeeeee; } .input-append.date .add-on i, .input-prepend.date .add-on i { display: block; cursor: pointer; width: 16px; height: 16px; }
@@ -0,0 +1,454 @@
1
+ /* =========================================================
2
+ * bootstrap-datepicker.js
3
+ * http://www.eyecon.ro/bootstrap-datepicker
4
+ * =========================================================
5
+ * Copyright 2012 Stefan Petre
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================= */
19
+
20
+ !function( $ ) {
21
+
22
+ // Picker object
23
+
24
+ var Datepicker = function(element, options){
25
+ this.element = $(element);
26
+ this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
27
+ this.picker = $(DPGlobal.template)
28
+ .appendTo('body')
29
+ .on({
30
+ click: $.proxy(this.click, this),
31
+ mousedown: $.proxy(this.mousedown, this)
32
+ });
33
+ this.isInput = this.element.is('input');
34
+ this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
35
+
36
+ if (this.isInput) {
37
+ this.element.on({
38
+ focus: $.proxy(this.show, this),
39
+ blur: $.proxy(this.hide, this),
40
+ keyup: $.proxy(this.update, this)
41
+ });
42
+ } else {
43
+ if (this.component){
44
+ this.component.on('click', $.proxy(this.show, this));
45
+ } else {
46
+ this.element.on('click', $.proxy(this.show, this));
47
+ }
48
+ }
49
+ this.minViewMode = options.minViewMode||this.element.data('date-minviewmode')||0;
50
+ if (typeof this.minViewMode === 'string') {
51
+ switch (this.minViewMode) {
52
+ case 'months':
53
+ this.minViewMode = 1;
54
+ break;
55
+ case 'years':
56
+ this.minViewMode = 2;
57
+ break;
58
+ default:
59
+ this.minViewMode = 0;
60
+ break;
61
+ }
62
+ }
63
+ this.viewMode = options.viewMode||this.element.data('date-viewmode')||0;
64
+ if (typeof this.viewMode === 'string') {
65
+ switch (this.viewMode) {
66
+ case 'months':
67
+ this.viewMode = 1;
68
+ break;
69
+ case 'years':
70
+ this.viewMode = 2;
71
+ break;
72
+ default:
73
+ this.viewMode = 0;
74
+ break;
75
+ }
76
+ }
77
+ this.startViewMode = this.viewMode;
78
+ this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
79
+ this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
80
+ this.fillDow();
81
+ this.fillMonths();
82
+ this.update();
83
+ this.showMode();
84
+ };
85
+
86
+ Datepicker.prototype = {
87
+ constructor: Datepicker,
88
+
89
+ show: function(e) {
90
+ this.picker.show();
91
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
92
+ this.place();
93
+ $(window).on('resize', $.proxy(this.place, this));
94
+ if (e ) {
95
+ e.stopPropagation();
96
+ e.preventDefault();
97
+ }
98
+ if (!this.isInput) {
99
+ $(document).on('mousedown', $.proxy(this.hide, this));
100
+ }
101
+ this.element.trigger({
102
+ type: 'show',
103
+ date: this.date
104
+ });
105
+ },
106
+
107
+ hide: function(){
108
+ this.picker.hide();
109
+ $(window).off('resize', this.place);
110
+ this.viewMode = this.startViewMode;
111
+ this.showMode();
112
+ if (!this.isInput) {
113
+ $(document).off('mousedown', this.hide);
114
+ }
115
+ this.set();
116
+ this.element.trigger({
117
+ type: 'hide',
118
+ date: this.date
119
+ });
120
+ },
121
+
122
+ set: function() {
123
+ var formated = DPGlobal.formatDate(this.date, this.format);
124
+ if (!this.isInput) {
125
+ if (this.component){
126
+ this.element.find('input').prop('value', formated);
127
+ }
128
+ this.element.data('date', formated);
129
+ } else {
130
+ this.element.prop('value', formated);
131
+ }
132
+ },
133
+
134
+ setValue: function(newDate) {
135
+ if (typeof newDate === 'string') {
136
+ this.date = DPGlobal.parseDate(newDate, this.format);
137
+ } else {
138
+ this.date = new Date(newDate);
139
+ }
140
+ this.set();
141
+ this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
142
+ this.fill();
143
+ },
144
+
145
+ place: function(){
146
+ var offset = this.component ? this.component.offset() : this.element.offset();
147
+ this.picker.css({
148
+ top: offset.top + this.height,
149
+ left: offset.left
150
+ });
151
+ },
152
+
153
+ update: function(newDate){
154
+ this.date = DPGlobal.parseDate(
155
+ typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date')),
156
+ this.format
157
+ );
158
+ this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
159
+ this.fill();
160
+ },
161
+
162
+ fillDow: function(){
163
+ var dowCnt = this.weekStart;
164
+ var html = '<tr>';
165
+ while (dowCnt < this.weekStart + 7) {
166
+ html += '<th class="dow">'+DPGlobal.dates.daysMin[(dowCnt++)%7]+'</th>';
167
+ }
168
+ html += '</tr>';
169
+ this.picker.find('.datepicker-days thead').append(html);
170
+ },
171
+
172
+ fillMonths: function(){
173
+ var html = '';
174
+ var i = 0
175
+ while (i < 12) {
176
+ html += '<span class="month">'+DPGlobal.dates.monthsShort[i++]+'</span>';
177
+ }
178
+ this.picker.find('.datepicker-months td').append(html);
179
+ },
180
+
181
+ fill: function() {
182
+ var d = new Date(this.viewDate),
183
+ year = d.getFullYear(),
184
+ month = d.getMonth(),
185
+ currentDate = this.date.valueOf();
186
+ this.picker.find('.datepicker-days th:eq(1)')
187
+ .text(DPGlobal.dates.months[month]+' '+year);
188
+ var prevMonth = new Date(year, month-1, 28,0,0,0,0),
189
+ day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
190
+ prevMonth.setDate(day);
191
+ prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
192
+ var nextMonth = new Date(prevMonth);
193
+ nextMonth.setDate(nextMonth.getDate() + 42);
194
+ nextMonth = nextMonth.valueOf();
195
+ html = [];
196
+ var clsName;
197
+ while(prevMonth.valueOf() < nextMonth) {
198
+ if (prevMonth.getDay() === this.weekStart) {
199
+ html.push('<tr>');
200
+ }
201
+ clsName = '';
202
+ if (prevMonth.getMonth() < month) {
203
+ clsName += ' old';
204
+ } else if (prevMonth.getMonth() > month) {
205
+ clsName += ' new';
206
+ }
207
+ if (prevMonth.valueOf() === currentDate) {
208
+ clsName += ' active';
209
+ }
210
+ html.push('<td class="day'+clsName+'">'+prevMonth.getDate() + '</td>');
211
+ if (prevMonth.getDay() === this.weekEnd) {
212
+ html.push('</tr>');
213
+ }
214
+ prevMonth.setDate(prevMonth.getDate()+1);
215
+ }
216
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
217
+ var currentYear = this.date.getFullYear();
218
+
219
+ var months = this.picker.find('.datepicker-months')
220
+ .find('th:eq(1)')
221
+ .text(year)
222
+ .end()
223
+ .find('span').removeClass('active');
224
+ if (currentYear === year) {
225
+ months.eq(this.date.getMonth()).addClass('active');
226
+ }
227
+
228
+ html = '';
229
+ year = parseInt(year/10, 10) * 10;
230
+ var yearCont = this.picker.find('.datepicker-years')
231
+ .find('th:eq(1)')
232
+ .text(year + '-' + (year + 9))
233
+ .end()
234
+ .find('td');
235
+ year -= 1;
236
+ for (var i = -1; i < 11; i++) {
237
+ html += '<span class="year'+(i === -1 || i === 10 ? ' old' : '')+(currentYear === year ? ' active' : '')+'">'+year+'</span>';
238
+ year += 1;
239
+ }
240
+ yearCont.html(html);
241
+ },
242
+
243
+ click: function(e) {
244
+ e.stopPropagation();
245
+ e.preventDefault();
246
+ var target = $(e.target).closest('span, td, th');
247
+ if (target.length === 1) {
248
+ switch(target[0].nodeName.toLowerCase()) {
249
+ case 'th':
250
+ switch(target[0].className) {
251
+ case 'switch':
252
+ this.showMode(1);
253
+ break;
254
+ case 'prev':
255
+ case 'next':
256
+ this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
257
+ this.viewDate,
258
+ this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
259
+ DPGlobal.modes[this.viewMode].navStep * (target[0].className === 'prev' ? -1 : 1)
260
+ );
261
+ this.fill();
262
+ this.set();
263
+ break;
264
+ }
265
+ break;
266
+ case 'span':
267
+ if (target.is('.month')) {
268
+ var month = target.parent().find('span').index(target);
269
+ this.viewDate.setMonth(month);
270
+ } else {
271
+ var year = parseInt(target.text(), 10)||0;
272
+ this.viewDate.setFullYear(year);
273
+ }
274
+ if (this.viewMode !== 0) {
275
+ this.date = new Date(this.viewDate);
276
+ this.element.trigger({
277
+ type: 'changeDate',
278
+ date: this.date,
279
+ viewMode: DPGlobal.modes[this.viewMode].clsName
280
+ });
281
+ }
282
+ this.showMode(-1);
283
+ this.fill();
284
+ this.set();
285
+ break;
286
+ case 'td':
287
+ if (target.is('.day')){
288
+ var day = parseInt(target.text(), 10)||1;
289
+ var month = this.viewDate.getMonth();
290
+ if (target.is('.old')) {
291
+ month -= 1;
292
+ } else if (target.is('.new')) {
293
+ month += 1;
294
+ }
295
+ var year = this.viewDate.getFullYear();
296
+ this.date = new Date(year, month, day,0,0,0,0);
297
+ this.viewDate = new Date(year, month, Math.min(28, day),0,0,0,0);
298
+ this.fill();
299
+ this.set();
300
+ this.element.trigger({
301
+ type: 'changeDate',
302
+ date: this.date,
303
+ viewMode: DPGlobal.modes[this.viewMode].clsName
304
+ });
305
+ }
306
+ break;
307
+ }
308
+ }
309
+ },
310
+
311
+ mousedown: function(e){
312
+ e.stopPropagation();
313
+ e.preventDefault();
314
+ },
315
+
316
+ showMode: function(dir) {
317
+ if (dir) {
318
+ this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
319
+ }
320
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
321
+ }
322
+ };
323
+
324
+ $.fn.datepicker = function ( option, val ) {
325
+ return this.each(function () {
326
+ var $this = $(this),
327
+ data = $this.data('datepicker'),
328
+ options = typeof option === 'object' && option;
329
+ if (!data) {
330
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
331
+ }
332
+ if (typeof option === 'string') data[option](val);
333
+ });
334
+ };
335
+
336
+ $.fn.datepicker.defaults = {
337
+ };
338
+ $.fn.datepicker.Constructor = Datepicker;
339
+
340
+ var DPGlobal = {
341
+ modes: [
342
+ {
343
+ clsName: 'days',
344
+ navFnc: 'Month',
345
+ navStep: 1
346
+ },
347
+ {
348
+ clsName: 'months',
349
+ navFnc: 'FullYear',
350
+ navStep: 1
351
+ },
352
+ {
353
+ clsName: 'years',
354
+ navFnc: 'FullYear',
355
+ navStep: 10
356
+ }],
357
+ dates:{
358
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
359
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
360
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
361
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
362
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
363
+ },
364
+ isLeapYear: function (year) {
365
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
366
+ },
367
+ getDaysInMonth: function (year, month) {
368
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
369
+ },
370
+ parseFormat: function(format){
371
+ var separator = format.match(/[.\/\-\s].*?/),
372
+ parts = format.split(/\W+/);
373
+ if (!separator || !parts || parts.length === 0){
374
+ throw new Error("Invalid date format.");
375
+ }
376
+ return {separator: separator, parts: parts};
377
+ },
378
+ parseDate: function(date, format) {
379
+ var parts = date.split(format.separator),
380
+ date = new Date(),
381
+ val;
382
+ date.setHours(0);
383
+ date.setMinutes(0);
384
+ date.setSeconds(0);
385
+ date.setMilliseconds(0);
386
+ if (parts.length === format.parts.length) {
387
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
388
+ val = parseInt(parts[i], 10)||1;
389
+ switch(format.parts[i]) {
390
+ case 'dd':
391
+ case 'd':
392
+ date.setDate(val);
393
+ break;
394
+ case 'mm':
395
+ case 'm':
396
+ date.setMonth(val - 1);
397
+ break;
398
+ case 'yy':
399
+ date.setFullYear(2000 + val);
400
+ break;
401
+ case 'yyyy':
402
+ date.setFullYear(val);
403
+ break;
404
+ }
405
+ }
406
+ }
407
+ return date;
408
+ },
409
+ formatDate: function(date, format){
410
+ var val = {
411
+ d: date.getDate(),
412
+ m: date.getMonth() + 1,
413
+ yy: date.getFullYear().toString().substring(2),
414
+ yyyy: date.getFullYear()
415
+ };
416
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
417
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
418
+ var date = [];
419
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
420
+ date.push(val[format.parts[i]]);
421
+ }
422
+ return date.join(format.separator);
423
+ },
424
+ headTemplate: '<thead>'+
425
+ '<tr>'+
426
+ '<th class="prev">&lsaquo;</th>'+
427
+ '<th colspan="5" class="switch"></th>'+
428
+ '<th class="next">&rsaquo;</th>'+
429
+ '</tr>'+
430
+ '</thead>',
431
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
432
+ };
433
+ DPGlobal.template = '<div class="datepicker dropdown-menu">'+
434
+ '<div class="datepicker-days">'+
435
+ '<table class=" table-condensed">'+
436
+ DPGlobal.headTemplate+
437
+ '<tbody></tbody>'+
438
+ '</table>'+
439
+ '</div>'+
440
+ '<div class="datepicker-months">'+
441
+ '<table class="table-condensed">'+
442
+ DPGlobal.headTemplate+
443
+ DPGlobal.contTemplate+
444
+ '</table>'+
445
+ '</div>'+
446
+ '<div class="datepicker-years">'+
447
+ '<table class="table-condensed">'+
448
+ DPGlobal.headTemplate+
449
+ DPGlobal.contTemplate+
450
+ '</table>'+
451
+ '</div>'+
452
+ '</div>';
453
+
454
+ }( window.jQuery )