jquery-time_duration_picker-rails 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6aaf09e25142aa2446a917c2d9f53809525a7acb
4
+ data.tar.gz: bcf7f9f1c9f541585589c2c4d18c2da52bc491b8
5
+ SHA512:
6
+ metadata.gz: 4322b13ee3ec41ed9c2433c575ad518c1bfe39af05f81e07721917e085920dc071a60e02b87bdf44a6145f0ccc08e38370598f3488c65fa1fab9a3aca1675905
7
+ data.tar.gz: 612078c55b80596f7388b656d600bb548b9a79cf121170ef635e554640b5b22a31ee9037d4c9646aa09dd87ec0b050d905b2ae99bc77b1fb52513a620cc7fa51
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-time_duration_picker-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # jQuery.timeDurationPicker Rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jquery-time_duration_picker-rails.svg)](https://badge.fury.io/rb/jquery-time_duration_picker-rails)
4
+
5
+ https://github.com/digaev/jQuery-timeDurationPicker
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jquery-time_duration_picker-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jquery-time_duration_picker-rails
22
+
23
+ ## Usage
24
+
25
+ Add this line in your application js:
26
+
27
+ ```js
28
+ //= require jquery.timeDurationPicker
29
+ ```
30
+
31
+ In your view:
32
+
33
+ ```html
34
+ <input type="text" name="duration" id="duration" readonly="readonly" />
35
+ <input type="hidden" name="seconds" id="seconds" value="0" />
36
+
37
+ ...
38
+
39
+ <script type="text/javascript">
40
+ $(document).ready(function() {
41
+ $('#duration').timeDurationPicker({
42
+ onselect: function(element, seconds, duration) {
43
+ $('#seconds').val(seconds);
44
+ $('#duration').val(duration);
45
+ }
46
+ });
47
+ });
48
+ </script>
49
+ ```
50
+
51
+ Also see [this example] (https://jsfiddle.net/73eonrox/1/).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/digaev/jquery-time_duration_picker-rails.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jquery/time_duration_picker/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery/time_duration_picker/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery-time_duration_picker-rails"
8
+ spec.version = Jquery::TimeDurationPicker::Rails::VERSION
9
+ spec.authors = ["Nikolay Digaev"]
10
+ spec.email = ["ffs.cmp@gmail.com"]
11
+
12
+ spec.summary = %q{jQuery.timeDurationPicker plugin}
13
+ spec.description = %q{jQuery.timeDurationPicker plugin for Ruby On Rails.}
14
+ spec.homepage = "https://github.com/digaev/jQuery-timeDurationPicker"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib", "vendor"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,10 @@
1
+ require "jquery/time_duration_picker/rails/version"
2
+
3
+ module Jquery
4
+ module TimeDurationPicker
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module TimeDurationPicker
3
+ module Rails
4
+ VERSION = "0.1.5"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,342 @@
1
+ /*!
2
+ * jQuery TimeDurationPicker Plugin v1.0.2
3
+ *
4
+ * https://github.com/digaev/jQuery-timeDurationPicker
5
+ *
6
+ * Copyright (c) 2015 Nikolay Digaev
7
+ * Released under the MIT license
8
+ */
9
+
10
+ (function($) {
11
+ $.timeDurationPicker = function(options) {
12
+ $.timeDurationPicker.defaults = $.extend({}, $.timeDurationPicker.defaults, options);
13
+ }
14
+
15
+ $.timeDurationPicker.defaults = {
16
+ lang: 'en',
17
+ seconds: false,
18
+ minutes: true,
19
+ hours: true,
20
+ days: true,
21
+ months: true,
22
+ years: true
23
+ }
24
+ })(jQuery);
25
+
26
+ (function($) {
27
+ var instances = [];
28
+
29
+ $(document).focusin(function(e) {
30
+ for (var i = 0, c = instances.length; i < c; ++i) {
31
+ var inst = instances[i];
32
+ for (var j = 0, l = inst.element.length; j < l; ++j) {
33
+ if (inst.element[j] == e.target) {
34
+ var offset = $(e.target).offset();
35
+ offset.top += $(e.target).outerHeight();
36
+ inst._content.div.css(offset).fadeIn();
37
+ }
38
+ }
39
+ }
40
+ }).focusout(function(e) {
41
+ // FIXME
42
+ setTimeout(function() {
43
+ var el = document.activeElement;
44
+ if ($(el).parents('.time-duration-picker-content').length == 0) {
45
+ for (var i = 0, c = instances.length; i < c; ++i) {
46
+ var hide = true;
47
+ var inst = instances[i];
48
+ for (var j = 0, l = inst.element.length; j < l; ++j) {
49
+ if (inst.element[j] == el) {
50
+ hide = false;
51
+ break;
52
+ }
53
+ }
54
+ if (hide) {
55
+ inst._content.div.fadeOut();
56
+ }
57
+ }
58
+ }
59
+ }, 10);
60
+ });
61
+
62
+ var YEAR = 12 * 30 * 24 * 60 * 60;
63
+ var MONTH = 30 * 24 * 60 * 60;
64
+ var DAY = 24 * 60 * 60;
65
+ var HOUR = 60 * 60;
66
+ var MINUTE = 60;
67
+
68
+ $.widget('custom.timeDurationPicker', {
69
+ options: {
70
+ },
71
+ _langs: {
72
+ en: {
73
+ seconds: 'Seconds',
74
+ minutes: 'Minutes',
75
+ hours: 'Hours',
76
+ days: 'Days',
77
+ months: 'Months',
78
+ years: 'Years',
79
+ human_years: 'years',
80
+ human_months: 'months',
81
+ human_days: 'days',
82
+ human_hours: 'hours',
83
+ human_minutes: 'minutes',
84
+ human_seconds: 'seconds',
85
+ and: 'and',
86
+ button_ok: 'Done'
87
+ },
88
+ ru: {
89
+ seconds: 'Секунды',
90
+ minutes: 'Минуты',
91
+ hours: 'Часы',
92
+ days: 'Дни',
93
+ months: 'Месяцы',
94
+ years: 'Годы',
95
+ human_years: 'лет',
96
+ human_months: 'месяцев',
97
+ human_days: 'дней',
98
+ human_hours: 'часов',
99
+ human_minutes: 'минут',
100
+ human_seconds: 'секунд',
101
+ and: 'и',
102
+ button_ok: 'Выбрать'
103
+ }
104
+ },
105
+ _create: function() {
106
+ var self = this;
107
+
108
+ this.options = $.extend({}, $.timeDurationPicker.defaults, this.options);
109
+
110
+ this._content = {};
111
+ this._content.div = $('<div />');
112
+ this._content.div.addClass('ui-widget ui-widget-content ui-helper-clearfix ui-corner-all');
113
+ this._content.div.addClass('time-duration-picker-content');
114
+ this._content.div.css({
115
+ display: 'none',
116
+ position: 'fixed',
117
+ "z-index": 401
118
+ });
119
+ this._content.div.appendTo(document.body);
120
+
121
+ this._content.table = $('<table style="width: 100%;"><tbody /></table>').appendTo(this._content.div);
122
+ this._content.tableBody = $('tbody', this._content.table);
123
+
124
+ this._content.button = $('<input type="button" />').val(this._tr('button_ok'));
125
+ this._content.button.addClass('ui-button ui-widget ui-state-default ui-corner-all');
126
+ this._content.button.css({
127
+ display: 'block',
128
+ margin: '0.5em auto',
129
+ padding: '0.5em 1em'
130
+ });
131
+ this._content.button.hover(function() {
132
+ $(this).addClass('ui-state-hover');
133
+ }, function() {
134
+ $(this).removeClass('ui-state-hover');
135
+ });
136
+ this._content.button.on('click', function(e) {
137
+ self._content.div.fadeOut();
138
+ if (self.options.onselect) {
139
+ self.options.onselect(self.element, self.getDuration(), self.getHumanDuration());
140
+ }
141
+ });
142
+ this._content.button.appendTo(this._content.div);
143
+
144
+ this._initUnits();
145
+
146
+ instances.push(this);
147
+ },
148
+ _initUnits: function() {
149
+ var i;
150
+ if (this.options.seconds) {
151
+ this._content.seconds = this._createSelectWithOptions(0, 59);
152
+ this._appendRow(this._tr('seconds'), this._content.seconds);
153
+ }
154
+ if (this.options.minutes) {
155
+ this._content.minutes = this._createSelectWithOptions(0, 59);
156
+ this._appendRow(this._tr('minutes'), this._content.minutes);
157
+ }
158
+ if (this.options.hours) {
159
+ this._content.hours = this._createSelectWithOptions(0, 23);
160
+ this._appendRow(this._tr('hours'), this._content.hours);
161
+ }
162
+ if (this.options.days) {
163
+ this._content.days = this._createSelectWithOptions(0, 29);
164
+ this._appendRow(this._tr('days'), this._content.days);
165
+ }
166
+ if (this.options.months) {
167
+ this._content.months = this._createSelectWithOptions(0, 11);
168
+ this._appendRow(this._tr('months'), this._content.months);
169
+ }
170
+ if (this.options.years) {
171
+ this._content.years = this._createSelectWithOptions(0, 10);
172
+ this._appendRow(this._tr('years'), this._content.years);
173
+ }
174
+ if (this.options.defaultValue) {
175
+ this.setDuration(this.options.defaultValue);
176
+ }
177
+ },
178
+ _createSelectWithOptions: function(min, max) {
179
+ var select = $('<select />')
180
+ .addClass('ui-widget ui-state-default ui-corner-all')
181
+
182
+ select.hover(function() {
183
+ $(this).addClass('ui-state-hover');
184
+ }, function() {
185
+ $(this).removeClass('ui-state-hover');
186
+ });
187
+
188
+ this._createOptionsForSelect(select, min, max);
189
+ return select;
190
+ },
191
+ _createOptionsForSelect: function(select, min, max) {
192
+ for (var i = min; i <= max; ++i) {
193
+ select.append($('<option />').val(i).text(i < 10 ? ('0' + i) : i));
194
+ }
195
+ },
196
+ _appendRow: function(text, el) {
197
+ var row = $('<tr />').appendTo(this._content.tableBody);
198
+ $('<td />').css({
199
+ width: '50%',
200
+ padding: '.5em 1em',
201
+ "text-align": 'right',
202
+ "vertical-align": 'middle'
203
+ }).append($('<strong />')
204
+ .text(text))
205
+ .appendTo(row);
206
+ $('<td />').css({
207
+ width: '50%',
208
+ padding: '.5em 1em',
209
+ "text-align": 'right',
210
+ "vertical-align": 'middle'
211
+ }).append(el)
212
+ .appendTo(row);
213
+ },
214
+ _tr: function(key) {
215
+ return this._langs[this.options.lang][key];
216
+ },
217
+ getSeconds: function() {
218
+ return parseInt(this._content.seconds.val());
219
+ },
220
+ getMinutes: function() {
221
+ return parseInt(this._content.minutes.val());
222
+ },
223
+ getHours: function() {
224
+ return parseInt(this._content.hours.val());
225
+ },
226
+ getDays: function() {
227
+ return parseInt(this._content.days.val());
228
+ },
229
+ getMonths: function() {
230
+ return parseInt(this._content.months.val());
231
+ },
232
+ getYears: function() {
233
+ return parseInt(this._content.years.val());
234
+ },
235
+ setDuration: function(value) {
236
+ value = parseInt(value);
237
+ if (isNaN(value)) {
238
+ return false;
239
+ }
240
+
241
+ var i;
242
+ if (this.options.years) {
243
+ i = Math.floor(value / YEAR);
244
+ value -= i * YEAR;
245
+ this._content.years.val(i);
246
+ }
247
+ if (this.options.months) {
248
+ i = Math.floor(value / MONTH);
249
+ if (i >= 12) {
250
+ i = 0;
251
+ }
252
+ value -= i * MONTH;
253
+ this._content.months.val(i);
254
+ }
255
+ if (this.options.days) {
256
+ i = Math.floor(value / DAY);
257
+ if (i >= 30) {
258
+ i = 0;
259
+ }
260
+ value -= i * DAY;
261
+ this._content.days.val(i);
262
+ }
263
+ if (this.options.hours) {
264
+ i = Math.floor(value / HOUR);
265
+ if (i >= 24) {
266
+ i = 0;
267
+ }
268
+ value -= i * HOUR;
269
+ this._content.hours.val(i);
270
+ }
271
+ if (this.options.minutes) {
272
+ i = Math.floor(value / MINUTE);
273
+ if (i >= 60) {
274
+ i = 0;
275
+ }
276
+ value -= i * MINUTE;
277
+ this._content.minutes.val(i);
278
+ }
279
+ if (this.options.seconds) {
280
+ i = Math.floor(value);
281
+ if (i >= 60) {
282
+ i = 0;
283
+ }
284
+ this._content.seconds.val(i);
285
+ }
286
+ return value;
287
+ },
288
+ getDuration: function() {
289
+ var seconds = 0;
290
+ if (this.options.seconds) {
291
+ seconds += this.getSeconds();
292
+ }
293
+ if (this.options.minutes) {
294
+ seconds += this.getMinutes() * MINUTE;
295
+ }
296
+ if (this.options.hours) {
297
+ seconds += this.getHours() * HOUR;
298
+ }
299
+ if (this.options.days) {
300
+ seconds += this.getDays() * DAY;
301
+ }
302
+ if (this.options.months) {
303
+ seconds += this.getMonths() * MONTH;
304
+ }
305
+ if (this.options.years) {
306
+ seconds += this.getYears() * YEAR;
307
+ }
308
+ return seconds;
309
+ },
310
+ getHumanDuration: function() {
311
+ var units = [];
312
+ var duration = '';
313
+
314
+ if (this.options.years && this.getYears() > 0) {
315
+ units.push({value: this.getYears(), name: this._tr('human_years')});
316
+ }
317
+ if (this.options.months && this.getMonths() > 0) {
318
+ units.push({value: this.getMonths(), name: this._tr('human_months')});
319
+ }
320
+ if (this.options.days && this.getDays() > 0) {
321
+ units.push({value: this.getDays(), name: this._tr('human_days')});
322
+ }
323
+ if (this.options.hours && this.getHours() > 0) {
324
+ units.push({value: this.getHours(), name: this._tr('human_hours')});
325
+ }
326
+ if (this.options.minutes && this.getMinutes() > 0) {
327
+ units.push({value: this.getMinutes(), name: this._tr('human_minutes')});
328
+ }
329
+ if (this.options.seconds && this.getSeconds() > 0) {
330
+ units.push({value: this.getSeconds(), name: this._tr('human_seconds')});
331
+ }
332
+
333
+ for (var i = 0, l = units.length; i < l; ++i) {
334
+ var unit = units[i];
335
+ var separator = i == l - 1 ? '' : (i == l - 2 ? ' ' + this._tr('and') + ' ' : ', ');
336
+
337
+ duration += unit.value + ' ' + unit.name + separator;
338
+ }
339
+ return duration;
340
+ }
341
+ });
342
+ })(jQuery);
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-time_duration_picker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Digaev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: jQuery.timeDurationPicker plugin for Ruby On Rails.
42
+ email:
43
+ - ffs.cmp@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - jquery-time_duration_picker-rails.gemspec
56
+ - lib/jquery/time_duration_picker/rails.rb
57
+ - lib/jquery/time_duration_picker/rails/version.rb
58
+ - vendor/assets/javascripts/jquery.timeDurationPicker.js
59
+ homepage: https://github.com/digaev/jQuery-timeDurationPicker
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ - vendor
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: jQuery.timeDurationPicker plugin
84
+ test_files: []