Skip to content

Commit aa7fcae

Browse files
committed
Make visibility check optional
There are use-cases where `document.documentElement` does not contain the element. In my case I was contributing to a Chrome Extension, and `document.documentElement` contained the background page only, which made the plugin stop working. There might be a smarter way to do this, i.e. finding out if the element is visible - maybe by specifying the parent in some way. But it is rather an edge case, so this solution should be sufficient.
1 parent ba8c44c commit aa7fcae

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

jquery.timeago.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
allowFuture: false,
4646
localeTitle: false,
4747
cutoff: 0,
48+
checkVisibility: true,
4849
strings: {
4950
prefixAgo: null,
5051
prefixFromNow: null,
@@ -177,15 +178,16 @@
177178
};
178179

179180
function refresh() {
181+
var $s = $t.settings;
182+
180183
//check if it's still visible
181-
if(!$.contains(document.documentElement,this)){
184+
if($s.checkVisibility && !$.contains(document.documentElement,this)){
182185
//stop if it has been removed
183186
$(this).timeago("dispose");
184187
return this;
185188
}
186189

187190
var data = prepareData(this);
188-
var $s = $t.settings;
189191

190192
if (!isNaN(data.datetime)) {
191193
if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {

0 commit comments

Comments
 (0)