clockpunch 0.1.4 → 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.
- data/CHANGELOG.md +8 -2
- data/README.md +17 -0
- data/app/assets/javascripts/clockpunch.js +42 -10
- data/lib/clockpunch/version.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
# Clockpunch Changelog
|
2
2
|
|
3
|
+
## Version 0.1.5 (July 12, 2013)
|
4
|
+
|
5
|
+
* Don't apply timeinput multiple times
|
6
|
+
* Ability to pass 'hm' as a time format
|
7
|
+
* Began refactoring to allow application-defined formats via strings and functions
|
8
|
+
|
3
9
|
## Version 0.1.4 (July 10, 2013)
|
4
|
-
|
10
|
+
|
5
11
|
* Support input type="number"
|
6
12
|
|
7
13
|
## Version 0.1.3 (July 2, 2013)
|
8
14
|
|
9
15
|
* Can replace <span> or other elements with the specified format
|
10
|
-
* Allow format as an option
|
16
|
+
* Allow format as an option
|
data/README.md
CHANGED
@@ -74,6 +74,23 @@ This library comprises the following pieces:
|
|
74
74
|
- "1:30.2" is read like "1:30"
|
75
75
|
- See spec/time_parser_spec.coffee for more examples of how input is handled.
|
76
76
|
|
77
|
+
### Formats
|
78
|
+
|
79
|
+
There are three built-in formats:
|
80
|
+
|
81
|
+
* default: "H:MM"
|
82
|
+
* Zero-padded minutes
|
83
|
+
* hm: "HmMMm"
|
84
|
+
* Zero-padded minutes
|
85
|
+
* minutes: MMm
|
86
|
+
* Not zero-padded. Always show total minutes. E.g. 90 minutes stays "90m"
|
87
|
+
|
88
|
+
To use one of the other formats, just pass it in the constructor, e.g. `new TimeParser('hm')`
|
89
|
+
|
90
|
+
#### Custom formats
|
91
|
+
|
92
|
+
You can also pass custom formats either as a string or a function. This feature is still in development.
|
93
|
+
|
77
94
|
# Use in Forms
|
78
95
|
|
79
96
|
Apply the jQuery plugin to the elements:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// Generated by CoffeeScript 1.4.0
|
2
2
|
|
3
3
|
/*
|
4
|
-
Clockpunch 0.1.
|
4
|
+
Clockpunch 0.1.5
|
5
5
|
https://github.com/tablexi/clockpunch
|
6
6
|
*/
|
7
7
|
|
@@ -27,7 +27,7 @@ https://github.com/tablexi/clockpunch
|
|
27
27
|
|
28
28
|
function TimeParsingInput(elem, format) {
|
29
29
|
if (format == null) {
|
30
|
-
format =
|
30
|
+
format = 'default';
|
31
31
|
}
|
32
32
|
this.$elem = $(elem);
|
33
33
|
this.$elem.data('timeparser', this);
|
@@ -51,6 +51,9 @@ https://github.com/tablexi/clockpunch
|
|
51
51
|
TimeParsingInput.prototype.configure_input = function(format) {
|
52
52
|
var self;
|
53
53
|
self = this;
|
54
|
+
if (this.$elem.hasClass('clockpunch-applied')) {
|
55
|
+
return;
|
56
|
+
}
|
54
57
|
this.create_hidden_field(format);
|
55
58
|
this.ensure_elem_is_text();
|
56
59
|
this.$elem.change(function() {
|
@@ -61,7 +64,8 @@ https://github.com/tablexi/clockpunch
|
|
61
64
|
return $this.val(self.parser.from_minutes(minutes));
|
62
65
|
});
|
63
66
|
this.$elem.trigger('change');
|
64
|
-
|
67
|
+
this.create_tooltip();
|
68
|
+
return this.$elem.addClass('clockpunch-applied');
|
65
69
|
};
|
66
70
|
|
67
71
|
TimeParsingInput.prototype.create_hidden_field = function() {
|
@@ -112,8 +116,10 @@ https://github.com/tablexi/clockpunch
|
|
112
116
|
window.TimeParser = (function() {
|
113
117
|
|
114
118
|
function TimeParser(time_format) {
|
115
|
-
|
116
|
-
|
119
|
+
if (time_format == null) {
|
120
|
+
time_format = null;
|
121
|
+
}
|
122
|
+
this.time_format = this.get_format_mapping(time_format);
|
117
123
|
}
|
118
124
|
|
119
125
|
/*
|
@@ -172,11 +178,7 @@ https://github.com/tablexi/clockpunch
|
|
172
178
|
}
|
173
179
|
hours = Math.floor(minutes / 60.0);
|
174
180
|
mins = minutes % 60;
|
175
|
-
return this.
|
176
|
-
};
|
177
|
-
|
178
|
-
TimeParser.prototype.format = function(hours, minutes) {
|
179
|
-
return this.time_format.replace('{HOURS}', hours).replace('{MINUTES}', TimeParser.pad(minutes.toString()));
|
181
|
+
return this.time_format(hours, mins);
|
180
182
|
};
|
181
183
|
|
182
184
|
TimeParser.prototype.transform = function(string) {
|
@@ -230,6 +232,36 @@ https://github.com/tablexi/clockpunch
|
|
230
232
|
};
|
231
233
|
};
|
232
234
|
|
235
|
+
TimeParser.prototype.get_format_mapping = function(format) {
|
236
|
+
var formats;
|
237
|
+
if (typeof format === 'function') {
|
238
|
+
return format;
|
239
|
+
}
|
240
|
+
formats = {
|
241
|
+
"default": function(hours, minutes) {
|
242
|
+
return this.default_string_format('{HOURS}:{MINUTES}', hours, minutes);
|
243
|
+
},
|
244
|
+
hm: function(hours, minutes) {
|
245
|
+
return this.default_string_format('{HOURS}h{MINUTES}m', hours, minutes);
|
246
|
+
},
|
247
|
+
minutes: function(hours, minutes) {
|
248
|
+
var total_minutes;
|
249
|
+
total_minutes = hours * 60 + minutes;
|
250
|
+
return total_minutes.toString();
|
251
|
+
}
|
252
|
+
};
|
253
|
+
if (format == null) {
|
254
|
+
return formats['default'];
|
255
|
+
}
|
256
|
+
return formats[format] || function(hours, minutes) {
|
257
|
+
return this.default_string_format(format, hours, minutes);
|
258
|
+
};
|
259
|
+
};
|
260
|
+
|
261
|
+
TimeParser.prototype.default_string_format = function(format_string, hours, minutes) {
|
262
|
+
return format_string.replace('{HOURS}', hours).replace('{MINUTES}', TimeParser.pad(minutes.toString()));
|
263
|
+
};
|
264
|
+
|
233
265
|
return TimeParser;
|
234
266
|
|
235
267
|
})();
|
data/lib/clockpunch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockpunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sass
|