Commit MetaInfo

修订版ec854b1457a18bb04deca57d6e4d97bf138d2d15 (tree)
时间2017-11-13 01:24:15
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2455 new plugin: Enable to work on cache

更改概述

差异

--- a/plugin/new.inc.php
+++ b/plugin/new.inc.php
@@ -15,18 +15,9 @@
1515
1616 define('PLUGIN_NEW_DATE_FORMAT', '<span class="comment_date">%s</span>');
1717
18-function plugin_new_init()
19-{
20- // Elapsed time => New! message with CSS
21- $messages['_plugin_new_elapses'] = array(
22- 60 * 60 * 24 * 1 => ' <span class="new1" title="%s">New!</span>', // 1day
23- 60 * 60 * 24 * 5 => ' <span class="new5" title="%s">New</span>'); // 5days
24- set_plugin_messages($messages);
25-}
26-
2718 function plugin_new_inline()
2819 {
29- global $vars, $_plugin_new_elapses;
20+ global $vars;
3021
3122 $retval = '';
3223 $args = func_get_args();
@@ -83,17 +74,10 @@ function plugin_new_inline()
8374 }
8475 }
8576 }
86-
87- // Add 'New!' string by the elapsed time
88- $erapse = UTIME - $timestamp;
89- foreach ($_plugin_new_elapses as $limit=>$tag) {
90- if ($erapse <= $limit) {
91- $retval .= sprintf($tag, get_passage($timestamp));
92- break;
93- }
94- }
95-
9677 if($date !== '') {
78+ // 1 day hot: <span class="new1">New!</span>
79+ // 5 days hot: <span class="new5">New</span>
80+ $retval .= '<span class="__plugin_new" data-mtime="' . get_date_atom($timestamp + LOCALZONE) . '"></span>';
9781 // Show a date string
9882 return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);
9983 } else {
--- a/skin/main.js
+++ b/skin/main.js
@@ -346,6 +346,29 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
346346 e.textContent = getSimplePassage(d, now);
347347 }
348348 });
349+ // new plugin
350+ var newItems = document.getElementsByClassName('__plugin_new');
351+ forEach(newItems, function(e) {
352+ var dt = e.getAttribute('data-mtime');
353+ if (dt) {
354+ var d = new Date(dt);
355+ var diff = now.getTime() - d.getTime();
356+ var daySpan = diff / 1000 / 60 / 60 / 24;
357+ if (daySpan < 1) {
358+ e.textContent = ' New!';
359+ e.title = getPassage(d, now);
360+ if (e.classList && e.classList.add) {
361+ e.classList.add('new1');
362+ }
363+ } else if (daySpan < 5) {
364+ e.textContent = ' New';
365+ e.title = getPassage(d, now);
366+ if (e.classList && e.classList.add) {
367+ e.classList.add('new5');
368+ }
369+ }
370+ }
371+ });
349372 }
350373 setYourName();
351374 autoTicketLink();
Show on old repository browser