clockpunch 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/clockpunch.js +38 -26
- data/lib/clockpunch/version.rb +1 -1
- metadata +1 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
// Generated by CoffeeScript 1.4.0
|
2
2
|
|
3
3
|
/*
|
4
|
-
Clockpunch 1.1
|
4
|
+
Clockpunch 0.1.1
|
5
5
|
https://github.com/tablexi/clockpunch
|
6
6
|
*/
|
7
7
|
|
@@ -9,17 +9,40 @@ https://github.com/tablexi/clockpunch
|
|
9
9
|
(function() {
|
10
10
|
var $, TimeParsingInput;
|
11
11
|
|
12
|
+
if (typeof jQuery !== "undefined" && jQuery !== null) {
|
13
|
+
$ = jQuery;
|
14
|
+
$.fn.extend({
|
15
|
+
timeinput: function(options) {
|
16
|
+
if (options == null) {
|
17
|
+
options = {};
|
18
|
+
}
|
19
|
+
return this.each(function(input_field) {
|
20
|
+
return new TimeParsingInput(this, options['format']);
|
21
|
+
});
|
22
|
+
}
|
23
|
+
});
|
24
|
+
}
|
25
|
+
|
12
26
|
TimeParsingInput = (function() {
|
13
27
|
|
14
28
|
function TimeParsingInput(elem, format) {
|
15
|
-
var self;
|
16
29
|
if (format == null) {
|
17
30
|
format = null;
|
18
31
|
}
|
19
|
-
|
32
|
+
console.debug('format');
|
20
33
|
this.$elem = $(elem);
|
21
34
|
this.$elem.data('timeparser', this);
|
22
|
-
this.parser = new TimeParser();
|
35
|
+
this.parser = new TimeParser(format);
|
36
|
+
if (this.$elem.is('input')) {
|
37
|
+
this.configure_input(format);
|
38
|
+
} else {
|
39
|
+
this.$elem.text(this.parser.transform(this.$elem.text()));
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
TimeParsingInput.prototype.configure_input = function(format) {
|
44
|
+
var self;
|
45
|
+
self = this;
|
23
46
|
this.create_hidden_field(format);
|
24
47
|
this.$elem.change(function() {
|
25
48
|
var $this, minutes;
|
@@ -29,8 +52,8 @@ https://github.com/tablexi/clockpunch
|
|
29
52
|
return $this.val(self.parser.from_minutes(minutes));
|
30
53
|
});
|
31
54
|
this.$elem.trigger('change');
|
32
|
-
this.create_tooltip();
|
33
|
-
}
|
55
|
+
return this.create_tooltip();
|
56
|
+
};
|
34
57
|
|
35
58
|
TimeParsingInput.prototype.create_hidden_field = function() {
|
36
59
|
var field_name;
|
@@ -41,7 +64,8 @@ https://github.com/tablexi/clockpunch
|
|
41
64
|
};
|
42
65
|
|
43
66
|
TimeParsingInput.prototype.create_tooltip = function() {
|
44
|
-
var $wrapper;
|
67
|
+
var $wrapper, self;
|
68
|
+
self = this;
|
45
69
|
$wrapper = $('<div/>').css('position', 'relative').css('display', 'inline-block');
|
46
70
|
this.$elem.wrap($wrapper);
|
47
71
|
this.$tooltip = $('<span/>').addClass('clockpunch-tooltip').hide();
|
@@ -51,7 +75,7 @@ https://github.com/tablexi/clockpunch
|
|
51
75
|
this.$elem.bind('keyup', function() {
|
52
76
|
var val;
|
53
77
|
val = $(this).val() || 0;
|
54
|
-
return $(this).data('tooltip').text(
|
78
|
+
return $(this).data('tooltip').text(self.parser.transform(val));
|
55
79
|
});
|
56
80
|
this.$elem.bind('focus', function() {
|
57
81
|
return $(this).data('tooltip').fadeIn('fast');
|
@@ -65,21 +89,11 @@ https://github.com/tablexi/clockpunch
|
|
65
89
|
|
66
90
|
})();
|
67
91
|
|
68
|
-
if (typeof jQuery !== "undefined" && jQuery !== null) {
|
69
|
-
$ = jQuery;
|
70
|
-
$.fn.extend({
|
71
|
-
timeinput: function(options) {
|
72
|
-
return this.each(function(input_field) {
|
73
|
-
return new TimeParsingInput(this);
|
74
|
-
});
|
75
|
-
}
|
76
|
-
});
|
77
|
-
}
|
78
|
-
|
79
92
|
window.TimeParser = (function() {
|
80
93
|
|
81
94
|
function TimeParser(time_format) {
|
82
|
-
this.time_format = time_format != null ? time_format :
|
95
|
+
this.time_format = time_format != null ? time_format : null;
|
96
|
+
this.time_format || (this.time_format = "{HOURS}:{MINUTES}");
|
83
97
|
}
|
84
98
|
|
85
99
|
/*
|
@@ -99,12 +113,6 @@ https://github.com/tablexi/clockpunch
|
|
99
113
|
return parser.from_minutes(minutes);
|
100
114
|
};
|
101
115
|
|
102
|
-
TimeParser.clean = function(string) {
|
103
|
-
var minutes;
|
104
|
-
minutes = TimeParser.to_minutes(string);
|
105
|
-
return TimeParser.from_minutes(minutes);
|
106
|
-
};
|
107
|
-
|
108
116
|
TimeParser.pad = function(str, max) {
|
109
117
|
if (max == null) {
|
110
118
|
max = 2;
|
@@ -151,6 +159,10 @@ https://github.com/tablexi/clockpunch
|
|
151
159
|
return this.time_format.replace('{HOURS}', hours).replace('{MINUTES}', TimeParser.pad(minutes.toString()));
|
152
160
|
};
|
153
161
|
|
162
|
+
TimeParser.prototype.transform = function(string) {
|
163
|
+
return this.from_minutes(this.to_minutes(string));
|
164
|
+
};
|
165
|
+
|
154
166
|
/*
|
155
167
|
# PRIVATE
|
156
168
|
*/
|
data/lib/clockpunch/version.rb
CHANGED