mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-11-23 07:47:54 -05:00
commit
61980c6e22
3 changed files with 44 additions and 1 deletions
|
@ -128,7 +128,7 @@
|
||||||
refresh_el();
|
refresh_el();
|
||||||
var $s = $t.settings;
|
var $s = $t.settings;
|
||||||
if ($s.refreshMillis > 0) {
|
if ($s.refreshMillis > 0) {
|
||||||
setInterval(refresh_el, $s.refreshMillis);
|
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
update: function(time){
|
update: function(time){
|
||||||
|
@ -138,6 +138,12 @@
|
||||||
updateFromDOM: function(){
|
updateFromDOM: function(){
|
||||||
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
|
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
|
||||||
refresh.apply(this);
|
refresh.apply(this);
|
||||||
|
},
|
||||||
|
dispose: function () {
|
||||||
|
if (this._timeagoInterval) {
|
||||||
|
window.clearInterval(this._timeagoInterval);
|
||||||
|
this._timeagoInterval = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,10 @@
|
||||||
<li><abbr id="testMillisSettings8" class="tomillis" title="90"></abbr> [90 sec]</li>
|
<li><abbr id="testMillisSettings8" class="tomillis" title="90"></abbr> [90 sec]</li>
|
||||||
<li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
|
<li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<h2>Disposal</h2>
|
||||||
|
<p><abbr class="disposal disposed"></abbr></p>
|
||||||
|
<p><abbr class="disposal notDisposed"></abbr></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||||
|
@ -238,6 +242,8 @@
|
||||||
$("abbr.tonumbers").each(toWords);
|
$("abbr.tonumbers").each(toWords);
|
||||||
unloadNumbers();
|
unloadNumbers();
|
||||||
|
|
||||||
|
setupDisposal();
|
||||||
|
|
||||||
loadYoungOldYears();
|
loadYoungOldYears();
|
||||||
$("abbr.toyoungold").each(toWords);
|
$("abbr.toyoungold").each(toWords);
|
||||||
|
|
||||||
|
@ -582,6 +588,28 @@
|
||||||
ok($("#testNoSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
ok($("#testNoSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
||||||
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module("Disposal");
|
||||||
|
|
||||||
|
asyncTest("disposal", function() {
|
||||||
|
$(".disposal.disposed").timeago('dispose');
|
||||||
|
var initialTime_disposedTimeago = $(".disposal.disposed").html();
|
||||||
|
var initialTime_activeTimeago = $(".disposal.notDisposed").html();
|
||||||
|
|
||||||
|
expect(2);
|
||||||
|
setTimeout(function() {
|
||||||
|
var updatedTime_disposedTimeago = $(".disposal.disposed").html();
|
||||||
|
var updatedTime_activeTimeago = $(".disposal.notDisposed").html();
|
||||||
|
|
||||||
|
ok(initialTime_disposedTimeago === updatedTime_disposedTimeago, "A disposed timeago didn't get updated");
|
||||||
|
ok(initialTime_activeTimeago !== updatedTime_activeTimeago, "A non-disposed timeago continued to be updated");
|
||||||
|
|
||||||
|
// Dispose still-active timeago
|
||||||
|
$(".disposal.notDisposed").timeago('dispose');
|
||||||
|
resetRefreshMillis();
|
||||||
|
start();
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
//]]>
|
//]]>
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -30,6 +30,11 @@ function unloadCutoffSetting() {
|
||||||
jQuery.timeago.settings.cutoff = 0;
|
jQuery.timeago.settings.cutoff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupDisposal() {
|
||||||
|
jQuery.timeago.settings.refreshMillis = 50;
|
||||||
|
$('abbr.disposal').attr("title", iso8601(new Date())).timeago();
|
||||||
|
}
|
||||||
|
|
||||||
function loadPigLatin() {
|
function loadPigLatin() {
|
||||||
jQuery.timeago.settings.strings = {
|
jQuery.timeago.settings.strings = {
|
||||||
suffixAgo: "ago-hay",
|
suffixAgo: "ago-hay",
|
||||||
|
@ -84,6 +89,10 @@ function loadRussian() {
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetRefreshMillis() {
|
||||||
|
jQuery.timeago.settings.refreshMillis = 60000;
|
||||||
|
}
|
||||||
|
|
||||||
function loadMillis() {
|
function loadMillis() {
|
||||||
var millisSubstitution = function(number, millis) { return millis + " milliseconds"; };
|
var millisSubstitution = function(number, millis) { return millis + " milliseconds"; };
|
||||||
jQuery.timeago.settings.strings = {
|
jQuery.timeago.settings.strings = {
|
||||||
|
|
Loading…
Reference in a new issue