anjlab-widgets 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +13 -0
  3. data/LICENSE +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +2 -0
  6. data/anjlab-widgets.gemspec +23 -0
  7. data/lib/anjlab-widgets.rb +7 -0
  8. data/lib/anjlab-widgets/engine.rb +8 -0
  9. data/lib/anjlab-widgets/version.rb +5 -0
  10. data/spec/dummy/README.rdoc +261 -0
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +17 -0
  13. data/spec/dummy/app/assets/stylesheets/application.css.scss +3 -0
  14. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  15. data/spec/dummy/app/controllers/widgets_controller.rb +10 -0
  16. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  17. data/spec/dummy/app/mailers/.gitkeep +0 -0
  18. data/spec/dummy/app/models/.gitkeep +0 -0
  19. data/spec/dummy/app/views/layouts/application.html.erb +20 -0
  20. data/spec/dummy/app/views/widgets/all.html.erb +7 -0
  21. data/spec/dummy/app/views/widgets/datepicker.html.erb +5 -0
  22. data/spec/dummy/app/views/widgets/timepicker.html.erb +1 -0
  23. data/spec/dummy/config.ru +4 -0
  24. data/spec/dummy/config/application.rb +61 -0
  25. data/spec/dummy/config/boot.rb +10 -0
  26. data/spec/dummy/config/database.yml +25 -0
  27. data/spec/dummy/config/environment.rb +5 -0
  28. data/spec/dummy/config/environments/development.rb +37 -0
  29. data/spec/dummy/config/environments/production.rb +67 -0
  30. data/spec/dummy/config/environments/test.rb +37 -0
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/dummy/config/initializers/inflections.rb +15 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  34. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  35. data/spec/dummy/config/initializers/session_store.rb +8 -0
  36. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  37. data/spec/dummy/config/locales/en.yml +5 -0
  38. data/spec/dummy/config/routes.rb +7 -0
  39. data/spec/dummy/db/development.sqlite3 +0 -0
  40. data/spec/dummy/lib/assets/.gitkeep +0 -0
  41. data/spec/dummy/log/.gitkeep +0 -0
  42. data/spec/dummy/log/development.log +11308 -0
  43. data/spec/dummy/public/404.html +26 -0
  44. data/spec/dummy/public/422.html +26 -0
  45. data/spec/dummy/public/500.html +25 -0
  46. data/spec/dummy/public/favicon.ico +0 -0
  47. data/spec/dummy/script/rails +6 -0
  48. data/spec/spec_helper.rb +9 -0
  49. data/spec/views/widgets/datepicker_spec.rb +9 -0
  50. data/vendor/assets/javascripts/anjlab/datepicker.js.coffee +369 -0
  51. data/vendor/assets/javascripts/anjlab/timepicker.js.coffee +135 -0
  52. data/vendor/assets/stylesheets/anjlab/datepicker.css.scss +85 -0
  53. data/vendor/assets/stylesheets/anjlab/timepicker.css.scss +34 -0
  54. metadata +225 -0
@@ -0,0 +1,135 @@
1
+ TimeTools =
2
+
3
+ template: "<div class='timepicker dropdown-menu'><div class='times'></div></div>"
4
+
5
+ class Timepicker
6
+
7
+ constructor: (element, options)->
8
+ @element = $(element)
9
+ @picker = $(TimeTools.template).appendTo('body').on({
10
+ click: $.proxy(@click, this)
11
+ mousedown: $.proxy(@mousedown, this)
12
+ }, "a")
13
+
14
+ @element.on {
15
+ focus: $.proxy(@show, this)
16
+ blur: $.proxy(@hide, this)
17
+ keyup: $.proxy(@update, this)
18
+ }
19
+
20
+ @step = options.step || @element.data('date-time-step') || 30
21
+ @minTime = options.minTime || @element.data('date-time-min') || 9 * 60
22
+ @maxTime = options.maxTime || @element.data('date-time-max') || 20 * 60
23
+
24
+ @fillTimes()
25
+ @update()
26
+ @scrollPlaced = false
27
+
28
+ initialScroll: ->
29
+ return if @scrollPlaced
30
+ time = @picker.find('.active')
31
+ if time.length > 0
32
+ @picker.find('.times').scrollTop(time.position().top - time.height())
33
+ @scrollPlaced = true
34
+
35
+ click: (e)->
36
+ e.stopPropagation()
37
+ e.preventDefault()
38
+ target = $(e.target)
39
+
40
+ if target.is 'a'
41
+ @time = target.data('time')
42
+ @setValue()
43
+ @update()
44
+ @element.trigger {
45
+ type: 'changeDate'
46
+ date: @time
47
+ }
48
+
49
+ mousedown: (e)->
50
+ e.stopPropagation()
51
+ e.preventDefault()
52
+
53
+ update: ->
54
+ @time = this.element.val()
55
+ @picker.find('a.active').removeClass('active')
56
+ @picker.find("a[data-time='#{@time}']").addClass('active')
57
+
58
+ setValue: ->
59
+ @element.prop('value', @time)
60
+
61
+ fillTimes: ->
62
+ timeCnt = 0
63
+ html = []
64
+ while timeCnt < 24 * 60
65
+ mm = timeCnt % 60
66
+ hh = Math.floor(timeCnt / 60)
67
+ mm = (if mm < 10 then '0' else '') + mm
68
+ hh = (if hh < 10 then '0' else '') + hh
69
+ time = "#{hh}:#{mm}"
70
+ html.push "<a href='#' data-time='#{time}'"
71
+ html.push " class='night'" if timeCnt <= @minTime || timeCnt >= @maxTime
72
+ html.push ">"
73
+ html.push time
74
+ html.push "</a>"
75
+ timeCnt += @step
76
+
77
+ @picker.find('.times').append(html.join(''))
78
+
79
+ show: (e) ->
80
+ @picker.show()
81
+ @height = @element.outerHeight()
82
+ @place()
83
+ @initialScroll()
84
+ $(window).on('resize', $.proxy(@place, this))
85
+ if e
86
+ e.stopPropagation()
87
+ e.preventDefault()
88
+
89
+ @element.trigger {
90
+ type: 'show'
91
+ date: @time
92
+ }
93
+
94
+ place: ->
95
+ offset = @element.offset()
96
+ @picker.css {
97
+ top: offset.top + @height
98
+ left: offset.left
99
+ }
100
+
101
+ hide: ->
102
+ @picker.hide()
103
+ $(window).off 'resize', @place
104
+
105
+ @setValue()
106
+ @element.trigger {
107
+ type: 'hide'
108
+ date: @time
109
+ }
110
+
111
+ nativePicker = false
112
+
113
+ $.fn.timepicker = (option) ->
114
+ @each ->
115
+ $this = $(this)
116
+ if nativePicker
117
+ $this.prop("type", "time")
118
+ else
119
+ data = $this.data('timepicker')
120
+ options = typeof option == 'object' && option
121
+ if !data
122
+ $this.data('timepicker', (data = new Timepicker(this, $.extend({}, $.fn.timepicker.defaults,options))))
123
+ data[option]() if typeof option == 'string'
124
+
125
+ $.fn.timepicker.defaults = { }
126
+ $.fn.timepicker.Constructor = Timepicker
127
+
128
+ $ ->
129
+ input = document.createElement("input")
130
+ input.setAttribute("type", "time")
131
+ nativePicker = input.type == "time"
132
+
133
+ $("input[data-widget=timepicker]").timepicker()
134
+
135
+
@@ -0,0 +1,85 @@
1
+ .datepicker {
2
+ top: 0;
3
+ left: 0;
4
+ padding: 4px;
5
+ margin-top: 1px;
6
+ @include border-radius(4px);
7
+
8
+ >div {
9
+ display: none;
10
+ }
11
+ .datepicker-days,
12
+ .datepicker-months,
13
+ .datepicker-years {
14
+ display: block;
15
+ }
16
+
17
+ table{
18
+ width: 100%;
19
+ margin: 0;
20
+ }
21
+ td,
22
+ th {
23
+ text-align: center;
24
+ @include square(20px);
25
+ @include border-radius(4px);
26
+ }
27
+ td {
28
+ &.day:hover {
29
+ background: $grayLighter;
30
+ cursor: pointer;
31
+ }
32
+ &.old,
33
+ &.new {
34
+ color: $grayLight;
35
+ }
36
+ &.active,
37
+ &.active:hover {
38
+ @include button-background($btnPrimaryBackground, adjust-hue($btnPrimaryBackground, 20));
39
+ color: #fff;
40
+ text-shadow: 0 -1px 0 rgba(0,0,0,.25);
41
+ }
42
+ span {
43
+ display: block;
44
+ width: 47px;
45
+ height: 54px;
46
+ line-height: 54px;
47
+ float: left;
48
+ margin: 2px;
49
+ cursor: pointer;
50
+ @include border-radius(4px);
51
+ &:hover {
52
+ background: $grayLighter;
53
+ }
54
+ &.active {
55
+ @include button-background($btnPrimaryBackground, adjust-hue($btnPrimaryBackground, 20));
56
+ color: #fff;
57
+ text-shadow: 0 -1px 0 rgba(0,0,0,.25);
58
+ }
59
+ &.old {
60
+ color: $grayLight;
61
+ }
62
+ }
63
+ }
64
+
65
+ th.switch {
66
+ width: 145px;
67
+ }
68
+
69
+ thead tr:first-child th {
70
+ cursor: pointer;
71
+ &:hover {
72
+ background: $grayLighter;
73
+ }
74
+ }
75
+ }
76
+ .input-append,
77
+ .input-prepend {
78
+ &.date {
79
+ .add-on i {
80
+ display: block;
81
+ cursor: pointer;
82
+ @include square(16px);
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,34 @@
1
+ .timepicker {
2
+ top: 0;
3
+ left: 0;
4
+ padding: 4px;
5
+ margin-top: 1px;
6
+ @include border-radius(4px);
7
+ height:224px;
8
+ width:70px !important;
9
+ min-width:70px;
10
+
11
+ .times {
12
+ overflow: auto;
13
+ height: 224px;
14
+ }
15
+
16
+ a {
17
+ @include border-radius(4px);
18
+
19
+ &:hover {
20
+ background: $grayLighter;
21
+ cursor: pointer;
22
+ }
23
+ &.night {
24
+ color: $grayLight;
25
+ }
26
+ &.active,
27
+ &.active:hover {
28
+ @include button-background($btnPrimaryBackground, adjust-hue($btnPrimaryBackground, 20));
29
+ color: #fff;
30
+ text-shadow: 0 -1px 0 rgba(0,0,0,.25);
31
+ }
32
+ }
33
+
34
+ }
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anjlab-widgets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yury Korolev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: anjlab-bootstrap-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.9.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.9.0
94
+ description: Collection of UI widgets on top of anjlab-bootstrap-rails. Datepicker
95
+ and Timepicker for now.
96
+ email:
97
+ - yury.korolev@gmail.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - anjlab-widgets.gemspec
108
+ - lib/anjlab-widgets.rb
109
+ - lib/anjlab-widgets/engine.rb
110
+ - lib/anjlab-widgets/version.rb
111
+ - spec/dummy/README.rdoc
112
+ - spec/dummy/Rakefile
113
+ - spec/dummy/app/assets/javascripts/application.js
114
+ - spec/dummy/app/assets/stylesheets/application.css.scss
115
+ - spec/dummy/app/controllers/application_controller.rb
116
+ - spec/dummy/app/controllers/widgets_controller.rb
117
+ - spec/dummy/app/helpers/application_helper.rb
118
+ - spec/dummy/app/mailers/.gitkeep
119
+ - spec/dummy/app/models/.gitkeep
120
+ - spec/dummy/app/views/layouts/application.html.erb
121
+ - spec/dummy/app/views/widgets/all.html.erb
122
+ - spec/dummy/app/views/widgets/datepicker.html.erb
123
+ - spec/dummy/app/views/widgets/timepicker.html.erb
124
+ - spec/dummy/config.ru
125
+ - spec/dummy/config/application.rb
126
+ - spec/dummy/config/boot.rb
127
+ - spec/dummy/config/database.yml
128
+ - spec/dummy/config/environment.rb
129
+ - spec/dummy/config/environments/development.rb
130
+ - spec/dummy/config/environments/production.rb
131
+ - spec/dummy/config/environments/test.rb
132
+ - spec/dummy/config/initializers/backtrace_silencers.rb
133
+ - spec/dummy/config/initializers/inflections.rb
134
+ - spec/dummy/config/initializers/mime_types.rb
135
+ - spec/dummy/config/initializers/secret_token.rb
136
+ - spec/dummy/config/initializers/session_store.rb
137
+ - spec/dummy/config/initializers/wrap_parameters.rb
138
+ - spec/dummy/config/locales/en.yml
139
+ - spec/dummy/config/routes.rb
140
+ - spec/dummy/db/development.sqlite3
141
+ - spec/dummy/lib/assets/.gitkeep
142
+ - spec/dummy/log/.gitkeep
143
+ - spec/dummy/log/development.log
144
+ - spec/dummy/public/404.html
145
+ - spec/dummy/public/422.html
146
+ - spec/dummy/public/500.html
147
+ - spec/dummy/public/favicon.ico
148
+ - spec/dummy/script/rails
149
+ - spec/spec_helper.rb
150
+ - spec/views/widgets/datepicker_spec.rb
151
+ - vendor/assets/javascripts/anjlab/datepicker.js.coffee
152
+ - vendor/assets/javascripts/anjlab/timepicker.js.coffee
153
+ - vendor/assets/stylesheets/anjlab/datepicker.css.scss
154
+ - vendor/assets/stylesheets/anjlab/timepicker.css.scss
155
+ homepage: https://github.com/anjlab/anjlab-widgets
156
+ licenses: []
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ segments:
168
+ - 0
169
+ hash: 1507446788624259173
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ segments:
177
+ - 0
178
+ hash: 1507446788624259173
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 1.8.22
182
+ signing_key:
183
+ specification_version: 3
184
+ summary: Collection of UI widgets on top of anjlab-bootstrap-rails
185
+ test_files:
186
+ - spec/dummy/README.rdoc
187
+ - spec/dummy/Rakefile
188
+ - spec/dummy/app/assets/javascripts/application.js
189
+ - spec/dummy/app/assets/stylesheets/application.css.scss
190
+ - spec/dummy/app/controllers/application_controller.rb
191
+ - spec/dummy/app/controllers/widgets_controller.rb
192
+ - spec/dummy/app/helpers/application_helper.rb
193
+ - spec/dummy/app/mailers/.gitkeep
194
+ - spec/dummy/app/models/.gitkeep
195
+ - spec/dummy/app/views/layouts/application.html.erb
196
+ - spec/dummy/app/views/widgets/all.html.erb
197
+ - spec/dummy/app/views/widgets/datepicker.html.erb
198
+ - spec/dummy/app/views/widgets/timepicker.html.erb
199
+ - spec/dummy/config.ru
200
+ - spec/dummy/config/application.rb
201
+ - spec/dummy/config/boot.rb
202
+ - spec/dummy/config/database.yml
203
+ - spec/dummy/config/environment.rb
204
+ - spec/dummy/config/environments/development.rb
205
+ - spec/dummy/config/environments/production.rb
206
+ - spec/dummy/config/environments/test.rb
207
+ - spec/dummy/config/initializers/backtrace_silencers.rb
208
+ - spec/dummy/config/initializers/inflections.rb
209
+ - spec/dummy/config/initializers/mime_types.rb
210
+ - spec/dummy/config/initializers/secret_token.rb
211
+ - spec/dummy/config/initializers/session_store.rb
212
+ - spec/dummy/config/initializers/wrap_parameters.rb
213
+ - spec/dummy/config/locales/en.yml
214
+ - spec/dummy/config/routes.rb
215
+ - spec/dummy/db/development.sqlite3
216
+ - spec/dummy/lib/assets/.gitkeep
217
+ - spec/dummy/log/.gitkeep
218
+ - spec/dummy/log/development.log
219
+ - spec/dummy/public/404.html
220
+ - spec/dummy/public/422.html
221
+ - spec/dummy/public/500.html
222
+ - spec/dummy/public/favicon.ico
223
+ - spec/dummy/script/rails
224
+ - spec/spec_helper.rb
225
+ - spec/views/widgets/datepicker_spec.rb