OK, 'works' in Chrome. But I'm not satisfied because two situations are not yet covered. If you post and just wait with the page sitting there for 10 minutes or whatever, the delete button is still there. Or if you refresh and 5 minutes haven't passed yet and just let it sit there, the delete button remains until time is up AND you refresh. It's only if you refresh the page and 5 minutes have passed that the delete button goes away.
Since the page initially reloads just after posting, these are really the same problem. So I've rewritten to take care of this. Changes/additions highlighted, also included the time allowed as a variable near the top in case you want to change it:
Code:
<script type="text/javascript">
/* Replace elapsed time with specific time (Sept 15, 2013) */
$(function(){
var howlongallowed = 5 * 60 * 1000; //5 minutes in milliseconds
function keepwatch($del, raw_time){
if(new Date().getTime() - raw_time > howlongallowed){
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time);}, 300);
}
}
var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var $del;
$(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
});
if($del){keepwatch($del, raw_date.getTime());}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}
})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})
</script>
Bookmarks