flashgrid-ext 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ebc19c8aaef5c8975ae70b739f043cda3298c3c
4
- data.tar.gz: 8e0516c4d22dafee14bdc5ba4822b2fdc5e7d8d0
3
+ metadata.gz: 7ed628cb8936e8d19cab4e0c388121df2bc0520c
4
+ data.tar.gz: e5311ff2be65c4ca95db9674af1138d2acad4b27
5
5
  SHA512:
6
- metadata.gz: 1cbe67175ef79f08cdb6966af5f20e2a5b885f3798eb8d684473f36067c86d7d6d6168097c0a147707afbb86ee216e620b2072e4dbeb5361c9e0bf821719be91
7
- data.tar.gz: 2997ce07db99c6458c357e09a069fc8ac79902f5f1a128e3046155ead742bb9e6f885b3de625e69213cb294cc2a45f4f81148b5541193d68f006355809eb3421
6
+ metadata.gz: 161b2d472b3cbc2f06f650baedac4dfa3a2fdb62347e7ab5aa877b51c79df01e97aa25de79ae0391b784170634c5f5fc406f84bd882a890e64399f192e37c1b5
7
+ data.tar.gz: 6dda2282b70093662a65c5f1d0a9fbf999e103f8471423929210c79f360b3d0e2d08c9394bf1c540df9a369238ce3c59c7973dce053dde0060807455740b111f
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module Flashgrid
2
2
  module Ext
3
- VERSION = "3.0.0"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
@@ -3,25 +3,21 @@
3
3
 
4
4
  TimeAgo = (function() {
5
5
  function TimeAgo(element, options) {
6
- this.startInterval = 60000;
7
- this.init(element, options);
8
- }
9
-
10
- TimeAgo.prototype.init = function(element, options) {
11
6
  this.$element = $(element);
12
7
  this.options = $.extend({}, $.fn.timeago.defaults, options);
13
- this.updateTime();
14
- return this.startTimer();
15
- };
8
+ this.refresh();
9
+ }
16
10
 
17
11
  TimeAgo.prototype.startTimer = function() {
18
- var self;
19
- self = this;
20
- return this.interval = setInterval($.proxy(self.refresh, this), this.startInterval);
12
+ return this.interval = setTimeout((function(_this) {
13
+ return function() {
14
+ return _this.refresh();
15
+ };
16
+ })(this), this.startInterval);
21
17
  };
22
18
 
23
19
  TimeAgo.prototype.stopTimer = function() {
24
- return clearInterval(this.interval);
20
+ return clearTimeout(this.interval);
25
21
  };
26
22
 
27
23
  TimeAgo.prototype.restartTimer = function() {
@@ -35,53 +31,50 @@
35
31
  };
36
32
 
37
33
  TimeAgo.prototype.updateTime = function() {
38
- var self;
39
- self = this;
40
- return this.$element.findAndSelf(this.options.selector).each(function() {
41
- var $el, text, timeAgoInWords;
42
- $el = $(this);
43
- timeAgoInWords = self.timeAgoInWords($el.attr(self.options.attr));
44
- if (!$el.prop('title')) {
45
- text = $el.text();
46
- if (text) {
47
- $el.prop('title', $el.text());
48
- }
49
- }
50
- return $el.html(timeAgoInWords);
51
- });
34
+ var timeAgoInWords;
35
+ timeAgoInWords = this.timeAgoInWords(this.$element.attr(this.options.attr));
36
+ return this.$element.html(timeAgoInWords);
52
37
  };
53
38
 
54
39
  TimeAgo.prototype.updateInterval = function() {
55
- var filter, newestTime, newestTimeInMinutes, newestTimeSrc;
56
- if (this.$element.findAndSelf(this.options.selector).length > 0) {
57
- if (this.options.dir === "up") {
58
- filter = ":first";
59
- } else if (this.options.dir === "down") {
60
- filter = ":last";
61
- }
62
- newestTimeSrc = this.$element.findAndSelf(this.options.selector).filter(filter).attr(this.options.attr);
63
- newestTime = this.parse(newestTimeSrc);
64
- newestTimeInMinutes = this.getTimeDistanceInMinutes(newestTime);
65
- if (newestTimeInMinutes >= 0 && newestTimeInMinutes <= 44 && this.startInterval !== 60000) {
66
- this.startInterval = 60000;
67
- return this.restartTimer();
68
- } else if (newestTimeInMinutes >= 45 && newestTimeInMinutes <= 89 && this.startInterval !== 60000 * 22) {
69
- this.startInterval = 60000 * 22;
70
- return this.restartTimer();
71
- } else if (newestTimeInMinutes >= 90 && newestTimeInMinutes <= 2519 && this.startInterval !== 60000 * 30) {
72
- this.startInterval = 60000 * 30;
73
- return this.restartTimer();
74
- } else if (newestTimeInMinutes >= 2520 && this.startInterval !== 60000 * 60 * 12) {
75
- this.startInterval = 60000 * 60 * 12;
76
- return this.restartTimer();
77
- }
40
+ var dis, newestTime, newestTimeSrc;
41
+ newestTimeSrc = this.$element.attr(this.options.attr);
42
+ newestTime = this.parse(newestTimeSrc);
43
+ dis = this.getTimeDistanceInSeconds(newestTime);
44
+ if (this.options.maxRelative && dis >= this.options.maxRelative) {
45
+ return this.stopTimer();
46
+ } else if (this.options.showNow && dis < this.options.showNow) {
47
+ this.startInterval = (this.options.showNow - dis) * 1000;
48
+ return this.restartTimer();
49
+ } else if (this.options.showSeconds && dis < 60) {
50
+ this.startInterval = 1000;
51
+ return this.restartTimer();
52
+ } else if (dis < 2700) {
53
+ this.startInterval = (60 - dis % 60) * 1000;
54
+ return this.restartTimer();
55
+ } else if (dis < 5400) {
56
+ this.startInterval = (5400 - dis) * 1000;
57
+ return this.restartTimer();
58
+ } else if (dis < 151200) {
59
+ this.startInterval = (3600 - dis % 3600) * 1000;
60
+ return this.restartTimer();
61
+ } else {
62
+ this.startInterval = (86400 - dis % 86400) * 1000;
63
+ return this.restartTimer();
78
64
  }
79
65
  };
80
66
 
81
67
  TimeAgo.prototype.timeAgoInWords = function(timeString) {
82
- var absolutTime;
68
+ var absolutTime, dis;
83
69
  absolutTime = this.parse(timeString);
84
- return "" + this.options.lang.prefixes.ago + (this.distanceOfTimeInWords(absolutTime)) + this.options.lang.suffix;
70
+ dis = this.getTimeDistanceInSeconds(absolutTime);
71
+ if (this.options.showNow && this.options.showNow > dis) {
72
+ return this.options.lang.prefixes.now;
73
+ } else if (this.options.maxRelative && this.options.maxRelative <= dis) {
74
+ return this.options.absoluteDate(absolutTime, timeString);
75
+ } else {
76
+ return this.options.relativeDate(this.options.lang.prefixes.ago, this.distanceOfTimeInWords(dis), this.options.suffix || this.options.lang.suffix);
77
+ }
85
78
  };
86
79
 
87
80
  TimeAgo.prototype.parse = function(iso8601) {
@@ -94,41 +87,49 @@
94
87
  return new Date(timeStr);
95
88
  };
96
89
 
97
- TimeAgo.prototype.getTimeDistanceInMinutes = function(absolutTime) {
90
+ TimeAgo.prototype.getTimeDistanceInSeconds = function(absolutTime) {
98
91
  var timeDistance;
99
92
  timeDistance = new Date().getTime() - absolutTime.getTime();
100
- return Math.round((Math.abs(timeDistance) / 1000) / 60);
93
+ return Math.round(Math.abs(timeDistance) / 1000);
101
94
  };
102
95
 
103
- TimeAgo.prototype.distanceOfTimeInWords = function(absolutTime) {
104
- var dim;
105
- dim = this.getTimeDistanceInMinutes(absolutTime);
106
- if (dim === 0) {
107
- return "" + this.options.lang.prefixes.lt + " " + this.options.lang.units.minute;
108
- } else if (dim === 1) {
109
- return "1 " + this.options.lang.units.minute;
110
- } else if (dim >= 2 && dim <= 44) {
111
- return "" + dim + " " + this.options.lang.units.minutes;
112
- } else if (dim >= 45 && dim <= 89) {
113
- return "" + this.options.lang.prefixes.about + " 1 " + this.options.lang.units.hour;
114
- } else if (dim >= 90 && dim <= 1439) {
115
- return "" + this.options.lang.prefixes.about + " " + (Math.round(dim / 60)) + " " + this.options.lang.units.hours;
116
- } else if (dim >= 1440 && dim <= 2519) {
117
- return "1 " + this.options.lang.units.day;
118
- } else if (dim >= 2520 && dim <= 43199) {
119
- return "" + (Math.round(dim / 1440)) + " " + this.options.lang.units.days;
120
- } else if (dim >= 43200 && dim <= 86399) {
121
- return "" + this.options.lang.prefixes.about + " 1 " + this.options.lang.units.month;
122
- } else if (dim >= 86400 && dim <= 525599) {
123
- return "" + (Math.round(dim / 43200)) + " " + this.options.lang.units.months;
124
- } else if (dim >= 525600 && dim <= 655199) {
125
- return "" + this.options.lang.prefixes.about + " 1 " + this.options.lang.units.year;
126
- } else if (dim >= 655200 && dim <= 914399) {
127
- return "" + this.options.lang.prefixes.over + " 1 " + this.options.lang.units.year;
128
- } else if (dim >= 914400 && dim <= 1051199) {
129
- return "" + this.options.lang.prefixes.almost + " 2 " + this.options.lang.units.years;
96
+ TimeAgo.prototype.distanceOfTimeInWords = function(dis) {
97
+ var space;
98
+ space = this.options.spacing ? ' ' : '';
99
+ if (dis < 60) {
100
+ if (this.options.showSeconds) {
101
+ if (dis === 0 || dis === 1) {
102
+ return "1" + space + this.options.lang.units.second;
103
+ } else {
104
+ return "" + dis + space + this.options.lang.units.seconds;
105
+ }
106
+ } else {
107
+ return "" + (this.options.approximate ? this.options.lang.prefixes.lt + " " : "1" + space) + this.options.lang.units.minute;
108
+ }
109
+ } else if (dis < 120) {
110
+ return "1" + space + this.options.lang.units.minute;
111
+ } else if (dis < 2700) {
112
+ return "" + (Math.round(dis / 60)) + space + this.options.lang.units.minutes;
113
+ } else if (dis < 5400) {
114
+ return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + "1" + space + this.options.lang.units.hour;
115
+ } else if (dis < 86400) {
116
+ return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + (Math.round(dis / 3600)) + space + this.options.lang.units.hours;
117
+ } else if (dis < 151200) {
118
+ return "1" + space + this.options.lang.units.day;
119
+ } else if (dis < 2592000) {
120
+ return "" + (Math.round(dis / 86400)) + space + this.options.lang.units.days;
121
+ } else if (dis < 5184000) {
122
+ return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + "1" + space + this.options.lang.units.month;
123
+ } else if (dis < 31536000) {
124
+ return "" + (Math.round(dis / 2592000)) + space + this.options.lang.units.months;
125
+ } else if (dis < 39312000) {
126
+ return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + "1" + space + this.options.lang.units.year;
127
+ } else if (dis < 54864000) {
128
+ return "" + (this.options.approximate ? this.options.lang.prefixes.over + " " : "") + "1" + space + this.options.lang.units.year;
129
+ } else if (dis < 63072000) {
130
+ return "" + (this.options.approximate ? this.options.lang.prefixes.almost + " " : "") + "2" + space + this.options.lang.units.years;
130
131
  } else {
131
- return "" + this.options.lang.prefixes.about + " " + (Math.round(dim / 525600)) + " " + this.options.lang.units.years;
132
+ return "" + (this.options.approximate ? this.options.lang.prefixes.about + " " : "") + (Math.round(dis / 31536000)) + space + this.options.lang.units.years;
132
133
  }
133
134
  };
134
135
 
@@ -141,8 +142,12 @@
141
142
  options = {};
142
143
  }
143
144
  return this.each(function() {
144
- var $this, data;
145
+ var $this, attr, data;
145
146
  $this = $(this);
147
+ attr = $this.attr(options.attr || $.fn.timeago.defaults.attr);
148
+ if (attr === void 0 || attr === false) {
149
+ return;
150
+ }
146
151
  data = $this.data("timeago");
147
152
  if (!data) {
148
153
  return $this.data("timeago", new TimeAgo(this, options));
@@ -159,9 +164,18 @@
159
164
  $.fn.timeago.Constructor = TimeAgo;
160
165
 
161
166
  $.fn.timeago.defaults = {
162
- selector: 'time.timeago',
163
167
  attr: 'datetime',
164
- dir: 'up',
168
+ spacing: true,
169
+ approximate: true,
170
+ showSeconds: false,
171
+ showNow: false,
172
+ maxRelative: false,
173
+ absoluteDate: function(date, datetime) {
174
+ return datetime;
175
+ },
176
+ relativeDate: function(prefix, distance, suffix) {
177
+ return "" + prefix + distance + suffix;
178
+ },
165
179
  lang: {
166
180
  units: {
167
181
  second: "second",
@@ -178,6 +192,7 @@
178
192
  years: "years"
179
193
  },
180
194
  prefixes: {
195
+ now: "just now",
181
196
  lt: "less than a",
182
197
  about: "about",
183
198
  over: "over",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flashgrid-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.4.1
89
+ rubygems_version: 2.4.2
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Flashgrid Extensions