From 7666ed3010f5a205247a0b17c32593dcc7232e8a Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 28 Aug 2013 02:32:38 +0800 Subject: [PATCH] fixed two bugs in admin, meta.buildTitle errors out because no notification icon is present; pagination element missing & final less cleanup for today --- public/css/style.less | 8 ++++---- public/src/ajaxify.js | 9 +++++++-- public/src/utils.js | 26 ++++++++++++++------------ public/templates/admin/header.tpl | 6 +++--- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/public/css/style.less b/public/css/style.less index 4d0f58edc3..266bdb2dcd 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -94,10 +94,10 @@ footer.footer { i { -webkit-transition: color 100ms linear; - -moz-transition: color 100ms linear; - -ms-transition: color 100ms linear; - -o-transition: color 100ms linear; - transition: color 100ms linear; + -moz-transition: color 100ms linear; + -ms-transition: color 100ms linear; + -o-transition: color 100ms linear; + transition: color 100ms linear; &.icon-twitter-sign:hover { color: #4099FF; diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index bbd5617669..370894927b 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -25,12 +25,17 @@ var ajaxify = {}; if (event !== null && event.state && event.state.url !== undefined) ajaxify.go(event.state.url, null, null, true); }; + var pagination; + ajaxify.go = function(url, callback, template, quiet) { - // the following should be set like so: ajaxify.onchange(function(){}); where the code actually belongs + // start: the following should be set like so: ajaxify.onchange(function(){}); where the code actually belongs $(window).off('scroll'); app.enter_room('global'); - document.getElementById('pagination').style.display = 'none'; + + pagination = pagination || document.getElementById('pagination'); + if (pagination) pagination.style.display = 'none'; window.onscroll = null; + // end var url = url.replace(/\/$/, ""); diff --git a/public/src/utils.js b/public/src/utils.js index b3d3f756f4..106ade3662 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -1,5 +1,5 @@ (function (module) { - + var utils, fs; try { @@ -39,15 +39,15 @@ }); }); }, - + relativeTime: function(timestamp, min) { var now = +new Date(), difference = now - Math.floor(parseFloat(timestamp)); difference = Math.floor(difference / 1000); - + if (difference < 60) return difference + (min ? 's' : ' second') + (difference !== 1 && !min ? 's' : ''); - + difference = Math.floor(difference / 60); if (difference < 60) return difference + (min ? 'm' : ' minute') + (difference !== 1 && !min ? 's' : ''); @@ -63,7 +63,7 @@ difference = Math.floor(difference / 12); return difference + (min ? 'y' : ' year') + (difference !== 1 && !min ? 's' : ''); }, - + //http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/ slugify: function(str) { str = str.replace(/^\s+|\s+$/g, ''); // trim @@ -93,7 +93,7 @@ isUserNameValid: function(name) { return (name && name !== "" && (/^[a-zA-Z0-9 _-]{3,14}$/.test(name))); }, - + isPasswordValid: function(password) { return password && password.indexOf(' ') === -1 && password.length > 5; }, @@ -132,10 +132,12 @@ a.href = document.location; url = a.pathname.slice(1); } + var notificationIcon; socket.emit('api:meta.buildTitle', url, function(title, numNotifications) { document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title; - if (numNotifications > 0) document.querySelector('.notifications a i').className = 'icon-circle active'; + notificationIcon = notificationIcon || document.querySelector('.notifications a i'); + if (numNotifications > 0 && notificationIcon) notificationIcon.className = 'icon-circle active'; }); jQuery.getJSON(RELATIVE_PATH + '/api/unread/total', function(data) { @@ -169,16 +171,16 @@ if (!String.prototype.ltrim) { String.prototype.ltrim=function(){return this.replace(/^\s+/,'');}; } - + if (!String.prototype.rtrim) { - String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}; + String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}; } - + if (!String.prototype.fulltrim) { - String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');}; + String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');}; } - + if ('undefined' !== typeof window) { window.utils = module.exports; } diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl index a0908daf88..7bb37ade4a 100644 --- a/public/templates/admin/header.tpl +++ b/public/templates/admin/header.tpl @@ -28,7 +28,7 @@ - + @@ -64,7 +64,7 @@
- +
@@ -102,4 +102,4 @@
-
\ No newline at end of file +
\ No newline at end of file