fanforce-plugin-factory 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +21 -0
  3. data/Gemfile +2 -0
  4. data/README.md +218 -0
  5. data/Rakefile +16 -0
  6. data/fanforce-plugin-factory.gemspec +42 -0
  7. data/lib/fanforce/plugin_factory.rake +71 -0
  8. data/lib/fanforce/plugin_factory.rb +60 -0
  9. data/lib/fanforce/plugin_factory/_init_sinatra.rb +53 -0
  10. data/lib/fanforce/plugin_factory/assets/css/add_edit_initiative.scss +1 -0
  11. data/lib/fanforce/plugin_factory/assets/css/add_source.scss +1 -0
  12. data/lib/fanforce/plugin_factory/assets/css/engage.scss +1 -0
  13. data/lib/fanforce/plugin_factory/assets/css/new_message.scss +1 -0
  14. data/lib/fanforce/plugin_factory/assets/css/promotional.scss +1 -0
  15. data/lib/fanforce/plugin_factory/assets/css/source_details.scss +1 -0
  16. data/lib/fanforce/plugin_factory/assets/img/icon-16.png +0 -0
  17. data/lib/fanforce/plugin_factory/assets/img/icon-32.png +0 -0
  18. data/lib/fanforce/plugin_factory/assets/img/icon-42.png +0 -0
  19. data/lib/fanforce/plugin_factory/assets/js/add_edit_initiative.js +1 -0
  20. data/lib/fanforce/plugin_factory/assets/js/add_source.js +1 -0
  21. data/lib/fanforce/plugin_factory/assets/js/add_source_popup.js +0 -0
  22. data/lib/fanforce/plugin_factory/assets/js/engage.js +1 -0
  23. data/lib/fanforce/plugin_factory/assets/js/new_message.js +1 -0
  24. data/lib/fanforce/plugin_factory/assets/js/promotional.js +2 -0
  25. data/lib/fanforce/plugin_factory/assets/js/source_details.js +0 -0
  26. data/lib/fanforce/plugin_factory/assets/lib/common/_mixins.scss +97 -0
  27. data/lib/fanforce/plugin_factory/assets/lib/common/_module-error.scss +11 -0
  28. data/lib/fanforce/plugin_factory/assets/lib/common/_module-search-to-add-initiative.scss +66 -0
  29. data/lib/fanforce/plugin_factory/assets/lib/common/_module-video-thumbnail.scss +15 -0
  30. data/lib/fanforce/plugin_factory/assets/lib/common/_tags.scss +83 -0
  31. data/lib/fanforce/plugin_factory/assets/lib/common/_variables.scss +27 -0
  32. data/lib/fanforce/plugin_factory/assets/lib/common/broadcaster-divider-arrow.png +0 -0
  33. data/lib/fanforce/plugin_factory/assets/lib/common/icons/dropdown-arrow.png +0 -0
  34. data/lib/fanforce/plugin_factory/assets/lib/common/icons/initiative.png +0 -0
  35. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_add_edit_initiative.scss +23 -0
  36. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_add_source.scss +17 -0
  37. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_engage.scss +39 -0
  38. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_new_message.scss +26 -0
  39. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_promotional.scss +26 -0
  40. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/_source_details.scss +16 -0
  41. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/add_edit_initiative.js +6 -0
  42. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/add_source.js +6 -0
  43. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/engage.js +0 -0
  44. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/new_message.js +5 -0
  45. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/promotional.js +1 -0
  46. data/lib/fanforce/plugin_factory/assets/lib/common/layouts/source_details.js +5 -0
  47. data/lib/fanforce/plugin_factory/assets/lib/common/module-error/arrow-left.png +0 -0
  48. data/lib/fanforce/plugin_factory/assets/lib/common/module-error/icon-error.png +0 -0
  49. data/lib/fanforce/plugin_factory/assets/lib/common/module-search-to-add-initiative/icon-search.png +0 -0
  50. data/lib/fanforce/plugin_factory/assets/lib/common/module-search-to-add-initiative/spinner.gif +0 -0
  51. data/lib/fanforce/plugin_factory/assets/lib/common/module-search-to-add-initiative/sprite-arrows.png +0 -0
  52. data/lib/fanforce/plugin_factory/assets/lib/common/module-video-thumbnail/icon-play.png +0 -0
  53. data/lib/fanforce/plugin_factory/assets/lib/promotional/fanforce_bg.png +0 -0
  54. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-42.png +0 -0
  55. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-behavior.png +0 -0
  56. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-broadcaster.png +0 -0
  57. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-data-connector.png +0 -0
  58. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-data-processor.png +0 -0
  59. data/lib/fanforce/plugin_factory/assets/lib/promotional/icon-identifier.png +0 -0
  60. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-datepicker/datepicker.css +7 -0
  61. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-datepicker/datepicker.js +454 -0
  62. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-timepicker/timepicker.css +82 -0
  63. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap-timepicker/timepicker.js +803 -0
  64. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/css/bootstrap.css +6103 -0
  65. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/css/bootstrap.min.css +868 -0
  66. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/img/glyphicons-halflings-white.png +0 -0
  67. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/img/glyphicons-halflings.png +0 -0
  68. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/js/bootstrap.js +2170 -0
  69. data/lib/fanforce/plugin_factory/assets/lib/vendors/bootstrap/js/bootstrap.min.js +7 -0
  70. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen-sprite.png +0 -0
  71. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen.jquery.min.js +10 -0
  72. data/lib/fanforce/plugin_factory/assets/lib/vendors/chosen/chosen.scss +399 -0
  73. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/css/font-awesome.css +540 -0
  74. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/css/font-awesome.min.css +33 -0
  75. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/font/FontAwesome.otf +0 -0
  76. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/font/fontawesome-webfont.eot +0 -0
  77. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/font/fontawesome-webfont.svg +284 -0
  78. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/font/fontawesome-webfont.ttf +0 -0
  79. data/lib/fanforce/plugin_factory/assets/lib/vendors/font-awesome/font/fontawesome-webfont.woff +0 -0
  80. data/lib/fanforce/plugin_factory/assets/lib/vendors/jquery/jquery.inputHint.js +154 -0
  81. data/lib/fanforce/plugin_factory/assets/lib/vendors/jquery/jquery.tmpl.debug.js +484 -0
  82. data/lib/fanforce/plugin_factory/assets/lib/vendors/knockout/knockout.custom-handlers.coffee +131 -0
  83. data/lib/fanforce/plugin_factory/assets/lib/vendors/knockout/knockout.debug.js +3223 -0
  84. data/lib/fanforce/plugin_factory/assets/lib/vendors/underscore/underscore.debug.js +999 -0
  85. data/lib/fanforce/plugin_factory/config/_error_handling.rb +26 -0
  86. data/lib/fanforce/plugin_factory/config/helpers/assets.rb +23 -0
  87. data/lib/fanforce/plugin_factory/config/helpers/fanforce.rb +21 -0
  88. data/lib/fanforce/plugin_factory/config/helpers/json.rb +10 -0
  89. data/lib/fanforce/plugin_factory/config/sinatra_config.rb +65 -0
  90. data/lib/fanforce/plugin_factory/initializers/ff_globals.rb +72 -0
  91. data/lib/fanforce/plugin_factory/layouts/add_edit_initiative.haml +14 -0
  92. data/lib/fanforce/plugin_factory/layouts/add_source.haml +14 -0
  93. data/lib/fanforce/plugin_factory/layouts/engage.haml +27 -0
  94. data/lib/fanforce/plugin_factory/layouts/new_message.haml +14 -0
  95. data/lib/fanforce/plugin_factory/layouts/promotional.haml +14 -0
  96. data/lib/fanforce/plugin_factory/layouts/source_details.haml +14 -0
  97. data/lib/fanforce/plugin_factory/public/favicon.ico +0 -0
  98. data/lib/fanforce/plugin_factory/routes.rb +35 -0
  99. data/lib/fanforce/plugin_factory/routes_behavior.rb +28 -0
  100. data/lib/fanforce/plugin_factory/routes_broadcaster.rb +9 -0
  101. data/lib/fanforce/plugin_factory/routes_data_connector.rb +21 -0
  102. data/lib/fanforce/plugin_factory/sprockets/compiler.rb +107 -0
  103. data/lib/fanforce/plugin_factory/sprockets/hacks.rb +43 -0
  104. data/lib/fanforce/plugin_factory/version.rb +5 -0
  105. data/lib/fanforce/plugin_factory/views/add_initiative.haml +1 -0
  106. data/lib/fanforce/plugin_factory/views/add_source.haml +1 -0
  107. data/lib/fanforce/plugin_factory/views/close_popup.haml +8 -0
  108. data/lib/fanforce/plugin_factory/views/edit_initiative.haml +1 -0
  109. data/lib/fanforce/plugin_factory/views/engage.haml +1 -0
  110. data/lib/fanforce/plugin_factory/views/index.haml +38 -0
  111. data/lib/fanforce/plugin_factory/views/new_message.haml +1 -0
  112. data/lib/fanforce/plugin_factory/views/source_details.haml +1 -0
  113. data/lib/fanforce/plugin_factory/views/widget_tmpls.haml +1 -0
  114. data/lib/fanforce/plugin_factory_workers.rb +1 -0
  115. metadata +436 -0
@@ -0,0 +1,39 @@
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/tags";
19
+
20
+ //////////////////////////////////////////////////////////////////////////////////////////////////
21
+ // FRAMEWORK: MODULE ACTIVATION
22
+ //////////////////////////////////////////////////////////////////////////////////////////////////
23
+ body { background-color:#292a2e; @include ff-gradient(#26262a,#2b2d31); text-align:center;
24
+ $content-width:content-width('engage');
25
+ @include sticky-footer(40px, ".lyt-root", ".lyt-root-footer", ".lyt-footer");
26
+
27
+ .lyt-root { @include ff-gradient(#26262a,#2b2d31); }
28
+ .lyt-header { height:100px; border-bottom:1px solid #000000; @include box-shadow(#343438 0 1px 0); background-position: center center; background-repeat:no-repeat;
29
+ img.logo { margin-top:18px; }
30
+ }
31
+ .lyt-footer { color:#565d65; font-size:10px; line-height:40px; border-top:1px solid #343438; @include box-shadow(#000000 0 -1px 0);
32
+ a { color:#565d65;
33
+ &:hover { color:#747d88; }
34
+ }
35
+ }
36
+
37
+ // layout-specific components
38
+ .widget { display:inline-block; @include box-shadow(#000000 2px 2px 2px); border:10px solid #ffffff; @include border-radius(3px); margin:50px 0 50px; }
39
+ }
@@ -0,0 +1,26 @@
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
+
14
+ //////////////////////////////////////////////////////////////////////////////////////////////////
15
+ // BASE STYLES (AS FEW AS POSSIBLE)
16
+ //////////////////////////////////////////////////////////////////////////////////////////////////
17
+
18
+ body { overflow:hidden;
19
+
20
+ .hide { display:none !important; }
21
+
22
+ .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; }
23
+
24
+ .page-loading { color:#cccccc; font-size:15px; text-align: center; padding-top:45px; }
25
+
26
+ }
@@ -0,0 +1,26 @@
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
+
14
+ //////////////////////////////////////////////////////////////////////////////////////////////////
15
+
16
+ body { background:#f6f8fa url(/assets/promotional/fanforce_bg.png) fixed; text-align: center; text-shadow: #ffffff 1px 1px 0; }
17
+ .header-icons { padding: 85px 0 25px;
18
+ img { margin: 0 5px; }
19
+ }
20
+
21
+ .about-box { @include box-shadow(0 1px 0 #ffffff inset, 0 1px 0 #ffffff); margin:125px auto 50px; border-top: 1px solid #b8c6d3; border-bottom: 1px solid #b8c6d3; width: 80%; padding: 35px 0 35px 45px; overflow: hidden;
22
+ .about { width: 50%; @include box-sizing(border-box); padding-right:35px; min-width:300px; text-align: left; float:left; line-height:1.5em;
23
+ .fanforce {}
24
+ .developer {}
25
+ }
26
+ }
@@ -0,0 +1,16 @@
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
+
14
+ //////////////////////////////////////////////////////////////////////////////////////////////////
15
+ // BASE STYLES (AS FEW AS POSSIBLE)
16
+ //////////////////////////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,6 @@
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.debug
5
+ //= require vendors/knockout/knockout.custom-handlers
6
+ //= require vendors/underscore/underscore.debug
@@ -0,0 +1,6 @@
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.debug
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.debug
5
+ //= require vendors/knockout/knockout.custom-handlers
@@ -0,0 +1 @@
1
+ //= require vendors/bootstrap/js/bootstrap.min
@@ -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.debug
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 )