Changeset 2164
- Timestamp:
- 04/06/10 17:08:54 (13 years ago)
- Location:
- plugins/commentNotifications
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/commentNotifications/_admin.js
r2151 r2164 11 11 # -- END LICENSE BLOCK ------------------------------------ 12 12 */ 13 $(document).ready(function(){14 var css ={15 background: 'transparent url(index.php?pf=commentNotifications/img/bubble.png) no-repeat top 20px',16 height: '24px',17 width: '24px',18 overflow: 'hidden',19 position: 'absolute',20 'text-align': 'center',21 'font-weight': 'bold',22 display: 'none',23 top: $('li a[href="comments.php"]').position().top - 20,24 left: $('li a[href="comments.php"]').position().left + $('li a[href="comments.php"]').width() - 2525 } ;26 $('li a[href="comments.php"]').parent().append('<li class="new" rel="comments"></li>');27 $('li[rel="comments"]').css(css);13 var notificator = { 14 css: { 15 'menu': { 16 'background': 'transparent url(index.php?pf=commentNotifications/img/bubble.png) no-repeat top 20px', 17 'height': '24px', 18 'width': '24px', 19 'overflow': 'hidden', 20 'position': 'absolute', 21 'text-align': 'center', 22 'font-weight': 'bold', 23 'display': 'none' 24 } 25 }, 26 cookie: 'dc_nb_comments', 27 msg: {}, 28 28 29 var name = 'dc_nb_comments='; 30 var ca = document.cookie.split(';'); 31 var nb = '9999999999'; 32 for(var i=0;i < ca.length;i++) { 33 var c = ca[i]; 34 while (c.charAt(0)==' ') c = c.substring(1,c.length); 35 if (c.indexOf(name) == 0) nb = c.substring(name.length,c.length); 36 } 37 if (nb < nb_comments) { 38 $('li[rel="comments"]').html(nb_comments-nb); 29 init: function () { 30 /* Set cookie */ 31 if ($.cookie(notificator.cookie) == null || notificator.reload_nb_comments == 'true') { 32 $.cookie(notificator.cookie,notificator.nb_comments); 33 } 34 /* Set menu */ 35 var p = { 36 'top': $('li a[href="comments.php"]').position().top - 20, 37 'left': $('li a[href="comments.php"]').position().left + $('li a[href="comments.php"]').width() - 25 38 }; 39 notificator.css.menu = $.extend(notificator.css.menu,p); 40 $('li a[href="comments.php"]').parent().append('<li class="new" rel="comments"></li>'); 41 $('li[rel="comments"]').css(notificator.css.menu); 42 43 notificator.getNbComments(); 44 }, 45 46 getNbComments: function () { 47 $.get('services.php',{f:'getNbComments'},function(data) { 48 var rsp = $(data).children('rsp')[0]; 49 50 if (rsp.attributes[0].value == 'ok') { 51 var delta = $(rsp).find('comments').text() - $.cookie(notificator.cookie); 52 53 if (delta > 0) { 54 notificator.applyChanges(delta); 55 } 56 }; 57 setTimeout('notificator.getNbComments()',10000); 58 }); 59 }, 60 61 applyChanges: function (num) { 62 /* Changes for the dasboard */ 63 var legend = $('span a[href="comments.php"]'); 64 var img = $('a[href="comments.php"] img'); 65 var html = ""; 66 html += (notificator.nb_comments + num) + " "; 67 html += notificator.nb_comments > 1 ? notificator.msg.comments : notificator.msg.comment; 68 html += " (" + num + " "; 69 html += (num > 1 ? notificator.msg.recents : notificator.msg.recent) + ")"; 70 legend.html(html); 71 img.attr("src","index.php?pf=commentNotifications/img/comments-b.png"); 72 73 /* Changes for the menu */ 74 $('li[rel="comments"]').html(num); 39 75 $('li[rel="comments"]').fadeIn("slow"); 40 76 } 41 42 getNbComments(); 77 }; 78 79 80 $(document).ready(function() { 81 notificator.init(); 43 82 }); 44 45 function getNbComments()46 {47 $.get('services.php',{f:'getNbComments'},function(data) {48 var rsp = $(data).children('rsp')[0];49 50 if (rsp.attributes[0].value == 'ok') {51 var nb = $(rsp).find('comments').text();52 if (nb > nb_comments) {53 $('li[rel="comments"]').html(nb-nb_comments);54 $('li[rel="comments"]').fadeIn("slow");55 }56 };57 setTimeout('getNbComments()',10000);58 });59 } -
plugins/commentNotifications/_define.php
r2151 r2164 15 15 $this->registerModule( 16 16 'commentNotifications', 17 'Displays small bubble notification for new comments on a right of comments link in administration interface',17 'Displays notifications on menu and dashboard when new comments arrive', 18 18 'Tomtom (http://blog.zenstyle.fr/)', 19 '0. 2',19 '0.3', 20 20 'usage' 21 21 ); -
plugins/commentNotifications/_prepend.php
r2151 r2164 13 13 if (!defined('DC_RC_PATH')) { return; } 14 14 15 # Init cookie16 if (defined('DC_CONTEXT_ADMIN')) {17 $params = array();18 $cookie_name = 'dc_nb_comments';19 $nb_comments = $core->blog->getComments($params,true)->f(0);20 21 if (!isset($_COOKIE[$cookie_name])) {22 setcookie($cookie_name,$core->blog->getComments($params,true)->f(0));23 }24 }25 26 15 $__autoload['commentNotificationsRestMethods'] = dirname(__FILE__).'/_services.php'; 27 16 28 17 $core->addBehavior('adminPageHTMLHead',array('commentNotificationsBehaviors','adminPageHTMLHead')); 29 $core->addBehavior('adminCommentsHeaders',array('commentNotificationsBehaviors','adminCommentsHeaders'));30 18 31 19 $core->rest->addFunction('getNbComments',array('commentNotificationsRestMethods','getNbComments')); … … 38 26 39 27 $params = array(); 40 $cookie_name = 'dc_nb_comments';41 28 $nb_comments = $core->blog->getComments($params,true)->f(0); 42 43 if (!isset($_COOKIE[$cookie_name])) { 44 setcookie($cookie_name,$core->blog->getComments($params,true)->f(0)); 45 } 29 $reload_nb_comments = preg_match('/comments.php(.*)?/',$_SERVER['REQUEST_URI']); 46 30 47 31 echo 48 '<script type="text/javascript">'. 49 'var nb_comments = '.$nb_comments.';'. 50 '</script>'. 51 '<script type="text/javascript" src="index.php?pf='. 52 basename(dirname(__FILE__)).'/_admin.js"></script>'; 53 } 54 55 public static function adminCommentsHeaders() 56 { 57 global $core; 58 59 $params = array(); 60 $cookie_name = 'dc_nb_comments'; 61 62 if (isset($_COOKIE[$cookie_name])) { 63 setcookie($cookie_name,$core->blog->getComments($params,true)->f(0)); 64 } 32 dcPage::jsLoad('index.php?pf='.basename(dirname(__FILE__)).'/_admin.js'). 33 '<script type="text/javascript">'."\n". 34 "//<![CDATA[\n". 35 dcPage::jsVar('notificator.nb_comments',$nb_comments). 36 dcPage::jsVar('notificator.reload_nb_comments',($reload_nb_comments ? 'true' : 'false')). 37 dcPage::jsVar('notificator.msg.comment',__('comment')). 38 dcPage::jsVar('notificator.msg.comments',__('comments')). 39 dcPage::jsVar('notificator.msg.recent',__('new')). 40 dcPage::jsVar('notificator.msg.recents',__('news')). 41 "\n//]]>\n". 42 "</script>\n"; 65 43 } 66 44 }
Note: See TracChangeset
for help on using the changeset viewer.